Summary of AVR-GCC 4 bit and 8 bit LCD library using ATmega8 microcontroller
This article discusses a merged LCD library for controlling standard alphanumeric LCDs via the 74HC164 controller, capable of handling both 4-bit and 8-bit data modes. Users can switch between modes by simply commenting or uncommenting a line in the library header. The library includes definitions for MCU ports and pins connected to the LCD and adds features like predefining custom characters and a progress bar function. The library supports functions for sending data, commands, initializing, clearing, and displaying strings on the LCD.
Parts used in the LCD Library Project:
- Standard Alphanumeric LCD Display
- 74HC164 LCD Controller
- Microcontroller Unit (e.g., ATmega8)
- Microcontroller Ports and Pins (PORTD and DDRD)
Standard alphanumeric LCD display controlled by 74HC164 LCD controller can accept 8 bit data bytes or 4 bit nibbles. Earlier my 4 bit and 8 bit LCD libraries were split in separate files as they were used in different projects. Now they are merged in to one library where simple logic is implemented to select 4 bit or 8 bit library just by modifying only three lines of code.
In the library header file there is line added:
//Uncomment this if LCD 4 bit interface isused
//******************************************
#define LCD_4bit
//******************************************
what allows to select different LCD modes by commenting and uncommenting this line. Also don’t forget to select proper ports and pins where LCD is connected:
#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 PORTD //define MCU port connected to LCD control pins
#define LDDR DDRD //define MCU direction register for port connected to LCD data pins
#define LCDR DDRD //define MCU direction register for port connected to LCD control pins
In newer library there is also couple new functionalities added:
Predefining 8 custom LCD characters during LCD initialisation;
LCDprogressBar() function have been adapted from AVRLib.
Complete function set:
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
For more detail: AVR-GCC 4 bit and 8 bit LCD library using ATmega8 microcontroller