INCLUDE <P18F4580.INC>
CONFIG OSC = HS
CONFIG WDT = OFF
CONFIG LVP = OFF
R1 EQU 0x01
R2 EQU 0x02
R3 EQU 0x03
ORG 000H
GOTO MAIN
ORG 008H ; default vector loc. for interrupt
BTFSS INTCON3, INT2IF ; INT2 = RB.2 If INT2IF 1->0 or 0->1 (change state), goto INT2_ISR
RETFIE
GOTO INT2_ISR ; interrupt main program
ORG 100H
MAIN
BCF TRISB, 7 ; RB.7 as Output (Green LED)
BCF TRISB, 5 ; RB.5 as Output (DC Motor)
BCF TRISD, 6 ; RD.6 as Output (Red LED)
BSF TRISB, INT2 ; RB.2 (INT2) as Input
BSF INTCON3, INT2IE ; INT2IE = 1 (Enable Interrupt INT2)
BCF INTCON2, INTEDG2 ; INTEDG2 = 0 (Disable Edge-trigger)
BSF INTCON, GIE ; GIE = 1 (Enable Global Interrupt)
AGAIN
BSF PORTB, 7 ; Send '1' to RB.7 (Light Up Green LED)
BSF PORTB, 5 ; Send '1' to RB.5 (Start Up Motor)
BCF PORTD, 6 ; Send '0' to RD.6 (Light OFF Red LED)
CALL DELAY
GOTO AGAIN
INT2_ISR
ORG 200H
BCF PORTB, 7 ; Send '0' to RB.7
BCF PORTB, 5 ; Send '0' to RB.5
BSF PORTD, 6 ; Send '1' to RD.6 (Light Up Red LED)
CALL DELAY
BTFSS PORTB, 2 ; Scan RB.2 1-->0, 0-->1
BRA INT2_ISR ; if no toggle, repeat INT2_ISR
BCF INTCON3, INT2IF ; if toggle, INT2IF = 0
RETFIE ; ended interrupt, back to state before interrupt (AGAIN)
DELAY
MOVLW d'100'
MOVWF R1
LOOP3
MOVLW d'250'
MOVWF R2
LOOP2
MOVLW d'25'
MOVWF R3
LOOP1 NOP
NOP
DECF R3, F
BNZ LOOP1
DECF R2, F
BNZ LOOP2
DECF R1, F
BNZ LOOP3
RETURN
END
PUT YOUR CURSOR AT MENU BUTTON AND SCROLL UP DOWN