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.

Recent Posts

I2C Bus for ATtiny and ATmega

I2C Bus for ATtiny and ATmega

I love the Atmel AVR microcontrollers! Since building the Ghetto Development System described in thi[...]
Interfacing GY 26 with atmega640

Interfacing GY 26 with atmega640

Hello friend once again with new instructable in this I will show you how to interface GY 26 with UA[...]
Using Atmega32 with Arduino IDE

Using Atmega32 with Arduino IDE

Over time I have used all kinds of Atmel microcontrollers in various projects. One of the mos[...]
Standalone Arduino / ATMega chip on breadboard

Standalone Arduino / ATMega chip on breadboard

Step 1: Parts needed I bought my parts from Digikey and Sparkfun Electronics - they're 2 of my favo[...]
Burning atmega328-pu and atmega328p-pu bootloader

Burning atmega328-pu and atmega328p-pu bootloader

Burning the boot loader in an atmega328 could be somewhat tricky but if u follow these steps correct[...]

Read more:
‘Bright spot’ on Ceres has dimmer companion
Close