Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;-------------------------------------------------------------------------------------
- ; FILE: IntrExample
- ; DESC: Interrupt Example - Demonstrates use of interrupts
- ; DATE: 5-18-16
- ; AUTH: Class
- ; DEVICE: PICmicro (PIC18F1220)
- ;-------------------------------------------------------------------------------------
- list p=18F1220 ; processor type
- radix hex ; default radix for data
- config WDT=OFF, LVP=OFF, OSC = INTIO2 ; Disable Watchdog timer, Low V. Prog, and RA6 as a clock
- #include p18f1220.inc
- #define countID 0x80
- #define countOD 0x81
- org 0x000 ; Executes after reset
- GOTO StartL
- org 0x008 ; Executes after high priority interrupt
- GOTO HPRIO
- org 0x018 ; Executes after low priority interrupt
- GOTO LPRIO
- org 0x20
- HPRIO: ; high priority interrupt
- BCF INTCON, INT0IF ; Clear Interrupt 0
- BSF PORTB,3 ;Enable Left Motor
- BSF PORTB,4 ;Enable Right motor
- BCF PORTA,6 ;Backward Right
- BSF PORTA,7 ;Forward Left
- MOVLW .20
- CALL Delay
- BCF PORTB,3 ;Disable Left Motor
- BCF PORTB,4 ;Disable Right Motor
- RETFIE ; Return from interrupt
- LPRIO: ; Low priority interrupt
- BTFSC INTCON3, INT1IF ; Check for Interrupt 1
- BRA Intr1
- RETFIE ; Return from interrupt
- Intr1: ; take care of Interrupt 1
- BCF INTCON3, INT1IF ; Clear interrupt 1 flag
- BSF PORTB,4 ;Enable Right motor
- BSF PORTB,3 ;Enable Left Motor
- BCF PORTA,7 ;Backward Left
- BSF PORTA,6 ;Forward Right
- MOVLW .20
- CALL Delay
- BCF PORTB,4 ;Disable Right Motor
- BCF PORTB,3 ;Disable Left Motor
- RETFIE ; Return from interrupt
- StartL: ; Initialization code to be executed during reset
- ; Initialize all I/O ports
- CLRF PORTA ; Initialize PORTA
- CLRF PORTB ; Initialize PORTB
- MOVLW 0x7F ; Set all A\D Converter Pins as
- MOVWF ADCON1 ; digital I/O pins
- MOVLW 0x0D ; Value used to initialize data direction
- MOVWF TRISA ; Set Port A direction
- MOVLW 0xC7 ; Value used to initialize data direction
- MOVWF TRISB ; Set Port B direction
- MOVLW 0x00 ; clear Wreg
- BSF INTCON, PEIE ; enable all peripheral interrupts
- BSF INTCON, INT0IE ; enable INT0
- BSF INTCON3, INT1IE ; enable INT1
- BCF INTCON3, INT1IP ; INT1 is set to low priority
- BSF RCON, IPEN ; enable priority levels on interrupts
- BCF INTCON, INT0IF ;flags must be cleared to allow an interrupt
- BCF INTCON3, INT1IF ;
- BSF INTCON, GIE ; enable interrupts globally
- MainL: ;Main loop
- BTG PORTB,5 ; LED Toggle
- MOVLW .5
- CALL Delay
- BRA MainL
- ;Function to delay for Wreg x 0.1 seconds
- Delay:
- MOVWF countOD
- DelayOL: ; delay Outer loop
- CLRF countID
- DelayIL: ; Delay Inner Loop
- INCF countID
- BNZ DelayIL
- DECF countOD
- BNZ DelayOL
- RETURN ; end delay function
- end ; Interrupt Example Program
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement