Hello
I'm a beginner in mcu programming and I have a small problem understanding how the following code works:
It's from mikroe and it's exlained but what I don't understand it's how the cnt is incremented up to 400 if he is assigned to 0 2 lines before and in the do loop the interrupt function isn't call ??
I'm a beginner in mcu programming and I have a small problem understanding how the following code works:
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
INTCON = 0x20; // Bit T0IE is set, bit T0IF is cleared
}
void main() {
OPTION_REG = 0x84; // Prescaler is assigned to timer TMR0
ANSEL = 0; // All I/O pins are configured as digital
ANSELH = 0;
TRISB = 0; // All port B pins are configured as outputs
PORTB = 0x0; // Reset port B
TMR0 = 96; // Timer T0 counts from 96 to 255
INTCON = 0xA0; // 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);
}
It's from mikroe and it's exlained but what I don't understand it's how the cnt is incremented up to 400 if he is assigned to 0 2 lines before and in the do loop the interrupt function isn't call ??