main: xor op1 1 op4 xor op2 1 op5 set ram1 CS # we need to know the current second for later set ram8 0 # clear A/D counter and total secloop: tstne ram1 CS # same second? goto sc tsteq op8[50] 1 # pulse the activity LED briefly to reduce power used tstgt cs 56 op8 # Leave it on solid for 3 seconds at the end of each minute to warn activity is about to happen delay 1 # this may get skiped add ram8 AIP3 ram8 # add A/D add ram8 1000000 ram8 # and incr counter tsteq ip8 1 # input pulled high? (high wind) add var4 10000 var4 # bump highwind threshold counter goto secloop sc: # each change-of-second, turn on the activity LED set op8 1 div ram8 1000000 ram2 # get A/D counter mul ram2 1000000 ram3 sub ram8 ram3 ram8 # take counter from total div ram8 ram2 ram8 fixvolts: add ram8 2153 ram8 # 21.53 volts offset for tom div ram8 10 var8 # display answer in tenths-of-volts set ram8 0 # reset # counts approx 50/second. tstgt var4 500000 # high wind triggered? (remember cccctttt) set var4 600 # (re)trigger highwind timer and clear trigger counter tsteq ip7 1 # Instant cancel-highwind set var4 0 tsteq ip1 0 # if not "manual drive east" goto mw # check for manual drive west tstge var5 10000 # if required position is greater than 0 sub var5 10000 var5 # decrement by one. mw: tsteq ip2 1 # "manual drive west"? add var5 10000 var5 # increment (west) 1 div var5 10000 ram1 # extract "desired" position mul ram1 10000 ram3 # Need actual position shortly, this makes it easier sub var5 ram3 ram2 # ram3 has desired position, ram2 has actual position. # now check limit switches tsteq ip3 1 # East limit active? set ram2 0 # we are now fully east tsteq ip4 1 # West limit active? set ram2 var2 # Fully west add ram3 ram2 var5 # update desired and actual positions div var4 10000 ram3 # calculate highwind timer mul ram3 10000 ram3 sub var4 ram3 ram3 tstgt ram3 0 # if high wind timer is inactive, use "desired" position already in ram1 div var2 2 ram1 # Oherwise, we use "parked" position tstgt ram3 0 dec var4 # decrement timer