Electrix
Member
I have tested two pieces of codes. Timer1 used at 32.678Khz to provide a timer of 16sec. PIC16F73 used. The First Code works..lights up LED after timer elapses..the Second Code does not work..ie PIC does not seem to wake up from sleep. My aim is to wake up the PIC from sleep using Timer1 Interrupt.
Please help !
CODE 1: (Working)
CODE 2: (Not Working)
Please help !
CODE 1: (Working)
Code:
list p=16f73 ; list directive to define processor
#include <p16f73.inc> ; processor specific variable definitions
__CONFIG _CP_OFF
; '__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
w_temp EQU 0x20 ; variable used for context saving
w_temp1 EQU 0xA0 ; reserve bank1 equivalent of w_temp
status_temp EQU 0x21 ; variable used for context saving
pclath_temp EQU 0x22 ; variable used for context saving
;**********************************************************************
ORG 0x000 ; processor reset vector
clrf PCLATH ; ensure page bits are cleared
goto main ; go to beginning of program
ORG 0x004 ; interrupt vector location
movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
bcf STATUS,RP0 ; ensure file register bank set to 0
movwf status_temp ; save off contents of STATUS register
movf PCLATH,w ; move pclath register into w register
movwf pclath_temp ; save off contents of PCLATH register
; isr code can go here or be located as a call subroutine elsewhere
bcf STATUS,RP0 ; ensure file register bank set to 0
movf pclath_temp,w ; retrieve copy of PCLATH register
movwf PCLATH ; restore pre-isr PCLATH register contents
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
retfie ; return from interrupt
main
; remaining code goes here
CLRF T1CON ; Stop Timer1, Internal Clock Source,
; T1 oscillator disabled, prescaler = 1:1
CLRF TMR1H ; Clear Timer1 High byte register
CLRF TMR1L ; Clear Timer1 Low byte register
CLRF INTCON ; Disable interrupts
BSF STATUS, RP0 ; Bank1
;movlw 0x01 ;Enable TMR1 Interrupt
;movwf PIE1
CLRF PIE1 ; Disable peripheral interrupts
BCF STATUS, RP0 ; Bank0
CLRF PIR1 ; Clear peripheral interrupts Flags
MOVLW 0x3E ; External Clock source with oscillator
MOVWF T1CON ; circuitry, 1:8 prescaler, Clock source
; is asynchronous to device
; Timer1 is stopped
BSF T1CON, TMR1ON ; Timer1 starts to increment
;
; The Timer1 interrupt is disabled, do polling on the overflow bit
;
T1_OVFL_WAIT
BTFSS PIR1, TMR1IF
GOTO T1_OVFL_WAIT
;
; Timer has overflowed
;
BCF PIR1, TMR1IF
BANKSEL TRISA
clrf TRISA
BANKSEL PORTA
bsf PORTA,0
END ; directive 'end of program'
CODE 2: (Not Working)
Code:
list p=16f73 ; list directive to define processor
#include <p16f73.inc> ; processor specific variable definitions
__CONFIG _CP_OFF
; '__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
w_temp EQU 0x20 ; variable used for context saving
w_temp1 EQU 0xA0 ; reserve bank1 equivalent of w_temp
status_temp EQU 0x21 ; variable used for context saving
pclath_temp EQU 0x22 ; variable used for context saving
;**********************************************************************
ORG 0x000 ; processor reset vector
clrf PCLATH ; ensure page bits are cleared
goto main ; go to beginning of program
ORG 0x004 ; interrupt vector location
movwf w_temp ; save off current W register contents
movf STATUS,w ; move status register into W register
bcf STATUS,RP0 ; ensure file register bank set to 0
movwf status_temp ; save off contents of STATUS register
movf PCLATH,w ; move pclath register into w register
movwf pclath_temp ; save off contents of PCLATH register
; isr code can go here or be located as a call subroutine elsewhere
bcf STATUS,RP0 ; ensure file register bank set to 0
movf pclath_temp,w ; retrieve copy of PCLATH register
movwf PCLATH ; restore pre-isr PCLATH register contents
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
retfie ; return from interrupt
main
; remaining code goes here
CLRF T1CON ; Stop Timer1, Internal Clock Source,
; T1 oscillator disabled, prescaler = 1:1
CLRF TMR1H ; Clear Timer1 High byte register
CLRF TMR1L ; Clear Timer1 Low byte register
CLRF INTCON ; Disable interrupts
BSF STATUS, RP0 ; Bank1
movlw 0x01 ;Enable TMR1 Interrupt
movwf PIE1
;CLRF PIE1 ; Disable peripheral interrupts
BCF STATUS, RP0 ; Bank0
CLRF PIR1 ; Clear peripheral interrupts Flags
MOVLW 0x3E ; External Clock source with oscillator
MOVWF T1CON ; circuitry, 1:8 prescaler, Clock source
; is asynchronous to device
; Timer1 is stopped
BSF T1CON, TMR1ON ; Timer1 starts to increment
;
; The Timer1 interrupt is disabled, do polling on the overflow bit
;
;T1_OVFL_WAIT
;BTFSS PIR1, TMR1IF
;GOTO T1_OVFL_WAIT
;
; Timer has overflowed
;
sleep
nop
BCF PIR1, TMR1IF
BANKSEL TRISA
clrf TRISA
BANKSEL PORTA
bsf PORTA,0
END ; directive 'end of program'