{
unsigned char num[4];
unsigned char input[4];
unsigned char a,b;
unsigned char keypad[]={0,1,2,3,0,
4,5,6,0,
7,8,9,0,
0,0,0,0};
unsigned int kp,i,j;
TRISC=0;
TRISD=0xFF;
Lcd_Init(&PORTC);
Keypad_Init(&PORTD);
Lcd_Cmd(LCD_CURSOR_OFF);
Lcd_Cmd(LCD_CLEAR);
Lcd_Out(1,1,"Enter 4 numbers");
for(i=0;i<4;i++)
{
while(!Keypad_Read());
kp=Keypad_Read();
num[i]=keypad[kp];
Lcd_Chr(2,i+1,keypad[kp]+48);
while(Keypad_Read());
}
while(Keypad_Read()!=15);
Return:Lcd_Cmd(LCD_CLEAR);
Lcd_Out(1,1,"What are 4 numbers?");
while(Keypad_Read());
for(i=0;i<4;i++)
{
while(!Keypad_Read());
kp=Keypad_Read();
input[i]=keypad[kp];
Lcd_Chr(2,i+1,keypad[kp]+48);
while(Keypad_Read());
}
while(Keypad_Read()!=15);
Lcd_Cmd(LCD_CLEAR);
while(Keypad_Read());
for(i=0;i<4;i++)
{
if(input[i]==num[i])
{
a++;
continue;
}
for(j=0;j<4;j++)
{
if(input[i]==num[j])b++;
}
}
Lcd_Chr(1,1,a+48);
Lcd_Chr(1,2,'A');
Lcd_Chr(1,3,b+48);
Lcd_Chr(1,4,'B');
if(a==4)Lcd_Out(2,1,"Correct");
else
{
Lcd_Out(2,1,"Wrong!");
a=0;b=0;
while(Keypad_Read()!=15);
goto Return;
}
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น