LCD Interfacing WinAVR Routines
Circuit Diagram For LCD interface
LCD.H
#define lcd_port PORTB //LCD Registers addresses #define LCD_RS 0×01 #define LCD_RW 0×02 #define LCD_EN 0×08 void lcd_reset(void) { lcd_port = 0xFF; _delay_ms(20); lcd_port = 0×30+LCD_EN; lcd_port = 0×30; _delay_ms(10); lcd_port = 0×30+LCD_EN; lcd_port = 0×30; _delay_ms(1); lcd_port = 0×30+LCD_EN; lcd_port = 0×30; _delay_ms(1); lcd_port = 0×20+LCD_EN; lcd_port = 0×20; _delay_ms(1); } void lcd_cmd (char cmd) { lcd_port = (cmd & 0xF0)|LCD_EN; lcd_port = (cmd & 0xF0); lcd_port = ((cmd << 4) & 0xF0)|LCD_EN; lcd_port = ((cmd << 4) & 0xF0); _delay_ms(2); _delay_ms(2); } void lcd_init (void) { lcd_reset(); // Call LCD reset lcd_cmd(0×28); // 4-bit mode – 2 line – 5×7 font. lcd_cmd(0×0C); // Display no cursor – no blink. lcd_cmd(0×06); // Automatic Increment – No Display shift. lcd_cmd(0×80); // Address DDRAM with 0 offset 80h. } void lcd_data (unsigned char dat) { lcd_port = ((dat & 0xF0)|LCD_EN|LCD_RS); lcd_port = ((dat & 0xF0)|LCD_RS); lcd_port = (((dat << 4) & 0xF0)|LCD_EN|LCD_RS); lcd_port = (((dat << 4) & 0xF0)|LCD_RS); _delay_ms(2); _delay_ms(2); }
void lcd_puts(char *aaa) { unsigned int i; for(i=0;aaa[i]!=0;i++) lcd_data(aaa[i]); }
MAIN.C
#include<avr/io.h> //HEADER FILE FOR AVR INPUT OUTPUT #include<compat/deprecated.h>//HEADER FILE FOR FUNCTIONS LIKE SBI #include<util/delay.h> #include<lcd.h> /*—————————————————————- —————–MAIN PROGRAM——-q—————————— —————————————————————–*/ int main(void) { //SET 1 for OUTPUT PORT DDRB=0xFF; //SET 0 FOR INPUT PORT PORTB=0×00; lcd_init(); lcd_puts(”Devesh LCD demo”); lcd_cmd(0xc0); lcd_puts(”electroons.com”); while(1) {; } return 0; }
Contact-
Devesh Samaiya
devesh@electroons.com
Comments
2 Comments on LCD Interfacing WinAVR Routines
-
Nimish on
Sun, 11th Oct 2009 2:51 am
-
Seema on
Mon, 18th Jan 2010 7:35 am
Good tutorial http://www.lcdinterfacing.info
Hey nice work man Keep it up. …DO you have any tutorial in which I can put LCD in a power down mode ….I am using ATmega16.
Tell me what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!




