Today , I begin a series of posts that will involve the things I hold dear – Sanskrit and Science.
Presenting , xkcd संस्कृतभाषायाम् !
पश्यन्तु , आनन्दम् अनुभवन्तु !
Pre – IISc :
ε> – Love
Post- IISc :
ε> – Epsilon greater than
They say love means different things at different ages.
I’m disappointed to know this what they meant.
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.
The LCD is
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.
These are the functions of the 16 pins :
- VCC (+5V)
- Contrast adjustment
- Register Select (R/S)
- Read/Write (R/W)
- Clock (Enable)
- Bit 0
- Bit 1
- Bit 2
- Bit 3
- Bit 4
- Bit 5
- Bit 6
- Bit 7
- Backlight positive power rail
- Backlight negative power rail
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 must be connected to ground in series with a 5K pot. 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.
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.
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 LCD has basically two operating modes : Instruction mode and Data Mode
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 Data 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 data mode , you connect it to Vcc.
The enable pin has a very simple function. It is just the clock input for the LCD. The LCD will perform whatever function you want it to do on the falling edge of the enable 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.
So this the flowchart for operating the LCD
1) Set the LCD in either Instruction mode or Data mode depending on your requirement.
2) Give the appropriate codes at the Data pins for the function that you wish to perform.
3) Give a short pulse at the Enable Pin from positive to negative and back to positive again.
4) Voila , your instruction will have been executed/ Data shown on LCD
5) Go back to 1
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 :
Here’s a quick review :
1) Goes to GND as it is a power supply pin.
2) Goes to +5v as it is a power supply pin.
3)VEE – contrast adjustment. Connect this to GND along with a series resistor of 2K.
4) RS – Register select. – You can use this to select between the instruction mode and data mode of the LC. 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.
There are 2 possibilites :
Switch Open : The pull up resistor holds the RS pin at Vcc. Data Mode is activated as RS = 1
Switch Closed : The RS pin becomes a part of the ground. Instruction Mode is activated as RS =0
5) RW - Permantently connect this to GND.
6) Enable – 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 is normally held at Vcc by the pull up resistor. When the momentary button switch is pressed , the Pin goes low and back to high again when you leave the switch.
Your instruction or data will be executed on the falling edge of the pulse. (ie. The moment the switch closes)
7-14) Data pins – This is where you give the LCD the ‘codes’ for any instruction or character.
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.
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 connected to GND in series with a resistor
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.
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.
To make the LCD first 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 pushbutton 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 Button once and leave. 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.
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. Try the same thing for “M” , M will appear next to A. You can totally write 16 characters in each row of the LCD. You would expect the 17th letter to appear at the 1st block of the 2nd row. However , this is not the case. For some silly reason , you have to do somemore things before that can happen. I’m pretty much bored of typing now , so i’m going to end this tutorial now.,
When the LCD starts , you have to initialize it first. That means that you have to give a certain instruction to it to make it work properly.
The initilizing instruction is 00001111.
Since it is an instruction , set the LCD in instruction mode by setting R/S to GND.
Then give the instruction code (00001111) at the data pins.
Then give a short pulse at the enable pin.
You should now be seeing a blinking cursor.
I finally finished collecting the next 150 data sheets (74150-74300) yesterday. Here are the links to the data sheets :
Set 2 – 74150 to 74300
Set 1 7400 to 74150
Here “trimmed” means that I’ve edited the pdfs and have removed all the crap like ” IC Physical Dimensions “, which we never use.
I have the unedited pdfs with me. I couldnt upload them as 110mb.com (where i store my files) has a cap of 8mb per file.
If anyone wants the unedited collection , please email me at firstname.lastname@example.org or leave a comment. I will be more than happy to email it to you.