LCD interfacing using AVR(ATMEGA 32)
SIMULATOR: PROTEUS
8.0
SOFTWARE: KEIL
4.0
CIRCUIT DIAGRAM:
PIN DESCRIPTION OF LCD:
PROGRAM:
#include<avr/io.h> // header file for AVR
#include<util/delay.h>
// header file for delay function
void lcd_init(void);
void
lcd_command(char c);
void lcd_data(char
d);
void str(char
a[]);
int main(void) // main program
{
DDRB=0XFF; // Select PORT B as an output port
DDRD=0XFF; // Select
PORT D as an output port
lcd_init(); // initialize the lcd
while(1) // continuous loop
{
str("WELCOME TO THE");
lcd_command(0xc0); // move cursor to the next
line
str("EMBEDDED
SYSTEM");
lcd_command(0x01); // clear display
}
}
void lcd_init(void) // lcd initialization function
{
lcd_command(0x38);
//8bit,2 line,5*7 matrix
lcd_command(0x0c);
//cursor off,display on
lcd_command(0x80);//force
cursor to the beginning of the first line
lcd_command(0x01);//
clear display
lcd_command(0x06);
// entry mode
}
void lcd_command(char c) // lcd command function
{
PORTB=c; // send data to PORT B
PORTD = 0xf2; //
RS=0,EN=1
_delay_us(10); // high to low
pulse on enable pin
PORTD = 0xf0; //EN
=0
_delay_ms(500);
}
void lcd_data(char
d) //lcd data function
{
PORTB=d; // send data to PORT B
PORTD = 0xf3; // RS
=1,EN =1
_delay_us(10); //
high to low pulse on enable pin
PORTD = 0xf1;//EN
= 0
_delay_ms(500);
}
void str(char a[])
// function to display string
{
int j;
for(j=0;a[j]!='\0';j++)
{
lcd_data(a[j]);
}
}
PROGRAM DESCRIPTION:
Lcd data pins are connected to PORT B and RS and EN pins of lcd are connected to
PORT D.0 AND PORT D.1 respectively. Hence I have set the direction of PORT B
and PORT D register as an output.
In the main program, I have set the direction of the PORT B register and PORT D register as an output. After that, I have initialized the lcd by providing the required lcd commands. After that, I have sent the data (which will get displayed on an lcd) in the string format.
In the lcd command function, RS is provided with logic 0 to select the command register. To pass the command to the lcd controller, enable pin is provided with a high to low pulse. In the string function, I have provided one by one character of a string to the lcd data function.
In the lcd data function, all the operations remain the same as getting performed in the lcd command function. Only RS is provided with '1' to select the data register.
VIDEO:
NOTE:
Comments
Post a Comment