I used the sample code to test the whether the keypad is working or not.
Code: Select all
unsigned short kp, cnt;
char txt[5];
void main() {
cnt = 0;
Keypad_Init(&PORTB);
Lcd_Init(&PORTC); // Initialize LCD on PORTC
Lcd_Custom_Config(&PORTC,7,6,5,4,&PORTC,2,0,3); // Initialize LCD on PORTB
Lcd_Cmd(LCD_CLEAR); // Clear display
Lcd_Cmd(LCD_CURSOR_OFF); // Cursor off
ADCON1 = 0x0F;
Lcd_Out(1, 1, "Key :");
Lcd_Out(2, 1, "Times:");
do {
kp = 0;
//--- Wait for key to be pressed
do
//--- un-comment one of the keypad reading functions
kp = Keypad_Released();
//kp = Keypad_Read();
while (!kp);
cnt++;
//--- prepare value for output
if (kp > 10)
kp += 54;
else
kp += 47;
//--- print it on LCD
Lcd_Chr(1, 10, kp);
WordToStr(cnt, txt);
Lcd_Out(2, 10, txt);
} while (1);
}//~!
It works in the simulation shows above but doesn't work in the real circuit.The Key and Times are complete random, when i keypressed the counting times can went up to several hundred and key was random... What should i do with it.