Advertisement
MateuszGrabarczyk

Untitled

Jan 16th, 2023
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. TurnLedsOn:
  2. ldi r16, (1 << OCIE1B) ;set compare interrupt
  3. sts TIMSK1, r16 ;set timer interrupt
  4. ;set ocr1b to 15625
  5. ldi r16, 0x3D ; high
  6. sts OCR1BH, r16
  7. ldi r16, 0x09 ; low
  8. sts OCR1BL, r16
  9. sei ;enable interrupts
  10. ldi r17, 0 ;interrupt counter
  11. ldi r18, 0 ;will change led state
  12. ldi r19, 1 ;led state 1 if on
  13. ldi r16, 0
  14. sts tcnt1h,r16 ;zero to counter
  15. sts tcnt1l,r16 ;zero to counter
  16. ldi r16, (1<<cs12) ;prescaler 256
  17. sts tccr1b, r16 ;start timer
  18. cbi PORTB, 7 ;turn diode on
  19.  
  20. Loop:
  21. cpi r18, 1 ;should change state
  22. breq Blink ;if true jump to blink
  23. Continue:
  24. cpi r17, 3 ;should end
  25. breq End
  26. jmp Loop
  27.  
  28. Blink:
  29. cpi r19, 1 ;if led on
  30. breq TurnOff ;jump to on
  31. jmp TurnOn ;jump to on
  32.  
  33. TurnOn:
  34. cbi PORTB, 7 ;turn on led
  35. ldi R19, 1 ;state led on
  36. ldi R18, 0 ;should change false
  37. jmp Continue
  38.  
  39. TurnOff:
  40. sbi PORTB, 7 ;turn led off
  41. ldi R19, 0 ;state led off
  42. ldi R18, 0 ;should change false
  43. ldi R16, (1<<cs11)|(1<<cs10) ;prescaler 64
  44. sts tccr1b, r16
  45. ;set ocr1b to 31250
  46. ldi R16, 122
  47. sts ocr1bh, r16
  48. ldi r16, 17
  49. sts ocr1bl, r16
  50. jmp Continue
  51.  
  52. End:
  53. rjmp END
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement