AVR 4-bit LCD interface library

Error message

Deprecated function: The each() function is deprecated. This message will be suppressed on further calls in menu_set_active_trail() (line 2405 of /home/minmaro3/domains/scienceprog.com/public_html/winavr/includes/menu.inc).

Standard alphanumeric LCD display controlled by 74HC164 controlled can accept 8 bit data bytes or 4 bit nibbles. Using 4 bit interface may give few benefits like you can save 4 microcontroller pins and use them for different purposes, or use small pin count Microcontrollers to control LCD like AVR ATtiny series.

When using 4 bit mode, only four data-lines of LCD (D4...D7) are used. So first is high nibble sent and then lower nibble has to be sent in order to form single byte. This way there are two cycles used to form one data or command byte. Earlier I have been using LCD library from Procyon AVRLIB, but I wasn’t satisfied with it as it generated a lots of HEX code because of many functionality included.

This is transformed 8 bit LCD library to 4 bit LCD control library that has been published previously. Library is written for WinAVR compiler toolset and is ready to use. To initialize LCD just enter


//---------initialize LCD----------------



And then you can print single character.


// print message on LCD



Or even constant character line that is stored in program memory to desired LCD location with simple command.


const uint8_t welcomeln[] PROGMEM="Test line\0";

CopyStringtoLCD(welcomeln1, 0, 0);


As in previous library there are also more LCD commands available:


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

void LCDshiftLeft(uint8_t);                    //shift by n characters Left

void LCDcursorOn(void);                       //Underline cursor ON

void LCDcursorOnBlink(void);               //Underline blinking cursor ON

void LCDcursorOFF(void);                     //Cursor OFF

void LCDblank(void);                           //LCD blank but not cleared

void LCDvisible(void);                            //LCD visible

void LCDcursorLeft(uint8_t);                 //Shift cursor left by n

void LCDcursorRight(uint8_t);               //shift cursor right by n


LCD library is as it is. I didn’t test it too much. It works on my Atmega8 at 8MHz. But it should work on any AVR with frequencies up to 16MHz and maybe more.

Feel free to modify if needed or add new functions.