' 14Nextion.bas drives Nextion oled
#picaxe 14m2
'#terminal 76800 ' 32mHz
'#terminal 4800 ' 4mHz
'#terminal 9600 ' 8mHz
#terminal 19200 ' 16mHz
table 0,("OATCoolMn",0,"OATHeatMx",0,"OATSup1Mx",0,"OATSup2Mx",0,"TankFeedMn",0,"TankFeedMx",0,"TankReturnMn",0,"TankReturnMx",0,"YardFeedMn",0,"YardFeedMx",0,"YardReturnMn",0,"YardReturnMx",0,"AirZoneSetMn",0,"AirZoneSetMx",0,0)
data 1,(75,60,45,35,35,120,35,110,33,120,33,120,40,99)
'symbol pNextion = C.1
'symbol nextion_baud_rate = T9600_32
'symbol nextion_baud_rate = T9600_8
symbol nextion_baud_rate = T9600_16
symbol pNextionOut = B.1 ' B.0
symbol pNextionIn = B.2
'symbol nextion_baud_rate = N4800 ' for simulation debugging
symbol ramAddrOffset = 28 ' offset in ram of variable table addresses
symbol ramValOffset = 27 ' offset in ram of variable values (+nVars)
symbol nvars = b4
symbol tblptr = b5
symbol cnt = b6
symbol ch = b7
symbol val = b8
symbol var = b9
symbol ActionCode = b10
symbol ActionVal = b11
symbol oldVal = b12
'Setfreq M32
'Setfreq M8
Setfreq M16
pause 8000 ' once for M8, twice for M16
pause 8000
sertxd("14Nextion",cr,lf)
bptr = ramAddrOffset ' first ram byte
tblptr = 0 ' just used as a variable
@bptrinc = tblptr ' address of first variable name
do
readtable tblptr,ch ; read value from table
inc tblptr
if ch = 0 then
@bptrinc = tblptr ' save address of first byte of next variable
readtable tblptr,ch ; check for final 0
endif
loop while ch <> 0 and tblptr < 255
nvars = bptr - ramAddrOffset - 1
sertxd(#nvars," min/max variables",cr,lf)
bptr = ramAddrOffset+nvars ' beginning in ram of variable values
for cnt = 1 to nvars
read cnt,val ' move values from eeprom
@bptrinc = val
next cnt
bptr = ramAddrOffset ' value in ram of table address of first variable
for cnt = 1 to nvars
peek bptr, tblptr
inc bptr
readtable tblptr,ch
inc tblptr
sertxd(#cnt," ")
do until ch = 0
sertxd(ch)
readtable tblptr,ch
inc tblptr
loop
read cnt,val ' value for variable
sertxd(" ",#val,cr,lf)
next cnt
var = 1 ' dealing with first variable
gosub outputP3
main:
do
Serin pNextionIn,nextion_baud_rate,ActionCode,ActionVal
' Serin C.1,nextion_baud_rate,ActionCode,ActionVal
select Actioncode
case "!" ' button release
select ActionVal
case "0" ' minus
val = val min 1 - 1 ' floor value of 0--don't underflow
Serout pNextionOut, nextion_baud_rate, ("t1.txt=",$22,#val,$22,$FF,$FF,$FF)
@bptr = val
case "1" ' plus
val = val max 254 + 1 ' max value of 255--don't overflow
Serout pNextionOut, nextion_baud_rate, ("t1.txt=",$22,#val,$22,$FF,$FF,$FF)
@bptr = val
case "2" ' prior variable
if val <> oldVal then
gosub updateVal
endif
var = var - 1 min 1
gosub outputP3
case "3" ' next variable
if val <> oldVal then
gosub updateVal
endif
var = var + 1 max nvars
gosub outputP3
case "4" ' done with this page
if val <> oldVal then
gosub updateVal
endif
endselect
endselect
loop
outputText:
readtable bptr, ch
inc bptr
do until ch = 0
' sertxd(ch)
Serout pNextionOut, nextion_baud_rate, (ch)
readtable bptr,ch
inc bptr
loop
return
outputP3:
serout pNextionOut,nextion_baud_rate,("t0.txt=",$22) ' $22 is quote
bptr = ramValOffset + var
peek bptr, bptr ' address of first character in variable name
gosub outputText
Serout pNextionOut, nextion_baud_rate, ($22,$FF,$FF,$FF)
bptr = var + ramValOffset + nvars ' location of value for this variable
val = @bptr
oldVal = val
sertxd("Var",#var," = ",#val,cr,lf)
Serout pNextionOut, nextion_baud_rate, ("t1.txt=",$22,#val,$22,$FF,$FF,$FF)
return
updateVal:
sertxd("Var",#var," = ",#val,cr,lf)
bptr = ramValOffset + nVars + var
@bptr = val ' update ram
write var,val ' update eeprom in case of power cycle
return