' LCD SERIE picaxe 20X2 06/08/12 MM
' Emulates basic serial operation of the popular AXE033 module
'
' Display Line 16 20 car/line
' Line 1: 128- 143 147
' Line 2: 192- 207 211
' Line 3: 144- 159 163
' Line 4: 208- 223 227
' Supported Commands
' 0-7, 8-15 CGRAM characters
' 16-252 normal ASCII characters, according to selected character map table
' 253, X display 16 character pre-saved message from EEPROM memory, X can be 0-15
' 254, X LCD command, X can be 0 to 255
' 255, X control outputs C.3,C.4,C.5et C.7 (from function bit X)
' Ex; X= %00010000 le port C.4 = 1 (5v)
' LCD data pins are on B.0 to B.7
' Please remember 4 line displays always use the strange 1-3-2-4 layout.
setfreq M64
#no_data
#no_table
symbol line_length = 20 ' replace by 20 = LCD 20 caract?res
'symbol baud = N4800_32 ' 32MHz est N4800_XX baud use : pulsout enable,2
symbol baud = N9600_64 ' 64MHz est N9600_XX baud use : pulsout enable,2
'symbol baud = N19200_64 ' 64MHz est N9600_64 baud use : pulsout enable,2
symbol RX = C.0 ' serial receive pin
symbol enable = C.2 ' LCD enable
symbol rs = C.1 ' LCD RS
'initialise LCD
init:
gosub LCD_init ' initialise LCD
main:
serin RX,baud,b1 ' wait for the next byte
' NB keep character mode test as first item in this list to optimise speed
if b1 < 253 then ' Char
pinsB = b1 ' output the data
pulsout enable,2 ' pulse the enable pin to send data.
goto main ' quickly loop back to top
else if b1 = 254 then ' command to excecute
low rs ' rs command mode
serin RX,baud,b1 ' wait command byte
pinsB = b1 ' output the data
pulsout enable,2 ' validation
high rs ' RS mode
goto main ' quickly loop back to top
else if b1 = 253 then ' EEPROM message
serin RX,baud,b1 ' wait for the next byte
;gosub msg ' do the 16 character message
goto main ' back to top
else ' 255 not in use
serin RX,baud,b1 ' wait for the next byte
pinsC =b1 & %10111000 |%00000010 ' Port : C.3; C.4; C.5; C.7
' RS (C.2)
goto main ' back to top
end if
'**********************************************************************
; power on LCD initialisation sub routine
LCD_init:
dirsC = %10111110 ; PortC C.6 C.0 In
dirsB = %11111111 ; PortB all outputs
; Standard LCD Module Initialisation
pause 15 ' Wait 15ms for LCD to reset.
pinsB = %00110000 ' 8 bit, 2 line
' Send data by pulsing enable
pause 5 ' Wait 5 ms 4800 baud
pulsout enable,1 ' Send data 48 again
pulsout enable,1 ' Send data 48 again
setfreq m64 ' now change to 16Mhz
pinsB = %00111000 ' LCD - 8 bit, 2 line, 5x8
pulsout enable,1
pinsB = %00000001 ' Clear Display
pulsout enable,1
pause 8 ' 8 = 2ms at 16MHz 4800 baud
pinsB = %00000010 ' return home
pulsout enable,1
pinsB = %00000110 ' Entry mode
pulsout enable,1
pause 1 ' 4800 baud
pinsB = %00001100 ' Display on, no cursor, no blink
pulsout enable,1
high rs ' Leave in character mode
return