Академический Документы
Профессиональный Документы
Культура Документы
programming), but it is still an opaque black box. If you want it to share information, or show you what it is
trying to do, you need to hook-up (interface) an output device. An output device is a thing that provides you a
way to show information from the microcontroller. That is to say, the output device allows the microcontroller to
"output" information to the "device". We have already worked with another output device, called the LED (Light
Emitting Diode), which gives off light when you program it to do so. We will take an in-depth look at interfacing
and programming the LCD (Liquid Crystal Display).
The LCD is a much more informative output device than a single LED. The LCD is a display that can easily
show characters on its screen. LCDs range in size, price and configuration, from having a couple of lines to
large displays. Some are even very specifically designed for a single application, having only that ability to
display set graphics. We will be usng an LCD that has the ability to display four (4) lines of characters that has
a 20 character line length. This is quite sufficient to show quite a bit of information. Another popular LCD has 2
lines and 16 characters per line.
In this video tutorial, we will look at how the LCD receives information and control, and the requirements to
make sure the information is sent to the LCD in the way that it can appropriately accept information. So, what
does all that mean?
First, we have a speed discrepancy between the LCD and the microcontroller. The microcontroller is much
faster than the LCD, so the microcontroller's program must be fully aware of this and compensate for the time
that the LCD is busy working on things you told it just prior. Fortunately, the LCD can inform us of this busy
status. So, we will create a function to wait until the LCD is not busy. For the LCD to accept information from
the microcontroller, or let it give you information, we must turn its enable pin on and off while the information is
present for the LCD to accept.
The pin on the LCD that is responsible for the read and write state is labeled R/W. The pin on the LCD that is
responsible for whether the infomation sent is a character or a control, is the RS pin (Register Select). And the
pin that helps the LCD accept informatin is called the EN pin (Enable).
There are three basic things you will want to do with an LCD for the proper functioning (more advanced
functions can be performed with these three fundamental routines): (1) to make sure the LCD is not busy; (2)
Control the LCD's cursor, or display function; and (3) Write a character to the LCD for it to display. Each of
these will require its own process:
(1) Checking if the LCD is busy (If you try to display a character to the LCD while the LCD is busy, then the
LCD will just ignor the character and it will not be displayed).
We set the port to receive data on the microcontroller (Data direction as input).
We put the LCD in read mode (RW on).
We put the LCD in command mode (RS off).
And the port now magically contains the data from the LCD (D7 pin will be ON if the LCD is busy and
OFF if the LCD is not busy).
(3) Send a character to the LCD: This is the same as sending a command except the RS is on and the port will
equal the character corresponding to the ASCII code.
So, we are really just turning pins on and off, just like we did with the LEDs from the past tutorials. It's as simple
as that. The only catch is that they must be done in the correct sequence.