Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help on interrupts with PIC16F877A FOR reading Signal Period

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
Activity points
0
I am designing a frequency meter with PIC16F877A,I use to read only the period of the signal and decide after:I want to read the period on the LCD after using a push button on C1 of my PIC;
In proteus the circuit is running but,when I put my program in my PIC the system stops.
See my codes below:
#include <16F877A.h>
#DEVICE ADC=10
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include "lcd.c"
#define ka PIN_C3
#use fast_io(c)
#use fast_io(b)
#use fast_io(a)

void tempdisplay();
void kagaba();
void messagedisplay();


int1 flag;
float voltsf;
float rise1, rise2;
int period;
int i;
unsigned int adc_value, volts;


#int_ccp1
void isr()
{
if (flag==0)
{
rise1 = CCP_1;
flag=1;
}
else if (flag==1)
{
rise2 = CCP_1;
period=(rise2-rise1);
flag=0;
}
}

void tempdisplay()
{
setup_adc_ports(AN0);
setup_adc(ADC_CLOCK_INTERNAL);
set_adc_channel(0);
adc_value = read_adc();
volts = ((float)(adc_value * 500)/1023.0);
voltsf=(volts*1.8)+32;
}
void main(void)
{

flag=0;
set_tris_c(0xff);
set_tris_b(0x00);
lcd_init();
lcd_gotoxy(1,1);
delay_us(200);
delay_ms(1000);
setup_ccp1(CCP_CAPTURE_RE|CCP_CAPTURE_DIV_16); // Configure CCP1 to capture rise
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8); // Start timer 1
enable_interrupts(INT_CCP1); // Setup interrupt on risining edge
enable_interrupts(GLOBAL);



while(true)
{
if(input(PIN_C1)==0)
{
output_high(PIN_B4);
if((input(PIN_C1)==0)&&(period==13))
{
tempdisplay();
printf(lcd_putc,"\f%3.0f",voltsf);
printf(lcd_putc,"\fWait...");
delay_ms(500);
printf(lcd_putc,"\f16%%");
output_low(PIN_B4);
break;
}

if((input(PIN_C1)==0)&&(period==15))
{
tempdisplay();
printf(lcd_putc,"\f%3.0f",voltsf);
printf(lcd_putc,"\fWait...");
delay_ms(500);
printf(lcd_putc,"\f14%%");
output_low(PIN_B4);
break;
}
if((input(PIN_C1)==0)&&(period==14))
{
tempdisplay();
printf(lcd_putc,"\f%3.0f",voltsf);
printf(lcd_putc,"\fWait...");
delay_ms(500);
printf(lcd_putc,"\f15%%");
output_low(PIN_B4);
break;
}
if((input(PIN_C1)==0)&&(period==16))
{
tempdisplay();
printf(lcd_putc,"\f%3.0f",voltsf);
printf(lcd_putc,"\fWait...");
delay_ms(500);
printf(lcd_putc,"\f13%%");
output_low(PIN_B4);
break;
}
if((input(PIN_C1)==0)&&(period==17))
{
tempdisplay();
printf(lcd_putc,"\f%3.0f",voltsf);
printf(lcd_putc,"\fWait...");
delay_ms(500);
printf(lcd_putc,"\f12%%");
output_low(PIN_B4);
break;
}
if((input(PIN_C1)==0)&&(period==18))
{
tempdisplay();
printf(lcd_putc,"\f%3.0f",voltsf);
printf(lcd_putc,"\fWait...");
delay_ms(500);
printf(lcd_putc,"\f19%%");
output_low(PIN_B4);
break;
}
if((input(PIN_C1)==0)&&(period==19))
{
tempdisplay();
printf(lcd_putc,"\f%3.0f",voltsf);
printf(lcd_putc,"\fWait...");
delay_ms(500);
printf(lcd_putc,"\f10%%");
output_low(PIN_B4);
break;

}

else
{
output_low(PIN_B4);
printf(lcd_putc,"\fWait...");
delay_ms(500);
printf(lcd_putc,"\fConnect Signal");
delay_ms(500);
break;
}
}

The percentage it the one which gives the level of the input signal,the period of the signal is tested together with the push button.

Thanks
 

Hi, Where are you clearing CCP interrupt flag? What is "flag" definitions in interrupt code? Also let us know which compiler is this? Enjoy!

Code:
#int_ccp1
void isr()
{
if (flag==0)
{
rise1 = CCP_1;
flag=1;
}
else if (flag==1)
{
rise2 = CCP_1;
period=(rise2-rise1);
flag=0;
}
}
 

Hi, Where are you clearing CCP interrupt flag? What is "flag" definitions in interrupt code? Also let us know which compiler is this? Enjoy!

Code:
#int_ccp1
void isr()
{
if (flag==0)
{
rise1 = CCP_1;
flag=1;
}
else if (flag==1)
{
rise2 = CCP_1;
period=(rise2-rise1);
flag=0;
}
}


the compiler I am using is ccs c compiler,the codes I have are the one given above nothing else.

Another issue ,with printf(lcd_putc,"............",RH);what should I fill in the blackets for printing RH with percantage symbol,when RH is an integer
Thanks
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top