void main()
{
unsigned int equ[4];
unsigned char keypad[]={0,7,8,9,0,
4,5,6,0,
1,2,3,0,
0,0,0,0};
unsigned char kp,i;
unsigned char r[4];
TRISC=0;
TRISD=0xFF;
Lcd_Init(&PORTC);
Keypad_Init(&PORTD);
Lcd_Cmd(LCD_CURSOR_OFF);
RETURN:while(Keypad_Read());
Lcd_Cmd(LCD_CLEAR);
Lcd_Chr(1,1,'0');
for(i=0;i<2;i++)
{
while(!Keypad_Read());
if(Keypad_Read()==16)
{
equ[1]=10;
goto STEP2;
}
if(Keypad_Read()==8)
{
equ[1]=11;
goto STEP2;
}
kp=Keypad_Read();
Lcd_Chr(1,i+1,keypad[kp]+48);
equ[0]=equ[0]*10*i+keypad[kp];
while(Keypad_Read());
}
while(Keypad_Read()!=8&&Keypad_Read()!=16);
if(Keypad_Read()==16)equ[1]=10;
if(Keypad_Read()==8)equ[1]=11;
STEP2:while(Keypad_Read());
Lcd_Cmd(LCD_CLEAR);
Lcd_Chr(1,1,'0');
for(i=0;i<2;i++)
{
while(!Keypad_Read());
if(Keypad_Read()==15)goto STEP3;
kp=Keypad_Read();
Lcd_Chr(1,i+1,keypad[kp]+48);
equ[2]=equ[2]*10*i+keypad[kp];
while(Keypad_Read());
}
while(Keypad_Read()!=15);
STEP3:if(equ[1]==10)equ[3]=equ[0]+equ[2];
if(equ[1]==11)equ[3]=equ[0]*equ[2];
r[3]=equ[3]/1000;
r[2]=(equ[3]%1000)/100;
r[1]=(equ[3]%100)/10;
r[0]=equ[3]%10;
Lcd_Cmd(LCD_CLEAR);
Lcd_Chr(1,1,'=');
for(i=0;i<4;i++)
{
Lcd_Chr(1,i+2,r[3-i]+48);
}
while(Keypad_Read()!=13);
goto RETURN;
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น