john120
Banned
- Joined
- Aug 13, 2011
- Messages
- 257
- Helped
- 11
- Reputation
- 22
- Reaction score
- 10
- Trophy points
- 1,298
- Activity points
- 0
Hello friends,can anyone please help me to handle the issue I have here see the 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"
void tempdisplay();
void kagabo();
void messagedisplay();
int1 flag;
float voltsf;
float rise1, rise2;
int period;
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);
delay_ms(20);
adc_value = read_adc();
volts = ((float)(adc_value * 500)/1023.0);
delay_ms(10);
voltsf=(volts*1.8)+32;
}
void kagabo()
{
//delay_ms(2000);
printf(lcd_putc, "\fOscillator");
//delay_ms(2000);
}
void messagedisplay()
{
//delay_ms(2000);
printf(lcd_putc, "\fFilter");
//delay_ms(2000);
}
void main(void)
{
flag=0;
set_tris_c(0xff);
set_tris_b(0x00);
lcd_init();
lcd_gotoxy(1,1);
delay_us(200);
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){
while ((input(PIN_C1)==0)&&(period==13))
{
tempdisplay();
printf(lcd_putc,"\f%3.0f",voltsf);
delay_ms(1200);
printf(lcd_putc,"\fWait...");
delay_ms(2500);
printf(lcd_putc,"\f16%%");
delay_ms(2000);
}
while ((input(PIN_C1)==0)&&(period==15))
{
tempdisplay();
printf(lcd_putc,"\f%3.0f",voltsf);
delay_ms(1200);
printf(lcd_putc,"\fWait...");
delay_ms(2500);
printf(lcd_putc,"\f14%%");
delay_ms(2000);
}
while((input(PIN_C1)==0)&&(period==14))
{
tempdisplay();
printf(lcd_putc,"\f%3.0f",voltsf);
delay_ms(2000);
printf(lcd_putc,"\fWait...");
delay_ms(2500);
printf(lcd_putc,"\f15%%");
delay_ms(2000);
}
while((input(PIN_C1)==0)&&(period==16))
{
tempdisplay();
printf(lcd_putc,"\f%3.0f",voltsf);
delay_ms(2000);
printf(lcd_putc,"\fWait...");
delay_ms(2500);
printf(lcd_putc,"\f13%%");
delay_ms(2000);
}
while((input(PIN_C1)==0)&&(period==17))
{
tempdisplay();
printf(lcd_putc,"\f%3.0f",voltsf);
delay_ms(2000);
printf(lcd_putc,"\fWait...");
delay_ms(2500);
printf(lcd_putc,"\f12%%");
delay_ms(2000);
}
while((input(PIN_C1)==0)&&(period==18))
{
tempdisplay();
printf(lcd_putc,"\f%3.0f",voltsf);
delay_ms(2000);
printf(lcd_putc,"\fWait...");
delay_ms(2500);
printf(lcd_putc,"\f19%%");
delay_ms(2000);
}
while ((input(PIN_C1)==0)&&(period==19))
{
tempdisplay();
printf(lcd_putc,"\f%3.0f",voltsf);
delay_ms(2000);
printf(lcd_putc,"\fWait...");
delay_ms(2500);
printf(lcd_putc,"\f10%%");
delay_ms(2000);
output_low(PIN_B4);
}
while ((input(PIN_C1)==0)&& (period=!13)||(period=!14)||(period=!15)||(period=!16)||(period=!17)||(period=!18)||(period=!19)||(period=!20))
{
printf(lcd_putc,"\f how are you?");
delay_ms(500);
tempdisplay();
printf(lcd_putc,"\f%3.0f",voltsf);
delay_ms(2000);
printf(lcd_putc,"\fLoad the circuit");
delay_ms(2000);
output_low(PIN_B4);
}
//display buttons
if((input(PIN_c3)==0))
{
messagedisplay();
if((input(PIN_c3)==0))
{
delay_ms(100);
printf(lcd_putc, "\fLow Freq");
delay_ms(2000);
}
}
if((input(PIN_c5)==0))
{
kagabo();
if((input(PIN_c5)==0))
{
delay_ms(100);
printf(lcd_putc, "\fHigh Freq");
delay_ms(2000);
}
}
}
}
I want this codes to use while statement for selecting the good condition which has to be executed at the first time;where we have while();I connected on CCP1 a GBF (function generator)which gives different frequencies,before using the same circuit I measured the period which I ae obtained depending on the frequency you are using;then I am using that period for taking decision of which value must be displayed on the lcd,but when I press PIN_C1 I am not getting anything because at start up the program starts displaying the the percentage corresponding to a number before I press the button;
but for the two other block using if conditions are working perfectly;I changed the first block I even used while() statement but it is not working on the board but with proteus all are working.
Can you plz help me to implement that first block easily without many if condition or while condition?and then check for me where I made a mistake on the first block with while statements?
The task of the program is to respect those two blocks which are using if statement,secondly the system takes decision basing on the period read AND if the button C1 has been pressed,how can I set default value in case the result of AND statement is false?
Waiting for your help.
Thanks
#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"
void tempdisplay();
void kagabo();
void messagedisplay();
int1 flag;
float voltsf;
float rise1, rise2;
int period;
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);
delay_ms(20);
adc_value = read_adc();
volts = ((float)(adc_value * 500)/1023.0);
delay_ms(10);
voltsf=(volts*1.8)+32;
}
void kagabo()
{
//delay_ms(2000);
printf(lcd_putc, "\fOscillator");
//delay_ms(2000);
}
void messagedisplay()
{
//delay_ms(2000);
printf(lcd_putc, "\fFilter");
//delay_ms(2000);
}
void main(void)
{
flag=0;
set_tris_c(0xff);
set_tris_b(0x00);
lcd_init();
lcd_gotoxy(1,1);
delay_us(200);
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){
while ((input(PIN_C1)==0)&&(period==13))
{
tempdisplay();
printf(lcd_putc,"\f%3.0f",voltsf);
delay_ms(1200);
printf(lcd_putc,"\fWait...");
delay_ms(2500);
printf(lcd_putc,"\f16%%");
delay_ms(2000);
}
while ((input(PIN_C1)==0)&&(period==15))
{
tempdisplay();
printf(lcd_putc,"\f%3.0f",voltsf);
delay_ms(1200);
printf(lcd_putc,"\fWait...");
delay_ms(2500);
printf(lcd_putc,"\f14%%");
delay_ms(2000);
}
while((input(PIN_C1)==0)&&(period==14))
{
tempdisplay();
printf(lcd_putc,"\f%3.0f",voltsf);
delay_ms(2000);
printf(lcd_putc,"\fWait...");
delay_ms(2500);
printf(lcd_putc,"\f15%%");
delay_ms(2000);
}
while((input(PIN_C1)==0)&&(period==16))
{
tempdisplay();
printf(lcd_putc,"\f%3.0f",voltsf);
delay_ms(2000);
printf(lcd_putc,"\fWait...");
delay_ms(2500);
printf(lcd_putc,"\f13%%");
delay_ms(2000);
}
while((input(PIN_C1)==0)&&(period==17))
{
tempdisplay();
printf(lcd_putc,"\f%3.0f",voltsf);
delay_ms(2000);
printf(lcd_putc,"\fWait...");
delay_ms(2500);
printf(lcd_putc,"\f12%%");
delay_ms(2000);
}
while((input(PIN_C1)==0)&&(period==18))
{
tempdisplay();
printf(lcd_putc,"\f%3.0f",voltsf);
delay_ms(2000);
printf(lcd_putc,"\fWait...");
delay_ms(2500);
printf(lcd_putc,"\f19%%");
delay_ms(2000);
}
while ((input(PIN_C1)==0)&&(period==19))
{
tempdisplay();
printf(lcd_putc,"\f%3.0f",voltsf);
delay_ms(2000);
printf(lcd_putc,"\fWait...");
delay_ms(2500);
printf(lcd_putc,"\f10%%");
delay_ms(2000);
output_low(PIN_B4);
}
while ((input(PIN_C1)==0)&& (period=!13)||(period=!14)||(period=!15)||(period=!16)||(period=!17)||(period=!18)||(period=!19)||(period=!20))
{
printf(lcd_putc,"\f how are you?");
delay_ms(500);
tempdisplay();
printf(lcd_putc,"\f%3.0f",voltsf);
delay_ms(2000);
printf(lcd_putc,"\fLoad the circuit");
delay_ms(2000);
output_low(PIN_B4);
}
//display buttons
if((input(PIN_c3)==0))
{
messagedisplay();
if((input(PIN_c3)==0))
{
delay_ms(100);
printf(lcd_putc, "\fLow Freq");
delay_ms(2000);
}
}
if((input(PIN_c5)==0))
{
kagabo();
if((input(PIN_c5)==0))
{
delay_ms(100);
printf(lcd_putc, "\fHigh Freq");
delay_ms(2000);
}
}
}
}
I want this codes to use while statement for selecting the good condition which has to be executed at the first time;where we have while();I connected on CCP1 a GBF (function generator)which gives different frequencies,before using the same circuit I measured the period which I ae obtained depending on the frequency you are using;then I am using that period for taking decision of which value must be displayed on the lcd,but when I press PIN_C1 I am not getting anything because at start up the program starts displaying the the percentage corresponding to a number before I press the button;
but for the two other block using if conditions are working perfectly;I changed the first block I even used while() statement but it is not working on the board but with proteus all are working.
Can you plz help me to implement that first block easily without many if condition or while condition?and then check for me where I made a mistake on the first block with while statements?
The task of the program is to respect those two blocks which are using if statement,secondly the system takes decision basing on the period read AND if the button C1 has been pressed,how can I set default value in case the result of AND statement is false?
Waiting for your help.
Thanks