#picaxe 20M2
'#terminal 4800
' hippy's generic string poking macro:
#Macro PokeString( toLoc, string )
' modified to include zero terminator
bPtr = toLoc
lookupAdr = 0
Do
Lookup lookupAdr, ( string, 0 ), lookupData
' If lookupData <> 0 Then
@bPtrInc = lookupData
lookupAdr = lookupAdr + 1
' End If
Loop Until lookupData = 0
#EndMacro
symbol stringAdrBase = $20 ' location of up to 16 offsets for strings
symbol stringBase = $30 ' location of strings
' hippy's I2C LCD with PCF8574 code, post 28:
' http://www.picaxeforum.co.uk/showthread.php?21872
' symbol b2,b3,secondNybble reserved for LCD
' b3 bits defined below
Symbol bitRS = bit24
Symbol bitWR = bit25
Symbol bitE = bit26
Symbol bitBKL = bit27
Symbol bitD4 = bit28
Symbol bitD5 = bit29
Symbol bitD6 = bit30
Symbol bitD7 = bit31
symbol secondNybble = b5 ' for LCD
symbol lookupAdr = b6 ' for PokeString Macro
symbol lookupData = b7 ' for PokeString Macro
symbol stringAdrOffset = b8 ' location of nth string address
Initialisation:
gosub InitializeLCD
stringAdrOffset = stringAdrBase
bptr = stringBase
poke stringAdrOffset, bptr
pokeString(bptr,"Line 1 8901234567890")
inc stringAdrOffset
poke stringAdrOffset, bptr
pokeString(bptr,"Line 2")
inc stringAdrOffset
poke stringAdrOffset, bptr
pokeString(bptr,"Line 3")
inc stringAdrOffset
poke stringAdrOffset, bptr
pokeString(bptr,"Line 4")
inc stringAdrOffset
poke stringAdrOffset, bptr
pokeString(bptr,"Another longer line")
inc stringAdrOffset
pause 2000
MainProgram:
b2 = $80 : Gosub Sendb2AsCommandByte
stringAdrOffset = stringAdrBase ' offset of first string
peek stringAdrOffset, bptr
' sertxd(#bptr, " ", @bptr," | ")
gosub sendString
b2 = $C0 : Gosub SendB2AsCommandByte ' LB 180526 was $A0
stringAdrOffset = stringAdrBase + 1 ' offset of 2nd string
peek stringAdrOffset, bptr
gosub sendString
b2 = $94 : Gosub Sendb2AsCommandByte ' LB 180526 was $C0
stringAdrOffset = stringAdrBase + 2 ' offset of 3rd string
peek stringAdrOffset, bptr
gosub sendString
b2 = $D4 : Gosub Sendb2AsCommandByte ' LB 180526 was $E0
stringAdrOffset = stringAdrBase + 3 ' offset of 4nd string
peek stringAdrOffset, bptr
gosub sendString
pause 5000
b2 = $C0 : Gosub SendB2AsCommandByte ' LB 180526 was $A0
stringAdrOffset = stringAdrBase + 4 ' offset of 5th string
peek stringAdrOffset, bptr
gosub sendString
Do : Loop
Sendb2AsInitByte:
Pause 15
bitWR = 0 ; Keep WR signal low
bitBKL = 1 ; keep backlight on
bitBKL = 0 ; keep backlight off
Sendb2AsCommandByte:
bitRS = 0 ; Send byte as a command
Sendb2AsDataByte:
bitD4 = bit20 ; Send msb first
bitD5 = bit21
bitD6 = bit22
bitD7 = bit23
bitE = 1
secondNybble = b3 ; secondNybble holds msb with E set
bitE = 0 ; b1 holds msb with E clear
HI2cOut b3, ( secondNybble, b3 )
bitD4 = bit16 ; Send lsb second
bitD5 = bit17
bitD6 = bit18
bitD7 = bit19
bitE = 1
secondNybble = b3 ; secondNybble holds lsb with E set
bitE = 0 ; b1 holds lsb with E clear
HI2cOut b3, ( secondNybble, b3 )
bitRS = 1 ; Send data byte next time
Return
InitializeLCD:
HI2cSetup I2CMASTER, $4E, I2CSLOW, I2CBYTE
b2 = $33 : Gosub Sendb2AsInitByte
b2 = $33 : Gosub Sendb2AsInitByte
b2 = $32 : Gosub Sendb2AsInitByte
b2 = $28 : Gosub Sendb2AsCommandByte
b2 = $0C : Gosub Sendb2AsCommandByte
b2 = $06 : Gosub Sendb2AsCommandByte
b2 = $01 : Gosub Sendb2AsCommandByte
Pause 2
return
sendString:
do : b2 = @bptrinc: if b2 <> 0 then: Gosub Sendb2AsDataByte: endif: loop until b2 = 0
return