Hi...
I have written code for timer0 in which every time TMR0 overflows,it toggles RC0,but i used TMR0IF to indicate that TMR0L and TMR0H are overflow,but when overflow occurs pic doesn't rise its TMR0IF flag and TMR0L resets to 00(TMR0H stays on 0xff). I will appreciate if you help me with this.
Thank you:-D
Reference PIC18F2455/2550/4455/4550 Data Sheet, pg 128, Section 11.2 Timer0 Reads and Writes in 16-Bit Mode
TMR0H is not the actual high byte of Timer0 in 16-bit
mode. It is actually a buffered version of the real high
byte of Timer0 which is not directly readable nor
writable (refer to Figure 11-2). TMR0H is updated with
the contents of the high byte of Timer0 during a read of
TMR0L. This provides the ability to read all 16 bits of
Timer0 without having to verify that the read of the high
and low byte were valid, due to a rollover between
successive reads of the high and low byte.
Similarly, a write to the high byte of Timer0 must also
take place through the TMR0H Buffer register. The high
byte is updated with the contents of TMR0H when a
write occurs to TMR0L. This allows all 16 bits of Timer0
to be updated at once.
The above section indicates that to store a 16-bit value in the TIMER0 registers you must first write the TMR0H followed by the write to TMR0L which triggers both values to be written into the timer module. When reading the TIMER0 16-bit value you must perform the reads exactly opposite, first read TMR0L followed by a read of TMR0H.
Therefore make the following code changes:
Code:
#include<P18F2550.h>
#pragma config FOSC=INTOSC_EC
#pragma config WDT=OFF
void main()
{
TRISCbits.TRISC0=0;
OSCCON=0x02;
OSCTUNE=0X80;
while(1)
{
T0CON=0x08;
[COLOR="#FF0000"]TMR0H=0XFF; //switch the TMR0H and TMR0L writes as shown here
TMR0L=0XF0;[/COLOR]
INTCONbits.TMR0IF=0;
T0CONbits.TMR0ON=1;
while(INTCONbits.TMR0IF==0);
PORTCbits.RC0^=1;
T0CONbits.TMR0ON=0;
}
}
Perform a similar switch in your assembly code version.