Symbol N = B2
Symbol OWord = W0
Symbol OByte = B3
' These variables are used in Sub BarDemo
Symbol NN = B8
Symbol LeftOver = B9
Symbol Num_5 = B10
Symbol J = B11
' These variables are used in Sub SerOutByteHex
Symbol X = B8
' Variables used in PWMDemo
Symbol Duty = B9
High 0 ' Be sure Tx Pin is idle for some time
Pause 5000 ' wait for PICAXE LCD to boot
' next is only done once
SerOut 0, T2400, ("?G420") ' configure LCD as 4 X 20
'Clear the screen
SerOut 0, T2400, ("?f") ' clear the LCD
Pause 2000
'Clear the screen
SerOut 0, T2400, ("?f") ' clear the LCD
' SerOut 0, T2400, ("?B00") ' set PWM to 0
SEROUT 0, T2400, ("?B40") ' set backlight to 40 hex
PAUSE 200 ' pause to allow LCD EEPROM to program
SerOut 0, T2400, ("?f") ' clear the LCD and home the cursor
Pause 100
SerOut 0, T2400, ( " PICAXE LCD?n") ' note new line
Pause 2000
SerOut 0, T2400, ("?0?1?2?3?4?5?6?7?n") ' display special characters
Pause 2000 ' pause to admire
SerOut 0, T2400, ("?y1?x00") ' position cursor at beginning of row 1
SerOut 0, T2400, ("?l?j?l?j?l?y1") ' clear lines 1, 2 and 3 and start at line 1
' note the use of down cursor command
OWord = 12345
For N = 0 to 25
SerOut 0, T2400, ("?x00?y1") ' locate cursor to beginning of line 1
SerOut 0, T2400, (#N) ' display in decimal
SerOut 0, T2400, ("?t")
OByte = N
GoSub SerOutByteHex ' display in hex
SerOut 0, T2400, ("?t")
SerOut 0, T2400, (#OWord, "?t") ' display a word in decimal
GoSub SerOutWordHex ' and in hex
SerOut 0, T2400, ("?n")
OWord = OWord + 1
' cj SerOut 0, T2400, ("?g") ' beep
Pause 1000
Next
'cj
SEROUT 0, T2400, ("?B40") ' set backlight to 40 hex
PAUSE 200 ' pause to allow LCD EEPROM to program
pause 2000
SerOut 0, T2400, ("?D00000000000000000") ' define special characters
Pause 200 ' delay to allow EEPROM to program
SerOut 0, T2400, ("?D11010101010101010")
Pause 200
SerOut 0, T2400, ("?D21818181818181818")
Pause 200
SerOut 0, T2400, ("?D31c1c1c1c1c1c1c1c")
Pause 200
SerOut 0, T2400, ("?D41e1e1e1e1e1e1e1e")
Pause 200
SerOut 0, T2400, ("?D51f1f1f1f1f1f1f1f")
Pause 200
SerOut 0, T2400, ("?c0") ' no cursor
SerOut 0, T2400, ("?y3?x00?l") ' cursor to beginning of line 3 and clear line
GoSub BarDemo
Pause 200
GoSub PWMDemo
Pause 200
' cj
SerOut 0, T2400, ("?f") ' clear the LCD
SEROUT 0, T2400, ("?B40") ' set backlight to 40 hex
PAUSE 200 ' pause to allow LCD EEPROM to program
pause 2000
AGAIN:
for n = 1 to 20 ' continually bring outputs 5 and 4 high and low
SerOut 0, T2400, ("?H5?L4")
SerOut 0, T2400, (".")
Pause 500
SerOut 0, T2400, ("?L5?H4")
SerOut 0, T2400, ("!")
Pause 500
' GoTo AGAIN ' cj took out
next
SerOut 0, T2400, ("?f") ' clear the LCD
SEROUT 0, T2400, ("?B40") ' set backlight to 40 hex
PAUSE 200 ' pause to allow LCD EEPROM to program
' =====================================================================
BarDemo:
'cj
SEROUT 0, T2400, ("?B40") ' set backlight to 40 hex
PAUSE 200 ' pause to allow LCD EEPROM to program
For N = 0 to 25 ' increasing bar
SerOut 0, T2400, ("?y3?x00")
NN = 4 * N
Num_5 = NN / 5
LeftOver = NN % 5
For J = 1 to Num_5
SerOut 0, T2400, ("?5")
Next
LeftOver = LeftOver + 48 ' convert to a character
SerOut 0, T2400, ("?", LeftOver)
Next
For N = 0 to 25 ' decreasing bar
SerOut 0, T2400, ("?y3?x00?l")
NN = 4 * N
NN = 100 - NN
Num_5 = NN / 5
LeftOver = NN % 5
For J = 1 to Num_5
SerOut 0, T2400, ("?5")
Next
LeftOver = LeftOver + 48 ' convert to a character
SerOut 0, T2400, ("?", LeftOver)
Next
pause 2000
Return
PWMDemo:
SEROUT 0, T2400, ("?B40") ' set backlight to 40 hex
PAUSE 200 ' pause to allow LCD EEPROM to program
SerOut 0, T2400, ("?f") ' clear the LCD
SerOut 0, T2400, (" PWM Duty Demo?n")
For N = 0 to 25
Duty = 10 * N
SerOut 0, T2400, ("?l")
OByte = Duty
GoSub SerOutByteHex ' display the PWM in hex
SerOut 0, T2400, ("?B") ' backlight control
GoSub SeroutByteHex
Pause 500
Next
SerOut 0, T2400, ("?f") ' clear the LCD
SEROUT 0, T2400, ("?B40") ' set backlight to 40 hex
PAUSE 200 ' pause to allow LCD EEPROM to program
Return
SerOutByteHex:
X = OByte / 16 ' high nibble
X = X + 48 ' add the character '0'
If X <= 57 Then SerOutByteHex_1
X = X + 7 ' it is alphabetic; A, B, C, D, E, F
SerOutByteHex_1:
SerOut 0, T2400, (X)
X = Obyte % 16 ' low nibble
X = X + 48 ' add the character '0'
If X <= 57 Then SerOutByteHex_2
X = X + 7 ' it is alphabetic; A, B, C, D, E, F
SerOutByteHex_2:
SerOut 0, T2400, (X)
Return
SerOutWordHex:
OByte = OWord / 256
GoSub SerOutByteHex
OByte = OWord % 256
GoSub SerOutByteHex
Return