Frequency meter using pic16f877a
It will count actual frequency of a wave and displays on LCD[]
Schematic is attached for connection diagram
Compiler CCS Pic C compiler
Code .......................................................................................
#include <16F877A.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_C6,rcv=PIN_C7)
#define LCD_ENABLE_PIN PIN_B3 ////
#define LCD_RS_PIN PIN_B1 ////
#define LCD_RW_PIN PIN_B2 ////
#define LCD_DATA4 PIN_B4 ////
#define LCD_DATA5 PIN_B5 ////
#define LCD_DATA6 PIN_B6 ////
#define LCD_DATA7 PIN_B7
#include <lcd.c>
#BYTE trisb = 0x86
int8 n1=0,frequency;
#int_EXT
void EXT_isr(void)
{
frequency = frequency+1;
}
#int_TIMER1
void TIMER1_isr(void)
{
n1=n1+1;
if(n1==5){
n1=0;
lcd_gotoxy(1 2);
printf(lcd_putc ,"frequency = %d" , frequency);
frequency=0;
}
#asm
bcf 0x0B , 1 ///////// Clear external interrupt flag
#endasm
set_timer1(15536);
}
void main(void) {
lcd_init();
delay_ms(500);
setup_timer_1(T1_INTERNAL | T1_DIV_BY_8);
#asm
bsf 0x03 , 5 //////////Bank 1
bsf trisb ,0
bcf 0x03 , 5 //////////Bank 0
bcf 0x0B , 1 ///////// Clear external interrupt flag
#endasm
enable_interrupts(INT_EXT);
enable_interrupts(INT_TIMER1);
enable_interrupts(GLOBAL);
lcd_gotoxy(1 1);
printf(lcd_putc , "Frequency Meter");
frequency=0;
set_timer1(15536);
while(1){};
}