#picaxe18m2
symbol lcddata = pinsB
symbol sign=b20 'to display +ve or -ve temperatures
symbol CS=C.0 ' CS on RF module (low to enable)
symbol SIGNAL=C.1 ' Data in on RF module
symbol REDLED=C.2 ' To be used as some sort of indicator - in this case, windspeed>10mph
'Can't use serial out=C.3
'Can't use serial in = C.4
'symbol sparepin=C.5 (on H2) - could be used if needed (e.g. indoor temp/atmospheric pressure?)
symbol enable = C.6
symbol rs = C.7
init:
dirsB = 255 'Set pinsB as outputs
low rs 'instruction mode
output enable 'set enable pin as output
lcddata = %00111011 : pulsout enable,16 'Function Set: 8-bit, 2 lines, font 11
lcddata = %00000001 : pulsout enable,608 'Clear display
lcddata = %00001100 : pulsout enable,608 'Display on/off control: Display on, cursor off, blink off
lcddata = %00000110 : pulsout enable,16 'Entry mode set: Increment, cursor shift
'set up line 1
low rs
lcddata = 128 : pulsout enable,1
high rs
for b9 = 0 to 15
lookup b9,("Windspeed mph"),lcddata
pulsout enable,1
next
'set up line 2
low rs
lcddata = 192 : pulsout enable,1
high rs
for b10 = 0 to 11
lookup b10,("Dir Temp"),lcddata
pulsout enable,1
next
'Get receiver ready
low CS 'CS connected to port C.0
main:
'Read in data from wireless link (3 times for error checking - loop back if errors)
serin SIGNAL,N600,("ABC"),b0,b1,b2,b3,b4,b5,b6,b7,b8 'direction = b0, speed = b1, temp = b2
if b0<>b3 or b0<>b6 or b1<>b4 or b1<> b7 or b2<>b5 or b2<>b8 then goto main
if b1>99 then goto main '(100mph+ exceeds spec. of anemometer)
'Now display variables received from wireless link
'First display wind direction on line 2 of OLED/LCD
low REDLED
low rs
lcddata = 196 : pulsout enable,1 'Start writing from line 2, position 5
high rs
' b0 values taken by testing (not bothering with NNE etc.)
if b0=58 or b0=59 then 'on the cusp of two values with the resistor chosen (10k)
for b11 = 0 to 2
lookup b11,("N "),lcddata
pulsout enable,1
next
elseif b0=139 or b0=140 then 'on the cusp of two values with the resistor chosen (10k)
for b11 = 0 to 2
lookup b11,("NE "),lcddata
pulsout enable,1
next
elseif b0=232 then
for b11 = 0 to 2
lookup b11,("E "),lcddata
pulsout enable,1
next
elseif b0=209 then
for b11 = 0 to 2
lookup b11,("SE "),lcddata
pulsout enable,1
next
elseif b0=183 then
for b11 = 0 to 2
lookup b11,("S "),lcddata
pulsout enable,1
next
elseif b0=97 then
for b11 = 0 to 2
lookup b11,("SW "),lcddata
pulsout enable,1
next
elseif b0=19 then
for b11 = 0 to 2
lookup b11,("W "),lcddata
pulsout enable,1
next
elseif b0=33 or b0=34 then
for b11 = 0 to 2
lookup b11,("NW "),lcddata
pulsout enable,1
next
endif
'Display wind speed
low rs
lcddata = 138 : pulsout enable,1 'Move back to line 1
high rs
bintoascii b1,b12,b13,b14
for b15 = 0 to 1
lookup b15,(b13,b14),lcddata 'don't bother with first digit as not within spec. (value discarded above)
pulsout enable,1
next
if b1<10 then 'blank out second digit
low rs
lcddata = 138 : pulsout enable,1 'Move back to line 1
high rs
lookup b12,(" "),lcddata
pulsout enable,1
endif
' flash red LED if windspeed>10mph
if b1> 10 then
high REDLED
endif
'Display temperature
low rs
lcddata = 204 : pulsout enable,1
high rs
sign = " "
if b2 > 127 then ; test for negative
sign="-"
let b2 = b2 - 128
bintoascii b2,b16,b17,b18
for b19 = 0 to 3
lookup b19,(sign,b17,b18,"C"),lcddata
pulsout enable,1
next
else ;positive temp
bintoascii b2,b16,b17,b18
if b2<10 then 'drop leading zero
for b19 = 0 to 2
lookup b19,(sign,b18,"C"),lcddata
pulsout enable,1
next
else
for b19 = 0 to 3
lookup b19,(sign,b17,b18,"C"),lcddata
pulsout enable,1
next
endif
endif
goto main