Advertisement
Guest User

Untitled

a guest
Nov 23rd, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  2. ; 1DT301, Computer Technology I
  3. ; Date: 2017-09-289
  4. ; Author:
  5. ; Christian Fagerholm
  6. ; Amelie Löwe
  7. ;
  8. ; Lab number: 4
  9. ; Title: How to use the PORTs. Digital input/output. Subroutine call.
  10. ;
  11. ; Hardware: STK600, CPU ATmega2560
  12. ;
  13. ; Function: Describe the function of the program, so that you can understand it,
  14. ; even if you're viewing this in a year from now!
  15. ;
  16. ; Input ports: None
  17. ;
  18. ; Output ports: example on-board LEDsonnected to PORTB.
  19. ;
  20. ;
  21. ; Subroutines: If applicable.
  22. ; Included files: m2560def.inc
  23. ;
  24. ; Other information:
  25. ;
  26. ; Changes in program: (Description and date)
  27. ;
  28. ;<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
  29.  
  30.  
  31. ; Replace with your application code
  32. .org 0x00
  33. rjmp setup
  34. .org OVF1addr
  35. rjmp timer1_int
  36.  
  37.  
  38. .org 0x72
  39. setup:
  40. .equ timer_start = 65036
  41. .def temp = r16
  42. .include "m2560def.inc"
  43. ldi r20, HIGH(RAMEND) ;Initiating Stack
  44. out SPH, r20 ;
  45. ldi r20, LOW(RAMEND)
  46. out SPL, r20
  47.  
  48. ldi r19, 0x00
  49.  
  50. ldi r17, 0xFF ;Outputs, Port B
  51. out DDRB, r17
  52.  
  53. ldi temp, 0x05 ; prescaler value 1024
  54. sts TCCR1B, temp
  55.  
  56. ldi temp, (1<<TOIE1) ; Timer 1 enable flag, TOIE1
  57. sts TIMSK1, temp ; to register TIMSK
  58.  
  59. ldi temp , HIGH(timer_start)
  60. sts TCNT1H, temp
  61. ldi temp, LOW(timer_start)
  62. sts TCNT1L, temp
  63.  
  64.  
  65. sei ; enable global interrupt
  66.  
  67.  
  68. start:
  69. nop
  70. rjmp start
  71.  
  72.  
  73. timer1_int:
  74. push temp ; timer interrupt routine
  75. in temp, SREG ; save SREG on stack
  76. push temp
  77.  
  78. ldi temp, HIGH(timer_start)
  79. sts TCNT1H, temp
  80. ldi temp, LOW(timer_start)
  81. sts TCNT1L, temp
  82.  
  83. com r19
  84. out PORTB, r19
  85.  
  86. pop temp ; restore SREG
  87. out SREG, temp
  88. pop temp ; restore register
  89.  
  90. reti
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement