- Sun Apr 30, 2017 9:10 pm
#194628
Hi guys how can i calculate the timer overflow for timer1 on pic16f877a in my code?
Code: Select all
sbit LED at RB0_bit;
void interrupt() {
time++ ;
if (time == 100) { // if time is 76
LED = ~LED; // then toggle led and
time = 0; // reset time
}
PIR1.TMR1IF = 0; // clear TMR1IF
TMR1H = 128;
TMR1L = 0;
}
void main() {
PORTB = 0x00; // Initialize PORTB
TRISB = 0; // PORTB is output
T1CON = 1; // Timer1 settings
PIR1.TMR1IF = 0; // clear TMR1IF
TMR1H = 0x80; // Initialize Timer1 register
TMR1L = 0x00;
PIE1.TMR1IE = 1; // enable Timer1 interrupt
time = 0; // initialize cnt
INTCON = 0xC0; // Set GIE, PEIE
do {
} while (1);
}