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

Consistent Compile Issue - Please advise

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



Joined: 14 Oct 2006
Posts: 5

View user's profile Send private message

Consistent Compile Issue - Please advise
PostPosted: Sat Oct 14, 2006 1:54 pm     Reply with quote

Greetings all,

I'm still pretty fresh to the PIC C scene, so please bear with me.

I can't seem to get it to compile due to a the error 'A numeric expression must appear here' on the
Code:
else if ((input(PIN_B0)) = 0)


Am I missing something totally obvious here? I've done something similar to this above and it works fine.

Any input would be great.

Thanks,
-Chris

Code:

#include <10F202.h>
#fuses NOWDT                              //WDT Disabled
#fuses NOMCLR                              //Master Clear Disabled
#fuses NOPROTECT                            //Code Protected from reads

#use delay(clock=4000000)                     //4MHz Clock
#use fast_io(B)                               //Otherwise the compiler will want to control the TRIS

//*** Pin Definitions ***//
//GPO = Start In
//GP1 = ICSPCLK (unused)
//GP2 = Start Out
//GP3 - MCLR (MCLR disabled, 12.5V to prog)

void main()
{   
   int1 flag = 1;                            //Flag to determine if read matches 'secret'
   int1 auth = 0;                            //Flag for state changes
   int1 samp=0;                              //Indicates determined pulse sample
   int i,x;                                //For loops
   
   int read[8];                              //Read byte from pulse train
   int secret[8] = {0,0,0,1,1,0,0,0};             //Byte for read comparison

   set_tris_b(0b11111001);                    //Set GP0 as input
   output_high(PIN_B2);                       //Set GP2 initially high
   
   while(TRUE)
          if((input(PIN_B0)) && (auth=0))         //If B0 goes low AND auth flag is 0
            for(x=0;x=7; x++)
               delay_us(100);                   //Delay between bits in pulse train   
               
               for (i=0;i=3;i++)             //Sample three times to determine bit
                  samp=input(PIN_B0);
                  samp=samp+samp;                     
               
               if (samp<1>=2)
                  samp=1;
               
               read[x]=samp;                  //Put sampled bit into array
            
            for(x=0;x=7;x++)                  
               if ((read[x])==(secret[x]))      //Compare sampled byte to known byte
                  flag=flag&&1;            //If sampled and known are equal, make Flag AND 1
                                        //if not equal, return to top
            if (flag==1)                  //If sampled byte was equal
               output_low(PIN_B2);            //Set GP2 low (enable START relay)
               auth=1;                     //Set auth flag to disable sample
               
         else if ((input(PIN_B0)) = 0)         //If B0 goes high
            output_high(PIN_B2);            //Set GP2 high (disable START relay)
            auth=0;                        //Set auth flag to allow for sample loop to start if
}                                       //GP0 goes low again
lewiseley



Joined: 30 Oct 2003
Posts: 24
Location: skegness

View user's profile Send private message Visit poster's website

PostPosted: Sat Oct 14, 2006 2:09 pm     Reply with quote

perhaps

else if ( input(pin_b0)==0)
cclough



Joined: 14 Oct 2006
Posts: 5

View user's profile Send private message

PostPosted: Sat Oct 14, 2006 2:12 pm     Reply with quote

Hello - thanks for the reply.

I've tried this as well; same error :(
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Oct 14, 2006 2:43 pm     Reply with quote

Your code has many errors in it. This isn't really a C learning forum.
But to at least get your code to compile without errors, you need to
add braces as shown below.
Code:

if(flag==1)
  {
   output_low(PIN_B2);     
   auth=1;                       
  }
else if ((input(PIN_B0)) == 0)         
  {
   output_high(PIN_B2);           
   auth=0;                     
  }

I don't want to go through your whole code and fix all the errors.
cclough



Joined: 14 Oct 2006
Posts: 5

View user's profile Send private message

PostPosted: Sat Oct 14, 2006 2:56 pm     Reply with quote

I appreciate your response, but did you need to add the criticism?

Your suggestion was helpful, and allowed me to compile. Thank you.

I'd love a critique of the code, if you're open to spending a few minutes to look it over.

-Chris
Ttelmah
Guest







PostPosted: Sat Oct 14, 2006 3:14 pm     Reply with quote

The biggest problem, is failure to bracket. C, does not magically understand what you want it to execute from a 'test'. It executes just the very next _statement/block_. If you want multiple lines to execute, then _you_ need to bracket the lines to form a single statement block.
So for example:
Code:

 while(TRUE)
    //This line _alone_ is executed by the while loop
    if((input(PIN_B0)) && (auth=0))   //If B0 goes low AND auth flag is 0
        //If the test is true, this line gets executed
        for(x=0;x=7; x++)
           //Which executes this line
           delay_us(100);                   //Delay between bits in pulse train   
               
           
        //We get here, if the 'if' fails
        for (i=0;i=3;i++)             //Sample three times to determine bit
             //when the 'for' is executed, it runs this line
             samp=input(PIN_B0);
             //but not this one...
             samp=samp+samp;


Best Wishes
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Oct 14, 2006 4:04 pm     Reply with quote

Quote:
but did you need to add the criticism?

I debated whether or not to put that in.

The reason for all my comments was this thread earlier in the week.
http://www.ccsinfo.com/forum/viewtopic.php?t=28403
I tried to help someone with similar types of errors in their code,
such as a mis-understanding of how to use braces.

That thread went on for two pages. I would suggest changes.
The person would make a few of them. I would ask the person to
please review their code and fix all bugs of the type that I pointed out.
The person would never really completely do it.

I don't want to get caught up in a thread like that again.
cclough



Joined: 14 Oct 2006
Posts: 5

View user's profile Send private message

PostPosted: Sat Oct 14, 2006 8:22 pm     Reply with quote

PCM: I figured there was another situation that sparked the statement; thank you for help.

Ttelmah: Thank you for the brief explanation.

I went through and put the brackets in the way they should be, and now things compile, and it's bouncing between statements properly. It doesn't work the way I want it to, but at least it's doing something. Wink
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun Oct 15, 2006 5:00 am     Reply with quote

One other error repeating in our code is the use of '=' for comparing values. A single '=' sign will assign a value, the correct way to compare a value is by using the '==' statement. Sometimes this is done correctly in your code but not always, for example all for-loops contain this error and there are more.
cclough



Joined: 14 Oct 2006
Posts: 5

View user's profile Send private message

PostPosted: Sun Oct 15, 2006 9:02 am     Reply with quote

Thanks for point this out. I fixed the for-loops already, but need to go through and deal with the others.

-Chris
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