Summary of Interfacing JHD404A (40×4) lcd with Microcontroller
This article details interfacing the JHD404A 40×4 character LCD with microcontrollers like the 89c51. It explains that the display uses two HD44780 controllers, requiring separate initialization via enable pins en1 and en2 for the top and bottom halves. The text provides a complete C code example for the 89c51 to initialize both sections and display text across all four rows.Parts used in the Interfacing JHD404A with 89c51 Project:
- JHD404A 40×4 Character LCD
- 89c51 Microcontroller (8051 Series)
- HD44780 LCD Controller
- P1 Port on Microcontroller
- P3 Port on Microcontroller
|
Like all other character lcd’s JHD404A also has a controller in it which controls its internal functions. 40×4 contains HD44780 lcd controller by hitachi in it. Which means same commands are used to initialize 40×4 lcd that are used to initialize 8×1, 16×1, 16×2 ,20×2 character lcd’s. The only difference between JHD404A and his siblings when compared is, it has two enable pins (en1 & en2). This is because a single HD44780 controller can handle up to 80 characters. To handle 160 characters we need an extra HD44780 controller.
|
Why two enable ports?

Interfacing JHD404A (40×4) Lcd with 89c51 Microcontroller
| #include <reg52.h> | |
| sbit rw =P3^0; //Read/Write Pin | |
| sbit en1=P3^1; //Enable for First 80 Characters | |
| sbit rs =P3^2; //Register select (RS) | |
| sbit en2=P3^3; //Enable for Second 80 Characters | |
| void delay(unsigned int time) //Time delay function | |
| { | |
| unsigned int i,j; | |
| for(i=0;i< time;i++) | |
| for(j=0;j< 5;j++); | |
| } | |
| //Function for sending values to the command register of LCD | |
| void lcdcmd1(unsigned char value) | |
| { | |
| P1=value; | |
| rs = 0; | |
| rw = 0; | |
| en1 = 1; | |
| delay(50); | |
| en1=0; | |
| delay(50); | |
| } | |
| //Function for sending values to the command register of LCD | |
| void lcdcmd2(unsigned char value) | |
| { | |
| P1=value; | |
| rs = 0; | |
| rw = 0; | |
| en2 = 1; | |
| delay(50); | |
| en2=0; | |
| delay(50); | |
| } | |
| //Function for sending values to the data register of LCD | |
| void display1(unsigned char value) | |
| { | |
| P1=value; | |
| rs = 1; | |
| rw = 0; | |
| en1 = 1; | |
| delay(500); | |
| en1=0; | |
| delay(50); | |
| } | |
| //Function for sending values to the data register of LCD | |
| void display2(unsigned char value) | |
| { | |
| P1=value; | |
| rs = 1; | |
| rw = 0; | |
| en2 = 1; | |
| delay(500); | |
| en2=0; | |
| delay(50); | |
| } | |
| //function to initialize the registers and pins of LCD | |
| //always use with every lcd of hitachi | |
| void lcdint1(void) | |
| { | |
| P1=0x00; | |
| P3=0x00; | |
| delay(15000); | |
| display1(0x30); | |
| delay(4500); | |
| display1(0x30); | |
| delay(300); | |
| display1(0x30); | |
| delay(650); | |
| lcdcmd1(0x38); | |
| delay(50); | |
| lcdcmd1(0x0F); | |
| delay(50); | |
| lcdcmd1(0x01); | |
| delay(50); | |
| lcdcmd1(0x06); | |
| delay(50); | |
| } | |
| void lcdint2(void) | |
| { | |
| P1=0x00; | |
| P3=0x00; | |
| delay(15000); | |
| display2(0x30); | |
| delay(4500); | |
| display2(0x30); | |
| delay(300); | |
| display2(0x30); | |
| delay(650); | |
| lcdcmd2(0x38); | |
| delay(50); | |
| lcdcmd2(0x0F); | |
| delay(50); | |
| lcdcmd2(0x01); | |
| delay(50); | |
| lcdcmd2(0x06); | |
| delay(50); | |
| } | |
| void main() | |
| { | |
| unsigned int count=0; | |
| char st[]="Its 40x4 Lcd microcontroller-project.com"; | |
| P1=0x00; //Port-1 as Output | |
| P3=0x00; //Port-2 as Output | |
| lcdint1(); | |
| lcdint2(); | |
| while(1){ | |
| lcdcmd1(0x80); | |
| while(count!=40){ | |
| display1(st[count]); | |
| count++; | |
| } | |
| count=0; | |
| delay(5); | |
| lcdcmd1(0xC0); | |
| while(count!=40){ | |
| display1(st[count]); | |
| count++; | |
| } | |
| count=0; | |
| delay(5); | |
| lcdcmd2(0x80); | |
| while(count!=40){ | |
| display2(st[count]); | |
| count++; | |
| } | |
| count=0; | |
| delay(5); | |
| lcdcmd2(0xC0); | |
| while(count!=40){ | |
| display2(st[count]); | |
| count++; | |
| } | |
| count=0; | |
| } | |
| } | |
Download the project code, folder includes the full keil uvision 4 project files and hex code. Please give us your feed back on the project.
Quick Solutions to Questions related to Interfacing JHD404A with 89c51:
- How many characters can the JHD404A display?
The total number of characters is 160, calculated as 40 columns multiplied by 4 rows. - What controller does the JHD404A use?
It contains the HD44780 lcd controller by Hitachi. - Why are there two enable ports on this LCD?
A single HD44780 handles up to 80 characters, so two controllers are needed for 160 characters, requiring en1 and en2 pins. - How are the rows initialized in the 40x4 LCD?
The first two rows are initialized using the en1 pin, while the third and fourth rows are initialized using the en2 pin. - Can I use the same commands for other character LCDs?
Yes, the same commands used to initialize 8x1, 16x1, 16x2, or 20x2 character LCDs apply here. - Which microcontroller series is used in the provided code example?
The code example demonstrates interfacing with the 89c51 microcontroller from the 8051 series. - How do you send data to the command register for the second half of the display?
You use the lcdcmd2 function which sets the en2 pin high. - What happens if you only initialize one enable pin?
Only half of the display would be active because both HD44780 controllers must be initialized separately.
Related projects
PIC16F877 Driving LCD in 4-Bit Mode using PIC16F877 with Proteus Simulation
Introduction This microcontroller project shows how a PIC16F877 can drive an LCD display using 4-bit mode inside a Proteus simulation.The project demonstrates...
Programmers & ICSP · PIC16F877AEPE PIC/LCD Demo using PIC16F877 with Proteus Simulation
IntroductionThe EPE PIC/LCD Demo is a classic microcontroller project that demonstrates how a PIC16F877 can fully control a PG12864F graphical LCD.Designed as...
Motors & Robotics · PIC16F877AEfficient Sun-Following Robot: A Solar Tracker with Microcontroller Control
Abstract The impending global challenge of dwindling non-renewable fuel resources underscores the urgency of transitioning towards renewable energy alternatives like solar power....
LCD & Display ProjectsLeveraging Blockout Banners for Effective Electronics and Tech Product Displays
Blockout banners have become a popular and effective tool for displaying electronics and tech products in various settings, from trade shows and...
LCD & Display Projects · PIC18F4520Interfacing PIC18F4520 microcontroller with an HD44780 LCD
Introduction Being able to display data from a microcontroller visually has many advantages. It allows for menus, status indicators, and instructions to...
LCD & Display ProjectsVideo Project Development in the Midst of an Impromptu Online Semester
Receiving robot parts in the mail was an unexpected conclusion to the Winter 2020 semester for students. However, when faced with a...