Tuesday, June 9, 2020

AT89C52 interfaces to a 16x2 character LCD

Character LCD With HD44780 LCD Controller

A character LCD has been a popular display device for many decades. Currently, there are a dozen of modern display devices in the market. Most display device have a built-in LCD controller and driver. The Hitachi HD44780 is an industrial standard character LCD controller in use for many decades. However there are many alternative controller IC compatible with this device today.

AT89C52 interfaces to a 16x2 character LCD
A sample of 16x2 LCD with HD44780 compatible controller.
AT89C52 interfaces to a 16x2 character LCD
Pin diagram

With a high level programming language, programming this device could make from scratch. MikroC is popular C compiler targeting many different microcontrollers. It has a lot of built-in libraries comes with the compiler. Libstock is a supporting website contain many shared libraries made by many developers.

In this example, I use AT89C52 microcontroller from Atmel. It's a non-ISP flash microcontroller. But we can test the program of this device in simulator.

For this LCD module, there are 16 pins connection including the back LED. VSS and VDD are supply voltage pins, typically 5 V DC. RS (register select) pin use for selecting between LCD command and display data register. RW (read/write) use for reading and writing between the LCD and the MCU. Typically it's wired to ground because we just only write to LCD for displaying texts. E (enable) used for latching the 8-bit data to the LCD controller. A and K are back LED pins.

We don't need to explain more about technical details because we gonna use the high level programming language with a ready-to-use LCD library.

MikroC LCD Library For HD44780

In MikroC there are some related LCD function we gonna use here.
  1. Lcd_Init() this function initialize the LCD operation with 4-bit mode
  2. Lcd_Cmd() this function write the command to LCD such as clearing the display, moving cursor and so on.
  3. Lcd_Out() write the string of characters to the LCD at any position.
Before we can use these functions, the LCD pin connection declaration must be done first. For more details, please see the library function help file comes with the compiler.

AT89C52 interfaces to a 16x2 character LCD
AT89C52 clocks at 24 MHz. LCD connects to P3 using 4-bit data mode.

MikroC source code.

/*Select the control pins*/
sbit LCD_RS at P3_0_bit;
sbit LCD_EN at P3_1_bit;
/*Select the 4-bit data pins*/
sbit LCD_D4 at P3_4_bit;
sbit LCD_D5 at P3_5_bit;
sbit LCD_D6 at P3_6_bit;
sbit LCD_D7 at P3_7_bit;
void main(){
  long seconds=0;
  
  /*LCD inititializing*/
  Lcd_Init();
  /*Cleaning up display data*/
  Lcd_Cmd(_LCD_CLEAR);
  /*Turning Off The Cursor*/
  Lcd_Cmd(_LCD_CURSOR_OFF);
  /*Starting the texts*/
  Lcd_Out(1,3,"HELLO AT89C52");
  Lcd_Out(2,2,"MikroC For 8051");
  Delay_ms(2000);
  /*Erasing all Texts*/
  Lcd_Cmd(_LCD_CLEAR);
  while(1);
}

AT89C52 interfaces to a 16x2 character LCD
A running program shows a displaying texts before the MCU clear them.

Click here to download source file of this example.

We can use SN74HC595N shift registers chip to drive this character LCD in 4-bit mode. This chip converts from serial data that use SPI interface from microcontroller to parallel output. Parallel output data will drive the character LCD. So microcontroller uses only 3 pins to send serial data to serial character LCD module.

1 comment:

  1. I think this is an informative post and it is very useful and knowledgeable. We provide LCD modules/LCD Displays, Graphic LCM, smart Display LCD, TFT LCM, Custom LCD Module Display, and LCD panels. china LCD Manufacturers.

    tft touch screen

    ReplyDelete

Search This Blog

Labels

25AA010A (1) 8051 (7) 93AA46B (1) ADC (30) Analog Comparator (1) Arduino (15) ARM (6) AT89C52 (7) ATMega32 (56) 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 (47) Master/Slave (1) MAX7221 (1) MCP23017 (5) MCP23S17 (4) Meter (3) MikroC (2) Motor (15) MPLABX (71) 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 (3) SPI (24) STM32 (6) STM32 Blue Pill (6) STM32CubeIDE (6) STM32F103C8T6 (6) SysTick (3) temperature sensor (11) Thermometer (21) Timer/Counter (31) TM1637 (2) UART (7) Ultrasonic (4) Voltmeter (7) WDT (1) XC16 (2) XC8 (94)