Hi friends,Welcome to my website!
I'm a student of electronics and communication systems. My real interest focus around Electronics and Computer programming. I enjoy micro-controller and computer programming.I'm familiar with micro-controllers, like 8051, AVR..I'm also interested in websites design especially blog template design..
Today we are going to discuss about the LCD interface with the atmega8 micro-controller.
Pin Configuration of ATMEGA8 |
16*2 LCD display |
Schematic diagram of LCD interface with ATMEGA8(click on image-full size view ) |
Configurations
Here,PORTB(PB0-PB7) set as data port in 8 bit mode LCD display.Connect D0-D7 with the PORTB.
- Ground the first lead of the lcd(vss) display.
- Connect vcc to a 5v power supply.
- Conncet VEE with a pot.It's used to adjust the contrast of the LCD display
C CODE
#define F_CPU 1000000void delay(unsigned char);
#include <avr/io.h>
//Main Code
int main()
{
DDRB=0xff; //set PORTB as out put
DDRD=0b01110000; //Set PD.4,5 and 6 as Output
/*R/W=PD6
RS=PD5
E=PD4 */
//Give Inital Delay for LCD to startup as LCD is a slower Device
delay(2);
init_lcd();
while(1)
{
lcd_cmd(0x80); //Goto Line-1,first position
lcd_send_string("WELCOME TO! ");
lcd_cmd(0xC0); //Goto Line-2, first position}
lcd_send_string("EGLOB :) ");
lcd_cmd(0x01); //Clear the lcd
delay(1);
}
//LCD function
/*------------------------------------------------------------------------------------------------------------*/
//Function for sending commands to LCD
void lcd_cmd(unsigned char command)
{
//Put command on the Data Bus
PORTB = command;
//Enable LCD for command writing
PORTD = 0b00010000;
//Allow delay for LCD to read the databus
delay(1);
//Disable LCD again
PORTD = 0b00000000;
//Allow some more delay
delay(1);
}
//Function for sending Data to LCD
void lcd_data(unsigned char data)
{
//Put data on Data Bus
PORTB= data;
//Set R/S (Regiter Select) to High, and Enable to High
PORTD = 0b00110000;
//Allow for delay
delay(1);
//Disable LCD again
PORTD = 0b00100000;
//Allow for some more delay
delay(1);
}
//Function to send String to LCD
void lcd_send_string(char* string)
{
while(*string)
{
//Send value of pointer as data to LCD
lcd_data(*string);
//Increment string pointer
string++;
}
}
//Function to Initilise LCD
void init_lcd()
{/*----------------------------------------------------------------------------------------------------------*/
//Setup both lines of LCD
lcd_cmd(0x38);
//Set Cursor off - Enable LCD
lcd_cmd(0x0E);
//Clear Screen
lcd_cmd(0x01);
//Goto first position
lcd_cmd(0x80);
}
//Delay function
void delay(unsigned char dtime)//You can use your own delay functions and replace this delay function with your code
{
int i,j;
for(i=0;i<=dtime;i++)
{
for(j=0;j<5000;j++);
}}
/*-----------------------------------------------------------------------------------------------------------*/
Feel free to ask your doubts..
ENJOY!
Thanks for sharing this post . i never face any problem with this LCD display from the date of purchase it
ReplyDeletenice explanation
ReplyDeletei will appreciate your work..thank you for your work
which compiler is used for lcd ??
ReplyDeleteR/S and RW needs to be swapped in the physical configuration of hardware in order to run this program.... great effort ... thanx.. it saved us a lot of time....keep up the good work....
ReplyDeletei have problem when i upload to my device, atmega8. This is problem.
ReplyDeleteavrdude.exe: set SCK frequency to 187500 Hz
avrdude.exe: error: programm enable: target doesn't answer. 1
avrdude.exe: initialization failed, rc=-1
Double check connections and try again, or use -F to override
this check.
avrdude.exe done. Thank you.
To solve this problem, that should i do?
In addition, My LCD device is AX07001-01
Delete