Advertisement
DimaT1

Untitled

Oct 7th, 2016
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .NOLIST
  2. #ifndef _TN13DEF_INC_
  3.   .include "tn13def.inc"
  4. #endif
  5.  
  6. ;.include "regs.inc"
  7.  
  8. ;timers
  9. .equ CLK1024 = (1<<CS00) | (1<<CS02)
  10.  
  11. ;ticks
  12. .equ T0MAXTICK = 2
  13.  
  14. ;work
  15. .def t0tick = R22
  16. .def state = R21
  17.  
  18. .org 0
  19.   rjmp reset
  20.  
  21. .org 0x0003
  22.   rjmp TIMER0OVF
  23.  
  24.  
  25. .MACRO outi
  26.   push R16
  27.   ldi    r16, @1        
  28.   out    @0, r16        
  29.   pop R16
  30. .ENDMACRO
  31.  
  32. ;==============================================================
  33. .macro show
  34.   push R17
  35.  
  36.   OUTI PORTB, 1
  37.  
  38.  
  39. ;  mov R17, state
  40. ;  dec R17
  41.  
  42. ;  breq PC+3
  43. ;  OUTI PORTB, (1 << 0)
  44. ;  rjmp m1
  45. ;  OUTI PORTB, (0 << 0)
  46.  
  47. ;  m1:
  48.  
  49.   pop R17
  50. .endm
  51.  
  52.  
  53. ;==============================================================
  54. ;ISR
  55. TIMER0OVF:
  56.  
  57.   OUTI PORTB, 1
  58.  
  59.   dec t0tick
  60.   breq PC+2
  61.   reti
  62.   push R17
  63.   ldi R17, 1
  64.   eor state, R17
  65.   ldi t0tick, T0MAXTICK
  66.   pop R17
  67.   reti
  68.  
  69. ;==============================================================
  70.  
  71. reset:
  72.   ;RAM stack
  73.     ldi R17, low(RAMEND)
  74.     OUT SPL, R17
  75.  
  76.   ;PORTS
  77.     OUTI DDRB, 0xFF
  78.     OUTI PORTB, 0
  79.  
  80.   outi COM0A1, 1
  81.   outi COM0A0, 0
  82.  
  83.   ;timers
  84.     ;outi tccr0a, 0b10100011      ; режим fast pwm
  85.     outi tccr0b, 0b0000010      ; делитель на 8
  86.     ;outi gtccr, 0b00000001        ; сброс предделителя
  87.   ;OUTI TCCR0A, 8
  88.    
  89.   ;init
  90.     ldi state, 1
  91.     ldi t0tick, T0MAXTICK  
  92.    
  93.     sei
  94.  
  95. ;==============================================================
  96. main:
  97.   ;show
  98.   breq main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement