Nothing Special   »   [go: up one dir, main page]

view more projects

Tuesday, 9 May 2017

#16x2 LCD DISPLAY interfacing with ATMEGA 16

16x2 LCD DISPLAY




Now you can see in the above figure showing the 16 PIN, 16 characters, 2 line display. 
LCD interfacing with atmega16: In both left and write most pis are Negative and both second last pins are Positive, But the PIN number 1 , 2 & 3 are mandatory to give supply otherwise you can not see the display. 

you may leave pin number 15 & 16  pin without connection because it is connected with LED inside this. As you know we doesn't connect LED without any resistance so it has resistance inside this. If we leave this pins it will not glow light. But it can show the display. 



In this figure you can see the DATA pins and control pins,

In case you want to give command for display the cursor you will have to give 

                   RS = 0;
                   R/W = 0;
                   EN = 1;
                  delay(5 mili second)
                   EN = 0;
As you can see we are enabling EN and pulling it down back , it is to latch the data (command) in the LCD, in case we does not pull it down it will miss match the data and command, it will unable to decide which one is command and witch is data, will give some garbage display.

In case you want to display data or string you have to give
                   

                   RS = 1;
                   R/W = 0;
                   EN = 1;
                  delay(5 mili second)
                   EN = 0;
this will decide what we are sending above it , is data.


**********************************************************
HERE I AM GOING TO SHOW YOU A HEADER FILE OF LCD 4-BIT MODE
BASED ON ATMEGA 16  :---


void lcd_init();
void lcd_cmd(unsigned char cmd);
void lcd_data(unsigned char data);
void lcd_str(char *str);

void lcd_init()
{
DDRB = 0xff;
lcd_cmd(0x02);
lcd_cmd(0x28);
lcd_cmd(0x0f);
}
void lcd_cmd(unsigned char cmd)
{
PORTB = cmd&(0xf0);
PORTB |= (1<<2);
PORTB &=~((1<<0)|(1<<1));
_delay_ms(5);
PORTB &=~(1<<2);

PORTB = (cmd<<4)&(0xf0);
PORTB |= (1<<2);
PORTB &=~((1<<0)|(1<<1));
_delay_ms(5);
PORTB &=~(1<<2);

}

void lcd_data(unsigned char data)
{
PORTB = data&(0xf0);
PORTB |= ((1<<0)|(1<<2));
PORTB &=~(1<<1);
_delay_ms(5);
PORTB &=~(1<<2);

PORTB = (data<<4)&(0xf0);
PORTB |= ((1<<0)|(1<<2));
PORTB &=~(1<<1);
_delay_ms(5);
PORTB &=~(1<<2);
}

void lcd_str(char *str)
{
while(*str!='\0')
{
lcd_data(*str);
str++;
}
}



No comments:

Post a Comment