[Tut] – Using HD44780 based LCDs – JHD162A
I finally dug out that LCD from the mess in my room and got it to work :). Turns out , its really simple. You dont even need a microcontroller to do it.
Ok. Lets get started :
That is the LCD that i bought from SP road (kwality electronics) for 100 bucks. It incorporates the widely popular HD44780 pin configuration. It has 16 pins.
This is how it looks from the back :
There are 16 pins in all. They are numbered from left to right 1 to 16 (if you are reading from the backside) . My LCD came with a marking to indicate which was the 1st pin and which was the 16th. You can see the markings right next to 1st and 16th pins.
I took the back view pic after I soldered a 8 pin connector between the 7 to 14 pins to make it easier to work with. When you buy the LCD ,all the pins will be bare. ( like in the first pic).
Did you notice that there is a fine film covering the LCD display in the first pic? DON’T remove it until you finish soldering wires and connectors to the pins. Otherwise ,the flux and the alcohol that you use during the soldering process will ruin the LCD.
What do the 16 pins do?
Pin 1 and 2 are the power supply pins. They need to be connected to the negative rail and the postive rail of a +5v power supply respectively. To get a stable +5v Power supply , you can use a 7805 voltage regulator. It will regulate any voltage that you give it into +5v. If you are confused about using the 7805 , check out this tutorial.
Pin 3 is the contrast setting pin. It is said that it must be connected to a potentiometer to control the contrast. However , i have found that it work if you just connect a variable resistor in series with it to GND. The lower the resistance , the greater the contrast. I recommend setting it at around 1.5K – 2K. If you set the value too low or short the pin directly to ground , you will see only dark boxes on the screen. As far as i know , doing this does not have any adverse affect on the LCD.
If putting the Var-resistor does not work out for you , try the old fashioned method with a 10K pot. You must set the voltage to around 1-1.5V for optimum contrast.
Pins 4 , 5 and 6 are control pins of the LCD. I’ll explain about them later on in the post.
Pins 7 to 14 are the Data pins of the LCD. Pin 7 is the Least Significant Bit (LSB) and pin 14 is the Most Significant Bit (MSB) of the data inputs. If you want to display some number or letter on the display , you have to input the appropriate ‘codes’ for that character on these pins. These pins are also used for giving certain commands to the display like clearing the display or moving the cursor to a different location. Upon giving the correct signals to the 3 control pins , the character codes or the commands that you have given to the Data pins will be written to the display or executed by the LCD respectively. To make it easier to give the appropriate inputs to these pins , i recommend wiring up a DIP switch to these pins.
Pins 15 and 16 : Most LCDs have a backlight. A backlight is a light within the LCD panel which makes seeing the chracters on screen easier. When you leave your cell phone or mp3 player untouched for sometime , the screen goes ‘dark’. That is the backlight turning off. It is possible to use the LCD without the backlight as well. Many LCDs come without a backlight. If your LCD has only 14 pins , then it has no backlight. However , the working of the LCD still remains the same even if your LCD doesnt have a backlight. The Backlight is nothing but an LED. So , a resistor must be connected in series with it to limit the current. I am not sure about what value of resistor must be used. This link mentions that the allowable current is 100ma. Then it is best to have a variable resistor (or a transistor) and adjust the current till it is around 90 ma.
Now for the important part : The 3 control pins : R/S , R/W and E
The RS Pin
The LCD has basically two operating modes : Instruction mode and Character Mode
Depending on the status of this pin , the data on the 8 data pins (D0-D7) is treated as either an instruction or as character data.
You have to activate the command mode if you want to give a Instruction to the LCD. Example – “Clear the display” , “Move cursor to home” etc.
You have to activate the character mode if you want to tell the LCD to display some character.
To set the LCD in Instruction mode , you set the 4th pin of the LCD (R/S) to GND. To put it in character mode , you connect it to Vcc.
The Enable Pin
The enable pin has a very simple function. It is just the clock input for the LCD. The instruction or the character data at the data pins (D0-D7) is processed by the LCD on the falling edge of this pin. The Enable pin should be normally held at Vcc by a pull up resistor. When a momentary button switch is pressed , the Pin goes low and back to high again when you leave the switch. Your instruction or character will be executed on the falling edge of the pulse. (ie. The moment the switch closes)
The RW Pin
Generally , we always use the LCD to show things on the screen. However , in some rare cases , we may need to read from the LCD what it is displaying. In such cases, the R/W pin is used. However , this function is beyond the scope of post and will not be explained. For all practical purposes , the R/W pin has to be permanently connected to GND.
The flowchart for operating the LCD
Making the hardware required for driving the LCD
Ok. Now that you have understood this , before starting , it would be more convenient if you soldered together a board with connectors and buttons for controlling all the pins.
Here’s the circuit :
You can solder together a board or you can mount the components on a breadboard. It is upto you to decide.
Note : In the diagram , The RS switch is a press and hold switch , and the Enable switch is a momentary switch. There is a capacitor across The Enable switch for debouncing.
Its not very convenient to have 8 wires and try to make them HIGH or LOW on breadboard. Hence , i recommend that you use a DIP switch along with 8 pin SIP connectors. This is the thing that i made for the job :
The circuit is very simple and you need only 8 pull down resistors (1K) to make the circuit. You can even use a SIP resistor pack to save space and soldering time.
I have mounted the DIP switch on quite a large PCB. You can make a small one if you want to conserve space.
Download the PCB files from here and make your own DIP switch board.
Join together two female connectors to make a female-female connector. Solder a male connector on the LCD data pins.
Now that you are ready with the supporting hardware, lets get started with the real stuff.
Double check the connections
But first , before powering up the LCD , double check all these things.
1) No pins are shorting on the backside of the panel. (It can happen if you have not cleaned the board after soldering)
2) The contrast pin (3) (Vee) is correctly configured.
3) The backlight (pins 15 , 16) has a resistor in series to limit current.
4) The DIP switch board is working properly.
5) The R/W pin is tied to ground.
6) The circuit is being powered by +5v. This is very important. Dont zap your LCD by accidentally powering it with 12V.
7) The connector for connecting the 8 data pins from the DIP switch board to the LCD is proper. Double check for any loose wires and any mismatched wires on the connector.
Get started with the real stuff
if you are sure that nothing is wrong with your setup , then go ahead and power up you LCD.
See nothing at all on the LCD? Dont panic. Thats what is supposed to happen.
Initializing the LCD
To make the LCD show some signs of life , you need to issue an instruction to it. That instruction is 00001111. Since you are giving an instruction to the LCD , you have to put it in instruction mode by holding the RS pin to GND. In the board that you wired up, you can put RS at GND by pressing the RS push and hold button, such that it remains in a depressed state.
Now , your LCD is in instruction mode and is ready to accept any instruction that we issue to it. Now , set the DIP switches as 00001111. This instruction tells it to turn on the display and show a blinking cursor. Once , you have set the DIP switch to 00001111 , press the Enable momentary Button. You should be seeing a blinking cursor on the screen now. This means that your LCD is initialized and ready to accept characters to display.
Wait , you did not get a blinking cursor? Triple check if your connectors and switches are proper. Check if you have accidentally reversed the MSBs and LSBs on each side of the connector. Check your soldering to see if there are any cold solder joints.
Making characters show up on the display
Ok , once you have got the cursor blinking , the LCD will now accept character data to display. Now , we have to put the LCD in character mode to make it accept characters to display. Press the RS switch to make it ‘undepressed’. Now set the DIP switches to 01000001 and then press the Enable button. If everything has gone right , then you should be seeing a capital A on the screen. But what if you want to display some other letter , like “M”? The procedure is the same , you only replace the 01000001 with the code for M , which is 01001101. The LCD automatically increments the cursor position by 1 everytime you write a character. Try the same thing for “M” , M will appear to the right of A.
After you write to the last location of the first line , you would expect the LCD to automatically jump to the second line. Sadly , it doesnt happen so. Using the second line is slightly more tricky. I’ll explain that in a later post.
Using a µController with the LCD
It is quite a pain to manually do this procedure every time. Using µControllers to automatically send the data and the required signals simplifies the entire job. Here is a video that i took of the LCD being controlled by a Attiny2313. It automatically writes my name continuously in a loop.
Some additional stuff
Here is an online LCD simulator. Practice everything on it first before practically trying it on your LCD.
Download the datasheet for the LCD JHD162A (which i’ve used in this tutorial).
Download the datasheet for HD44780 which is the chip that controls the LCD.
Here’s the instruction set for the LCD which i’ve copied and pasted from the LCD datasheet for your reference :
Here’s the character code table for the LCD which shows the corresponding binary values for each character :
Thats it , you now know how to use an LCD!! Have fun playing with your LCD module !! :)