Simplified AVR LCD routines using ATmega8 microcontroller

Feb 16, 2013 by


Controlling numeric LCD isn’t so tricky as it may look like. O course you can find numbers of LCD libraries. One of more universal you can find in AVRLIB library for WinAVR AVR GCC compiler. Main disadvantage of such universal libraries that they compile all functions even if you don’t want them. This way huge libraries occupy more program memory than you would like to. One way is to write simple routines specified only to your design.

My simple LCD library include only 8 bit mode. Each pin, connected to LCD, can be configured separately. For instance:

 LCD routines

#define LCD_RS 0 //define MCU pin connected to LCD RS

#define LCD_RW 1 //define MCU pin connected to LCD R/W

#define LCD_E 2 //define MCU pin connected to LCD E

#define LCD_D0 0 //define MCU pin connected to LCD D0

#define LCD_D1 1 //define MCU pin connected to LCD D1

#define LCD_D2 2 //define MCU pin connected to LCD D1

#define LCD_D3 3 //define MCU pin connected to LCD D2

#define LCD_D4 4 //define MCU pin connected to LCD D3

#define LCD_D5 5 //define MCU pin connected to LCD D4

#define LCD_D6 6 //define MCU pin connected to LCD D5

#define LCD_D7 7 //define MCU pin connected to LCD D6

#define LDP PORTD //define MCU port connected to LCD data pins

#define LCP PORTB //define MCU port connected to LCD control pins

#define LDDR DDRD //define MCU direction register for port connected to LCD data pins

#define LCDR DDRB //define MCU direction register for port connected to LCD control pins

 

I have written several LCD controlling functions that may be used more frequently:

 

void LCDsendChar(uint8_t); //forms data ready to send to 74HC164

void LCDsendCommand(uint8_t); //forms data ready to send to 74HC164

void LCDinit(void); //Initializes LCD

void LCDclr(void); //Clears LCD

void LCDhome(void); //LCD cursor home

void LCDstring(uint8_t*, uint8_t); //Outputs string to LCD

void LCDGotoXY(uint8_t, uint8_t); //Cursor to X Y position

void CopyStringtoLCD(const uint8_t*, uint8_t, uint8_t);//copies flash string to LCD at x,y

void LCDdefinechar(const uint8_t *,uint8_t);//write char to LCD CGRAM

void LCDshiftRight(uint8_t); //shift by n characters Right

Leave a Comment

You must be logged in to post a comment.

Read more:
First infrared satellite monitoring of peak pollution episodes in China
Close