|
DAN128
Build a Serial LCD
By Michael
Simpson
You can build a very fast
and functional serial LCD using just the Dios. The default baud rate is
9600 but you can set it to just about any thing you want. See the
hsersetup command.

Dios Carrier 4
The hookup is simple.
You can change the LCD control pins if you wish. Just remember to change
the LCDinit function. Also your LCD may need to have a contrast trimmer
or backlight connection.
We will only be using one
pin to connect to the serial LCD. If you need to transmit data from the
serial LCD to the microcontroller. You will need to connect P8 as well.
Dios Ultra Notes
After Programming the Dios
Ultra You can change the RS232 Jumpers. This will allow you to
connect RS232 Level data into the 9 pin programming port.
The Program
(Download it here)
'This program will turn
the Dios into a serial LCD.
func main()
dim inchar as integer
dim cmd as integer
'Dios Ultra
LCDinit(23,25,24,29,28,27,26) 'RS, E, RW, D0,D1,D2,D3
LCDcls()
LCDcharxy(1,1,"Kronos Robotics")
LCDcharxy(2,1,"Serial LCD v1.0")
pause 1000
LCDcls()
hsersetup baud,HBAUD9600,start
cmd = 0
mainloop:
hserin mainloop,inchar
branch cmd,cmd0,line1,line2,line3,line4,control,raw
'----------------------------------
'Fall through point
'----------------------------------
cmd0:
if inchar < 7 then
cmd = inchar
goto mainloop
endif
LCDraw(inchar)
goto mainloop
'---------------------------------
'1,x Select character on line 1
'---------------------------------
line1:
LCDgoto(1,inchar)
cmd = 0
goto mainloop
'---------------------------------
'2,x Select character on line 2
'---------------------------------
line2:
LCDgoto(2,inchar)
cmd = 0
goto mainloop
'---------------------------------
'3,x Select character on line 3
'---------------------------------
line3:
'Reserverd for future use
'---------------------------------
'4,x Select character on line 4
'---------------------------------
line4:
'Reserverd for future use
'---------------------------------
'5,x Send LCD control codes
'---------------------------------
control:
LCDcontrol(inchar)
cmd = 0
goto mainloop
'---------------------------------
'6,x Send characters 0-6
'---------------------------------
raw:
print "raw =",inchar
LCDraw(inchar)
cmd = 0
goto mainloop
endfunc
include \lib\DiosLCD.lib
The program uses the
interrupt driven UART in the Dios. All the work is done behind the
scenes so you don't have the mess with the details. The Dios is set up
with a 256 byte buffer. So it can take quite a bit serial
pounding.
The hserin command just
checks the buffer for any characters. If no characters are in the buffer
the command jumps to the mainloop.
If a character is received
the hserin command falls through so you can process the character.
The program uses a state
machine to keep track of the current state command state. The actual
state is stored in the variable cmd. When a character is received we
branch to the correct handler to process the data. If we are in state 0
then we set the correct state if its 1-6 and continue on.
| Byte 1 |
Byte 2 |
Description |
| 1 |
x |
Sets the character
position to line1 column x |
| 2 |
x |
Sets the character
position to line 2 column x |
| 3 |
x |
Reserved |
| 4 |
x |
Reserved |
| 5 |
x |
Send LCD control byte
to LCD |
| 6 |
x |
Allows you to send
characters 0-6 to the LCD |
| All others |
|
Sends characters to
LCD |
Some code examples for
sending to the Serial LCD.
serout IOpin,1,1,"Hello
World"
serout IOpin,5,1
'Clear the LCD
There is a lot of room for
expansion in the program. Here are a couple of ideas.
-
Add counter to main loop
that resets then state to 0 if threshold is reached.
-
Add Analog to digital
ports
-
Add button or keyboard
interface
-
Add ability to change baud
rate. Current baud rate is 9600.
-
Add the ability to set
line positions 3 and 4 for 4 line LCD.
Test Programs
here is a test program
that will test most aspects of the Serial LCD. This will show you the
kind of Dios commands needed to communicate with the Serial LCD
Get it here
Here is the same program
with all the pause statements removed so that you can see what kind of speeds
you can get out of this serial LCD.
Get it here
Parts
list
DiosPro 40 Pin Chip
Dios Workboard
Deluxe
Easy RS232 Driver
DiosPro 28 Pin Chip
Dios 32 Pin Carrier
(Carrier #1)
9 Pin Cable
Breadboard Regulator
|