Copyright Brian Starkey 2012-2014
Valid HTML 4.01 Transitional

Valid CSS!
iconAVR HD44770 Drivermax, min, close
Example CircuitExample Circuit
This library provides basic control of any HD44780-based character LCD display using a 74164 shift register. This reduces the display interface to using just 3 pins:
  • SH_CLOCK - The data clock
  • SH_DATA/RS - The data/Register Select
  • EN - Enable strobe
The code was written for AVR, but changing the port definition should be all that is needed for other platforms.
The interface is bit-banged, allowing any 3 (or 4) pins to be used (as-is the pins must all be on the same port). The RS and SH_DATA pins can be shared, as the RS pin is only read when EN goes high.
In this way, the data can be clocked out, the RS pin set, and then EN strobed. The code does not allow for reading (or checking of the busy flag), instead, a fixed delay is inserted after every write operation.

// Module for HD44780 LCD Module
// through 74168 shift register
// This work is provided as-is without any warranty whatsoever
// Use it at your own risk
// Modify and redistribute at will, as long as this disclaimer remains
// (C) Brian Starkey, 2010

#define LCD_MOD 1

#define SH_DATA 5
#define SH_CLOCK 3
#define RS 5
#define EN 4

#define LCD_COLS 16         //Number of Cols
#define LCD_ROWS 2          //Number of Rows
#define NEXT_STATION 0x10   //Just offscreen Right
#define PREV_STATION 0x18   //Offscreen Left - 16
#define LINE1_START 0x00
#define LINE1_END 0x27
#define LINE2_START 0x40
#define LINE2_END 0x67

#define E_MODE 0x04         //Entry Mode
#define E_MODE_INCDEC 0x02  //Increment/Decrement Cursor
#define E_MODE_SHIFT 0x01   //Display Shift
#define D_CNT 0x08		    //Display Control
#define D_CNT_POW 0x04		//Display on/off
#define D_CNT_CUR 0x02      //Cursor on/off
#define D_CNT_BLINK 0x01    //Cursor Blink on/off
#define D_SHIFT 0x10        //Display Shift
#define D_SHIFT_CD 0x08     //Shift Cursor/Display
#define D_SHIFT_LR 0x04     //Move Right/Left
#define SET_DDRAM 0x80      //Set DDRAM Address

void init_lcd(void);
void instruction_cmd(char data);
void data_cmd(char data);
void print_string(char * string, char pos);
void print_string_pmem(PGM_P pstring, char pos);
void shift_out(char data);
/* void ctos(char * s, char i); */