forislam
Newbie level 1
hi,
I face a problem in timer0 interrupt where it can count perfectly, but it after reach it's end it should set the timer0 interrupt flag and directly go to 004 to execute the ISR.
what it done is that it correctly count and set the flag , but it can't go to ISR cuz it can't go to 004 "interrupt vector"
here is the code where my program load values in eeprom and read it after 1 sec interrupt
list p=16F84A ; list directive to define processor
#include <p16F84A.inc> ; processor specific variable definitions
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC
; '__CONFIG' directive is used to embed configuration data within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.
;***** VARIABLE DEFINITIONS
STATUS EQU 03h ; Address of the STATUS register
TRISA EQU 85h ; Address of the tristate register for port A
PORTA EQU 05h ; Address of Port A
EEADR EQU 09h
EEDATA EQU 08h
addressC EQU 20h
w_temp EQU 0x24 ; variable used for context saving
status_temp EQU 0x25 ; variable used for context saving
INTCON EQU 0x0B ; Interrupt Control Register // bank 0
COUNT1 EQU 22h
OPTION_REG EQU 81h
EECON1 EQU 88h
EECON2 EQU 89h
CNT EQU 24h
TMR0 EQU 01h
ORG H'2100'
DE 0x01,0x03,0x07,0x0F,0x1F,0x3F,0x3E,0x3C,0x38,0x30,0x10,0xFF ;to Enter the data in memory
;**********************************************************************
ORG 0x000 ; processor reset vector
goto main ; go to beginning of program
;============================
; INTERRUPTS
;============================
ORG 0x004 ; interrupt vector location <-------------------------- here the timer can't enter !!!
btfsc INTCON,T0IF
call intsrv
bcf INTCON,T0IF ; Clear INTCON bit 1 - i.e clear intflag -
; To be able recieve more interrupts
retfie
;===========================
main
bsf STATUS,5 ; Switch to Bank 1
movlw 00h ; Set the Port A pins with zeros
movwf TRISA ; All port A is output
bcf STATUS,5 ; Switch back to Bank 0
movlw 0x0c ; load 11 in count 1 to wait for 11 timer interrupt
movwf COUNT1
movlw 0x01
movwf addressC
; SETUP INTERRUPTS
bcf INTCON,T0IF ; Clear internal interrupt flag (INTF = bit 1)
bsf INTCON,GIE ; Enable global interrupts (GIE = bit 7)
;=========================
; Timer0
;=========================
MOVLW .96
MOVWF TMR0
bsf STATUS,5
movlw b'00010100' ; set timer0 with prescaler 1:4
movwf OPTION_REG
bcf STATUS,5
bsf INTCON,GIE ; Enable global interrupts (GIE = bit 7)
CLRF CNT
;===============================================
Start
goto Start
;===============================================
intsrv
movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
movwf status_temp ; save off contents of STATUS register
;=================
; VERIFY 1 SEC
;=================
INCF CNT,F ; increament counter
MOVLW .196 ; w <--- h'c4'
SUBWF CNT,W ; cnt - w
BTFSS STATUS,Z ; if cnt = 0 we can execute read operation else return to wait more
retfie
;=================
; READ
;=================
bcf STATUS,5 ;bank0, because EEADR is at 09h
movf addressC,w ;address of location being read
movwf EEADR ;address transferred to EEADR
bsf STATUS,5 ;bank1 because EECON1 is at 88h
bsf EECON1,RD ;reading from EEPROM
bcf STATUS,5 ;bank0 because EEDATA is at 08h
movf EEDATA,W ; W < EEDATA
movwf PORTA ;portA <-- data
;=================
; End Read
;=================
movf addressC,w ; increment addressc to read the next value in EEPROM
addlw 0x01
movwf addressC
exitISR movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
DECFSZ COUNT1, 1 ; that for doing 11 interrupt only
return
;-----------------------------------------------------------
END ; directive 'end of program'
I face a problem in timer0 interrupt where it can count perfectly, but it after reach it's end it should set the timer0 interrupt flag and directly go to 004 to execute the ISR.
what it done is that it correctly count and set the flag , but it can't go to ISR cuz it can't go to 004 "interrupt vector"
here is the code where my program load values in eeprom and read it after 1 sec interrupt
list p=16F84A ; list directive to define processor
#include <p16F84A.inc> ; processor specific variable definitions
__CONFIG _CP_OFF & _WDT_OFF & _PWRTE_ON & _XT_OSC
; '__CONFIG' directive is used to embed configuration data within .asm file.
; The lables following the directive are located in the respective .inc file.
; See respective data sheet for additional information on configuration word.
;***** VARIABLE DEFINITIONS
STATUS EQU 03h ; Address of the STATUS register
TRISA EQU 85h ; Address of the tristate register for port A
PORTA EQU 05h ; Address of Port A
EEADR EQU 09h
EEDATA EQU 08h
addressC EQU 20h
w_temp EQU 0x24 ; variable used for context saving
status_temp EQU 0x25 ; variable used for context saving
INTCON EQU 0x0B ; Interrupt Control Register // bank 0
COUNT1 EQU 22h
OPTION_REG EQU 81h
EECON1 EQU 88h
EECON2 EQU 89h
CNT EQU 24h
TMR0 EQU 01h
ORG H'2100'
DE 0x01,0x03,0x07,0x0F,0x1F,0x3F,0x3E,0x3C,0x38,0x30,0x10,0xFF ;to Enter the data in memory
;**********************************************************************
ORG 0x000 ; processor reset vector
goto main ; go to beginning of program
;============================
; INTERRUPTS
;============================
ORG 0x004 ; interrupt vector location <-------------------------- here the timer can't enter !!!
btfsc INTCON,T0IF
call intsrv
bcf INTCON,T0IF ; Clear INTCON bit 1 - i.e clear intflag -
; To be able recieve more interrupts
retfie
;===========================
main
bsf STATUS,5 ; Switch to Bank 1
movlw 00h ; Set the Port A pins with zeros
movwf TRISA ; All port A is output
bcf STATUS,5 ; Switch back to Bank 0
movlw 0x0c ; load 11 in count 1 to wait for 11 timer interrupt
movwf COUNT1
movlw 0x01
movwf addressC
; SETUP INTERRUPTS
bcf INTCON,T0IF ; Clear internal interrupt flag (INTF = bit 1)
bsf INTCON,GIE ; Enable global interrupts (GIE = bit 7)
;=========================
; Timer0
;=========================
MOVLW .96
MOVWF TMR0
bsf STATUS,5
movlw b'00010100' ; set timer0 with prescaler 1:4
movwf OPTION_REG
bcf STATUS,5
bsf INTCON,GIE ; Enable global interrupts (GIE = bit 7)
CLRF CNT
;===============================================
Start
goto Start
;===============================================
intsrv
movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
movwf status_temp ; save off contents of STATUS register
;=================
; VERIFY 1 SEC
;=================
INCF CNT,F ; increament counter
MOVLW .196 ; w <--- h'c4'
SUBWF CNT,W ; cnt - w
BTFSS STATUS,Z ; if cnt = 0 we can execute read operation else return to wait more
retfie
;=================
; READ
;=================
bcf STATUS,5 ;bank0, because EEADR is at 09h
movf addressC,w ;address of location being read
movwf EEADR ;address transferred to EEADR
bsf STATUS,5 ;bank1 because EECON1 is at 88h
bsf EECON1,RD ;reading from EEPROM
bcf STATUS,5 ;bank0 because EEDATA is at 08h
movf EEDATA,W ; W < EEDATA
movwf PORTA ;portA <-- data
;=================
; End Read
;=================
movf addressC,w ; increment addressc to read the next value in EEPROM
addlw 0x01
movwf addressC
exitISR movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
DECFSZ COUNT1, 1 ; that for doing 11 interrupt only
return
;-----------------------------------------------------------
END ; directive 'end of program'