saviourm
Junior Member level 3

Good Morning Guys
I am learning Interrupts using pic 16F84A.I tried this below program and worked well in my pic . I found this program on the web. I can't understand the interrupt speciaclly line between 13-18. **broken link removed**
Thanks
org 0x00 ;This is where we come on power up and reset 1
;*******************SETUP CONSTANTS*******************
INTCON EQU 0x0B ;Interrupt Control Register 2
PORTB EQU 0x06 ;Port B register address 3
PORTA EQU 0x05 ;Port A register address 4
TRISA EQU 0x85 ;TrisA register address 5
TRISB EQU 0x86 ;TrisB register address 6
STATUS EQU 0X03 ;Status register address 7
COUNT EQU 0x0c ;This will be our counting variable 8
TEMP EQU 0x0d ;Temporary store for w register 9
goto main ;Jump over the interrupt address 10
;***************INTERRUPT ROUTINE***************
org 0x04 ;This is where PC points on an interrupt 11
movwf TEMP ;Store the value of w temporarily 12
incf COUNT,1 ;Increment COUNT by 1, and put the result 13
;back into COUNT
movlw 0x0A ;Move the value 10 into w 14
subwf COUNT,0 ;Subtract w from COUNT, and put the 15
;result in w
btfss STATUS,0 ;Check the Carry flag. It will be set if 16
;COUNT is equal to, or is greater than w,
;and will be set as a result of the subwf
;instruction
goto carry_on ;If COUNT is <10, then we can carry on 17
goto clear ;If COUNT is >9, then we need to clear it 18
carry_on
bcf INTCON,0x01 ;We need to clear this flag to enable 19
;more interrupts
movfw TEMP ;Restore w to the value before the interrupt20
retfie ;Come out of the interrupt routine 21
clear 22
clrf COUNT ;Set COUNT back to 0 23
bcf INTCON,1 ;We need to clear this flag to enable 24
;more interrupts
retfie ;Come out of the interrupt routine 25
;*******************Main Program*********************
main
;*******************Set Up The Interrupt Registers****
bsf INTCON,7 ;GIE – Global interrupt enable (1=enable) 26
bsf INTCON,4 ;INTE - RB0 Interrupt Enable (1=enable) 27
bcf INTCON,1 ;INTF - Clear FLag Bit Just In Case 28
;*******************Set Up The Ports******************
bsf STATUS,5 ;Switch to Bank 1 29
movlw 0x01 30
movwf TRISB ;Set RB0 as input 31
movlw 0x10 32
movwf TRISA ;Set R 0 to RA3 on PortA as output 33
bcf STATUS,5 ;Come back to Bank 0 34
;*******************Now Send The Value Of COUNT To Port A
loop 35
movf COUNT,0 ;Move the contents of Count into W 36
movwf PORTA ;Now move it to Port A 37
goto loop ;Keep on doing this 38
end ;End Of Program 39
I am learning Interrupts using pic 16F84A.I tried this below program and worked well in my pic . I found this program on the web. I can't understand the interrupt speciaclly line between 13-18. **broken link removed**
Thanks
org 0x00 ;This is where we come on power up and reset 1
;*******************SETUP CONSTANTS*******************
INTCON EQU 0x0B ;Interrupt Control Register 2
PORTB EQU 0x06 ;Port B register address 3
PORTA EQU 0x05 ;Port A register address 4
TRISA EQU 0x85 ;TrisA register address 5
TRISB EQU 0x86 ;TrisB register address 6
STATUS EQU 0X03 ;Status register address 7
COUNT EQU 0x0c ;This will be our counting variable 8
TEMP EQU 0x0d ;Temporary store for w register 9
goto main ;Jump over the interrupt address 10
;***************INTERRUPT ROUTINE***************
org 0x04 ;This is where PC points on an interrupt 11
movwf TEMP ;Store the value of w temporarily 12
incf COUNT,1 ;Increment COUNT by 1, and put the result 13
;back into COUNT
movlw 0x0A ;Move the value 10 into w 14
subwf COUNT,0 ;Subtract w from COUNT, and put the 15
;result in w
btfss STATUS,0 ;Check the Carry flag. It will be set if 16
;COUNT is equal to, or is greater than w,
;and will be set as a result of the subwf
;instruction
goto carry_on ;If COUNT is <10, then we can carry on 17
goto clear ;If COUNT is >9, then we need to clear it 18
carry_on
bcf INTCON,0x01 ;We need to clear this flag to enable 19
;more interrupts
movfw TEMP ;Restore w to the value before the interrupt20
retfie ;Come out of the interrupt routine 21
clear 22
clrf COUNT ;Set COUNT back to 0 23
bcf INTCON,1 ;We need to clear this flag to enable 24
;more interrupts
retfie ;Come out of the interrupt routine 25
;*******************Main Program*********************
main
;*******************Set Up The Interrupt Registers****
bsf INTCON,7 ;GIE – Global interrupt enable (1=enable) 26
bsf INTCON,4 ;INTE - RB0 Interrupt Enable (1=enable) 27
bcf INTCON,1 ;INTF - Clear FLag Bit Just In Case 28
;*******************Set Up The Ports******************
bsf STATUS,5 ;Switch to Bank 1 29
movlw 0x01 30
movwf TRISB ;Set RB0 as input 31
movlw 0x10 32
movwf TRISA ;Set R 0 to RA3 on PortA as output 33
bcf STATUS,5 ;Come back to Bank 0 34
;*******************Now Send The Value Of COUNT To Port A
loop 35
movf COUNT,0 ;Move the contents of Count into W 36
movwf PORTA ;Now move it to Port A 37
goto loop ;Keep on doing this 38
end ;End Of Program 39