Timer 0 Help needed
I am using PIC18F252 with 20MHz crystal, I have tried to use the following program to get the delay(ON/OFF time of LED) minimum i.e. 200ns, but the delay I am getting is 5ms.
Please let me know what is the mistake in my program.
unsigned cnt;
void interrupt() {
cnt++; // Increment value of cnt on every interrupt
TMR0L = 96;
INTCON = 0x20; // Set T0IE, clear T0IF
}
void main() {
ADCON1 = 0x0F; // Set AN pins to Digital I/O
T0CON = 0xC4; // Set TMR0 in 8bit mode, assign prescaler(1/32) to TMR0
TRISB = 0; // PORTB is output
PORTB = 0x00; // Initialize PORTB
TMR0L = 96; // Timer0 initial value
INTCON = 0xA0; // Enable TMRO interrupt, TMR0 Overflow Interrupt Enable bit(bit 5)
cnt = 0; // Initialize cnt
do {
if (cnt == 1) {
PORTB = ~PORTB; // Toggle PORTB LEDs
cnt = 0; // Reset cnt
}
} while(1);
}