Hi. Guys I'm working with MikroC pro. How z u all, I hope all good. Now i am working on Timer and actually i have done my coding using a pic 18f4520 microcontroller with internal oscillator having freq= 8 MHz.Here it is necessary to provide a delay long enough to notice a change on a port. TMR0 with assigned prescaler is used for this purpose.An interrupt is generated on every timer register overflow and every interrupt routine automatically increments the cnt variables by 1.
Hope u may have got my point, But I'm not getting output.
[
Rich (BB code):
unsigned cnt; // Define variable cnt
void interrupt()
{
cnt++; // Interrupt causes cnt to be incremented by 1
TMR0= 96; // Timer TMR0 is returned its initial value
T0CON = 0b00100000; // Bit T0IE is set, bit T0IF is cleared
}
void main() {
T0CON = 0b11000100; // Prescaler is assigned to timer TMR0
ADRESL = 0b00000000; // All I/O pins are configured as digital
ADRESH = 0b00000000;
TRISB = 0b00000000; // All port B pins are configured as outputs
PORTB = 0b00000000; // Reset port B
CMCON =07;
TMR0 = 96; // Timer T0 counts from 96 to 255
T0CON = 0b10100000; // Enable interrupt TMR0
cnt = 0; // Variable cnt is assigned a 0
do { // Endless loop
if (cnt == 400) { // Increment port B after 400 interrupts
PORTB = PORTB++; // Increment number on port B by 1
cnt = 0; // Reset variable cnt
}
} while(1);
}