LCD interfacing with AVR

this article illustrate  the text display on 16*2 using atmega32. but before proceeding further we need to make tight hand on LCDDisplaying string is used in many real life applications. it is an important output device for all automated and semi-automated devices.

PROTEUS DESIGN

8 bit data line of parallel communication is used to transfer data on LCD which  is to be displayed on screen. rs,rw,en of LCD is being connected to portA. The connection of the LCD with the AVR micro-controller is shown in diagram above.

CODE

steps for printing any string on LCD

1>>LCD initializing

in this step we have to select mode of operation(4bit or 8bit),fix cursor position and set other properties of LCD. 

void lcdint()

lcdcmd(0x38);
_delay_ms(1);
lcdcmd(0x01);
_delay_ms(1);
lcdcmd(0x0E);
_delay_ms(1);
}

2>>send commands to LCD

to make it sure that the data so transfer to it is either command or not.if it's command we have to select rs=0,the instruction command code register is selected.

void lcdcmd(unsigned char x)
{
lcdport=x;
signal=(0<<rs)|(0<<rw)|(1<<en);
_delay_ms(1);
signal=(0<<rs)|(0<<rw)|(0<<en);
_delay_ms(50);
 }

3>> send a character

 for the character you want to print on LCD you have to make rs=1,the instruction data code register is selected allowing user to send data to be displayed on LCD.

void lcddata(unsigned char data)
{
lcdport= data;
signal= (1<<rs)|(0<<rw)|(1<<en);
_delay_ms(1);
signal= (1<<rs)|(0<<rw)|(0<<en);
_delay_ms(50);
}

complete code

#include<avr/io.h>
#include<util/delay.h>
#define lcdport PORTA        
#define signal PORTB
#define en PB2        
#define rw PB1        
#define rs PB0        
void lcdcmd(unsigned char cmd);
void lcdint();
void lcddata(unsigned char data);
void lcd_print(char * str);
 
void main()
{
    while(1)
    {
    DDRA=0xff;    
    DDRB=0x07;        
    lcdint();    
    lcdcmd(0x84);
    _delay_ms(50);
    lcd_print("WELCOME!!!");    
    lcdcmd(0xc2);
    lcd_print("projectsguru");        
        _delay_ms(1000);
}

void lcdint()
{
    lcdcmd(0x38);        
    _delay_ms(1);
    lcdcmd(0x01);        
    _delay_ms(1);
    lcdcmd(0x0E);        
    _delay_ms(1);
}
 void lcdcmd(unsigned char x)
{
    lcdport=x;
    signal=(0<<rs)|(0<<rw)|(1<<en);    
    _delay_ms(1);
    signal=(0<<rs)|(0<<rw)|(0<<en);    
    _delay_ms(50);
}
void lcddata(unsigned char data)
{
    lcdport= data;
    signal= (1<<rs)|(0<<rw)|(1<<en);    
    _delay_ms(1);
    signal= (1<<rs)|(0<<rw)|(0<<en);    
    _delay_ms(50);                
}

void lcd_print(char * str)
{
  unsigned char i = 0;
  while(str[i]!=0)

  lcddata(str[i]);
  i++;
}
}

VIDEO

 

Category: 

tags: 

Share

Who's new

  • ravirajpatil871...
  • shubhambajoria
  • yassir
  • demiholyman890954
  • scottgillum51169040

Get Notified

 

Share

We are Social

Syndicate

Subscribe to Syndicate