mikroC

making it simple...

Library Example

mikroC - C Compiler for Microchip PIC microcontrollers

The following code can be used for testing the keypad. It supports keypads with 1 to 4 rows and 1 to 4 columns. The code returned by the keypad functions (1..16) is transformed into ASCII codes [0..9,A..F]. In addition, a small single-byte counter displays the total number of keys pressed in the second LCD row.

unsigned short kp, cnt;

char txt[5];

void main() { cnt = 0; Keypad_Init(&PORTC); Lcd_Init(&PORTB); Lcd_Cmd(LCD_CLEAR);

Lcd_Cmd(LCD_CURSOR_OFF);

Lcd_Out(1, 1, "Key :"); Lcd_Out(2, 1, "Times:");

do {

kp = 0;

//Initialize LCD on PORTC

//Clear display

//Cursor off

//--- 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); }//~!

MikroElektronika: Development tools - Books - Compilers

page

195