Creating 1Hz pulse using PIC
internal timer interrupt
pic16f877a has 3 timers. they are: - Timer0 (8 bit) - Timer1 (16 bit) - Timer2 (8bit)
1. Setting Up Timer1 OPTION_REG
register
- Set
prescale
of 8
2. Set up the Interrupt INTCON
register
- Enable Global an Peripheral interrupt
- Enable Timer1
overflow
interupt
- Clear the
interrupt flag
initially
3. Timer value calculation for the desired delay
RegValue = 65536-((Delay * Fosc)/(Prescalar*4))
4. Writing the Interrupt Service Routine ISR
- Clear overflow interrupt flag
- Reset timer value
void __interrupt() isr(void) {
if(TMR1IF==1) {
TMR1H=0x9E; // Load the time value(0xBDC) for 100 milli delay
TMR1L=0x58;
TMR1IF=0; // reset overflow flag
count++; // counter increments every 100 milli
}
return;
}
Circuit Diagram:
License
This work is licensed under GNU General Public License v3.0.