This example is based on a LCD module with the Hitachi HD44780 LCD-controller.You can get these displays in various kinds, from 1 to 4 lines and from 8 to 40 characters per line.

A display with 16 characters per line and 2 lines is used in this example. The display uses a power supply of 5V DC. The LCD controller can accept 8 bit data bytes or 4 bit nibbles. In this example the 4-bit mode is used. There are more to find on the internet. But I wanted to make my own 4-bit LCD interface, to develop my skills in C-programming.

Schematic and build

The interface uses the 4-bit mode of the LCD so you need only one port. Here PORTB is used, but you can use any other port. 

See the schematic below.

To control the LCD a ATTiny2313 microcontroller is used, that is placed on the ATTiny2313 board.The LCD is connected to the LCD Interface Board.

You can buy the ATTiny2313 board and the LCD Interface Board at www.bizztronix.eu

 

lcdavr 1

Software

To make the software code is build with the WINAVR compilier.

The program can be adapted to use another port.  The program can write instructions and data to the LCD controller. There are also functions to control the display and to write text string to the LCD.

The complete function set:

void LCD_init(void)   // init LCD
void LCD_inst(unsigned char inst)   // writes a instruction to the LCD
void LCDclr(void)   // clear display
void LCDhome(void)   // return home
void LCDoff(void) // LCD off
void LCDon(void)   // LCD on
void LCDcursor(void)  // cursor on
void LCDblink(void)  // blink on
void LCDall(void)   // cursor all on
void LCDline(x)   //go to first line
void LCDline(x)   //go to second line
void LCDgoto (x,y)   // goto position x,y
void LCDtext(data)   //write text to the LCD
void LCDint(data)   //write integer to the LCD

Download the complete code below.

LCD_interface.c