#no_data
#no_table
'setfreq m16
symbol config0 = w0 'variable used for configuring comparitor
symbol reserved0 = b0 'reserved byte for tempory bits
symbol reserved1 = b1
'symbol = w1
symbol sys_flags = b2
symbol lite = bit16
symbol delay_flag = bit17
symbol strobe_flag= bit18
symbol tempword0 = w2
symbol tempbyte0 = b4
symbol tempbyte1 = b5
symbol scratch_val = b6
symbol last_scratch = b7
symbol loopcount1 = b8
symbol page_number = b9
symbol pointer = b10
symbol shutter_delay = b11
symbol strobe_dur = w6
symbol strobe_lsb = b12
symbol strobe_msb = b13
symbol strobes = b14
symbol acti_sens = b15
symbol acti_trig = b16
symbol inverted = b17
symbol reserved = b18
symbol threshhold = b19
symbol dis_in = c.7
symbol dis_out = c.6
symbol baud = T9600
#terminal 9600
init:
pause 1000
hsersetup b9600_8, %00000001
hserout 0, ("page ","1",$FF,$FF,$FF)
hserptr = 0
bptr = 56
main:
if hserptr <> 0 then gosub readback
'first data will be page 1 0x66 0x01
'timer page = 0x66 0x02
'shutter delay = 0x66 0x03
'page can will 2 variables when accept pressed followed by page 0x02
'page number can be considered page number -1 due to first page being diplayed during startup
goto main
selection:
bptr = 56
if @bptr = 60 then
page_number = 60
end if
select case page_number
case 1
'page 1 will only send light flag
'both start as zero - light off
bptr = 56
if @bptr = 1 then
high b.6
lite = 1
else
low b.6
lite = 0
end if
sertxd (#lite,44,13,10)
case 3
'page 3 send flag then shutter delay
bptr = 56
if @bptr = 1 then
delay_flag = 1
else
delay_flag = 0
end if
'data is only 1 byte
bptr = bptr + 2
shutter_delay = @bptr
sertxd (#sys_flags,44,#shutter_delay,13,10)
case 4
'page 4 sends strobe duration (word) strobes (byte) flag
bptr = 56
strobe_lsb = @bptrinc
strobe_msb = @bptrinc
strobes = @bptr
sertxd (#strobes,44,#strobe_dur,13,10)
case 10
bptr = 56
acti_sens = @bptr
bptr = bptr + 2
acti_trig = bptr
bptr = bptr + 2
inverted = bptr
sertxd (#acti_sens,44,#acti_trig,44,#inverted,13,10)
case 60
sertxd ("calib",13,10)
do while hserptr = 0
readadc 0, b18
hserout 0, ("sensor1.val=",#b18,$FF,$FF,$FF)
let tempword0 = b18 *10 *4 /100
'value over 100 causes error code and stopping of display update due to b4 and b5 not meeting requirements
if tempword0> 100 then
tempword0 = 100
end if
let b18 = tempword0
hserout 0, ("bar1.val=",#b18,$FF,$FF,$FF)
readadc 1, b18
hserout 0, ("sensor2.val=",#b18,$FF,$FF,$FF)
let tempword0 = b18 *10 *4 /100
if tempword0 > 100 then
tempword0 = 100
end if
let b18 = tempword0
hserout 0, ("bar2.val=",#b18,$FF,$FF,$FF)
loop
case 11
bptr = 56
threshhold = @bptr
sertxd (#threshhold,13,10)
endselect
return
readback:
high b.7
pause 100
let scratch_val = 0
'find data in scratch pad
do while loopcount1 < 5
get scratch_val, tempbyte0
if tempbyte0 = $00 then
inc loopcount1
else
loopcount1 = 0
end if
inc scratch_val
loop
last_scratch = scratch_val - 6 'last address
'now find instruction - first 2
'address 0-2 will always be instruction/data
'Test values: $71,$06,$00,$00,$00,$ff,$ff,$ff,$66,$01,$ff,$ff,$ff - only two selections
'0x71 - numeric data lsb first sends long work but only interested in word - ie first 2 data points
'LSB first
bptr = 56
for scratch_val = 0 to 2
'get scratch_val, tempbyte0
'sertxd (#tempbyte0,44)
gosub data_check
next scratch_val
'inc scratch_val
loopcount1 = 0
'now look for next until address matches last_scratch
do while scratch_val < last_scratch
get scratch_val, tempbyte0
if tempbyte0 = $FF then
inc loopcount1
else
loopcount1 = 0
end if
if loopcount1 = 3 then 'next start bit?
inc scratch_val
for tempbyte1 = 0 to 2
'get scratch_val, tempbyte0
'sertxd (#tempbyte0,44)
gosub data_check
'inc scratch_val
next tempbyte1
get scratch_val, tempbyte0
loopcount1 = 0
if tempbyte0 = $FF then 'correct address if only 2 byte sent before stop
scratch_val = scratch_val - 1
end if
'sertxd (13,10)
end if
inc scratch_val
loop
bptr = 56
sertxd ("Page: ",#page_number,13,10,"Data 1: ",#@bptrinc,44,#@bptrinc,13,10,"Data 2: ",#@bptrinc,44,#@bptrinc,13,10,"Data 3: ",#@bptrinc,44,#@bptrinc,13,10)
#rem
for scratch_val = 0 to 20
get scratch_val, tempbyte0
sertxd (#tempbyte0,44)
next scratch_val
#endrem
for scratch_val = 0 to last_scratch
put scratch_val, 0
next scratch_val
sertxd (13,10)
last_scratch = 0
loopcount1 = 0
hserptr = 0
gosub selection
low b.7
return
data_check:
get scratch_val, tempbyte0
if tempbyte0 = $66 then
inc scratch_val
get scratch_val, tempbyte0
let page_number = tempbyte0
else if tempbyte0 = $71 then
inc scratch_val
get scratch_val, @bptrinc
inc scratch_val
get scratch_val, @bptrinc
end if
inc scratch_val
return