Sunday, August 30, 2020

ATMega32 Interfaces To HD44780 Character LCD Module

Overview Of HD44780 LCD Controller

HD44780 is character LCD controller developed by Hitachi. It usually equipped with a Fax machine, a printer and photocopier machine.

This controller embedded in any LCD module with different number of lines and characters, a 8x1, a 16x1, a 16x2, or a 20x4 LCD module, etc. Currently, there are many equivalent controller to this old one's, for example a ST7066U and ST7065C controller. 

ATMega32 Interfaces To HD44780 Character LCD Module
A JHD162A 16x2 Character LCD Module

ATMega32 Interfaces To HD44780 Character LCD Module
A 1602ZFA 16x2 LCD Module. This module uses both ST7066U and ST7065C controller, but it's compatible to HD44780 controller.

Interfacing With HD44780

This controller typically work at 5 V DC. Its communication to the MCU is in parallel mode - 8-bit or 4-bit data lines. Here I select JHD162A LCD module to work with.

ATMega32 Interfaces To HD44780 Character LCD Module
JHD162A pins function

The data bus is 8-bit wide, with three control lines. The R/W uses for read and write. Usually, the programmer only need to write to the module, thus this pin must wires to the ground.

Register select (RS) pin is the module input, commanding the the controller to accept between instruction (command) and data. Command is any LCD instruction - clearing the display or returning home.

Enable (E) pin is the module input, the 8-bit data is fetch into the controller at the HIGH logic level of this pin.

ATMega32 Interfaces To HD44780 Character LCD Module
Writing A Command To HD44780


ATMega32 Interfaces To HD44780 Character LCD Module
Writing A Data To HD44780

The interfacing I talk here is 8-bit mode only. For the 4-bit interfacing, it will be discuss in the later post.

Internal RAM and ROM

Characters to display are any ASCII or Japanese characters. They are mask-programmed and creates by the character generator ROM (CGROM). The character could be in 5x8 or 5x10 dot.
The display data RAM (DDRAM) output the characters to LCD module display. DDRAM size varies depend on the number of lines and characters of the module.
Any custom characters outside the pre-build character of the module could be created using the character generator RAM. The process of creating the custom character is not discuss here.

LCD Configuring And Displaying A Character

Displaying a character need an initial LCD configuration. Configuration is made by writing some LCD command to the module with some preferred commands. After the configuration is done, the character is displayed by sending the data (ASCII character) to the module.
There are many commands for this controller.

All instructions set from JHD162A datasheet.

Each writing the controller requires a time of at least 40 micro seconds to a few milli seconds a listed in the table above.
There are many types of this module, hence its DDRAM are different in size.
  • A 16x2 LCD Type
- Line 1 starts from the address 0x80 to 0x8F.
- Line 2 starts from the address 0xC0 to 0xCF.
  • A 20x1 LCD Type
- Line 1 starts from the address 0x80 to 0x93.
  • A 20x2 LCD Type
- Line 1 starts from the address 0x80 to 0x93.
- Line 2 starts from the address 0xC0 to 0xD3.
  • A 20x4 LCD Type
- Line 1 starts from the address 0x80 to 0x93.
- Line 2 starts from the address 0xC0 to 0xD3.
- Line 3 starts from the address 0x94 to 0xA7.
- Line 4 starts from the address 0xD4 to 0xE7.
  • A 40x2 LCD Type
- Line 1 starts from the address 0x80 to 0xA7.
- Line 2 starts from the address 0xC0 to 0xE7.

This information I got from an AVR microcontroller book.

Interfacing And Programming With ATMega32

Example 1

I follow the controller operation example from its datasheet. The scrapped operational steps in the picture below.

It use the 8-bit data mode for a 8x1 LCD type. However, I use JHD162A with instead due to its availability.

ATMega32 Interfaces To HD44780 Character LCD Module
Schematic Diagram

I clock the ATMega32 to 16 MHz due to an on-board oscillator. The 8-bit data connects to PORTD. The control pins connect to PORTC.

The programming example below use the 8-bit interfacing mode to display the text "A.K.I". Each character display has a delay of 2 seconds. Source codes of this example is fetch from my GitHub gist respiratory.



A simulation screen shot shown below.

ATMega32 Interfaces To HD44780 Character LCD Module
A simulation screen shot of this example, The display shows the text "A.K.I".

I stored a zip file of this example in my GitHub respiratory here.

Example 2

In this example, I use this 16x2 LCD to display text at on all the two lines of the display. We set the cursor to auto increment by 1, then it moves to next DDRAM address. Additionally, a C pointer is a dynamic RAM addressing. Increasing the pointer, to space up the data size in the unit of 8-bit. With this advantage, we can write a continuous text string to the display without writing each character one by one as we have done in the previous example.

I add a new function. It relies on writeCharacter() function.

void writeString(char *text){
while(*text) writeChararacter(*text++);
}

The display show time in seconds since the MCU powered up. It counts the time in seconds - from 0 to 255 because I use only an 8-bit "char" data type. 

I fetch the source codes from my GitHub gist directory.

The simulation result is shown below.

ATMega32 Interfaces To HD44780 Character LCD Module
The time counts reaches 200 seconds since the MCU powered up.

Example 3

I have read the AVR microcontroller book. I got some techniques from that. We can set the position of the cursor easily by writing an additional function. This function set the DDRAM address on the display.

In the source code I name this function to setXy().

/*This function ease of setting the cursor position*/
void setXy(int x,int y){
char numberOfLines[2]={0x80,0xC0};
/* The position starts from (x,y)=(0,0) */
writeCommand(numberOfLines[x]+y);
}

The source codes is updated as follow.

The program remains the same in schematic diagram, except an additional setXy function and some displaying texts.

ATMega32 Interfaces To HD44780 Character LCD Module

We can add an SN74HC595N to drive this character LCD in 4-bit mode. Since the SN74HC595 uses SPI interface, the microcontroller requires only three pins to connect to the SPI character LCD module.

There is another simple serial to parallel shift register chip that need only two pins - serial data and serial clock. It's the SN74HC164. This chip also able to drive this LCD in 4-bit or 8-bit mode. However it requires a few microcontroller control pins beside the two serial pins. For 4-bit mode we will need to add E(Enable) pin that drive from any microcontroller pin. 

No comments:

Post a Comment

Search This Blog

Labels

25AA010A (1) 8051 (7) 93AA46B (1) ADC (30) Analog Comparator (1) Arduino (15) ARM (6) AT89C52 (7) ATMega32 (54) AVR (57) CCS PICC (28) DAC (1) DHT11 (2) Display (105) Distance Sensor (3) DS18B20 (3) dsPIC (2) dsPIC30F1010 (2) EEPROM (5) Environment Sensor (4) esp8266 (1) I2C (29) Input/Output (67) Interrupt (19) Keil (5) Keypad (10) LCD (46) Master/Slave (1) MAX7221 (1) MCP23017 (5) MCP23S17 (4) Meter (3) MikroC (2) Motor (15) MPLABX (66) Nokia 5110 LCD (3) OLED (2) One-Wire (6) Oscillator (8) PCB (6) PCD8544 (3) PCF8574 (5) PIC (107) PIC12F (2) PIC16F628A (2) PIC16F630 (1) PIC16F716 (3) PIC16F818 (10) PIC16F818/819 (2) PIC16F84A (15) PIC16F876A (1) PIC16F877A (9) PIC16F88 (1) PIC16F887 (60) PIC18 (19) PIC18F1220 (4) PIC18F2550 (3) PIC18F4550 (12) PWM (11) RTC (8) Sensor (10) SH1106 (1) Shift Register (11) Shift Registers (2) SPI (24) STM32 (6) STM32 Blue Pill (6) STM32CubeIDE (6) STM32F103C8T6 (6) SysTick (3) temperature sensor (11) Thermometer (21) Timer/Counter (30) TM1637 (2) UART (7) Ultrasonic (4) Voltmeter (7) WDT (1) XC16 (2) XC8 (94)