AVR 3-Wire HD44780 LCD Interface (avr-gcc)
- Initialize Display
- Turn on/off backlight
- Load a byte into the 74HCT164 shift register
- Send the byte in the '164 as a command to the LCD
- Send the byte in the '164 as a character to the LCD
- Send a character to the LCD
- Move the cursor to a specified position (row and column)
- Increment the cursor position
- Decrement the cursor position
Circuit Description
Below is the schematic diagram for the circuit I'm using. The circuit is derived from Stefan Heinzmann's circuit which is a 3-wire interface to a PIC12C508 microcontroller (see Resources).
[click to enlarge]
The AvrUsb500 connector is not necessary. That's just my in-circuit connector for programming AVRs using the AvrUsb500 programmer. You can omit that if you have other means of programming your AVRs. The LCD uses PORTD of the ATMega8. PD7 is "dashed" in the schematic because that is an optional connection. That is for the backlight. You could optionally pull it high or low manually to enable/disable the backlight respectively. You could also use a '555 timer to setup a "one shot" with the E signal to turn on the backlight for a predetermined amount of time after the LCD is written to.
The way this works, is the E pin at PD4 is held low, "disabling" the LCD. The DS/RS at PD5 serves two purposes: DS when E is low and RS when E is high. As DS, the byte is shifted out one bit at a time into the '164 with the CLOCK signal at PD6. Once the byte is loaded into the '164, the E signal is pulsed to move that byte into the LCD in 8-bit parallel mode. Before strobing E, the DS/RS line at PD5 is set high if the data in the '164 is a character and is set low if the data in the '164 is a command. Thus, the DS/RS line is operating as RS for the duration that the E is high.
Download Project Files
Download lcd_pc1202a.tar.gz This tarball contains the following files to build pc1202a.hex, a program for the ATMega8 that outputs "Micah" to line one of the LCD and "Carrick" to the second line.- circuit.png - the schematic diagram shown above
- gpl.txt - GPL license information
- main.c - the test program
- lcd.h - header for the LCD routines
- lcd.c - LCD routines
- Makefile - the Makefile that builds pc1202a.hex and optionally programs the chip using the AvrUsb500
Resources
- Powertip PC-1202A LCD Datasheet
- Powertip PC-1202A LCD from Wright Hobbies - $7.95
- Powertip PC-1202A LCD from Electronics Goldmine - $7.95
- Stefan Heinzmann's original PIC12C508 3-wire Interface
- avr-libc Reference Documentation
- Peter Fleury's "Interfacing a HD44780 Based LCD to an AVR"
- Myke Predko's "LCD Interfacing Reference Page"
- Hitachi HD44780 Datasheet

7 Comments about "AVR 3-Wire HD44780 LCD Interface (avr-gcc)"
RSS Feed
I've tried the above codes and circuit and it doesn't seem to be working although I did exactly the same as you mentioned.
Do you know what might be the problem I'm facing? Could you please reply me if you think my problem is?
i'm using ATMEGA88PA-PU
what clock frequency do i need to use it for this? thanks
* Prints a string at line 1 of the LCD
*
*/
void lcd_puts_1(const unsigned char *str) {
uint8_t i;
/* goto line 1 */
lcd_move_cursor(LCD_LINE_1, 0);
i=0;
while (str[i] && (i
Try this way -
void lcd_print(const char* str) {
do {
lcd_putc((char)*str);
str++;
} while (*str != 0);
}
and don't forget to add null terminate char to string.
- const char text[] = "this is my test!";
Have you made the proper adjustments in the Makefile? I was having similar results running this code on a tiny13 until I changed the MCU to attiny13. Working great with 16x2 LCD now!
I'm test it!
All it Ok, but I try to write a function, it don't work, I have black caracteres (5x7) on LCD.
void lcd_puts(const char *s)
{
register char *c;
while ( (c = *s++) ) {
lcd_putc(c);
}
}/* lcd_puts */
Can you help me ?
Tanks.
Leave a Comment about "AVR 3-Wire HD44780 LCD Interface (avr-gcc)"