Truncated match.
PICList
Thread
'Help with Interrupts using Timer1'
1998\11\16@172521
by
Ohtsji, Randie
|
Hello,
This is the first time I'm attempting to use interrupts and I could use a
little help........
I'm using a PIC16C63 and would like to use interrupts with the timer1
module. I would like an interrupt routine to do something every 1 second,
so I am using a 32.768KHz crystal between RC0 and RC1 and using a prescale
of 1:2. I have set up the program something like the following but I do not
seem to be getting the interrupt. Can someone please comment on what I may
be doing wrong.
Thanks
Randie
=====================================================================
org 0x0000
goto start
=====================================================================
org 0x0004 ;interrupt address
bcf intcon,7 ;disable global interrupts
movwf _w ;save w
movf status,w
movwf _status ;save status
movf fsr,w
movwf _fsr ;save fsr
call isr ;do interrupt routine
movf _fsr,w
movwf fsr ;restore fsr
movf _status,w
movwf status ;restore status
swapf _w,f ;restore w without affecting status
swapf _w,w
retfie ;exit and re-enable global
interrupts
=======================================================================
start ;main program
.....
call isr_init ;intialize interrupts
call timer_init
.....
========================================================================
isr_init
movlw b'11000000' ;enable global & peripheral
interrupts
movwf intcon
bcf pir1,tmr1if ;clear tmr1 overflow interrupt flag
bsf pie1,tmr1ie ;enable tmr1 overflow interrupt
return
=========================================================================
timer_init
movlw b'00011111' ;1:2 prescale,osc ena,async,extl
clk,start timer
movwf t1con,f
return
==========================================================================
isr ;interrupt routine
movf pir1,w ;check for tmr1 overflow
andlw b'00000001',w ;mask everything but tmr1 overflow
btfss status,z
goto yes_ov
goto no_ov
yes_ov ... ;timer1 overflow.....do so do this
...
...
goto end_isr
no_ov ... ;no timer1 overflow.....so do that
...
...
end_isr bcf pir1,tmr1if ;clear tmr1 overflow interrupt flag
return
1998\11\17@045222
by
Nigel Orr
|
At 14:14 16/11/98 -0800, you wrote:
> org 0x0000
> goto start
> org 0x0004 ;interrupt address
> bcf intcon,7 ;disable global interrupts
Not necessary- global interrupts are disabled when ISR received
>From 16C7X "Interrupts" documentation:-
"When an interrupt is responded to, the GIE bit is cleared to disable any
further interrupt"
{Quote hidden}>start ;main program
> .....
> call isr_init ;intialize interrupts
> call timer_init
> .....
>
>========================================================================
>isr_init
> movlw b'11000000' ;enable global & peripheral
>interrupts
> movwf intcon
Problem may be because you are enabling interrupts before setting the timer
up? Have you tried doing both your init routines, _then_ setting GIE?
> bcf pir1,tmr1if ;clear tmr1 overflow interrupt flag
> bsf pie1,tmr1ie ;enable tmr1 overflow interrupt
pie1 is in Bank 1, so you need to change STATUS,RP0 or use indirect addressing
either
bcf pir1,tmr1if ;clear tmr1 overflow interrupt flag
bsf STATUS,RP0
bsf pie1,tmr1ie ;enable tmr1 overflow interrupt
bcf STATUS,RP0
or
bcf pir1,tmr1if ;clear tmr1 overflow interrupt flag
movlw pie1
movwf FSR
bsf INDF,tmr1ie ;enable tmr1 overflow interrupt
Hope that helps,
Nigel
--
Nigel Orr Research Associate O ______
Underwater Acoustics Group, o / o \_/(
Dept of Electrical and Electronic Engineering (_ < _ (
University of Newcastle Upon Tyne \______/ \(
1998\11\17@122600
by
Ohtsji, Randie
Thanks Nigel,
Yes, my problem was that pie1 is in Bank 1. I changed over to Bank 1 on to
enable the tmr1 overflow interrupt and all is working now.
Thanks again
Randie
> {Original Message removed}
More... (looser matching)
- Last day of these posts
- In 1998
, 1999 only
- Today
- New search...