Advertisement
Slyfoxx724

ENGR270 LAB4(2)

Feb 23rd, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 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. GOTO StartL
  18.  
  19. org 0x008 ; Executes after high priority interrupt
  20. GOTO HPRIO
  21.  
  22. org 0x018 ; Executes after low priority interrupt
  23. GOTO LPRIO
  24.  
  25. org 0x20
  26. HPRIO: ; high priority interrupt
  27. BCF INTCON, INT0IF ; Clear Interrupt 0
  28. BSF PORTB,3 ;Enable Left Motor
  29. BSF PORTB,4 ;Enable Right motor
  30. BCF PORTA,6 ;Backward Right
  31. BSF PORTA,7 ;Forward Left
  32. MOVLW .20
  33. CALL Delay
  34. BCF PORTB,3 ;Disable Left Motor
  35. BCF PORTB,4 ;Disable Right Motor
  36. RETFIE ; Return from interrupt
  37.  
  38.  
  39. LPRIO: ; Low priority interrupt
  40. BTFSC INTCON3, INT1IF ; Check for Interrupt 1
  41. BRA Intr1
  42. RETFIE ; Return from interrupt
  43.  
  44. Intr1: ; take care of Interrupt 1
  45. BCF INTCON3, INT1IF ; Clear interrupt 1 flag
  46. BSF PORTB,4 ;Enable Right motor
  47. BSF PORTB,3 ;Enable Left Motor
  48. BCF PORTA,7 ;Backward Left
  49. BSF PORTA,6 ;Forward Right
  50. MOVLW .20
  51. CALL Delay
  52. BCF PORTB,4 ;Disable Right Motor
  53. BCF PORTB,3 ;Disable Left Motor
  54. RETFIE ; Return from interrupt
  55.  
  56. StartL: ; Initialization code to be executed during reset
  57. ; Initialize all I/O ports
  58. CLRF PORTA ; Initialize PORTA
  59. CLRF PORTB ; Initialize PORTB
  60. MOVLW 0x7F ; Set all A\D Converter Pins as
  61. MOVWF ADCON1 ; digital I/O pins
  62. MOVLW 0x0D ; Value used to initialize data direction
  63. MOVWF TRISA ; Set Port A direction
  64. MOVLW 0xC7 ; Value used to initialize data direction
  65. MOVWF TRISB ; Set Port B direction
  66. MOVLW 0x00 ; clear Wreg
  67. BSF INTCON, PEIE ; enable all peripheral interrupts
  68. BSF INTCON, INT0IE ; enable INT0
  69. BSF INTCON3, INT1IE ; enable INT1
  70. BCF INTCON3, INT1IP ; INT1 is set to low priority
  71. BSF RCON, IPEN ; enable priority levels on interrupts
  72. BCF INTCON, INT0IF ;flags must be cleared to allow an interrupt
  73. BCF INTCON3, INT1IF ;
  74. BSF INTCON, GIE ; enable interrupts globally
  75.  
  76. MainL: ;Main loop
  77. BTG PORTB,5 ; LED Toggle
  78. MOVLW .5
  79. CALL Delay
  80. BRA MainL
  81. ;Function to delay for Wreg x 0.1 seconds
  82.  
  83. Delay:
  84. MOVWF countOD
  85.  
  86. DelayOL: ; delay Outer loop
  87. CLRF countID
  88.  
  89. DelayIL: ; Delay Inner Loop
  90. INCF countID
  91. BNZ DelayIL
  92. DECF countOD
  93. BNZ DelayOL
  94. RETURN ; end delay function
  95.  
  96. end ; Interrupt Example Program
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement