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.

use of many while statement in ccs c compiler

Status
Not open for further replies.

john120

Banned
Full Member level 5
Joined
Aug 13, 2011
Messages
257
Helped
11
Reputation
22
Reaction score
10
Trophy points
1,298
Visit site
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
 

I would think that you could go a lighter way using IF and CASE statements if available.

One thing you should be aware of is that the 16F877A has a limited stack size, only 8 levels. This could be the difference between simulating and using target hardware.
Try to take a look at the assembly listing for your code, and count stack operations, to see if you overflow the stack.
 

One thing you should be aware of is that the 16F877A has a limited stack size, only 8 levels. This could be the difference between simulating and using target hardware.
How do you see stack depth related to while statements? PIC16 stack isn't accessible for other instructions than call/return.

It seems to me that the original post is of the kind "how to write code for an unclear defined problem".

Specifying the problem respectively intended states and state transitions clearly is the missing link. Coding of state machine (if then else, case construct, whatsoever) is mainly a matter of taste.
 

Hello everybody can some body help me to solve the issue of push buttons in my program here,see the codes:
#include <16f877a.h>
#DEVICE ADC=10
#Device *=16
#fuses HS,NOWDT,NOPROTECT,NOLVP,NOBROWNOUT
#use delay(clock=20000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include "lcd.c"
#define ARRAY_SIZE 191
//#define ARRAY_SIZE 250


float voltsf,volts;
float value;
float value1;
int i,found;


unsigned int adc_value;

int search;
float l;

const float k[]={
12349,12341,12319,12315,12300.9,12289,12260,12262,12248,12230.01,
12229.99,12209.99,12200.01,12199.99,12179.95,12180,12179.39,12170,12160,12151.3,
12150,12120,12100,12099,12095,12094.99,12085,12070,12050,12025,
12015,12010,12000,11995,11990,11985,11970,11968.99,11960,11955,
11950,11945,11940,11935,11930,11900,11885,11870,11841,11832.4};
const float t[]={
11822.3,11812,11810,11800,11790,11738.5,11736.5,11735,11725,11715,
11700,11685,11675,11660,11645,11630,11599.99,11585,11575,11565,
11550,11535,11515,11505,11498.8,11440,11430,11418,11415,11426,
11415,11404,11396,11385.6,11375,11365,11355,11345,11335,11299.99,
11285,11274.99,11274,11235,11225,11215,11199.5,11185,11175,11165};
const float u[]={
11150,11135,11120,11105,11080,11065,11052,11035,11025,11010,
10997.99,10985,10975,10964,10952,10940,10925,10915,10900,10885,
10875,10862,10850,10820,10800,10785,10775,10765,10759,10758.6,
10758.3,10748.2,10735,10725,10712,10700,10685,10672,10661,10650,
10632,10624,10613,10610,10600,10580,10560,10550,10540,10530};
const float s[]={
10519.5,10515,10500,10485,10470,10455,10440,10425,10412,10400,
10385,10370,10355,10340,10320,10300,10289.99,10275,10265,10260,
10250,10240,10225,10215,10210,10200,10185,10182,10180,10175,
10170,10165,10160,10155,10155,10145,10140,10135,10125,10120,
};

//one array divided into 3 arrays
const float j[]={
12359,12348,12340,12318,12303,12301,12280,12264,12261.2,12245,
12230,12230,12210,12200,12199.99,12199.96,12179.99,12179.38,12169.99,12159.99,
12151.29,12149.99,12120,12099.99,12098.99,12098,12097.99,12084.99,12069.99,12049.99,
12024.99,12014.99,12009.99,11999.99,11994.99,11989.99,11980,11969,11968.99,11959.99,
11954.99,11949.99,11944.99,11939.99,11934.99,11929.99,11899.99,11880,11869.99,11840.99};

const float m[]={
11832.39,11822.29,11811.99,11809.99,11799.99,11749.49,11738.49,11736.49,11734.99,11724.99,
11714.99,11699.99,11684.99,11674.99,11659.99,11644.99,11629.99,11599.97,11584.99,11574.99,
11564.99,11549.99,11525,11514.99,11504.99,11498.7,11439.99,11429.99,11417.99,11434.99,
11425.99,11414.99,11403.99,11395.99,11385.59,11374.99,11364.99,11354.99,11344.99,11334.99,
11299.98,11284.99,11275,11249.98,11234.99,11224.99,11214.99,11199.49,11184.99,11174.99};
//11274.99
const float n[]={
11164.99,11149.99,11134.99,11119.99,11090,11079.99,11064.99,11051.99,11034.99,11024.99,
11009.99,10997.98,10984.99,10974.99,10963.99,10951.99,10939.99,10924.99,10914.99,10899.99,
10884.99,10874.99,10861.99,10849.99,10819.99,10799.99,10784.99,10774.99,10764.99,10758.99,
10758.59,10758.29,10748.19,10734.99,10724.99,10711.99,10699.99,10684.99,10671.99,10660.99,
10649.99,10631.99,10623.99,10612.99,10609.99,10599.99,10579.99,10559.99,10549.99,10539.99};

const float p[]={
10529.99,10519.49,10514.99,10499.99,10484.99,10469.99,10454.99,10439.99,10424.99,10411.99,
10399.99,10384.99,10369.99,10354.99,10330,10319.99,10299.99,10289.98,10274.99,10264.99,
10259.99,10249.99,10239.99,10224.99,10214.99,10209.99,10199.99,10184.99,10181.99,10179.99,
10174.99,10169.99,10164.99,10159.99,10159.99,10149.99,10144.99,10139.99,10129.99,10124.99,
};
void main()
{
//set_tris_c(0xff);
set_tris_b(0x00);
set_tris_c(0xff);
lcd_init();
delay_us(200);


kj: printf(lcd_putc,"\fLoad165");
delay_ms(5000);
break;


kji:
set_timer1(0);
setup_timer_1(t1_external | T1_DIV_BY_8);
// delay_ms(1000);
delay_ms(250);

setup_timer_1(T1_DISABLED);
value=get_timer1();
// value1=((value*32)-56936)/100;
value1=((value*32)-59528)/100;
printf(lcd_putc,"\f%f",value1);
delay_ms(1500);

while(true)
{
if(input(PIN_C4)==0)
{
if(input(PIN_C4)==0)
for ( i =0,found=-1;i <ARRAY_SIZE ; i++)
if((value1<= j)&&(k<=value1))
{

l=(0.1*i)+8.0;
printf(lcd_putc,"\f%2.1d", i);
output_high(PIN_B6);
delay_ms(1500);
printf(lcd_putc,"\f%2.1f", l);
printf(lcd_putc,"\%%");
delay_ms(1500);
output_low(PIN_B6);
goto kj;
// break;
}

else if((value1<= m)&&(t<=value1))
{
l=(0.1*i)+13.0;
printf(lcd_putc,"\f%2.1d", i);
delay_ms(1500);
lcd_gotoxy(4,1);
printf(lcd_putc,"\f%2.1f", l);
printf(lcd_putc,"\%%");
delay_ms(1500);
goto kagabo;
//break;
}
else if((value1<= n)&&(u<=value1))
{
l=(0.1*i)+18.0;
printf(lcd_putc,"\f%2.1d", i);
delay_ms(1500);
lcd_gotoxy(4,1);
printf(lcd_putc,"\f%2.1f", l);
printf(lcd_putc,"\%%");
delay_ms(1500);
goto kagabo;
// break;
}
else if((value1<= p)&&(s<=value1))
{
l=(0.1*i)+23.0;
printf(lcd_putc,"\f%2.1d", i);
delay_ms(1500);
lcd_gotoxy(4,1);
printf(lcd_putc,"\f%2.1f", l);
printf(lcd_putc,"\%%");
delay_ms(1500);
goto kagabo;
//break;
}
else
delay_ms(5);
lcd_gotoxy(4,1);
printf(lcd_putc,"\fConnect Probe");
delay_ms(5);
//break;
}


if((input(PIN_c5)==0))

{

if((input(PIN_c5)==0))
{
delay_ms(100);
printf(lcd_putc, "\fSineWave");
delay_ms(2000);
}
}

if((input(PIN_c6)==0))
{

if((input(PIN_c6)==0))
{
delay_ms(100);
printf(lcd_putc, "\fSquare");
delay_ms(2000);
}
}





}
}
I am using ccs c compiler and PIC16F877A;when I push the buttons there is no reaction of the display;the buttons I am using are referred to this link:
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top