Вы находитесь на странице: 1из 5

#include<avr/io.

h>
/*Includes io.h header file where all the Input/Output Registers and its Bits ar
e defined for all AVR microcontrollers*/
#define
F_CPU
1000000
/*Defines a macro for the delay.h header file. F_CPU is the microcontroller freq
uency value for the delay.h header file. Default value of F_CPU in delay.h heade
r file is 1000000(1MHz)*/
#include<util/delay.h>
/*Includes delay.h header file which defines two functions, _delay_ms (milliseco
nd delay) and _delay_us (microsecond delay)*/
#define
KEYPAD_PORT
PORTC
/*Defines a macro for the keypad.h header file. KEYPAD_PORT is the microcontroll
er PORT Register to which 4X4 keypad is connected. Default PORT Register in keyp
ad.h header file is PORTB*/
#define
KEYPAD_PIN
PINC
/*Defines a macro for the keypad.h header file. KEYPAD_PIN is the microcontrolle
r PIN Register to which 4X4 keypad is connected. Default PIN Register in keypad.
h header file is PINB*/
#include<avr/keypad.h>
/*Includes keypad.h header file which defines one function: read_keypad () to re
ad the 4X4 keypad. Keypad header file version is 1.1*/
#define
LCD_DATA_PORT
PORTB
/*Defines a macro for the lcd.h header File. LCD_DATA_PORT is the microcontrolle
r PORT Register to which the data pins of the LCD are connected*/
#define
LCD_CONT_PORT
PORTD
/*Defines a macro for the lcd.h header File. LCD_CONT_PORT is the microcontrolle
r PORT Register to which the control pins of the LCD are connected*/
#define
LCD_RS
PD0
/*Defines a macro for the lcd.h header file. LCD_RS is the microcontroller Port
pin to which the RS pin of the LCD is connected*/
#define
LCD_RW
PD1
/*Defines a macro for the lcd.h header file. LCD_RW is the microcontroller Port
pin to which the RW pin of the LCD is connected*/
#define
LCD_EN
PD2
/*Defines a macro for the lcd.h header file. LCD_EN is the microcontroller Port
pin to which the EN pin of the LCD is connected*/
#include<avr/lcd.h>
/*Includes lcd.h header file which defines different functions for all Alphanume
ric LCD(8-Bit Interfacing Method). LCD header file version is 1.1*/
void main(void)
{
DDRB=0xff;
/*All 8 pins of PortB are declared output (data pins of LCD are connected)*/
DDRD=0x07;
/*PD0, PD1 and PD2 pins of PortD are declared output (control pins of LCD are co
nnected)*/

DDRC=0x0f;
/*PortC s upper 4 bits are declared input and lower 4 bits are declared output(44 K
eypad is connected)*/
PORTC=0xff;
/*PortC s lower 4 bits are given high value and pull-up are enabled for upper 4 bi
ts*/
unsigned char keypad_value;
/*Variable declarations*/
lcd_init();
/*LCD initialization*/
lcd_string_write( ABLab Solutions );
/*String display in 1st row of LCD*/
lcd_command_write(0xc0);
/*Cursor moves to 2nd row 1st column of LCD*/
lcd_string_write( www.ablab.in );
/*String display in 2nd row of LCD*/
_delay_ms(500);
_delay_ms(500);
_delay_ms(500);
_delay_ms(500);
/*Display stays for 2 second*/
lcd_command_write(0x01);
/*Clear Screen*/
/*Start of infinite loop*/
while(1)
{
lcd_command_write(0x80);
/*Cursor moves to 1st row 1st column of LCD*/
lcd_string_write( Press any Key );
/*String display in 1st row of LCD*/
lcd_command_write(0xc0);
/*Cursor moves to 2nd row 1st column of LCD*/
lcd_string_write( Key_Value: );
/*String display in 2nd row of LCD*/
keypad_value=read_keypad();
/*Scan s 4X4 keypad and returns pressed key value or default value*/
/*Checking if any key is pressed or not*/
if(keypad_value!=0xff)
{
switch(keypad_value)
{
case 0:

lcd_data_write( 0 );
/*Displays 0 in 2nd row of LCD*/
break;
/*Break statement*/
case 1:
lcd_data_write( 1 );
/*Displays 1 in 2nd row of LCD*/
break;
/*Break statement*/
case 2:
lcd_data_write( 2 );
/*Displays 2 in 2nd row of LCD*/
break;
/*Break statement*/
case 3:
lcd_data_write( 3 );
/*Displays 3 in 2nd row of LCD*/
break;
/*Break statement*/
case 4:
lcd_data_write( 4 );
/*Displays 4 in 2nd row of LCD*/
break;
/*Break statement*/
case 5:
lcd_data_write( 5 );
/*Displays 5 in 2nd row of LCD*/
break;
/*Break statement*/
case 6:
lcd_data_write( 6 );
/*Displays 6 in 2nd row of LCD*/
break;
/*Break statement*/
case 7:
lcd_data_write( 7 );
/*Displays 7 in 2nd row of LCD*/

break;
/*Break statement*/
case 8:
lcd_data_write( 8 );
/*Displays 8 in 2nd row of LCD*/
break;
/*Break statement*/
case 9:
lcd_data_write( 9 );
/*Displays 9 in 2nd row of LCD*/
break;
/*Break statement*/
case 10:
lcd_data_write( * );
/*Displays * in 2nd row of LCD*/
break;
/*Break statement*/
case 11:
lcd_data_write( # );
/*Displays # in 2nd row of LCD*/
break;
/*Break statement*/
case 12:
lcd_data_write( A );
/*Displays A in 2nd row of LCD*/
break;
/*Break statement*/
case 13:
lcd_data_write( B );
/*Displays B in 2nd row of LCD*/
break;
/*Break statement*/
case 14:
lcd_data_write( C );
/*Displays C in 2nd row of LCD*/
break;
/*Break statement*/;
case 15:

lcd_data_write( D );
/*Displays D in 2nd row of LCD*/
break;
/*Break statement*/;
}
}
else
{
;
/*Null statement*/
}
_delay_ms(200);
/*200ms delay as guard time between two consecutive pressing of key*/
}
}

Вам также может понравиться