daily pastebin goal
63%
SHARE
TWEET

Untitled

a guest Mar 26th, 2019 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * timer.asm
  3.  *
  4.  *  Created: 26/03/2019 2:04:19 PM
  5.  *   Author: Peter Ph
  6.  */
  7.  
  8.  .include "m2560def.inc"
  9.  .dseg
  10.  
  11.  .cseg
  12.  
  13.  .def temp = r16
  14.  .def leds = r17
  15.  .def r_floor = r18
  16.  .def r_direction = r19
  17.  .def pattern = r20
  18.  .def pattern1 = r21
  19.  .def curr_floor = r22
  20.  .def flippy = r23
  21.  .def dest_floor = r24
  22.  .def temp1 = r1
  23.  nums: .db 3, 4, 7, 9
  24.  
  25.  .equ floor_number = 2
  26.  .equ direction = 1
  27.  
  28.  
  29.  .macro clear
  30.     ldi YL, low(@0)
  31.     ldi YH, high(@0)
  32.     clr temp
  33.     st Y+, temp
  34.     st Y, temp
  35. .endmacro
  36.  
  37.  
  38.  .dseg
  39.  BlinkCounter:
  40.     .byte 2
  41. TempCounter:
  42.     .byte 2
  43.  
  44. .cseg
  45.     jmp RESET
  46.     jmp DEFAULT
  47.     jmp DEFAULT
  48. .org OVF0addr
  49.     jmp Timer0OVF
  50.  
  51. DEFAULT: reti
  52.  
  53.  RESET: ldi temp, high(RAMEND)
  54.         out SPH, temp
  55.         ldi temp, low(RAMEND)
  56.         out SPL, temp
  57.  
  58.         ldi ZL, low(nums<<1)
  59.         ldi ZH, high(nums<<1)
  60.  
  61.         lpm dest_floor, Z+
  62.  
  63.         ldi r_floor, floor_number
  64.         ldi r_direction, direction
  65.         ldi flippy, 1
  66.  
  67.         ldi pattern, 0
  68.         clr temp
  69.  
  70. get_pattern:
  71.         cpi temp, floor_number
  72.         brsh got_pattern
  73.         lsl pattern
  74.         inc pattern
  75.         inc temp
  76.         rjmp get_pattern
  77. got_pattern:
  78.         ldi pattern1, 0
  79. get_pattern1:
  80.         cpi r_floor, 9
  81.         brne check_ten
  82.         ldi pattern1, 1
  83. check_ten:
  84.         cpi r_floor, 10
  85.         brne got_pattern1
  86.         ldi pattern1, 3
  87. got_pattern1:
  88.  
  89.         mov curr_floor, r_floor
  90.  
  91.         ser temp
  92.         out DDRC, temp
  93.         out DDRG, temp
  94.  
  95.         out PORTC, pattern
  96.         out PORTG, pattern1
  97.  
  98.         rjmp main
  99.  Timer0OVF:
  100.     in temp, SREG
  101.     push temp
  102.     push YH
  103.     push YL
  104.     push r25
  105.     push r24
  106.  
  107.  
  108.     lds r24, TempCounter
  109.     lds r25, TempCounter+1
  110.     adiw r25:r24, 1
  111.  
  112. ; check if we want to wait for 5s or 2s
  113.     cpi curr_floor, 5
  114.     brne two_sec
  115.     cpi r24, low(39060)
  116.     ldi temp, high(39060)
  117.     cpc r25, temp
  118.     brne wait
  119.     rjmp start
  120.  
  121. two_sec:
  122.     cpi r24, low(15624)
  123.     ldi temp, high(15624)
  124.     cpc r25, temp
  125.     brne NotSecond
  126.     // if a second has passed lets change it up nigger
  127. start:
  128.     ;out PORTC, pattern
  129.     ;out PORTG, pattern1
  130.  
  131.     cpi r_direction, 1
  132.     brne going_down
  133. going_up:
  134.     cpi curr_floor, 10
  135.     brne continue_up
  136. // change dir
  137.     ldi r_direction, 0
  138.     rjmp start
  139. continue_up:
  140.     lsl pattern
  141.     inc pattern
  142.  
  143.     cpi curr_floor, 8
  144.     brne check_if_ten
  145.     ldi pattern1, 1
  146.     rjmp done_up
  147. check_if_ten:
  148.     cpi curr_floor, 9
  149.     brne done_up
  150.     ldi pattern1, 3
  151.     rjmp done_up
  152. change_direction:
  153.     com r_direction
  154.     rjmp start
  155. going_down:
  156.     cpi curr_floor, 0
  157.     brne keep_going_down
  158.     ldi r_direction, 1
  159.     rjmp start
  160. keep_going_down:
  161.     cpi curr_floor, 10
  162.     brne check_if_nine
  163.     ldi pattern1, 1
  164.     rjmp done_down
  165. check_if_nine:
  166.     cpi curr_floor, 9
  167.     brne continue_down
  168.     ldi pattern1, 0
  169.     rjmp done_down
  170. continue_down:
  171.     lsr pattern
  172.     rjmp done_down
  173. done_up:
  174.     inc curr_floor
  175.     rjmp done
  176. done_down:
  177.     dec curr_floor
  178. done:
  179.     clear TempCounter
  180. //----------------------------------------------------------
  181.     rjmp EndIF
  182. NotSecond:
  183.     sts TempCounter, r24
  184.     sts TempCounter+1, r25
  185.     rjmp EndIF
  186. wait:
  187.     sts TempCounter, r24
  188.     sts TempCounter+1, r25
  189.  
  190. start_blink:
  191.     lds r24, BlinkCounter
  192.     lds r25, BlinkCounter+1
  193.     adiw r25:r24, 1
  194.  
  195.     cpi r24, low(3750)
  196.     ldi temp, high(3750)
  197.     cpc r25, temp
  198.     brne NotBlink
  199.     ;cp curr_floor, dest_floor
  200.     ;brne done_blink
  201.     ;lpm dest_floor, Z+
  202.     cpi flippy, 1
  203.     brne flip_zero
  204.     clr temp
  205.     out PORTC, temp
  206.     out PORTG, temp
  207.     ldi flippy, 0
  208.     rjmp done_blink
  209. /*flip_zero:
  210.     mov temp, pattern
  211.     mov temp1, pattern1
  212.     ldi flippy, 1
  213.     out PORTC, temp
  214.     out PORTG, temp1
  215.     rjmp done_blink*/
  216.  
  217. NotBlink:
  218.     sts BlinkCounter, r24
  219.     sts BlinkCounter+1, r25
  220.     rjmp EndIF
  221. done_blink:
  222.     clear BlinkCounter
  223.     rjmp EndIF
  224.  
  225. EndIF:
  226.     out PORTC, pattern
  227.     out PORTG, pattern1
  228.  
  229.     pop r24
  230.     pop r25
  231.     pop YL
  232.     pop YH
  233.     pop temp
  234.     out SREG, temp
  235.     reti
  236.  
  237. main:
  238.     ;out PORTC, pattern
  239.     clear TempCounter
  240.     clear BlinkCounter
  241.     ldi temp, 0b00000000
  242.     out TCCR0A, temp
  243.     ldi temp, 0b00000010
  244.     out TCCR0B, temp
  245.     ldi temp, 1<<TOIE0
  246.     sts TIMSK0, temp
  247.     sei
  248. loop: rjmp loop
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