|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
Before You StartIf you want to understand the logic of these I/O ports and want to make a quick start to LCD you have to check out my first article. If you don't need the logic and only need a quick live work, do the circuit in part 2 and download my program to make LCD live.Part 1 - What is an LCD and what is it for?Don't be afraid, I won't give a history lesson like every other article out there does but I want to say why we are using all these LCDs from the time when it was first invented. At first we used LEDs and then 7SDs appeared now we are using LCDs because of their capability of showing not only numbers also showing letters and all kind of symbols. I used a character based LCD see it's datasheet here. It has a HD44780(Hitachi) compatible KS0066U controller. Samsung made this controller and if you are interested in the electronic stuff, you can download the controller info from here These controllers are not much complicated like today's graphic LCDs' (Palms, New Generation Digital Cameras, Nokia and other cell phones) controllers but they have been used in commercial and industrial products around the world. Because of their basic interface they can talk to the old Z80, 6502 and/or the PIC microcontrollers which are considered as one of the most popular microcontrollers by the hobbyists. You can find additional info on microcontrollers at http://www.microchip.com/ Let me explain what VFDs are: VFDs (Vacuum Fluorescent Displays) are also like LCDs. These are commonly used in microwaves and some pocket calculators. See a sample picture of a VFD here. The key is controllers so there are HD44780 compliant VFDs around. I like VFDs more than LCDs because they are brighter than LCDs but they are also more expensive than LCDs so I used an LCD in my article. What are the shapes of these LCDs? I used a 2x16 (2 row(line) x 16 column) LCD in my article as you can see in the above picture. There are lots of LCD types such as 1x8, 2x8, 1x16, 1x20, 2x20, 2x20, 2x10, 1x40 and there are also many different vendors. And if there are more than 80 characters, mostly they use 2 controllers on the LCD (Mine has one - This is important). I don't give any lcd structure information due to codeproject's concept if somebody wants to learn about how these LCD structures are check these two urls:Part 2 - LCD Connections, Pinout Descriptions and CircuitLCD ConnectionsMostly an LCD has a 14 pin connection which are D0-D7 (Data Bits), E (Enable), R/W (Read/Write), RS (Register Select), Vee or Vo (Contrast), Vdd or Vcc (+5V supply), Vss (Ground/Earth connection) so there are 8 data, 3 power and 3 control lines for a standard non-backlight LCD. If an LCD has a backlight it has additional two lines for that which are 15th (VB+) and 16th(VB- or Ground) lines. Below there is a table of the pin matches and pictures of my LCD's backsides: Standard LCD Pin Matches (Character number <80)
If your LCD has more than 80 characters (like 4x40)
Pinout DescriptionsPin 1,2,3According to the table, I call Pin 1(Vss),2(Vdd/Vcc),3(Vee/Vo) power pins because they are the gates to power. Pin 1 is for ground so you have to connect to ground/earth and Pin 2 is for the +5V power supply. 6V or 4,5V is mostly acceptable in few amperes and also 3V is acceptable on some of the LCD modules (You can also power these modules with a battery in a very economical way). In my application I get the voltage from the molex cable of the pc which is inside the case. And pin 3 is for the LCD's contrast adjustment. I did not but you could use a potentiometer(10K pot will be ok) for changing the contrast of your LCD. See the schematics below Pin 4,5,6I call Pin4(RS),5(R/W),6(E) the control buddies because these pins are the arms of your controller inside your LCD module. Pin 4(RS) is registration select if this pin is low the data perceived by the data pins taken as commands by the LCD and if this pin is high the LCD can receive/send 8 or 4 bit character data. I call Pin 5(R/W) clerk because when this pin is low you can write character to the LCD, if the pin is high you can read character data or the status information from the LCD. I didn't make any read operations in my app so I solder this pin to the ground (with soldering this to the ground I made this pin low - "0" see the below circuits). Pin 6(E) which I call the guardian, is used to initiate the actual transfer of commands or character data between the LCD module and the data pins. Pin 7,8,9,10,11,12,13,14The eight pins which are DB0-DB7 are the data pins which I call them the workers. The data can be transferred or fetched from the LCD by 8 or 4 bits. Which one is better? This is up to you, by the way if you are using a microcontroller and you have few pins you can use your module in 4 bit mode(by using DB4-DB7). I used 8 bit mode in my LCD because I used the parallel port which already have 8 bit data lines (remember my first article, part 1 D0-D7) Pin 15,16These two pins are for the backlight of the LCD module. 15th pin goes to the power supply(VB+) and 16th pin goes to the ground(VB-). Backlight is very useful in dim environments but some LCD modules don't have backlights. There are multicolored LCDs around as well. CircuitWhat we need to supply for our circuit? Below is a list of that:
Make the circuit as its shown in the pictures below. The circuit with potentiometer The circuit without potentiometer
If your soldering goes well you get a typical test screen of a character based LCD as its shown below:
Part 3 - Before CodingBefore coding you have to know some of the basic instructions of a HD44780 controller. Below is a table from the Hitachi's old web site which explains the instructions for HD44780 compatible LCD. Note: I add some extra info for easy understanding.
If you decide to develop your own program after this article, this instruction table will come in handy. If it comes a bit complicated see Part 4 then you can understand the logic behind the instructions with coding. Part 4 - Coding TimeNow we know a lot of things about LCDs so we can write some codes to make our LCD live. There are three important functions in my app which are The below code( private void Prepare_LCD(int cursor_status)
{
/* Look at the instruction table to make these comments make sense */
/* Thread.Sleep() function is not needed for some type of LCD instructions
* and also this is changeable from an LCD
* to another so tryout the best for your module */
/* Sends 12(d) = 1100 binary to open the entire display and
* makes a delay that LCD needs for execution */
if(cursor_status == 0)
PortAccess.Output(data, 12); //Thread.Sleep(1);
//The delays can be smaller, Check Busy Flag info in the article
/* Sends 14(d) = 1110 binary to open the entire display
* and makes the cursor active and also
* makes a delay that LCD needs for execution */
if(cursor_status == 1)
PortAccess.Output(data, 14); //Thread.Sleep(1);
//The delays can be smaller, Check Busy Flag info in the article
/* Sends 15(d) = 1111 binary to open the entire display, makes
* the cursor active and blink and also
* makes a delay that LCD needs for execution */
if(cursor_status == 2)
PortAccess.Output(data, 15); //Thread.Sleep(1);
//The delays can be smaller, Check Busy Flag info in the article
/* Makes the enable pin high and register pin low */
PortAccess.Output(control, 8); Thread.Sleep(1);
//The delays can be smaller, Check Busy Flag info in the article
/* Makes the enable pin low for LCD to read its
* data pins and also register pin low */
PortAccess.Output(control, 9); Thread.Sleep(1);
//The delays can be smaller, Check Busy Flag info in the article
/* Clears entire display and sets DDRAM address
* 0 in address counter */
PortAccess.Output(data, 1); //Thread.Sleep(1);
//The delays can be smaller, Check Busy Flag info in the article
/* Makes the enable pin high and register pin low */
PortAccess.Output(control, 8); Thread.Sleep(1);
//The delays can be smaller, Check Busy Flag info in the article
/* Makes the enable pin low for LCD to read its
* data pins and also register pin low */
PortAccess.Output(control, 9); Thread.Sleep(1);
//The delays can be smaller, Check Busy Flag info in the article
/* We are setting the interface data length to 8 bits
* with selecting 2-line display and 5 x 7-dot character font.
* Lets turn the display on so we have to send */
PortAccess.Output(data, 56); //Thread.Sleep(1);
//The delays can be smaller, Check Busy Flag info in the article
/* Makes the enable pin high and register pin low */
PortAccess.Output(control, 8); Thread.Sleep(1);
//The delays can be smaller, Check Busy Flag info in the article
/* Makes the enable pin low for LCD to read its
* data pins and also register pin low */
PortAccess.Output(control, 9); Thread.Sleep(1);
//The delays can be smaller, Check Busy Flag info in the article
}
private void move_to_specific(int line, int column)
{
/* Makes the RS pin low */
PortAccess.Output(control, 8); //Thread.Sleep(1);
if(line == 1)
{
/* Sets RAM address so that the cursor is positioned
* at a specific column of the 1st line. */
PortAccess.Output(data, 127+column); //Thread.Sleep(1);
}
if(line == 2)
{
/* Sets RAM address so that the cursor
* is positioned at a specific column of the 2nd line. */
PortAccess.Output(data, 191+column); //Thread.Sleep(1);
}
}
See the below table for the ascii code binary equivalent for understanding the
Now you can look at the Note: You can enable Part 5 - Before Final NoteSome people say "what will I benefit from an extra LCD?" For those, I made a tiny thing which grabs codeproject or the msdn rss headlines from the net and displays them on the LCD screen. Now you can check out the news while you are playing or watching full screen TV on your computer.
As you can see in the video the first line is fixed and the second line scrolls with the news after a period of time the second news scrols and the third, fourth and goes on. If you have online site which has some member systems or forums on it, you could send information using a php or an asp file to a xml or txt file and then fetch the info from there and send to the screen of your LCD or maybe even your area's forecast. You can make some periodic e-mail checks and display them on your LCD screen. You can also interface with your winamp for some spectrum visualization like a plugin but this will be outer world plugin to your winamp :) so see the motion1 and motion2 buttons for info how to develop these type of solutions:
You can make lots of things with an extra LCD on your desktop and these type of things are bounded by your imagination so I can say here "Enjoy your imagination" :) Final NoteFinally I come to the end of my second article in codeproject. I hope I was able to put a smile on the faces of those waiting for my second article. After my first article I get 35-40 e-mails from various people who are interested in these type of things. People send their works also their circuits about various projects, for ex: some people sent their year(s) lasting problems on similar projects. So I want to thank you all for e-mails and also the threads in codeproject. I will be expecting your new suggestions and comments on this article. Don't abstain to mail at ls@izdir.com if you have problems. What will be the third?I don't want to talk about my next article so I didn't put a picture of it like I did in the end of my first article because it is after all a mystery. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||