Datasheet
unsigned short kp, cnt, oldstate = 0;
char txt[6];
// Keypad module connections
sfr char keypadPort at PORTB;
sfr char keypadPort_Direction at DDRB;
// End Keypad module connections
// LCD module connections
sbit LCD_RS at PORTD.B2;
sbit LCD_EN at PORTD.B3;
sbit LCD_D4 at PORTD.B4;
sbit LCD_D5 at PORTD.B5;
sbit LCD_D6 at PORTD.B6;
sbit LCD_D7 at PORTD.B7;
sbit LCD_RS_Direction at DDRD.B2;
sbit LCD_EN_Direction at DDRD.B3;
sbit LCD_D4_Direction at DDRD.B4;
sbit LCD_D5_Direction at DDRD.B5;
sbit LCD_D6_Direction at DDRD.B6;
sbit LCD_D7_Direction at DDRD.B7;
// End LCD module connections
void main() {
cnt = 0; // Reset counter
Keypad_Init(); // Initialize Keypad
Lcd_Init(); // Initialize LCD
Lcd_Cmd(LCD_CLEAR); // Clear display
Lcd_Cmd(LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1, 1, "1");
Lcd_Out(1, 1, "Key :"); // Write message text on LCD
Lcd_Out(2, 1, "Times:");
do {
kp = 0; // Reset key code variable
// Wait for key to be pressed and released
do
//kp = Keypad_Key_Press(); // Store key code in kp variable
kp = Keypad_Key_Click(); // Store key code in kp variable
while (!kp);
// Prepare value for output, transform key to it's ASCII value
switch (kp) {
switch (kp) {
//case 10: kp = 42; break; // '*' // Uncomment this block
for keypad4x3
//case 11: kp = 48; break; // '0'
//case 12: kp = 35; break; // '#'
//default: kp += 48;
302
MIKROELEKTRONIKA - SOFTWARE AND HARDWARE SOLUTIONS FOR EMBEDDED WORLD
Libraries
mikroC PRO for AVR
CHAPTER 6