Advertisement
bobbinz

Fishometer

Apr 14th, 2011
328
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.42 KB | None | 0 0
  1. 'Fishometer
  2. 'Adam Robbins 2010
  3.  
  4. Initialise:
  5. 'blank display
  6. pause 10
  7. serout 5,T2400,(254,1)
  8. serout 5,T2400,(254,1)
  9. pause 50
  10.  
  11. ' set up variable titles
  12. SYMBOL asciib = b0
  13. SYMBOL Minutes = b1
  14. SYMBOL Hours = b2
  15. SYMBOL Day = b3
  16. SYMBOL addmin = b4
  17. SYMBOL addhour = b5
  18. SYMBOL asciia = b6
  19. SYMBOL Control = b7
  20. SYMBOL Temp = b8
  21. SYMBOL Neg = b9
  22. SYMBOL Fahrenheit = b10
  23. SYMBOL FeedFish = b11
  24. SYMBOL Batt = b12
  25. SYMBOL DayChange = b13
  26.  
  27. ' initialise variables
  28. let asciib = 0
  29. let Minutes = 0
  30. let Hours = 0
  31. let Day = 0
  32. let addmin = 0
  33. let addhour = 0
  34. let asciia = 0
  35. let Control = 0
  36. let DayChange = 0
  37. let temp = 0
  38. let neg = 0
  39. let Fahrenheit = 0
  40. let FeedFish = 0
  41. let Batt = 0
  42.  
  43.  
  44. Main:
  45. ' start off by setting the right time
  46. if pin2=1 then gosub timeset
  47.  
  48. ' now the welcome message
  49. gosub welcome
  50. gosub flashlights
  51.  
  52.  
  53. ' set interrupt on button 0 being pressed
  54. setint %00000000,%00000001
  55.  
  56. ' the main program, in a loop for ever
  57. Mainloop:
  58. gosub Tempp
  59. gosub time
  60. gosub Tempp
  61. gosub time
  62. gosub Tempp
  63. gosub name
  64. goto mainloop
  65.  
  66. ' infinite loop above , should never get to here.
  67. serout 5,T2400,(254,1)
  68. pause 500
  69. serout 5,T2400,(254,12)
  70. serout 5,T2400,(254,128,"ERROR (1)")
  71. high 7
  72. high 3
  73. high 6
  74. wait 60
  75. end
  76.  
  77.  
  78. ' subroutines
  79.  
  80.  
  81. Tempp:
  82. ' Tempp - read the temprature, display it and set status ligths
  83. Readtemp 1,temp
  84. serout 5,T2400,(254,1)
  85. pause 50
  86. neg = 0
  87. ' test for negative temp
  88. if temp>127 then
  89. {
  90. ' show -ve numbers
  91. let neg = temp - 128
  92. let Fahrenheit = neg *9/5
  93. ' assumption - will never go below 0 Fahrenheit
  94. let Fahrenheit = 32 - Fahrenheit
  95. serout 5,T2400,(254,128,"Temperature: -")
  96. serout 5,T2400,(#neg)
  97. serout 5,T2400,(254,192,"Fahrenheit: ")
  98. serout 5,T2400,(#Fahrenheit)
  99.  
  100. } else {
  101. ' show +ve numbers
  102. let Fahrenheit = temp *9/5
  103. let Fahrenheit = Fahrenheit + 32
  104. serout 5,T2400,(254,128,"Temperature: ")
  105. serout 5,T2400,(#temp)
  106. serout 5,T2400,(254,192,"Fahrenheit: ")
  107. serout 5,T2400,(#Fahrenheit)
  108.  
  109. } endif
  110.  
  111. ' now set the status lights
  112. gosub clear
  113.  
  114. if neg>0 then {
  115. gosub flashlights
  116. gosub red
  117. }
  118. elseif temp<16 OR temp>25 then {
  119. gosub red
  120. }
  121. elseif temp>=21 AND temp<=24 then {
  122. gosub green
  123. }
  124. else
  125. gosub orange
  126. }
  127. endif
  128.  
  129. pause 4000
  130.  
  131. return
  132.  
  133.  
  134. Time:
  135. ' Time - show the current time, and do time based functions
  136. ' turn light on / off depending on time of day
  137. ' set feed fish light, based on day of the week
  138. i2cslave %11010000, i2cslow, i2cbyte
  139. readi2c 0, (b0,b1,b2,b3,b4,b5,b6,b7)
  140. serout 5,T2400,(254,1)
  141. pause 50
  142. ' calculate & print hour
  143. bcdtoascii b2,b0,b6
  144. serout 5,T2400,(254,128,b0,b6)
  145. ' calculate & print minute
  146. bcdtoascii b1,b0,b6
  147. serout 5,T2400,(":",b0,b6)
  148.  
  149. ' manage fishtank light
  150. if b2 >=7 AND b2<32 then { ' 32 == BCD for 20 = 8pm
  151. ' daytime -> turn light on
  152. high 3
  153. } else
  154. ' turn light off
  155. low 3
  156. } endif
  157.  
  158. ' workout if the fish have been fed yet today
  159. if daychange=0 or daychange!= day then
  160. {
  161. daychange = day
  162. if day=1 or day=4 then let Feedfish = 1 ' feed on Sunday & Wednesday
  163. endif
  164. }
  165. endif
  166.  
  167. if day=1 then serout 5,T2400,(254,192," Sunday")
  168. elseif day=2 then serout 5,T2400,(254,192," Monday")
  169. elseif day=3 then serout 5,T2400,(254,192," Tuesday")
  170. elseif day=4 then serout 5,T2400,(254,192," Wednesday")
  171. elseif day=5 then serout 5,T2400,(254,192," Thursday")
  172. elseif day=6 then serout 5,T2400,(254,192," Friday")
  173. elseif day=7 then serout 5,T2400,(254,192," Saturday")
  174. endif
  175.  
  176. if FeedFish = 1 then
  177. {
  178. ' fish need feeding so set light on.
  179. ' will be turned off by interrupt if switch pressed.
  180. high 0
  181. serout 5,T2400,(254,192," Feed Fish Today")
  182. }
  183. endif
  184.  
  185. pause 4000
  186.  
  187. return
  188.  
  189. ' Subroutines to control lights
  190. Red:
  191. high 7
  192. return
  193. Orange:
  194. high 6,7
  195. return
  196. Green:
  197. high 6
  198. return
  199. Clear:
  200. low 6
  201. low 7
  202. low 2
  203. return
  204. Flashlights:
  205. for b5 = 0 to 3 ' b5 not in use at this point
  206. high 7
  207. pause 200
  208. low 7
  209. high 6,7
  210. pause 200
  211. low 6,7
  212. high 6
  213. pause 200
  214. low 6
  215. next b5
  216. return
  217.  
  218. Welcome:
  219. ' Display welcome banner
  220. pause 100
  221. serout 5,T2400,(254,1)
  222. serout 5,T2400,(254,1)
  223. pause 500
  224. serout 5,T2400,(254,12)
  225. serout 5,T2400,(254,128,"Welcome to:")
  226. pause 1000
  227. serout 5,T2400,(254,192," Fishometer")
  228. return
  229.  
  230. Name:
  231. ' show project creator
  232. serout 5,T2400,(254,1)
  233. pause 50
  234. serout 5,T2400,(254,128," Adam Robbins")
  235. serout 5,T2400,(254,192," DT GCSE 2009")
  236. pause 3000
  237. return
  238.  
  239. Interrupt:
  240. ' interrupt handling code
  241. serout 5,T2400,(254,1)
  242. pause 50
  243. if FeedFish = 1 then
  244. {
  245. serout 5,T2400,(254,128," Lid Opened")
  246. serout 5,T2400,(254,192," Fish Fed")
  247. let FeedFish = 0
  248. low 0
  249. } else
  250. serout 5,T2400,(254,128," Lid Opened")
  251. serout 5,T2400,(254,192," Fish Overfed")
  252. endif
  253. pause 1000
  254. intloop:
  255. if pin0 = 0 then intloop ' wait until button released
  256.  
  257. setint %00000000,%00000001 ' reset interrupt
  258. return
  259.  
  260. timeset:
  261. serout 5,T2400,(254,128,"Set Time:")
  262. intloop1:
  263. ' wait until button released
  264. if pin2 = 1 then intloop1
  265. pause 500
  266. ' set Day - $b3
  267. serout 5,T2400,(254,192,"Sunday ")
  268. pause 750
  269. if pin2 = 1 then
  270. { b3 = 1
  271. goto doneday
  272. } endif
  273. serout 5,T2400,(254,192,"Monday ")
  274. pause 750
  275. if pin2 = 1 then
  276. { b3 = 2
  277. goto doneday
  278. } endif
  279. serout 5,T2400,(254,192,"Tuesday ")
  280. pause 750
  281. if pin2 = 1 then
  282. { b3 = 3
  283. goto doneday
  284. } endif
  285. serout 5,T2400,(254,192,"Wednesday ")
  286. pause 750
  287. if pin2 = 1 then
  288. { b3 = 4
  289. goto doneday
  290. } endif
  291. serout 5,T2400,(254,192,"Thursday ")
  292. pause 750
  293. if pin2 = 1 then
  294. { b3 = 5
  295. goto doneday
  296. } endif
  297. serout 5,T2400,(254,192,"Friday ")
  298. pause 750
  299. if pin2 = 1 then
  300. { b3 = 6
  301. goto doneday
  302. } endif
  303. serout 5,T2400,(254,192,"Saturday ")
  304. pause 750
  305. if pin2 = 1 then
  306. { b3 = 7
  307. goto doneday
  308. } endif
  309. goto intloop1
  310.  
  311. doneday:
  312. ' set hour - $b2
  313. ' wait until button released
  314. if pin2 = 1 then doneday
  315.  
  316. serout 5,T2400,(254,1)
  317. pause 100
  318.  
  319. nexthour:
  320. serout 5,T2400,(254,192,"Hour: ", #b2, " ")
  321. pause 750
  322. if pin2 = 0 then
  323. { b2 = b2 + 1
  324. if b2 > 23 then let b2 = 0
  325. endif
  326. goto nexthour
  327. } endif
  328.  
  329. ' convert to BCD
  330. if b2>=20 then {
  331. b4 = b2 - 20
  332. b5 = 32 + b4
  333. } elseif b2>=10 then {
  334. b4 = b2 - 10
  335. b5 = 16 + b4
  336. } endif
  337.  
  338.  
  339. ' set Minute - $b1
  340. donehour:
  341. ' set hour - $b2
  342. ' wait until button released
  343. if pin2 = 1 then donehour
  344.  
  345. serout 5,T2400,(254,1)
  346. pause 100
  347.  
  348. nextmin:
  349. serout 5,T2400,(254,192,"Minute: ", #b1, " ")
  350. pause 750
  351. if pin2 = 0 then
  352. { b1 = b1 + 1
  353. if b1 > 59 then let b1 = 0
  354. endif
  355. goto nextmin
  356. } endif
  357.  
  358. ' convert to BCD
  359. if b1 >= 50 then {
  360. b4 = b1 - 50
  361. b6 = 64 + 16 + b4
  362. } elseif b1>=40 then {
  363. b4 = b1 - 40
  364. b6 = 64 + b4
  365. } elseif b1>=30 then {
  366. b4 = b1 - 30
  367. b6 = 32 + 16 + b4
  368. } elseif b1>=20 then {
  369. b4 = b1 - 20
  370. b6 = 32 + b4
  371. } elseif b1>=10 then {
  372. b4 = b1 - 10
  373. b6 = 16 + b4
  374. } endif
  375.  
  376. serout 5,T2400,(254,192,"T: ",#b2,":",#b1," D: ",#b3)
  377. pause 5000
  378.  
  379. ' if time is wrong, try again
  380. if pin2 = 1 then timeset
  381.  
  382. ' now set the time
  383. i2cslave %11010000, i2cslow, i2cbyte
  384.  
  385. writei2c 0, ($00, b6, b5, b3, $00, $00, $00, $80)
  386. return
  387.  
  388. ' end of subroutines, should never get to here.
  389. serout 5,T2400,(254,1)
  390. pause 500
  391. serout 5,T2400,(254,12)
  392. serout 5,T2400,(254,128,"ERROR (2)")
  393. high 7
  394. high 4
  395. high 6
  396. wait 60
  397. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement