Can anyone advise please?
I am running a PIC18F252 from a 4MHZ crystal and I want to use TMR0 (in 16 bit mode) to generate a time delay of 10 seconds.
Firstly, despite clearing TMR0IP, I can't get the program to branch to the 18h interrupt vector. I have got this part set correctly as I can service a port level change in another part of the program.
So, I decided to just poll the TMR0IF bit. This works but the interrupt occurs every 16 seconds (approx). The only way I can change (reduce) the time delay is by altering the prescaler. Changing the values in TMR0H and TMR0L have no effect.
I'm convinced I am not initialising correctly, either that, or I have completely misunderstood how the timers work. All I want to do is to test a flag/register bit periodically to see if the 10 second period has expired. My code is below, any advice would be most welcome.
Thanks
START BCF INTCON,TMR01E ;Interrupt disabled. BCF INTCON,TMR01F ;Flag cleared. BCF INTCON2,TMR0IP ;Low priority interrupt. MOVLW H'07' MOVWF T0CON ;Prescale=256. MOVLW HIGH_TIME_VALUE ;Set time to 10 seconds. MOVWF TMR0H MOVLW LOW_TIME_VALUE MOVWF TMR0L BSF INTCON,TMR0IE ;Interrupt enabled. BSF T0CON,TMR0ON ;Start timer. ; LOOP BTFSS INTCON,TMR01F ;Loop until timeout. GOTO LOOP ; STOP GOTO STOP