This program illustrates many features of the LCD #117 command set. The language is Parallax PBASIC for the Nasic Stamp 2. However the user should be able to adapt this to any processor.
This routine was specifically written for an interface with the Emerging Technology ED10020TRU 16 X 4 LCD.
' {$STAMP BS2}
' {$PBASIC 2.5}
' LCD117_1.BS2 (Parallax Basic Stamp 2)
'
' Configured for 9600 baud, 8 bits, no parity.
'
' Basic Stamp 2 LCD #117
'
' P0 (term 5) -----------------------------------> RX (term 7)
'
'
' Sets geometry of LCD as 4X16 and clears the LCD and writes a byte in decimal
' and in hex, an integer and a word to the LCD display.
'
' Defines, special characters 0 - 5 as no vertical lines, 1 vertical line,
' 2 vertical lines etc. Displays an increasing bar and then a decreasing bar
' on line 3.
'
' Enters an infinite loop winking output 3.
'
' copyright, Peter H. Anderson, Baltimore, MD, Dec, '07
BaudMode CON 84 ' 9600 baud, non-inverted
N VAR Byte
I VAR Byte
WordVar VAR Word
ByteVar VAR Byte
NN VAR Byte
Remainder VAR Byte
Num_5 VAR Byte
DIR0 = 1 ' make P0 an output
HIGH 0 ' this is the steady state for non-inverted
PAUSE 1000 ' allow to stabilize
SEROUT 0, Baudmode, ["?G416"] ' configure LCD geometry
PAUSE 200 ' pause to allow LCD EEPROM to program
SEROUT 0, Baudmode, ["?f"] ' clear the LCD
PAUSE 200
SEROUT 0, Baudmode, [" LCD #117?n"] 'note new line
SEROUT 0, Baudmode, [" phanderson.com?n"]
SEROUT 0, Baudmode, ["?0?1?2?3?4?5?6?7?n"] ' display special characters
PAUSE 5000 ' pause five secs to admire
SEROUT 0, Baudmode, ["?y1?x00"] ' cursor at line 1, col 0
SEROUT 0, Baudmode, ["?l?j?l?j?l?y1"]' clear lines 1, 2 and 3 and start at line 1
' note use of down cursor
WordVar = 12345
ByteVar = 123
FOR N = 0 TO 25
SEROUT 0, Baudmode, ["?x00?y1"] ' locate cursor to beginning of line 1
SEROUT 0, Baudmode, [DEC N, "?t", HEX N, "?t"] ' display N in Dec and Hex
SEROUT 0, Baudmode, [DEC ByteVar, "?n"]
SEROUT 0, Baudmode, [DEC WordVar, "?n"] ' display a word
ByteVar = ByteVar + 1
WordVar = WordVar + 1
FOR I = 1 TO 4
SEROUT 0, Baudmode, ["?g"] ' beep four times
PAUSE 50
NEXT
PAUSE 500
NEXT
SEROUT 0, Baudmode, ["?D00000000000000000"] ' define special characters
PAUSE 200 ' delay to allow write to EEPROM
SEROUT 0, Baudmode, ["?D11010101010101010"]
PAUSE 200
SEROUT 0, Baudmode, ["?D21818181818181818"]
PAUSE 200
SEROUT 0, Baudmode, ["?D31c1c1c1c1c1c1c1c"]
PAUSE 200
SEROUT 0, Baudmode, ["?D41e1e1e1e1e1e1e1e"]
PAUSE 200
SEROUT 0, Baudmode, ["?D51f1f1f1f1f1f1f1f"]
PAUSE 200
SEROUT 0, Baudmode, ["?c0"] ' no cursor
PAUSE 200
SEROUT 0, Baudmode, ["?y3?x00?l"] ' cursor to beginning of line 3 and clear line
FOR N = 0 TO 20 ' increasing bar
SEROUT 0, Baudmode, ["?y3?x00"]
NN = 4 * N
Num_5 = NN / 5
Remainder = NN // 5
FOR I = 1 TO Num_5
SEROUT 0, Baudmode, 10,["?5"]
NEXT
SEROUT 0, Baudmode, 10, ["?", DEC1 Remainder]
NEXT
PAUSE 1000
FOR N = 0 TO 20 ' decreasing bar
SEROUT 0, Baudmode, ["?y3?x00?l"]
NN = 4 * N
NN = 80 - NN
Num_5 = NN / 5
Remainder = NN // 5
IF (Num_5 >= 1) THEN
FOR I = 1 TO Num_5
SEROUT 0, Baudmode, 10, ["?5"]
NEXT
ENDIF
SEROUT 0, Baudmode, 10, ["?", DEC1 Remainder]
NEXT
DO ' continually bring output 3 high and low
SEROUT 0, Baudmode, ["?H3"]
PAUSE 500
SEROUT 0, Baudmode, ["?L3"]
PAUSE 500
LOOP