alaalwi11
Member level 1
- Joined
- Nov 30, 2010
- Messages
- 32
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 1,288
- Location
- Al khurtum-Sudan
- Activity points
- 1,626
hi friends,i need some assistant to catch the error in my
i have caculator using keybad+lcd in mikro c with pic16f452
/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
in the project a 4 x 4 keypad is connected to PORTB of a PIC18F452
microcontroller. Also an LCD is connected to PORTC. The project is a
simple calculator which can perform integer arithmetic.
The keys are organized as follows:
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15
The keys are labeled as follows:
1 2 3 4
5 6 7 8
9 0 Enter
+ − *
this is the Img of errors
i have caculator using keybad+lcd in mikro c with pic16f452
/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗
in the project a 4 x 4 keypad is connected to PORTB of a PIC18F452
microcontroller. Also an LCD is connected to PORTC. The project is a
simple calculator which can perform integer arithmetic.
The keys are organized as follows:
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15
The keys are labeled as follows:
1 2 3 4
5 6 7 8
9 0 Enter
+ − *
HTML:
#define MASK 0xF0
#define Enter 11
#define Plus 12
#define Minus 13
#define Multiply 14
#define Divide 15
//
// This function gets a key from the keypad
//
unsigned char getkeypad()
{
unsigned char i, Key = 0;
PORTB = 0x01; // Start with column 1
while((PORTB & MASK) == 0) // While no key pressed
{
PORTB = (PORTB << 1); // next column
Key++; // column number
if(Key == 4)
{
PORTB = 0x01; // Back to column 1
Key = 0;
}
}
Delay_Ms(20); // Switch debounce
for(i = 0x10; i !=0; i <<=1) // Find the key pressed
{
if((PORTB & i) != 0)break;
Key = Key + 4;
}
PORTB=0x0F;
while((PORTB & MASK) != 0); // Wait until key released
Delay_Ms(20); // Switch debounce
return (Key); // Return key number
}
//
// Start of MAIN program
//
void main()
{
unsigned char MyKey, i,j,lcd[5],op[12];
unsigned long Calc, Op1, Op2;
TRISC = 0; // PORTC are outputs (LCD)
TRISB = 0xF0; // RB4-RB7 are inputs
//
// Configure LCD
//
Lcd_Init(&PORTC); // LCD is connected to PORTC
Lcd_Cmd(LCD_CLEAR);
Lcd_Out(1,1,"CALCULATOR"); // Display CALCULATOR
Delay_ms(2000); // Wait 2 seconds
Lcd_Cmd(LCD_CLEAR); // Clear display
//
// Program loop
//
for(;;) // Endless loop
{
MyKey = 0;
Op1 = 0;
Op2 = 0;
Lcd_Out(1,1,"No1: "); // Display No1:
while(1) // Get first no
{
MyKey = getkeypad();
if(MyKey == Enter)break; // If ENTER pressed
MyKey++;
if(MyKey == 10)MyKey = 0; // If 0 key pressed
Lcd_Chr_Cp(MyKey + '0');
Op1 = 10*Op1 + MyKey; // First number in Op1
}
Lcd_Out(2,1,"No2: "); // Display No2:
while(1) // Get second no
{
MyKey = getkeypad();
if(MyKey == Enter)break; // If ENTER pressed
MyKey++;
if(MyKey == 10)MyKey = 0; // If 0 key pressed
Lcd_Chr_Cp(MyKey + '0');
Op2 = 10*Op2 + MyKey; // Second number in Op2
}
Lcd_Cmd(LCD_CLEAR); // Clear LCD
Lcd_Out(1,1,"Op: "); // Display Op:
MyKey = getkeypad(); // Get operation
Lcd_Cmd(LCD_CLEAR);
Lcd_Out(1,1,"Res="); // Display Res=
switch(MyKey) // Perform the operation
{
case Plus:
Calc = Op1 + Op2; // If ADD
break;
case Minus:
Calc = Op1 - Op2; // If Subtract
break;
case Multiply:
Calc = Op1 * Op2; // If Multiply
break;
case Divide:
Calc = Op1 / Op2; // If Divide
break;
}
LongToStr(Calc, op); // Convert to string in op
//
// Remove leading blanks
//
j=0;
for(i=0;i<=11;i++)
{
if(op[i] != ' ') // If a blank
{
lcd[j]=op[i];
j++;
}
}
Lcd_Out_Cp(lcd); // Display result
Delay_ms(5000); // Wait 5 seconds
Lcd_Cmd(LCD_CLEAR);
}
}