Frequency counter with pic16f877a and display on the lcd

Status
Not open for further replies.

john120

Banned
Joined
Aug 13, 2011
Messages
257
Helped
11
Reputation
22
Reaction score
10
Trophy points
1,298
Visit site
Activity points
0
Hi,every body I want to read the frequency from the function generator and use the PIC16F877A
here below are my codes which are not working can you please help me to handle the issue.


Help me plz.

- - - Updated - - -

The codes are here below:
#include <16F877A.h>
#device adc=10
#fuses XT, NOWDT, NOPROTECT, PUT, BROWNOUT
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C2, INVERT)
#include "lcd.c"

int16 capture_rising_edge;
int16 got_pulse_width;
int16 ccp_delta;

#int_ccp1
void ccp1_isr(void)
{
static int16 t1_rising_edge;

// If current interrupt is for rising edge.
if(capture_rising_edge)
{
setup_ccp1(CCP_CAPTURE_FE);
capture_rising_edge = FALSE;
t1_rising_edge = CCP_1;
}
else
{
setup_ccp1(CCP_CAPTURE_RE);
capture_rising_edge = TRUE;
ccp_delta = CCP_1 - t1_rising_edge;
got_pulse_width = TRUE;
}

}

//==================================
main()
{
int16 pulse_width_ms, local_ccp_delta;

got_pulse_width = FALSE;
capture_rising_edge = TRUE;

output_low(pin_C0);

setup_ccp1(CCP_CAPTURE_RE);
setup_timer_1(T1_INTERNAL | T1_DIV_BY_8 );
clear_interrupt(INT_CCP1);
enable_interrupts(INT_CCP1);
enable_interrupts(GLOBAL);

while(1)
{
output_high(pin_C0);
delay_ms(100);
output_low(pin_C0);

if(got_pulse_width)
{
disable_interrupts(GLOBAL);
local_ccp_delta = ccp_delta;
enable_interrupts(GLOBAL);
pulse_width_ms = local_ccp_delta / (125);

printf("%lu\n\r", pulse_width_ms);

got_pulse_width = FALSE;
}

delay_ms(500);
}

}
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…