BlackOps
Full Member level 5
- Joined
- Jan 1, 2005
- Messages
- 279
- Helped
- 14
- Reputation
- 28
- Reaction score
- 3
- Trophy points
- 1,298
- Location
- AZERBAIJAN
- Activity points
- 2,496
rb0 interrupt
Hello, experimenting with interrupts using PIC16F84A
So i connected one LED to the RB7 line of PORTB.
and i connected active-LOW Push button to RB0 line of PORTB.
pressing the button toggles On/OFF the LED.
so here is the code which i took from the book "Microcontroller Programming: the Microchip PIC", and remaked for my current circuit:
well, the programs were not so well documented in book, and when i remaked the initial program i didnt include this piece of code:
delay:
movlw 4
movwf count1 ; Store value in counter
repeat:
decfsz count1,f ; Decrement counter
goto repeat ; Continue if not 0
return
and my push button did not work correctly....
but when i included it, the program worked well! and no quit and hanging in simulation in Proteus! why? what does that piece of code do?
i tried to debug this program, and noticed that PC never goes to that piece of code... it reaches retfie instruction which is right before this piece of code, and then Loop begins again...and so on.... so...i notice that this code never executes....then how does it affect my program?
thanks
Hello, experimenting with interrupts using PIC16F84A
So i connected one LED to the RB7 line of PORTB.
and i connected active-LOW Push button to RB0 line of PORTB.
pressing the button toggles On/OFF the LED.
so here is the code which i took from the book "Microcontroller Programming: the Microchip PIC", and remaked for my current circuit:
Code:
;=====================================================
; File: RB0Int.ASM
; Date: April 22, 2006
; Author: Julio Sanchez
; Processor: 16F84A
;=====================================================
; Description:
; Program to test interrupt on port RB0
; A pushbutton switch is connected to port RB0.
; The pushbutton toggles a LED on port-B, line 7
;
;
;=====================================================
;=========================
; setup and configuration
;=========================
processor 16f84A
include <p16f84A.inc>
__config _XT_OSC & _WDT_OFF & _PWRTE_ON & _CP_OFF
;=====================================================
; variables in PIC RAM
;=====================================================
cblock 0x0d ; Start of block
count2 ; ISR counter
old_w ; Context saving
old_STATUS
Delay1
count1
endc
;========================================================
; ********** PROGRAM START **********
;========================================================
org 0 ; Program start at address 0
goto main
;=============================
; INTERRUPT HANDLER
;=============================
org 0x04
goto IntServ
;=============================
; MAIN PROGRAM
;=============================
main:
bsf STATUS,RP0 ; Select Bank1
bcf OPTION_REG,INTEDG ; Set interrupt on falling edge
; by clearing INTEDG bit of OPTION_REG
movlw b'00000001' ; PORTB bit 0
movwf TRISB ; is Input, all other bits are Output
bcf STATUS,RP0 ; Go back to Bank0
clrf PORTB ; Clear PORTB
;bsf PORTB,0 ; set PORTB bit 0
; SETUP INTERRUPTS
bcf INTCON,INTF ; Clear external interrupt flag (INTF = bit 1)
bsf INTCON,GIE ; Enable global interrupts (GIE = bit 7)
bsf INTCON,INTE ; Enable RB0 interrupt (INTE = bit 4)
;============================
; flash led
;============================
Loop:
nop
nop
nop
goto Loop
;clrf PORTB
;=======================================================
; Interrupt Service Routine
;=======================================================
IntServ: ; First test if source is an RB0 interrupt
btfss INTCON,INTF ; INTF flag is RB0 interrupt
goto notRB0 ; Go if not RB0 origin
; Save context
movwf old_w ; Save w register
swapf STATUS,w ; STATUS to w
movwf old_STATUS ; Save STATUS
; Make sure that interrupt occurred on the falling edge
; of the signal. If not, abort handler
btfsc PORTB,0 ; Is bit set?
goto exitISR ; Go if clear
;=========================
; interrupt action
;=========================
;clrf PORTB
movlw 10 ; Number of repetitions
movwf count2 ; To counter
wait: ; Check to see that port-B bit 0 is still 0
; If not, wait until it changes
btfsc PORTB,0 ; Is bit set?
goto exitISR ; Go if bit not 0
; At this point RB0 bit is clear
decfsz count2,f ; Count this iteration
goto wait ; Continue if not zero
; Interrupt action consists of toggling bit 2 of
; port-B to turn LED on and off
; ACTION!!!!
movlw b'10000000' ; Xoring with a 1-bit produces
; the complement
xorwf PORTB,1 ; Complement bit 2, port-B
;=========================
; exit ISR
;=========================
exitISR: ; Restore context
swapf old_STATUS,w ; Saved STATUS to w
swapf old_w,f ; Swap file register in itself
swapf old_w,w ; re-swap back to w
notRB0: ; Reset,interrupt
bcf INTCON,INTF ; Clear INTCON bit 1
retfie
delay:
movlw 4
movwf count1 ; Store value in counter
repeat:
decfsz count1,f ; Decrement counter
goto repeat ; Continue if not 0
return
end
well, the programs were not so well documented in book, and when i remaked the initial program i didnt include this piece of code:
delay:
movlw 4
movwf count1 ; Store value in counter
repeat:
decfsz count1,f ; Decrement counter
goto repeat ; Continue if not 0
return
and my push button did not work correctly....
but when i included it, the program worked well! and no quit and hanging in simulation in Proteus! why? what does that piece of code do?
i tried to debug this program, and noticed that PC never goes to that piece of code... it reaches retfie instruction which is right before this piece of code, and then Loop begins again...and so on.... so...i notice that this code never executes....then how does it affect my program?
thanks