Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. .include "m2560def.inc"
  2. .def temp = r16
  3. .def curr = r17
  4. .def last_interrupt0 = r18
  5. .def last_interrupt1 = r19
  6. .def temp2 = r20
  7.  
  8. .cseg
  9. .org 0x0
  10. jmp RESET ; interrupt vector for RESET
  11. .org INT0addr ; INT0addr is the address of EXT_INT0 (External Interrupt 0)
  12. jmp EXT_INT0 ; interrupt vector for External Interrupt 0
  13. .org INT1addr ; INT1addr is the address of EXT_INT1 (External Interrupt 1)
  14. jmp EXT_INT1 ; interrupt vector for External Interrupt 1
  15.  
  16. RESET:
  17. ldi temp, low(RAMEND) ; initialise stack pointer to point to the high end of SRAM
  18. out SPL, temp
  19. ldi temp, high(RAMEND)
  20. out SPH, temp
  21. ldi temp, 0b1111 ; temp = 0b00001111
  22. mov curr, temp ; copy temp to curr
  23. out DDRC, temp ; 6~9 LEDs of Port C is set to outputs
  24. out PORTC, temp ; 6~9 LEDs are set to ones
  25. out DDRD, temp ; Port D is set to all inputs
  26. out PORTD, temp
  27. ldi temp, (2<<ISC10)|(2<<ISC00) ; The build-in constants ISC10=2 and ISC00=0 are their bit numbers in EICRA register
  28. sts EICRA, temp ; temp = 0b00001010, so both interrupts are configured as falling edge triggered interrupts
  29. in temp, EIMSK
  30. ori temp, (1<<INT0)|(1<<INT1) ; INT0=0 & INT1=1
  31. out EIMSK, temp ; Enable External Interrupts 0 and 1
  32. sei ; Enable the global interrupt
  33. jmp main
  34.  
  35. EXT_INT0: ; Interrupt handler for External Interrupt 0
  36. ; prologue
  37. push temp
  38. in temp, SREG
  39. push temp
  40. ; sub-routine code start
  41. mov temp2, temp
  42. sub temp2, last_interrupt0
  43. cpi temp2, 10
  44. brlt epilogue0
  45.  
  46. dec curr
  47. out PORTC, curr
  48. mov last_interrupt0, temp
  49. ; epilogue
  50. epilogue0:
  51. pop temp
  52. out SREG, temp
  53. pop temp
  54. reti
  55.  
  56. EXT_INT1: ; Interrupt handler for External Interrupt 1
  57. ; prologue
  58. push temp
  59. in temp, SREG
  60. push temp
  61. ; sub-routine code start
  62. mov temp2, temp
  63. sub temp2, last_interrupt1
  64. cpi temp2, 10
  65. brlt epilogue1
  66.  
  67. inc curr
  68. out PORTC, curr
  69. mov last_interrupt1, temp
  70. ; epilogue
  71. epilogue1:
  72. pop temp
  73. out SREG, temp
  74. pop temp
  75. reti
  76.  
  77. main: ; main does nothing but increments a counter
  78. clr temp
  79. clr last_interrupt0 ; Clear last interrupt time for PB0
  80. clr last_interrupt1 ; Clear last interrupt time for PB1
  81. loop: inc temp
  82. rjmp loop ; An infinite loop must be at the end of the interrupt handler for RESET
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement