LCDOUT command with PicBasic Pro
Providing an interface for
user data entry, terminal displays, and even using them to debug your
applications during development is a must for any design.
Controlling an LCD using PicBasic is so incredibly simple that even the
casual hobbyist can now fully integrate an LCD display into a new design
with an absolute minimum of effort, and code requirements. Below is
the schematic, and simple PicBasic code to control the LCD module.
Display Items on an intelligent Liquid
Crystal Display. PBP supports LCD modules with a Hitachi 44780 controller
or equivalent. These LCDs usually have a 14- or 16-pin single- or dual-row
header at one edge.
If a pound sign (#) precedes an
Item, the ASCII representation for each digit is sent to the LCD. LCDOUT
can also use any of the modifiers used with SEROUT2. See the
section on SEROUT2 for this information.
A program should wait for at least half a
second before sending the first command to an LCD. It can take quite a
while for an LCD to start up.
Commands are sent to the LCD by sending a
$FE followed by the command. Some useful commands are listed in the
||Return home (beginning
of first line)
||Underline cursor on
||Blinking cursor on
||Move cursor left one
||Move cursor right one
||Move cursor to beginning
of second line
Note that there is a command to move the
cursor to the beginning of the second line of a 2-line display. For most
LCDs, the displayed characters and lines are not consecutive in display
memory - there can be a break in between locations. For most 16x2
displays, the first line starts at $0 and the second line starts at $40.
sets the display to start writing
characters at the beginning of the second line. 16x1 displays are usually
formatted as 8x2 displays with a break between the memory locations for
the first and second 8 characters. 4-line displays also have a mixed up
See the data sheet for the particular LCD
device for the character memory locations and additional commands..
1, "Hello" Clear display and show "Hello"
The LCD may be connected to the PICmicro
using either a 4-bit bus or an 8-bit bus. If an 8-bit bus is used, all 8
bits must be on one port. If a 4-bit bus is used, it must be connected to
either the bottom 4 or top 4 bits of one port. Enable and Register Select
may be connected to any port pin. R/W should be tied to ground as the LCDOUT
command is write only.
PBP assumes the LCD is connected to
specific pins unless told otherwise. It assumes the LCD will be used with
a 4-bit bus with data lines DB4 - DB7 connected to PICmicro PORTA.0 -
PORTA.3, Register Select to PORTA.4 and Enable to PORTB.3. It's also
preset to initialize the LCD to a 2 line display.
That's it....! Now try
the same thing in assembly language, and you'll quickly begin to
understand the real power & time savings you'll
experience when you use PicBasic.
Looks pretty darn simple
doesn't it..? That's because PicBasic takes care of all the details
for controlling the LCD for you.
Notice the spare I/O-pins
left over on the PIC16F84..? You have seven I/O-pins left to control
additional circuitry, and if you're even just a little creative here you
can design your very own Serial LCDs' at a fraction of the cost of
purchasing them off the shelf..
Using the simple serin
command in PicBasic you can receive serial data on any I/O-pin with the
PIC16F84 controlling your LCD, and very easily create your own serial LCDs'.