Sunday, February 7, 2010

Easy LCD screen interface on Atmega32 using Peter Fleury's LCD Driver

How easy is it to connect an LCD screen to an Atmega32? Well very easy.

Peter Fleury's HD44780 compatible LCD library works quite well with only one modification to the code; you must edit the clock frequency in the test_lcd.c file to your desired target, mine was 16000000 for 16mHz.

Talk about easy!!!

In this example I use PORT A which is commonly used as an 10-bit analog to digital converter. Seeing as I have no use for A-to-D on this project PORT A seems like the logical choice. In this project the port is running as standard digital I/O for screen display using 4-bits. PORTA,0-4 are the 4-bit data lines and PORTA,5-7 are the Reg. Select, Read/Write, and Enable pins. The test_lcd.c file requires no editing and the lcd.h file only requires the change of

"#define XTAL 4000000"


"#define XTAL 16000000"

to the desired clock speed of the target MCU. The size of the test_lcd.hex file loaded to the atmega32 was 3kb, which is quite small and leaves 29kb of free Flash space for your program code. If one so desired much of the driver is written in C which could be optimized in assembler to decrease the size of the code base. I however am willing to let 3kb go.

Compilation of the test_lcd.c was done with AVR-GCC 4.4.2 on Mac OS 10.6, then loaded with AVR Studio 4.18 on Windows XP using an AVR ISP MkII.