Advertisement
Slyfoxx724

Lab4 ENGR270

Feb 22nd, 2017
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. ;-------------------------------------------------------------------------------------
  2. ; FILE: IntrExample
  3. ; DESC: Interrupt Example - Demonstrates use of interrupts
  4. ; DATE: 5-18-16
  5. ; AUTH: Class
  6. ; DEVICE: PICmicro (PIC18F1220)
  7. ;-------------------------------------------------------------------------------------
  8. list p=18F1220 ; processor type
  9. radix hex ; default radix for data
  10. config WDT=OFF, LVP=OFF, OSC = INTIO2 ; Disable Watchdog timer, Low V. Prog, and RA6 as a clock
  11.  
  12. #include p18f1220.inc
  13. #define countID 0x80
  14. #define countOD 0x81
  15.  
  16. org 0x000 ; Executes after reset
  17.  
  18. GOTO StartL
  19. org 0x008 ; Executes after high priority interrupt
  20.  
  21. GOTO HPRIO
  22. org 0x018 ; Executes after low priority interrupt
  23.  
  24. GOTO LPRIO
  25. org 0x20
  26.  
  27. HPRIO: ; high priority interrupt
  28. ADDLW .2 ; when interrupt 0 occurs
  29. BCF INTCON, INT0IF ; Clear Interrupt 0
  30. BSF PORTB,3 ;Enable Left Motor
  31. BSF PORTB,4 ;Enable Right motor
  32. BCF PORTA,6 ;Backward Right
  33. BSF PORTA,7 ;Forward Left
  34. MOVLW .10
  35. CALL Delay
  36. BCF PORTB,3 ;Disable Left Motor
  37. BCF PORTB,4 ;Disable Right Motor
  38. RETFIE ; Return from interrupt
  39.  
  40.  
  41. LPRIO: ; Low priority interrupt
  42. BTFSC INTCON3, INT1IF ; Check for Interrupt 1
  43. BRA Intr1
  44.  
  45.  
  46. RETFIE ; Return from interrupt
  47.  
  48. Intr1: ; take care of Interrupt 1
  49. ADDLW 0xFB ; W?(W-5). {note: SUBLW .5 will not work}
  50. BCF INTCON3, INT1IF ; Clear interrupt 1 flag
  51. BSF PORTB,4 ;Enable Right motor
  52. BSF PORTB,3 ;Enable Left Motor
  53. BCF PORTA,7 ;Backward Left
  54. BSF PORTA,6 ;Forward Right
  55. MOVLW .10
  56. CALL Delay
  57. BCF PORTB,4 ;Disable Right Motor
  58. BCF PORTB,3 ;Disable Left Motor
  59. RETFIE ; Return from interrupt
  60.  
  61. StartL: ; Initialization code to be executed during reset
  62. ; Initialize all I/O ports
  63. CLRF PORTA ; Initialize PORTA
  64. CLRF PORTB ; Initialize PORTB
  65. MOVLW 0x7F ; Set all A\D Converter Pins as
  66. MOVWF ADCON1 ; digital I/O pins
  67. MOVLW 0x0D ; Value used to initialize data direction
  68. MOVWF TRISA ; Set Port A direction
  69. MOVLW 0xC7 ; Value used to initialize data direction
  70. MOVWF TRISB ; Set Port B direction
  71. MOVLW 0x00 ; clear Wreg
  72. BSF INTCON, PEIE ; enable all peripheral interrupts
  73. BSF INTCON, INT0IE ; enable INT0
  74. BSF INTCON3, INT1IE ; enable INT1
  75. BCF INTCON3, INT1IP ; INT1 is set to low priority
  76. BSF RCON, IPEN ; enable priority levels on interrupts
  77. BCF INTCON, INT0IF ;flags must be cleared to allow an interrupt
  78. BCF INTCON3, INT1IF ;
  79. BSF INTCON, GIE ; enable interrupts globally
  80. MOVLW .10 ; Set starting delay to 0.5 seconds
  81.  
  82. MainL: ;Main loop
  83. BTG PORTB,5 ; LED Toggle
  84. CALL Delay
  85. BRA MainL
  86. ;Function to delay for Wreg x 0.1 seconds
  87.  
  88. Delay:
  89. MOVWF countOD
  90.  
  91. DelayOL: ; delay Outer loop
  92. CLRF countID
  93.  
  94. DelayIL: ; Delay Inner Loop
  95. INCF countID
  96. BNZ DelayIL
  97. DECF countOD
  98. BNZ DelayOL
  99. RETURN ; end delay function
  100.  
  101. end ; Interrupt Example Program
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement