tn.asm 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. .include "tn2313def.inc"
  2. .equ _1WDDR = DDRB
  3. .equ _1WPIN = PINB
  4. .equ _1WL = PB4
  5. .equ _1WPORT = PORTB
  6. ;rejestry
  7. .def sregtmp =r0
  8. .def ZERO =r1
  9. .def minus =r2
  10. ;r3
  11. ;r4
  12. ;r5
  13. ;r6
  14. ;r7
  15. ;r8
  16. ;r9
  17. ;r10
  18. ;r11
  19. ;r12
  20. ;r13
  21. ;r14
  22. ;r15
  23. .def tmp =r16
  24. .def tmp1 =r17
  25. .def tmpi =r18
  26. .def ARG =r19
  27. .def ARGL =r19
  28. .def ARGH =r20
  29. .def ARGD =r21
  30. .def temp10 =r22
  31. .def temp1 =r23
  32. .def temp01 =r24
  33. .def tmp2 =r25
  34. .def tmp3 =r26
  35. ;r27
  36. ;r28
  37. ;r29
  38. .def ZL =r30
  39. .def ZH =r31
  40. ;.macro adi
  41. ; subi @0, 256-@1
  42. ;.endmacro
  43. .dseg
  44. .cseg
  45. ldi tmp, RAMEND ;stos
  46. out SPL, tmp
  47. ldi tmp, 1<<WGM01
  48. out TCCR0A, tmp
  49. ldi tmp, (1<<CS02)|(1<<CS00)
  50. out TCCR0B, tmp
  51. ser tmp
  52. out DDRD, tmp
  53. out DDRA, tmp
  54. ldi tmp, 0b10001111
  55. out DDRB, tmp
  56. clr ZERO
  57. rjmp main
  58. vector_TM0A:
  59. in sregtmp, SREG
  60. push ARGD
  61. ldi tmpi, 200 ;start rejestru timera
  62. out TCNT0, tmpi
  63. sbi PORTB, 1
  64. ldi tmpi, 5
  65. sbrc minus, 0
  66. ldi tmpi, 6
  67. rcall set_digit
  68. ;
  69. cpi temp10, 1
  70. brlo wygas
  71. sbi PORTB, 0
  72. wygas:
  73. mov tmpi, temp10
  74. rcall set_digit
  75. sbi PORTB, 3
  76. mov tmpi, temp1
  77. rcall set_digit
  78. ;
  79. sbi PORTB, 7
  80. mov tmpi, temp01
  81. rcall set_digit
  82. pop ARGD
  83. out SREG, sregtmp
  84. reti
  85. main:
  86. ldi tmp, 1<<OCIE0A
  87. out TIMSK, tmp
  88. ; sei
  89. loop:
  90. ldi ARG, 255
  91. rcall _delay_ms
  92. rcall wysw_temp
  93. ; inc minus
  94. ; inc temp01
  95. ; cpi temp01, 10
  96. ; brlo loop
  97. ; clr temp01
  98. ; inc temp1
  99. ; cpi temp1, 10
  100. ; brlo loop
  101. ; clr temp1
  102. ; inc temp10
  103. ; cpi temp10, 10
  104. ; brlo loop
  105. ; clr temp10
  106. rjmp loop
  107. set_digit:
  108. cpi tmpi, 10
  109. brsh op
  110. ldi ZL, low(tab_digit)
  111. ldi ZH, high(tab_digit)
  112. add tmpi, tmpi
  113. add ZL, tmpi
  114. ; adc ZH, ZERO
  115. ijmp
  116. tab_digit:
  117. digit_0:
  118. sbi PORTA, 0
  119. rjmp op
  120. digit_1:
  121. sbi PORTD, 2
  122. rjmp op
  123. digit_2:
  124. sbi PORTD, 3
  125. rjmp op
  126. digit_3:
  127. sbi PORTD, 4
  128. rjmp op
  129. digit_4:
  130. sbi PORTD, 5
  131. rjmp op
  132. digit_5:
  133. sbi PORTD, 6
  134. rjmp op
  135. digit_6:
  136. sbi PORTB, 2
  137. rjmp op
  138. digit_7:
  139. sbi PORTD, 0
  140. rjmp op
  141. digit_8:
  142. sbi PORTD, 1
  143. rjmp op
  144. digit_9:
  145. sbi PORTA, 1
  146. op:
  147. ldi ARGD, 255
  148. rcall _delay_us
  149. ldi ARGD, 255
  150. rcall _delay_us
  151. ldi ARGD, 255
  152. rcall _delay_us
  153. in tmpi, PORTB
  154. andi tmpi, 1<<_1WL
  155. out PORTA, ZERO
  156. out PORTB, tmpi
  157. out PORTD, ZERO
  158. ldi ARGD, 180
  159. rcall _delay_us
  160. ret
  161. wysw_temp:
  162. rcall _1wire_init ;odczyt i konwersja
  163. ldi ARG, 0xCC
  164. rcall _1wire_write
  165. ldi ARG, 0x44
  166. rcall _1wire_write
  167. sbi _1WPORT, _1WL ;zasilanie 'parasite'
  168. sbi _1WDDR, _1WL
  169. sei
  170. ldi ARG, 255
  171. rcall _delay_ms
  172. ldi ARG, 255
  173. rcall _delay_ms
  174. ldi ARG, 255
  175. rcall _delay_ms
  176. cbi _1WPORT, _1WL
  177. cbi _1WDDR, _1WL
  178. rcall _1wire_init
  179. ldi ARG, 0xCC
  180. rcall _1wire_write
  181. ldi ARG, 0xBE
  182. rcall _1wire_write
  183. sei
  184. rcall _1wire_read
  185. push ARG
  186. rcall _1wire_read
  187. pop tmp
  188. mov tmp1, tmp
  189. ldi tmp2, 0b01010000
  190. eor tmp1, tmp2
  191. brne conv_continue
  192. mov tmp1, ARG
  193. ldi tmp2, 0b00000101
  194. eor tmp1, tmp2
  195. brne conv_continue
  196. ret
  197. conv_continue:
  198. bst ARG, 7
  199. bld minus, 0
  200. mov temp01, tmp
  201. brtc not_negative
  202. com ARG
  203. neg temp01
  204. not_negative:
  205. mov tmp1, temp01 ;stopnie beda w ARG
  206. andi tmp1, 0xf0
  207. or ARG, tmp1
  208. swap ARG
  209. andi temp01, 0x0f ;dziesiate beda w temp01
  210. add temp01, temp01
  211. mov tmp1, temp01
  212. add temp01, temp01
  213. add temp01, temp01
  214. add temp01, tmp1
  215. swap temp01
  216. andi temp01, 0x0f
  217. rcall divmod
  218. mov temp10, ARGH
  219. mov temp1, ARGL
  220. ret
  221. _delay_ms:
  222. delay_loop:
  223. ldi ARGD, 255
  224. rcall _delay_us
  225. ldi ARGD, 255
  226. rcall _delay_us
  227. ldi ARGD, 255
  228. rcall _delay_us
  229. ldi ARGD, 235
  230. rcall _delay_us
  231. dec ARG
  232. brne delay_loop
  233. ret
  234. _delay_us:
  235. cpi ARGD, 0
  236. brne cz
  237. ldi ARGD, 60
  238. cz:
  239. nop
  240. nop
  241. nop
  242. nop
  243. nop
  244. dec ARGD
  245. brne cz
  246. ret
  247. _1wire_init:
  248. cli
  249. sbi _1WDDR, _1WL
  250. ldi ARG, 1
  251. rcall _delay_ms
  252. cbi _1WDDR, _1WL
  253. rcall _delay_us
  254. sei
  255. ldi ARG, 1
  256. rcall _delay_ms
  257. ret
  258. _1wire_write:
  259. ldi tmp, 8
  260. _write_loop:
  261. cli
  262. sbi _1WDDR, _1WL
  263. ldi ARGD, 1
  264. rcall _delay_us
  265. sbrc ARG, 0
  266. cbi _1WDDR, _1WL
  267. rcall _delay_us
  268. cbi _1WDDR, _1WL
  269. dec tmp
  270. breq _write_finish
  271. sei
  272. lsr ARG
  273. rjmp _write_loop
  274. _write_finish:
  275. ret
  276. _1wire_read:
  277. clr ARG
  278. ldi tmp, 1
  279. _read_loop:
  280. cli
  281. sbi _1WDDR, _1WL
  282. ldi ARGD, 1
  283. rcall _delay_us
  284. cbi _1WDDR, _1WL
  285. ldi ARGD, 14
  286. rcall _delay_us
  287. sbic _1WPIN, _1WL
  288. or ARG, tmp
  289. sei
  290. rcall _delay_us
  291. lsl tmp
  292. brne _read_loop
  293. ret
  294. divmod: ;wej: ARGL, wyj mod: ARGL, wyj div: ARGH
  295. clr ARGH
  296. div_loop:
  297. cpi ARGL, 10
  298. brlo div_finish
  299. inc ARGH
  300. subi ARGL, 10
  301. rjmp div_loop
  302. div_finish:
  303. ret