|
study details | entire paper | PBASIC program | pictures | circuit diagram
Rain Gauge Program Listing
'{$STAMP BS2}
'Rain Gauge
'11 Apr 2002
debug cls
input 15 ' clock output line
output 14 ' clock input line
input 12 ' show_data push button
z var word ' keep track of mem location
numwrite var word ' count the number of writes to mem
x var nib ' used in blink
'used for clock
ss var byte
mm var byte
hh var byte
dd var byte
mo var byte
yl var byte
'used for dump counting
a var bit
b var bit
c var bit
d var bit
e var bit
f var bit
h var nib
i var nib
j var nib
k var nib
l var byte
m var byte
n var byte
'IC 6bit count
input 0
input 1
input 2
input 3
input 4
input 5
input 6 'IC reset line
high 6
low 6
high 14
numwrite = 0
z = 0
'set the clock
pause 1000
SetTimeCommand:
'The line below can be commented out if the time/date is already set and the power is not removed from the stamp
'SEROUT 14,84,[$55,$00,$00,$32,$0E,$09,$04,$02] 'syncByte, milisec, ss, mm, hh, dd, mo, yl (in hex)
bed:
gosub blink 'before sleeping check for show_data
debug cr,"Zzzzz....."
sleep(900) '15 minutes
goto check_dumps
check_dumps:
a = in0
b = in1
c = in2
d = in3
e = in4
f = in5
h = a*1
i = b*2
j = c*4
k = d*8
l = e*16
m = f*32
n = h+i+j+k+l+m
if n = 0 then bed 'no rain so back to bed, otherwise increase numwrite and record the dumps
numwrite = numwrite + 1
ReadTimeCommand: 'get the current time/date
SEROUT 14,188,[$55,$02]
SERIN 15,188,5000,check_dumps,[ss,mm,hh,dd,mo,yl]
debug cr, cr, dec2 hh, ":", dec2 mm, ":", dec2 ss," ", dec2 mo, "/", dec2 dd, "/20", dec2 yl, cr
debug dec n," dump(s)", cr 'show how many dumps occured since last reading
debug dec numwrite, " writes to memory", cr, cr 'show num writes into memory
'after each write increase mem location by 1
WRITE z, n
z = z + 1
WRITE z, mo
z = z + 1
WRITE z, dd
z = z + 1
WRITE z, hh
z = z + 1
WRITE z, mm
z = z + 1
high 6 'reset counting IC
low 6
goto bed
show_data:
numwrite = 0 'reading data so reset numwrite
if z = 0 then bed 'if zero then we've read it all
z = z - 1
READ z, mm
z = z - 1
READ z, hh
z = z - 1
READ z, dd
z = z - 1
READ z, mo
z = z - 1
READ z, n
debug cr, "---------------------------------------------------",cr
debug "On ", dec2 mo, "/", dec2 dd, "/20", dec2 yl, " at ", dec2 hh, ":", dec2 mm," ", dec n, " dump(s)", cr
debug "---------------------------------------------------",cr
goto show_data
blink:
'blink for 10 seconds while checking button
for x = 1 to 10
if in12 = 0 then show_data
low 13
pause 500
high 13
pause 500
next
return
|
 |

|