CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Need help first timer!

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Scottl



Joined: 21 Feb 2005
Posts: 25

View user's profile Send private message

Need help first timer!
PostPosted: Mon Oct 09, 2006 7:39 pm     Reply with quote

I have just started using the PCWH Compiler. I have a simple application that seems to run one time then stops. I cannot get it to continue running. Here is some of my code if someone can point out what I am doing wrong it would be greatly appreciated. I get everything on my website one time then I must reset the board then it sends the data once then stops.

Code:

void main()
{

init(); // Configure peripherals/hardware
while(1) // Continuous loop
{

for (loops=0; loops<=1; loops++)
{
for (channel=0; channel<=7; channel++) // A/D channel select 0 to 3
{
set_adc_channel( channel ); // Set A/D channel
delay_us(20);
ad = read_adc(); // Read A/D channel into ad variable
volts = (float)ad * (5.0/1023); // Convert 10-bit reading
Show_AD(); // Show results as channels A,B,C,D
delay_ms(1067);
}
}

goto connect;

connect:

printf( "CXXX.XXX.XXX.XXX/80\n" ); // connect to my webserver
inbyte = getch(); // Get C for connected

if (inbyte == 'C') // IF C send data
{
printf( "GET /XXX/XXX.php?site=" );
printf( "%ld", inc );
printf( "&an1=%01.3f",ad_0 );
printf( "&an2=%01.3f",ad_1 );
printf( "&an3=%01.3f",ad_2 );
printf( "&an4=%01.3f",ad_3 );
printf( "&an5=%01.3f",ad_4 );
printf( "&an6=%01.3f",ad_5 );
printf( "&an7=%01.3f",ad_6 );
printf( "&an8=%01.3f",ad_7 );
printf( " HTTP/1.0\n\n");
printf("Host: www.XXXXXXXX.com");
goto stepout;
}
else if (inbyte == 'N') // If N Try again
{
goto connect;
}
else // Anything else stepout try later
{
goto stepout;
}

stepout:
delay_ms(5000); // Wait 5 seconds

inc = inc + 1; // Increment

if ( inc > 15000 )
{
inc = 0;
}

} // Do it again!
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Oct 09, 2006 11:21 pm     Reply with quote

I don't know what your code is supposed to do, but I made it into
a test program, made a few changes and got it to produce some output.
It displays the following:
Code:

Start
CXXX.XXX.XXX.XXX/80
GET /XXX/XXX.php?site=0
&an1=0.000
&an2=1.000
&an3=2.000
&an4=3.000
&an5=4.000
&an6=5.000
&an7=6.000
&an8=7.000
 HTTP/1.0
Host: www.XXXXXXXX.com
CXXX.XXX.XXX.XXX/80
GET /XXX/XXX.php?site=1
&an1=0.000
&an2=1.000
&an3=2.000
&an4=3.000
&an5=4.000
&an6=5.000
&an7=6.000
&an8=7.000
 HTTP/1.0
Host: www.XXXXXXXX.com
CXXX.XXX.XXX.XXX/80
GET /XXX/XXX.php?site=2
&an1=0.000
&an2=1.000
&an3=2.000
&an4=3.000
&an5=4.000
&an6=5.000
&an7=6.000
&an8=7.000
 HTTP/1.0
Host: www.XXXXXXXX.com
CXXX.XXX.XXX.XXX/80           

Etc.


The changes I made were:

1. Your code has some large delays in it. You go through a
loop 16 times, and delay for about 1 second each time.
The program will appear to be locked up during this time.
Then down at the bottom, you've got another 5 second delay.
I greatly reduced all those delays.

2. Most of your printf() statements don't have a carriage return-
linefeed after them, so they didn't display properly in my
serial terminal window. I fixed that by adding "\n\r" at the end
of most printf statements.

3. You didn't show any variable declarations. I declared them all
in what seemed to be the most logical data type, based on the
usage.

4. I put in stubs for the routines that you didn't show in your post.
I also put in the #include, #fuses, and #use statements.

5. Your code waits for a 'C' character. I don't know if this comes from
some device or if you are typing it in. If you type it in, then because
you're only checking for a capital 'C', the program won't respond to a
lower case 'c' if that character is typed in. This could also be a reason
why the program would appear to be "locked up". I always made
sure that I typed in a capital 'C'.

You have several other things in there, such as 'goto' statements, that
should be removed. The code should be written in a different way so
they aren't needed.

Code:

#include <16F877.H>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

void init(void)
{
   
}   

//-------------------------
void show_AD(void)
{

}

//========================
void main()
{
int8 loops;
int8 channel;
int8 ad;
int8 inbyte;
float ad_0 = 0.0;
float ad_1 = 1.0;
float ad_2 = 2.0;
float ad_3 = 3.0;
float ad_4 = 4.0;
float ad_5 = 5.0;
float ad_6 = 6.0;
float ad_7 = 7.0;
int16 inc = 0;
float volts;

printf("Start\n\r");


init(); // Configure peripherals/hardware

while(1) // Continuous loop
  {
   for(loops=0; loops<=1; loops++)
      {
       for(channel=0; channel<=7; channel++) // A/D channel
          {
           set_adc_channel( channel ); // Set A/D channel
           delay_us(20);
           ad = read_adc(); // Read A/D channel into ad variable
           volts = (float)ad * (5.0/1023); // Convert 10-bit reading
           Show_AD(); // Show results as channels A,B,C,D
           delay_ms(100);
          }
      }

   // goto connect;

   connect:

   printf( "CXXX.XXX.XXX.XXX/80\n\r" ); // connect to webserver
   inbyte = getch(); // Get C for connected

   if(inbyte == 'C') // IF C send data
     {
      printf( "GET /XXX/XXX.php?site=\n\r" );
      printf( "%ld\n\r", inc );
      printf( "&an1=%01.3f\n\r",ad_0 );
      printf( "&an2=%01.3f\n\r",ad_1 );
      printf( "&an3=%01.3f\n\r",ad_2 );
      printf( "&an4=%01.3f\n\r",ad_3 );
      printf( "&an5=%01.3f\n\r",ad_4 );
      printf( "&an6=%01.3f\n\r",ad_5 );
      printf( "&an7=%01.3f\n\r",ad_6 );
      printf( "&an8=%01.3f\n\r",ad_7 );
      printf( " HTTP/1.0\n\r");
      printf("Host: www.XXXXXXXX.com\n\r");
      goto stepout;
     }
   else if (inbyte == 'N') // If N Try again
     {
      goto connect;
     }
   else // Anything else stepout try later
     {
      goto stepout;
     }

stepout:
   delay_ms(1000); // Wait 5 seconds

   inc = inc + 1; // Increment

   if( inc > 15000 )
     {
      inc = 0;
     }

   } // Do it again!
}
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group