Toll-Free Customer Support 24/7

Keypad Interfacing with Atmega Code

#include<avr/io.h>
#include <avr/keypad.h> // to initialize the keypad

#define F_CPU 1000000UL
#include <util/delay.h> //header to use delay function

#define KEYPAD_PORT PORTC // connecting keypad to port c
#define KEYPAD_PIN PINC //initializing pins for keypad

#define LCD_DATA_PORT PORTB
#define LCD_CONT_PORT PORTD
#define LCD_RS PD0
#define LCD_RW PD1
#define LCD_EN PD2
#include <lcd.h> //header to initialize LCD commands

void main(void)
{
DDRB=0xFF; //make PORTB as output
DDRD=0X07; //make PORTD pin 0, 1, 2 as output
DDRB=0X0F;
PORTC=0xFF; //make PORTC as output
unsigned char keypad_valve;
lcd_init();

while(1)
{
lcd_command_write(0x08); //display off cursor off
lcd_string_write("PRESS ANY KEY");
lcd_command_write(0xc0);//2nd line display
keypad_valve=read_keypad();

if(keypad_valve!=0xFF)
{
lcd_number_write(keypad_valve,10);//if key is pressed corresponding valve will be displayed
lcd_data_write(' ');
}
else
;

_delay_ms(300);
}
}

Back to top