AVR Development Board – AVR-DK20A User Manual
44
A.13 Tutorial 5 – Keypad scanning to LCD Display
//Tutorial 5
//Title : Keypad scanning and LCD Display
//Jumper for LCD : LK2-LK8
//Jumper Setting: A1-E,A2-RS,A3-RW,A4-LD4,A5-LD5,A6-LD6,A7-LD7
//Jumper for Keypad : LK17-LK19, LK21-LK24
//Jumper Setting: C0-CL1,C1-CL2,C2-CL3,C4-RW1,C5-RW2,C6-RW3,C7-RW4
// LCD module connections
sbit LCD_RS at PORTA2_bit;
sbit LCD_EN at PORTA1_bit;
sbit LCD_D4 at PORTA4_bit;
sbit LCD_D5 at PORTA5_bit;
sbit LCD_D6 at PORTA6_bit;
sbit LCD_D7 at PORTA7_bit;
sbit LCD_RS_Direction at DDA2_bit;
sbit LCD_EN_Direction at DDA1_bit;
sbit LCD_D4_Direction at DDA4_bit;
sbit LCD_D5_Direction at DDA5_bit;
sbit LCD_D6_Direction at DDA6_bit;
sbit LCD_D7_Direction at DDA7_bit;
// End LCD module connections
int i;
void keypad(unsigned);
void main(){
DDRA = 0xff;
PORTA3_bit = 0;
DDRC = 0X0F; //PORTC0-C2 FOR COLUMN AS OUTPUT ;
//PORTC4-C7 FOR ROW AS INPUT
PORTC = 0X00;
do{
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
keypad(1);
} while(1);
}
void keypad(unsigned){
do{
i=1;
PORTC = 0x01; //1st column
if (PINC4_bit = 1) {
lcd_out(1,i,"0");
delay_ms(100);
}
if (PINC5_bit = 1){
lcd_out(1,i,"3");
delay_ms(100);
}
if (PINC6_bit = 1){
lcd_out(1,i,"6");