SHARE
TWEET

Untitled

a guest Jan 19th, 2020 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .nolist
  2. .include "./m128def.inc"
  3. .include "lcd.inc"
  4. .list
  5.  
  6. .dseg
  7. .def temp = r16
  8. .def sys = r17
  9. .def counter = r18
  10. .def hours = r19
  11. .def minutes = r20
  12.  
  13. .equ FREQ = 8000000
  14. .equ LCD_PORT = PORTB
  15. .equ LCD_DDR = DDRB
  16. .equ LCD_PIN = PINB
  17. .equ LCD_D4 = 4
  18. .equ LCD_D5 = 5
  19. .equ LCD_D6 = 6
  20. .equ LCD_D7 = 7
  21. .equ LCD_RS = 0
  22. .equ LCD_EN = 2
  23.  
  24. .cseg
  25. .org 0 ;reset interruption
  26. jmp Reset
  27. .org $0014
  28. jmp TIM2_OVF ; Timer2 Overflow Handler
  29. .org $0020
  30. jmp TIM0_OVF ; Timer0 Overflow Handler
  31.  
  32. Reset:
  33. ldi temp, high(RAMEND)
  34. out sph, temp
  35. ldi temp, low(RAMEND)
  36. out spl, temp
  37.  
  38. ldi temp, 0b11110111
  39. out DDRB, temp
  40.  
  41. rcall LCD_init
  42.  
  43. ldi temp, 0xff
  44. out DDRD, temp
  45. out DDRE, temp
  46.  
  47. out DDRA, temp
  48. out DDRB, temp
  49.  
  50. ldi temp, 0b00000101
  51. out TCCR2, temp
  52. ldi temp, 0b00000010
  53. out TCCR0, temp
  54.  
  55. ldi temp, 0b01000001
  56. out TIFR, temp
  57. out TIMSK, temp
  58.  
  59. ldi temp, 0xf0
  60. out TCNT0, temp
  61.  
  62. ldi temp, 0xf0
  63. out TCNT2, temp
  64.  
  65. ldi hours, 0x17
  66. ldi minutes, 0x3b
  67. ldi counter, 0x00
  68. sei
  69.  
  70. start:
  71. nop
  72. rjmp start
  73.  
  74. TIM2_OVF:
  75. cli
  76. push temp
  77. inc counter
  78. cpi counter, 0xff
  79. breq Timer_DEC
  80. Vix:
  81.  
  82. ldi temp, 0xf0
  83. out TCNT2, temp
  84.  
  85. pop temp
  86. sei
  87. reti
  88.  
  89. Timer_DEC:
  90. dec minutes
  91. ldi counter, 0x00
  92. cpi minutes, 0x00
  93. breq Minutes_RESET
  94. rjmp Vix
  95.  
  96. Hours_RESET:
  97. ldi hours, 0x17
  98. rjmp Vix
  99.  
  100. Minutes_RESET:
  101. ldi minutes, 0x3b
  102. dec hours
  103. cpi hours, 0x00
  104. brlt Hours_RESET
  105. rjmp Vix
  106.  
  107. TIM0_OVF:
  108. cli
  109. push temp
  110. push sys
  111.  
  112. ldi temp, (128+0x00)
  113. rcall LCD_command
  114.  
  115. mov temp, minutes
  116. call bin_to_dec ;temp - единицы / sys - десятки
  117.  
  118. /*
  119. ldi zh, high(strixt*2)
  120. ldi zl, low(strixt*2)
  121. ldi sys, 14
  122.  
  123. loop:
  124. lpm temp, z+
  125. rcall LCD_data
  126. dec sys
  127. brne loop*/
  128.  
  129. mov temp, hours
  130. mov R1, temp
  131. rcall fpconv8
  132. mov temp, R7
  133. rcall LCD_data
  134. mov temp, R8
  135. rcall LCD_data
  136. ldi temp, ':'
  137. rcall LCD_data
  138. mov temp, minutes
  139. mov R1, temp
  140. rcall fpconv8
  141. mov temp, R7
  142. rcall LCD_data
  143. mov temp, R8
  144. rcall LCD_data
  145.  
  146. pop sys
  147. pop temp
  148. sei
  149. reti
  150.  
  151. LCD_init:
  152. sbi LCD_DDR, LCD_D4
  153. sbi LCD_DDR, LCD_D5
  154. sbi LCD_DDR, LCD_D6
  155. sbi LCD_DDR, LCD_D7
  156. sbi LCD_DDR, LCD_RS
  157. sbi LCD_DDR, LCD_EN
  158. cbi LCD_PORT, LCD_RS
  159. cbi LCD_PORT, LCD_EN
  160. ldi temp, 100
  161. rcall WaitMiliseconds
  162. ldi sys, 0b0000011
  163.  
  164. LCD_init_loop:
  165. ldi temp, 0x03
  166. rcall LCD_write_nibble
  167. ldi temp, 5
  168. rcall WaitMiliseconds
  169. dec sys
  170. brne LCD_init_loop
  171. ldi temp, 0x02
  172. rcall LCD_write_nibble
  173. ldi temp, 1
  174. rcall WaitMiliseconds
  175. ldi temp, HD44780_FUNCTION_SET | HD44780_FONT5x7 | HD44780_TWO_LINE | HD44780_4_BIT
  176. rcall LCD_command
  177. ldi temp, HD44780_DISPLAY_ONOFF | HD44780_DISPLAY_OFF
  178. rcall LCD_command
  179. ldi temp, HD44780_CLEAR
  180. rcall LCD_command
  181. ldi temp, HD44780_ENTRY_MODE | HD44780_EM_SHIFT_CURSOR | HD44780_EM_INCREMENT
  182. rcall LCD_command
  183. ldi temp, HD44780_DISPLAY_ONOFF | HD44780_DISPLAY_ON | HD44780_CURSOR_OFF | HD44780_CURSOR_NOBLINK
  184. rcall LCD_command
  185. ret
  186.  
  187. LCD_data:
  188. push zh
  189. push zl
  190. sbi LCD_PORT, LCD_RS
  191. push temp
  192. swap temp
  193. rcall LCD_write_nibble
  194. pop temp
  195. rcall LCD_write_nibble
  196. clr xh
  197. ldi xl, low(FREQ/80000)
  198. rcall Wait4xCycles
  199. pop zl
  200. pop zh
  201. ret
  202.  
  203. LCD_command:
  204. cbi LCD_PORT, LCD_RS
  205. push temp
  206. swap temp
  207. rcall LCD_write_nibble
  208. pop temp
  209. rcall LCD_write_nibble
  210. ldi temp, 2
  211. rcall WaitMiliseconds
  212. ret
  213.  
  214. LCD_write_nibble:
  215. sbi LCD_PORT, LCD_EN
  216. sbrs temp, 0
  217. cbi LCD_PORT, LCD_D4
  218. sbrc temp, 0
  219. sbi LCD_PORT, LCD_D4
  220. sbrs temp, 1
  221. cbi LCD_PORT, LCD_D5
  222. sbrc temp, 1
  223. sbi LCD_PORT, LCD_D5
  224. sbrs temp, 2
  225. cbi LCD_PORT, LCD_D6
  226. sbrc temp, 2
  227. sbi LCD_PORT, LCD_D6
  228. sbrs temp, 3
  229. cbi LCD_PORT, LCD_D7
  230. sbrc temp, 3
  231. sbi LCD_PORT, LCD_D7
  232. cbi LCD_PORT, LCD_EN
  233. ret
  234.  
  235. WaitMiliseconds:
  236. push zh
  237. push zl
  238. push temp
  239. WaitMsLoop:
  240. ldi xh, high(FREQ/17777)
  241. ldi xl, low(FREQ/17777)
  242. rcall Wait4xCycles
  243. ldi xh, high(FREQ/17777)
  244. ldi xl, low(FREQ/17777)
  245. rcall Wait4xCycles
  246. dec temp
  247. brne WaitMsLoop
  248. pop temp
  249. pop zl
  250. pop zh
  251. ret
  252.  
  253. Wait4xCycles:
  254. sbiw xh:xl, 1
  255. brne Wait4xCycles
  256. ret
  257.  
  258. bin_to_dec:
  259. ldi sys, 0
  260. subi temp, 10
  261. inc sys
  262. brcc PC-2
  263. dec sys
  264. subi temp, -10
  265. ret
  266.  
  267. fpconv8:
  268. rcall fpconv8a ; convert to ASCII string
  269. ldi temp,'.' ; set decimal char
  270. mov R6,temp
  271. ret ; all done
  272. fpconv8m:
  273. clr R4 ; set the multiplicant to 502
  274. ldi temp,$01
  275. mov R3,temp
  276. ldi temp,$F6
  277. mov R2,temp
  278. clr R7 ; clear the result
  279. clr R6
  280. clr R5
  281. fpconv8m1:
  282. or R1,R1 ; check if the number is all zeros
  283. brne fpconv8m2 ; still one's, go on convert
  284. ret ; ready, return back
  285. fpconv8m2:
  286. lsr R1 ; shift number to the right (div by 2)
  287. brcc fpconv8m3 ; if the lowest bit was 0, then skip adding
  288. add R5,R2 ; add the number in R6:R5:R4:R3 to the result
  289. adc R6,R3
  290. adc R7,R4
  291. fpconv8m3:
  292. lsl R2 ; multiply R4:R3:R2 by 2
  293. rol R3
  294. rol R4
  295. rjmp fpconv8m1
  296. fpconv8r:
  297. clr temp ; put zero to rmp
  298. lsl R5 ; rotate bit 7 to carry
  299. adc R6,temp ; add LSB with carry
  300. adc R7,temp ; add MSB with carry
  301. mov R2,R7 ; copy the value to R2:R1 (divide by 256)
  302. mov R1,R6
  303. ret
  304. fpconv8a:
  305. clr R4 ; Set the decimal divider value to 100
  306. ldi temp,100
  307. mov R3,temp
  308. rcall fpconv8d ; get ASCII digit by repeated subtraction
  309. mov R5,temp ; set hundreds string char
  310. ldi temp,10 ; Set the decimal divider value to 10
  311. mov R3,temp
  312. rcall fpconv8d ; get the next ASCII digit
  313. mov R7,temp ; set tens string char
  314. ldi temp,'0' ; convert the rest to an ASCII char
  315. add temp,R1
  316. mov R8,temp ; set ones string char
  317. ret
  318. fpconv8d:
  319. ldi temp,'0' ; start with decimal value 0
  320. fpconv8d1:
  321. cp R1,R3 ; Compare word with decimal divider value
  322. cpc R2,R4
  323. brcc fpconv8d2 ; Carry clear, subtract divider value
  324. ret ; done subtraction
  325. fpconv8d2:
  326. sub R1,R3 ; subtract divider value
  327. sbc R2,R4
  328. inc temp ; up one digit
  329. rjmp fpconv8d1 ; once again
  330.  
  331. strixt:
  332. .db "Almaz pidor33!"
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top