PIC16F877A Timer1 module and interrupt with CCS C compiler

Blink without delay using PIC16F877A and CCS C

Related topics:
PIC16F877A Timer0 module and interrupt with CCS C compiler
PIC16F877A Timer2 module and interrupt with CCS C compiler 
The Timer1 module is a 16-bit timer/counter consisting of two 8-bit registers (TMR1H and TMR1L) which are readable and writable. The TMR1 register pair (TMR1H:TMR1L) increments from 0000h to FFFFh and rolls over to 0000h.
This topic shows a simple example of the PIC16F877A Timer1 module and its interrupt.

PIC16F877A Timer1 interrupt:
The TMR1 interrupt, if enabled, is generated on overflow which is latched in interrupt flag bit, TMR1IF (PIR1<0>). This interrupt can be enabled/disabled by setting/clearing TMR1 interrupt enable bit, TMR1IE (PIE1<0>).
PIC16F877A Timer1 prescaler rate:
Prescaler rate of the timer1 can be: 1, 2, 4 or 8.
The following equation computes timer1 frequency:

Timer1_freq = MCU_freq / {4 * Prescaler * (65536 – TMR1)}

Where TMR1 is preload value.
And Timer1 overflow time = 1/Timer1_freq
PIC16F877A Timer1 interrupt example:
This is a simple example which uses timer1 interrupt to make an LED connected to RB0 blinking at a frequency of 1Hz.
PIC16F877A Timer1 interrupt example circuit

PIC16F877A Timer1 interrupt example CCS PIC C code:
The timer is used to interrupt every 500 ms which makes the LED ON for 500 ms and OFF for 500 ms. HS oscillator used with frequency of 4MHz.

1 thought on “PIC16F877A Timer1 module and interrupt with CCS C compiler”

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top