I am using an LCD from output pin0 but i can't figure out what is wrong with the code. I am using the default code given in the picaxe manual but i have changed the pin numbers to correspond to correct pins when starting from 0.
However, something tells me that i need to change the masking as well as the pins are no longer the same, am i right in thinking this?
any help would be much appreciated as i cannot say i fully understand how LCDs work!
However, something tells me that i need to change the masking as well as the pins are no longer the same, am i right in thinking this?
Code:
#picaxe 40x1
EEPROM 0, ("Test1 Master") ' 0 to 11
EEPROM 12, ("Test Screen") ' 12 to 22
symbol MEM_1ST_START = 0
symbol MEM_1ST_END = 11
symbol MEM_2ND_START = 12
symbol MEM_2ND_END = 22
gosub init
let b1 = 1 'set b1 to ‘clear display’ instruction
gosub wrins 'send instruction to LCD
for b3 = MEM_1ST_START to MEM_1ST_END 'setup a for...next loop
read b3, b1 'read letter from EEPROM into variable b1
gosub wrchr 'send character to LCD
next b3 'next loop
let b1 = 12 'set b1 to ‘hide cursor’ instruction
gosub wrins 'send instruction to LCD
let b1 = 192
gosub wrins
for b3 = MEM_2ND_START to MEM_2ND_END 'setup a for...next loop
read b3, b1 'read letter from EEPROM into variable b1
gosub wrchr 'send character to LCD
next b3 'next loop
let b1 = 12 'set b1 to ‘hide cursor’ instruction
gosub wrins 'send instruction to LCD
CLRserPTR:
HSerPtr = 0 'Reset (background) write pointer
HSerInFlag = 0 'Reset reception indicator
Ptr = 0 'Reset read pointer
@Ptr = 0 'Clear the first scratchpad location
return
CLRscratchpad:
for b0=0 to 127
put b0,0
next
return
init:
let pins = 0 'Clear all output lines RS = 0
let b3 = 0 'Reset variable b3 EN = 1
pause 200 'Wait 200 ms for LCD to reset. D4 = 5
let pins = 48 'Set to 8-bit operation. D5 = 4
pulsout 1,1 'Send data by pulsing ‘enable’ D6 = 3
pause 10 'Wait 10 ms D7 = 2
pulsout 1,1 'Send data again
pulsout 1,1 'Send data again
let pins = 32 'Set to 4-bit operation.
pulsout 1,1 'Send data.
pulsout 1,1 'Send data again.
let pins = 128 'Set to two line operation
pulsout 1,1 'Send data.
let b1 = 14 'Screen on, cursor on instruction
gosub wrins 'Write instruction to LCD
return
wrchr:
let pins = b1 & 240 'Mask the high nibble of b1 into b2.
high 0 'Make sure RS is high
pulsout 1,1 'Pulse the enable pin to send data.
let b2 = b1 * 16 'Put low nibble of b1 into b2.
let pins = b2 & 240 'Mask the high nibble of b2
high 0 'Make sure RS is high
pulsout 3,1 'Pulse enable pin to send data.
return
wrins:
let pins = b1 & 240 'Mask the high nibble of b1 into b2.
pulsout 1,1 'Pulse the enable pin to send data.
let b2 = b1 * 16 'Put low nibble of b1 into b2.
let pins = b2 & 240 'Mask the high nibble of b2
pulsout 1,1 'Pulse enable pin to send data.
high 0 'Back to character mode
return