//Timer 0 will count and Timer 1 will measure 1 second time using interrupts ; mikro=16f877a
// OUTPUTS
#define led PORTB.F2 // simple blinking led to show the system is working
sbit LCD_RS at RD5_bit;
sbit LCD_EN at RD4_bit;
sbit LCD_D4 at RC4_bit;
sbit LCD_D5 at RC5_bit;
sbit LCD_D6 at RC6_bit;
sbit LCD_D7 at RC7_bit;
sbit LCD_RS_Direction at TRISD5_bit;
sbit LCD_EN_Direction at TRISD4_bit;
sbit LCD_D4_Direction at TRISC4_bit;
sbit LCD_D5_Direction at TRISC5_bit;
sbit LCD_D6_Direction at TRISC6_bit;
sbit LCD_D7_Direction at TRISC7_bit;
//=======End LCD Connections=============================================
unsigned int x=0,frq=0, cnt=0;
void interrupt()
{
if(PIR1.TMR1IF)
{
T1CON.TMR1ON=0; //stop
TMR1L=0XEE; // <------------- reload the timer
TMR1H=0X85;
if(cnt>=4)
{
led=~led;
frq=1;
cnt=0;
x=tmr0;
tmr0=0;
}
//frq=1;
PIR1.TMR1IF=0; // <------------- clear the timer interrupt flag
}
}
void main()
{
OPTION_REG=0xA0; // for timer 0; NO presscaller; counter mode at T0CKI
T1CON=0X60; // 1:8 prescallar, timer off
ADCON1=0x07; // adc reg initialization ; changes port a to digital I/O
INTCON=0x80; // globle interrupt enabled
TMR1L=0xEE;
TMR1H=0x85;
T1CON.TMR1ON=1; // timer on
PIR1.TMR1IF=0;
TRISA.f4=1;// making ra4 as input
x=0;
frq=0;
lcd_init();
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF);
Lcd_Cmd(_LCD_MOVE_CURSOR_RIGHT); //*/
Lcd_Out(1,1,"Frequency");
while(1)
{
if(frq==1)
{
Lcd_Out(2,2,X);
Lcd_Out_CP("Hz");
frq=0;
}
}
}