We are using the PIC16f887 microcontroller’s internal Timer1 module in External Clock mode to count the number of clocks on the associated pin RC0. While using the timer1 module, we have two options for selecting the clock source, 1 is to use the internal clock or we can select the external clock source by setting the TIMER1_CS pin in T1CON(Timer1 Configuration) Register. The Clock Select (CS) bit is the 1st bit. The 0th bit of the T1CON register is for enabling and disabling the TIMER1 module.
We can also use the PORTC.F1 pin for counting the clock if we enable the T1OSCEN bit in the T1CON register. Which is the 3rd bit of the T1CON register. If we enable (write 1 to the bit) we will be able to use the PortC F1 bit for counting the external clock.
So overall Configuration for TIMER1 to use the external clock source is just by setting the 0th and 1st bit of the T1CON register. If we need to count the frequency, we need to enable this clock counting process for 1 second. For a rough estimate, we can use the built-in Delay_ms(1000); function in the MIKROC Pro for the PIC compiler. Once the 1-second delay is complete, we will disable the TIMER1 and read the TMR1H and TMR1L register. Combine the value into integer and display on LCD or seven-segment display (whichever you prefer) after converting the integer to string if we are displaying over the LCD.
Here is the complete code.