| Description: |
LCD Tutorial Table of Contents
- LCD Panels: An Introduction to Serial Programming
- NetMedia's LCD
- Connecting the LCD to the BX-24 via the RAMB
- Creating the LCD Queues
- Initializing the LCD
- Outputting Text to the LCD
- LCD Control Codes
- Putting It All Together: Creating a Simple LCD Application
- Creating an Advanced LCD Application
- Using My LCD Module
|
|
I'd sure like to hear from you.
If you find my tutorial helpful or if you would like
to leave a comment,
please send me an email.
|
|
|
LCD Panels: An Introduction to Serial Programming
The abbreviation, LCD, stands for "liquid crystal display", and therefore the term "LCD display" is a bit
redundant -- however, this is the term most people use. You'll also see it as "LCD panel", "LCD screen",
or simply "LCD". The LCD panel is just the thing to use when you need your BX-24 application
to display a message or echo some value for a human audience or user:
Say, for example, that you wish to build a weather station
and would like to display the ambient
temperature, humidity, and wind speed in real time. You could, of course, use
the Debug.Print
command and display the weather data to your computer's monitor, but it is unlikely that
you'd set up the station near your PC or that you'd dedicate your computer to one application.
Or, say that you'd like to debug your robot's code without having to be tethered to the PC. With an LCD
panel, you can print sensor values or debugging messages in real time -- as robot roams around.
These applications are just two examples where one could use an LCD display to display data or sensor values.
Knowing what LCD panels do is one thing; knowing how to program them is another. Programming an
LCD display is not difficult, but, unfortunately, there are not a lot of straightforward tutorials on the topic.
Below, I outline how to program
NetMedia's 2x16 LCD display
with a BX-24
and a Robodyssey motherboard
(RAMB II
and RAMB).
Hopefully, you'll find this LCD tutorial helpful and informative.
Let me know.
[Return to the top.]
NetMedia's LCD
If you don't have an LCD display but are ready to purchase one, may I suggest that you check out the
2x16 LCD display panel
sold by NetMedia?
If you already have an LCD display, that's great; they're all pretty similar.
I prefer NetMedia's LCD display because:
- It is relatively inexpensive (about $40).
- It is ready to go right out of the box -- literally, plug and play.
- It offers two rows with which to display messages.
- It can be back-lit.
- The brightness and contrast are easily controlled with code.
[Return to the top.]
Connecting the LCD to the BX-24 via the RAMB
|
Before we program the LCD, let's connect it to our BX-24. Of course, you can't connect wires
directly to the BX-24, so you'll have to build your own circuit or use
a commercial motherboard. Years ago, I happily started using Robodyssey's motherboards.
They're small, thoughtfully designed, inexpensive, and robust (I've launched one into space at
20G's). They call it the Robodyssey Advanced Mother Board, or RAMB. In 2006, Robodyssey
released an updated version of their board called the RAMB II, shown in Figure 1.
(For more on this motherboard, see my
RAMB II tutorial.)
The method I'll describe for connecting the LCD to the BX-24 will work for any RAMB motherboard,
but it uses up one of the BX-24's A-to-D pins. Usually this is not a problem
unless your application makes use of a lot of
sensors. (If you have the RAMB II you can also use pins dedicated for serial communication.
In this tutorial, however, I will only describe how to connect the LCD to one of the I/O pins
since this method works for all motherboards. If you need help using the RAMB II's dedicated
serial pins, email me.)
The LCD requires a minimum of 3 wires connecting it to the motherboard. I prefer to
make the connection with a cable that has a 3-wire connector on each end, as shown in Figure 2.
Each wire performs a specific
task:
- One wire (preferably the darkest) is used to supply a ground connection to the LCD panel.
- Another wire (usually red or orange) is used to supply +5V to the LCD panel.
- And the third wire (preferably the lightest) is used to send serial commands from
the BX-24 to the LCD.
The LCD must be powered with a 5V source, so be sure to use the RAMB's regulated power for
this purpose. The RAMB motherboards deliver regulated power via pins 8-15. (Since RAMB pins
8-15 correspond to BX-24 A-to-D pins 13-20, we lose access to one of the A-to-D channels if we
use a 3-conductor cable.)
Before connecting any wires to our motherboard, make sure the power switch to the RAMB
is turned off. (Or, if you are using a RAMB II, make sure both power switches are turned off.)
This will keep us from damaging the LCD before we've had a chance to double-check our connections.
Let's now connect the ground, power, and signal pins of the LCD to the appropriate pins
on the RAMB. Figure 3 shows the underside of the LCD. We are specifically interested
in the set of male pins (see Figure 4) located in one corner of the back panel.
The pin labeled GND
is the ground pin and should be connected to a ground pin on the RAMB. The pin labeled
+5 is the power pin and should be connected to a regulated 5V pin on the RAMB.
The pin labeled Rx (short for receive) is the signal pin and should be connected
to one of the BX-24's I/O pin via the RAMB. Figure 5 shows a 3-conductor cable
attached to these LCD pins. Figure 6 shows that the other end of the cable is
attached to pin 15 on the RAMB, which corresponds to pin 20 on the BX-24. Because the
LCD panel must be powered with 5V, I can use any one of the RAMB pins 8-15; my choice
of using pin 20 was completely arbitrary.
The LCD's Backlight
NetMedia's LCD display can be back-lit, as shown in Figure 7, making the text on the
LCD screen much easier to read. An additional wire is required if you wish to power the
Backlight, which operates on DC voltages ranging from 5-12V. With the Backlight at full
brightness, the LCD panel consumes 150mA. (Without the Backlight, the LCD only consumes
15mA of current.) I use a single wire with two female end connectors (see Figure 8)
to connect the LCD's Backlight pin to the RAMB. Figure 9 shows this wire
(plus the 3-wire cable) connected
to the LCD's Backlight pin, which is labeled LEDSV+ on the underside of the LCD panel.
Since the Backlight operates on voltages between 5V and 12V, it does not matter which side of
the RAMB we use to power the light. From Figure 10, we see that I have chosen to power the
Backlight with pin 7 on the RAMB. (If you are using the RAMB II, you will be able to manually
turn off the Backlight simply by turning the Secondary ("Sub") switch to off.)
Before preceding, double-check your connections. Make sure your wires look like mine
as shown in Figures 6, 9, and 10.
If you power up the motherboard, don't expect the LCD panel does not come to life -- it
won't! We must first create LCD queues and
initialize the LCD.
|
Click on the images below to enlarge them.

Figure 1. The RAMB II Motherboard.

Figure 2. A 3-conductor cable for connecting the LCD to the RAMB.

Figure 3. The back side of the LCD panel.

Figure 4. The LCD's male connector pins.

Figure 5. The 3-conductor cable is attached to the LCD's ground, power and signal pins.

Figure 6. The 3-conductor cable is connected to RAMB pin 15 (BX-24 pin 20).

Figure 7. With the Backlight on, messages are easy to read.

Figure 8. A single wire is all that is needed to power the LCD's Backlight.

Figure 9. The Backlight wire is connected to the LEDSV+ pin on the LCD.

Figure 10. Here, the Backlight is powered with unregulated power from RAMB pin 7.
|
[Return to the top.]
Creating the LCD Queues
The way that we communicate with the LCD is via "queues". A queue is a block of memory used to store data.
For our purposes, we will open a COM port (COM3) to send and receive data stored in queues.
Queues are created from data arrays. The data in these arrays must be of the Byte data type.
NetMedia's LCD panel requires the creation of two queues: one for sending and one for receiving data.
So, let's first create two arrays and name them "Com3In" and "Com3Out":
Dim Com3In(1 to 15) as Byte ' Create the Com3In array
Dim Com3Out(1 to 40) as Byte ' Create the Com3Out array
(There's no need to enter any code at this time -- just study it for now.) Notice that the size of the
Com3In array is 15 bytes and Com3Out is 40 bytes.
To create the two queues from these data arrays, we will use the OpenQueue
procedure, whose syntax is
Call OpenQueue(Queue, Size)
where Queue is the name of the queue's data array, and
Size is the queue's size. (Note that the creation of the
queue requires 9 bytes of overhead.) Therefore, we would type the following to create two queues
of 15 and 40 bytes:
Call OpenQueue(Com3In, 15) ' Create the Com3In queue
Call OpenQueue(Com3Out, 40) ' Create the Com3Out queue
[Return to the top.]
Initializing the LCD
Now that the queues have been established, let's define and open a COM3 port. To do this, we'll need to
use two procedures: DefineCom3 and OpenCom.
DefineCom3 must be called before OpenCom is used.
The syntax for DefineCom3 is as follows:
Call DefineCom3(InputPin, OutputPin, ParameterMask)
where InputPin is the BX-24's pin number with which we will
receive information from the external device,
OutputPin is the BX-24's pin number with which we will
transmit information to the external device, and
ParameterMask is a set of bits that sets the communication
parameters between the BX-24 and the LCD display.
- Since we will not receive any data from the LCD panel (it is, after all, a passive device), we will
set the value of the InputPin to 0 (zero).
This is known as a "dummy pin".
- Recall that we plugged the LCD's signal pin into the BX-24 pin 20 (RAMB pin 15) -- see
Figure 6 to refresh your memory. Therefore, we'll set the value of the
OutputPin to 20.
- NetMedia's LCD panel requires the following communication parameters: inverted logic, no parity,
and 8 data bits. The bit pattern for these parameters is 10001000, as described by BasicX's
System Library documentation. (The documentation can be bundled with the BasicX software from
NetMedia's download site.) Therefore, we'll set the
ParameterMask
as the pre-defined constant, bx1000_1000.
We would then type the following to set up the BX-24 to transmit serial data
via BX-24 pin 20 with inverted logic, no parity, and 8 data bits:
Call DefineCom3(0, 20, bx1000_1000) ' Define Com3 parameters
It is often helpful to define constants to make your code more readable and more easily altered. To this
end, we can create a constant named LCDOutputPin, and incorporate it into our code like this:
Const LCDOutputPin as Byte = 20 ' RAMB 15
Call DefineCom3(0, LCDOutputPin, bx1000_1000) ' Define Com3 parameters
Let's now examine how to use the OpenCom procedure, which initializes a serial
port on the BX-24. The syntax for OpenCom is as follows:
Call OpenCom(PortNumber, BaudRate, InputQueue, OutputQueue)
where PortNumber is the number of the port,
BaudRate is the rate at which data is transmitted,
InputQueue is the queue for incoming data, and
OutputQueue is the queue for outgoing data.
- For our application, we'll set the PortNumber to 3.
- The baud rate for NetMedia's LCD display can be altered with a jumper labeled J1 on the
underside of the LCD panel. The default setting is 9600 bps (J1 = On), so we will set the
BaudRate to 9600.
(See NetMedia's LCD
documentation for more information on this jumper.)
- We'll set the InputQueue to Com3In. Recall that
this queue was created with the OpenQueue procedure described above.)
- We'll set the OutputQueue to Com3Out. Recall that
this queue was created with the OpenQueue procedure described above.)
It is my experience that a small delay of about 0.7s should be placed after OpenCom
is called to allow the LCD sufficient time to power up. Therefore, we would initialize our
LCD's COM port with code like this:
Call OpenCom(3, 9600, Com3In, Com3Out) ' Inititalize Com3
Call Delay(0.7) ' Allow LCD time to power up
[Return to the top.]
Outputting Text to the LCD
We will use the PutQueueStr procedure to send messages to the LCD screen.
This procedure sends a String to a specified queue with the following syntax:
Call PutQueueStr(Queue, MyString)
where Queue is the name of the queue into which the
MyString will be written. As the name implies,
MyString must be a String data type.
- For our application, we'll set Queue equal to
Com3Out because this is the queue contains the data that will be output to the LCD screen.
- To display any text message to the LCD, replace MyString
with any String.
- As always, String literals must be surrounded by quotes.
- Numeric data can be converted to a String with the CStr
function.
- ASCII characters can be converted to a String with the Chr
function.
Therefore, to print the phrase, "Hello World!" to the LCD screen, we would enter:
Call PutQueueStr(Com3Out, "Hello World!")
This might appear as:

Figure 11. "Hello World!" is displayed.
[Return to the top.]
LCD Control Codes
We can control the output of the LCD screen using so-called Control Codes. While there are nearly
20 such codes, I will explain only four of them in this tutorial. Namely, these codes will clear the LCD screen,
set the cursor position on the LCD screen, control the contrast of the screen, and control the
brightness of the Backlight (if used).
Controlling the LCD to do one of these tasks is not difficult -- all you have to
do is send an ASCII code to a specified queue with the
PutQueueStr command. Recall that PutQueueStr sends
only Strings to the queue (Com3Out in our case). Therefore, we must convert the ASCII Control Code
to a String with the Chr function.
It will prove helpful to define constants for each of the Control Codes that we want to use.
(Of course, this is done with the Const statement!) Here is a table
of ASCII Control Codes, their descriptions, and the user-defined constants that we'll incorporate in our code:
| Table 1. Common LCD Control Codes |
| ASCII Value |
Description |
User-defined Constant |
| 12 |
Clear the LCD Screen |
CLear_LCD |
| 17 |
Set the Cursor Position |
Set_Cursor |
| 19 |
Set the Contrast Level |
Contrast |
| 20 |
Set the Backlight Brightness |
Backlight |
When examining the code snippets below, assume that the user-defined constants
listed in Table 1 have already been created with the Const statement.
For example:
Const Clear_LCD as Byte = 12 ' Control Code 12 Clears the LCD
Below, I show how to use four of the most common LCD Control Codes:
- ASCII 12: Clearing the LCD Screen
To clear the LCD screen, simply enter the line:
' Clear the LCD Screen using raw ASCII code
Call PutQueueStr(Com3Out, 12)
Or, we can make use of our user-defined constants and make the code a bit easier to decipher
like so:
' Clear the LCD Screen with user-defined constant
Call PutQueueStr(Com3Out, Chr(Clear_LCD))
The above two lines of code perform identical tasks, but I find the latter one easier to read.
Use this code any time you wish to wipe the LCD screen clear.
- ASCII 17: Setting the Cursor Position
This ASCII command must be followed by two additional bytes to give the row number and column number
of the desired cursor position. (Use the concatenation operator to join the numbers into one String.)
These row and column numbers start with 0 (zero), so the Row number can be 0 or 1, and the Column
number can be 0-15. For example, to set the cursor to the top-left corner of the screen, you'd enter:
' Move the cursor to the top-left corner of screen (Row 0, Column 0)
Call PutQueueStr(Com3Out, Chr(Set_Cursor) & Chr(0) & Chr(0))
Say, you wanted to display the letter "X" in the bottom-right corner of the screen. (Why
anyone would want to do this is beyond me!) At any rate, to accomplish this, you might first
clear the screen, then set the cursor position, and finally print the "X" like so:
' Print "X" in the bottom-right corner of screen (Row 1, Column 15)
Call PutQueueStr(Com3Out, Chr(Clear_LCD))
Call PutQueueStr(Com3Out, Chr(Set_Cursor) & Chr(1) & Chr(15))
Call PutQueueStr(Com3Out, "X")

Figure 12. "X" is displayed in the bottom-right corner of the LCD screen.
- ASCII 19: Setting the Contrast Level
It is often necessary to adjust the contrast of the LCD. The ASCII contrast command must be
followed by an additional byte to give the give the level of contrast. (Use the concatenation
operator to join the contrast number to the ASCII command as one String.) Since the contrast level is given as
a Byte, the range of values is 0-255, with 0 indicating the highest contrast and 255 the lowest.
Therefore, to set the LCD's contrast to the highest level, enter this code:
' The LCD display is set to maximum contrast
Call PutQueueStr(Com3Out, Chr(Contrast) & Chr(0))
The following images show three contrast levels: 0, 125, and 255 from left-to-right. (Incidentally,
the Backlight is operating at full brightness in these images.)
Click on the images to enlarge them.

Figure 13. The contrast level = 0.
|

Figure 14. The contrast level = 125.
|

Figure 15. The contrast level = 255.
|
- ASCII 20: Setting the Backlight Brightness (if used)
If you have chosen to power-up your LCD's Backlight (as described above),
you can control the brightness of the Backlight. This is very similar to
controlling the contrast, as described above.
The ASCII Backlight brightness command must be
followed by an additional byte to give the give the brightness level. (Use the concatenation
operator to join the brightness number to the ASCII command as one String.) Since the brightness
level is given as a Byte, the range of values is 0-255, with 0 indicating no light and 255
indicating the brightest light possible. Therefore, to set the LCD's Backlight to the highest
level, enter this code:
' The LCD's Backlight is set to the highest level
Call PutQueueStr(Com3Out, Chr(Backlight) & Chr(255))
The following images show three brightness levels: 0, 125, and 255 from left-to-right. (Incidentally,
the LCD is operating at the hightest contrast level in these images.)
Click on the images to enlarge them.

Figure 16. The brightness level = 0.
|

Figure 17. The brightness level = 125.
|

Figure 18. The brightness level = 255.
|
It is important to remember that when the Backlight is operated at full brightness, the LCD panel consumes 150mA.
Without the Backlight, the LCD only consumes 15mA of current, causing the battery to last much longer.
In a very bright environment the Backlight may not be necessary, but it certainly
is useful in a poorly lit room. Here's a great idea for a BX-24 application you might
wish to create: With a photoresistor or other light sensor, continually monitor the ambient
light and adjust the LCD's brightness accordingly.
These are just a few of the control codes for NetMedia's LCD panel. Other codes can be used for
such things as displaying custom characters, displaying ASCII characters, backspacing, and setting the tab
spacing. The entire list of LCD codes can be found on NetMedia's website. (You can
open the document here
and turn to page 4 to learn more.)
[Return to the top.]
Putting It All Together: Creating a Simple LCD Application
Now that we understand the basics of LCD programming, let's build a simple application and put to use
our newfound knowledge. Double-check that the LCD cables are connected as described
above. Then create a new BasicX application named "LCDSimple"
and enter the following code. (You can also view or download this code from the actual files
from the top of this page, or take a sneak-peek at a short video illustrating
what this program does.)
' LCDSimple.bas
' A simple application to print text and numbers to NetMedia's 2x16 LCD screen.
Public Sub Main()
Dim i as Integer
' Pin Constants
Const LCDOutputPin as Byte = 20 ' RAMB 15
' LCD Control Constants
' The following are ASCII codes sent to the LCD. These are NOT pin numbers!
Const Clear_LCD as Byte = 12
Const Set_Cursor as Byte = 17
Const Contrast as Byte = 19
Const BackLight as Byte = 20 ' Power Backlight with any RAMB power pin
' Open the COM 3 Port
Dim Com3In(1 to 15) as Byte ' Create an input data array
Dim Com3Out(1 to 40) as Byte ' Create an output data array
Call OpenQueue(Com3In, 15) ' Create an input queue
Call OpenQueue(Com3Out, 40) ' Create an output queue
Call DefineCom3(0, LCDOutputPin, bx1000_1000) ' Define Com3 parameters
Call OpenCom(3, 9600, Com3In, Com3Out) ' Inititalize Com3 port
Call Delay(0.7) ' Allow the LCD time to power up
Set the LCD's Contrast and Backlight Levels
Call PutQueueStr(Com3Out, Chr(Contrast) & Chr(0)) ' 0 = Dim, 255 = Bright
Call PutQueueStr(Com3Out, Chr(BackLight) & Chr(125)) ' 0 = High, 255 = Low
' Clear the LCD screen, and print "Hello World" to the LCD.
Call PutQueueStr(Com3Out, Chr(Clear_LCD))
Call PutQueueStr(Com3Out, "Hello World!")
Call Delay(3.0) ' Delay to read message
' Clear the LCD screen and print a second message.
Call PutQueueStr(Com3Out, Chr(Clear_LCD))
Call PutQueueStr(Com3Out, Chr(Set_Cursor) & Chr(0) & Chr(3)) ' Row 0, Col 3
Call PutQueueStr(Com3Out, "It is good")
Call PutQueueStr(Com3Out, Chr(Set_Cursor) & Chr(1) & Chr(2)) ' Row 1, Col 2
Call PutQueueStr(Com3Out, "to be alive")
Call Delay(2.0) ' Delay to read message
' Clear the LCD screen and print a third message.
Call PutQueueStr(Com3Out, Chr(Clear_LCD))
Call PutQueueStr(Com3Out, Chr(Set_Cursor) & Chr(0) & Chr(0))
Call PutQueueStr(Com3Out, "Testing...")
For i = 0 to 4
Call PutQueueStr(Com3Out, Chr(Set_Cursor) & Chr(1) & Chr(i*3))
Call PutQueueStr(Com3Out, CStr(i+1) & ",")
Call Delay(1.0)
Next
' Say good-bye.
Call PutQueueStr(Com3Out, Chr(Clear_LCD))
Call PutQueueStr(Com3Out, Chr(Set_Cursor) & Chr(0) & Chr(5))
Call PutQueueStr(Com3Out, "The")
Call PutQueueStr(Com3Out, Chr(Set_Cursor) & Chr(1) & Chr(8))
Call PutQueueStr(Com3Out, "End")
End Sub
Compile and run the code. If you are using the RAMB II motherboard, be sure to also turn on the
Secondary ("Sub") power switch -- otherwise, the Backlight will not be powered. Your LCD panel should
mimic mine, as shown in the short video below.
[Return to the top.]
Creating an Advanced LCD Application
I have created an advanced LCD application that is a bit more involved than the
simple application described above. While this application is meant
to serve as a tutorial, it is a more complex piece of code in that it utilizes string manipulation,
subprograms, and parameter passing, and it displays real-time data with an attached sensor.
This application even shows how to scroll text across the LCD screen and how to animate simple
graphics. Take a sneak-peek at a short video illustrating what this program does.
As far as the sensor is concerned, it doesn't matter what sensor you use.
I elected to use a Sharp infrared range finder (see Figure 19 below), but you could use
any sensor you want. For consistency's sake, however, you should follow my lead and connect your sensor
to RAMB pin 8 (BX-24 pin 13) as shown in Figure 20. The advanced program concludes by displaying the
sensor's data to the LCD screen in real-time, shown in Figure 21, below.

Figure 19. The Sharp IR Range Finder in a Robodyssey Sensor Bracket.
|

Figure 20. The Range Finder is plugged into RAMB pin 8 (BX-24 pin 13).
|

Figure 21. The sensor's raw data is displayed on the LCD.
|
Double-check that the LCD cables are connected as described
above. Also, verify that your sensor is properly connected to RAMB pin 8
(BX-24 pin 13), as shown in Figure 20. Next, create a new BasicX application named "LCDAdvanced".
Due to space considerations, I will not print-out the code for my Advanced LCD application on this page.
However, you can download or view my code here:
Somehow, get my code from the above table into your "LCDAdvanced" project.
When that's done, compile and run the code. If you are using the RAMB II motherboard, be sure to
also turn on the Secondary ("Sub") power switch -- otherwise, the Backlight will not be powered.
Your LCD panel should mimic mine, as shown in these short videos.
[Return to the top.]
Using My LCD Module
One of the easiest ways to add LCD functionality to your BasicX applications is to use my
LCD module. A module is a file that contains procedures and functions that usually perform
one type of tasks. A module can be thought of as a library file. For example, when my students
created their firefighting robot, Thor, they seperated all their code into well-defined modules. One of
their modules contained all their global variables and constants; in another module was the code for all
the robot motion; and in another was the code that dealt with locating and extinguishing the fire.
Seperating code one's code like this into distinct library files is known as modular programming
and is one the niceties of the BasicX language.
Take a look at my LCD module
by clicking here.
Notice the code looks just like any other application with lots of subprograms,
however there is no Main procedure in the LCD module.
This means that the LCD module file cannot stand alone
and must be used in conjunction with another module that contains the
Main procedure.
(Each project can have only one Main procedure.)
LCDModule.bas will allow you to do the following:
- Initialize the LCD screen by simply typing: Call InitLCD().
- Display a one-line message with the Display procedure.
- Display a two-line message with the Display2Lines procedure.
- Display an integer value with the DisplayInt procedure.
- Display a single (floating point) value with the DisplaySng procedure.
- Display two single (floating point) values with the Display2Sng procedure.
Of course, you can add your own code to this module as needed.
Incorporating my LCD procedure into your programs is easy. Super easy, actually. Here's all you need to do:
- Download my LCD module (named LCDModule.bas) to your computer by
clicking here. Some people like to put the LCD module in each of
their application folders that use the LCD screen. Others like to store it in one
dedicated folder entitled something like "LCD Module" and simply use this one file as needed.
It's your choice.
- Now add the LCDModule file to your current application. To do this select Project >> Files
from the BasicX Editor's menu. Then press the Add File button. When you've located the
LCDModule.bas file, press the Open button. Your dialog box should look something like this:
- Press OK at add the LCDModule.bas file to your application. Your editor will now show
two modules: your original module and the LCD module. You can easily access both modules
by clicking on the tabs shown below:
- You may need to alter a few constants given at the top of the LCDModule code. Specifically,
verify that your LCD I/O cable is connected to the same output pin given by the
LCDOutPutPin constant. (I have mine set up to use BX-24 pin 20 (RAMB pin 15).)
You may also wish to adjust the BackLiteBrightness and
ContrastLevel constants to suit your particular lighting conditions.
- Now return to your main module (mine is called "Sensors") and let's add some code that will allow us
to use the LCD screen. For example, let's say I want to print the message "Infrared Ranger" to two
lines of the LCD screen for two seconds, and then continually display the value of an
infrared ranger attached
to BX-24 pin 13 (RAMB pin 8). Here's the code to do it:
Simple, huh?
Notice I initialized the LCD first. Also notice that I used the
DisplayInt procedure because GetADC
returns an Integer data type.
IF you want this application, download it below!
(The files are compressed in a folder entitled "Sensors and LCD".)
[Return to the top.]
|
|
I'd sure like to hear from you.
If you find my tutorial helpful or if you would like
to leave a comment,
please send me an email.
|
|
|
|