> From: Bill Merson > [cut] > My problem is with a little device which when turned on > starts flashing a LED at once a second. When four interrupts are seen on the > int port, the flashing stops and a minutes timer begins which is determined > by bcd switches on the portb lines (up to 127 minutes since portb,0 is > occupied with the interrupt) Reasonably good accuracy is needed so I am using > a 32.768 khz xtal. It seems like a straight forward case of setting up tmr0 > getting the one second from btfss tmr0,4, decrementing a counter which has 60 > stored in it, and the end of that sequence, decrement the minutes storred in > 'time'. The program begins fine, after four interrupts the 60 sec timer > counts down, and the time counts down. The problem is when I return to begin > the LED flashing again, the program jumps back to the seconds and minutes > timer. Here is some code: > delay clrf tmr0 > again btfss tmr0,4 > goto again > decfsz count,f ;count is loaded with b'01111000' > return > decfsz time,f ;switch one is on for one minute > return > bcf status,0 > rrf time,f ;to move it one bit from interrupt > iserv incf icount,f ; interrupts > bcf intcon,1 > retfie A few things... if you are using RB1-7 as a minutes count input, then surely you should be using RLF instead of RRF if you are going to compare with the port setting. Also, your indentation is confusing (to me, not the assembler). The convention is to indent only the single instruction after a conditional skip. You are probably not using interrupts correctly, since you are mixing RETURN and RETFIE. Without seeing the rest of your code, this would be extremely unusual. What is even more unusual is that you don't restore the current context before RETFIE. If you read the datasheet, it will show the correct way of saving and restoring W and status. I suggest you try using the MPSIM program to see what happens. It is good enough to ferret out your problem for this simple application. If you are unfamiliar with programming, then there is almost zero probability of your code working if you do not use MPSIM (or an ICE, if you have one). Personally, I would not keep resetting TMR0. Far better to let it run free, and capture the timer overflow events in an interrupt routine. Since your xtal period is 1 second divided by a power of 2, then it would be a piece of cake to get 1 second interrupts if you use the prescaler correctly. Without a prescaler, TMR0 will clock over every 1024/32768 seconds. Set the prescaler to divide by 32 and it will clock over every second, which is what you want. Only clear TMR0 when you want to start the timer. The interrupt routine will get called every second, in which you decrement a counter which is initialised to 60. When this counter decrements to 0, you should set a flag which the mainline code can continuously poll. The interrupt routine would also reset the counter to 60. When the mainline routine sees the flag being set, it knows that 1 minute has passed. It then resets the flag and increments the minute count, comparing it to port B (shifted). Regards, SJH Canberra, Australia