View previous topic :: View next topic |
Author |
Message |
albe01
Joined: 02 Jul 2010 Posts: 30 Location: italy
|
help for improper use of a function in ccs |
Posted: Tue Jul 13, 2010 7:24 pm |
|
|
Hello to everyone, i have a problem with this code, i use ccs compiler and i use a pic 18f4525... i can not resolve this errors
thank to all!
Code: |
void get_packet() {
int i;
for(i=0;i<80;i++){ THIS "FOR" IS THE PROBLEM, THE COMPILER GENERATE THIS 2 ERROR:1 improper of a function identifier, 2 expect ;
bte=0xFF;
}
numbyte=0; //reset numbyte
#if 1
while (cbyte != 0x7e){ //find the first flag
shift_right(&cbyte,1,bitin()); //add a new bit to the left of cbyte,
discard right bit
} //end of while //244=824 243 = 831.0
output_high(DCD_LED);
#endif
cbyte = 0x7e;
While (cbyte == 0x7e){ //find the other flags
for(i=0;i<8;i++){ //repeat this 8 times //244=834.6 243=831.2
shift_right(&cbyte,1,bitin()); //add a new bit to the left of cbyte,
discard right bit
} //end of for
} //end of while -- now at end of all the flags
bte[0] = cbyte; //you've now got the first address byte
numbyte++; //we already collected 1 byte
while (test != 1){ //do this until the flag at the end of
the packet
for(i=0;i<8;i++){ //collect 8 bits
newbit = bitin(); //get a bit
if (newbit == 1) (ones++); //increment the ones counter
else (ones = 0); //if bit is a zero, reset the ones counter
if (ones == 5) { //removes bit stuffing
test = bitin(); //get the next bit but don't add it to cbyte
ones = 0; //reset the ones counter
}
shift_right(&cbyte,1,newbit); //append the new bit to cbyte
} //end of for
if (test==0 ){
bte[numbyte] = cbyte; //add cbyte to the array
numbyte++; //increment the number of received bytes
}
}//end of while
output_low(DCD_LED);
}//end get_packet()
|
|
|
|
albe01
Joined: 02 Jul 2010 Posts: 30 Location: italy
|
|
Posted: Tue Jul 13, 2010 7:26 pm |
|
|
Last edited by albe01 on Wed Jul 14, 2010 5:56 am; edited 1 time in total |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1933 Location: Norman, OK
|
|
Posted: Tue Jul 13, 2010 7:33 pm |
|
|
Code: | int numbyte,cbyte=0,ones; int1 test=0,newbit;
//---------------------------------------------
int1 bitin(){ //function to read a bit
static int oldstate; //oldstate retained between runs of this function
int k;
for (k=0;k<244;k++){ //this loop allows 838 us to go by. If no state change, bit is 1
if (input(rcvPin) != oldstate){ //if state has changed
oldstate = input(rcvPin); //update oldstate
delay_us(430); // move to halfway thru the next bit
return 0; //return 0 if state changed
} //end of if
} //end of for
return 1; //return 1 if state did not change
<===*** What do you not see that should be here? ***
//end of bitin()
//-------------------------------------------------
void get_packet() {
int i;
for(i=0;i<80;i++){
bte=0xFF;
}
numbyte=0; //reset numbyte |
What is the point of the next part? 1 will always be 1 ....
Code: | numbyte=0; //reset numbyte
#if 1
while (cbyte != 0x7e){ //find the first flag
shift_right(&cbyte,1,bitin()); //add a new bit to the left of cbyte, discard right bit
} //end of while //244=824 243 = 831.0
output_high(DCD_LED);
#endif
|
_________________ Google and Forum Search are some of your best tools!!!! |
|
|
kender
Joined: 09 Aug 2004 Posts: 768 Location: Silicon Valley
|
|
Posted: Tue Jul 13, 2010 11:49 pm |
|
|
dyeatman wrote: | What is the point of the next part? 1 will always be 1 .... Code: | numbyte=0; //reset numbyte
#if 1
while (cbyte != 0x7e){ //find the first flag
shift_right(&cbyte,1,bitin()); //add a new bit to the left of cbyte, discard right bit
} //end of while //244=824 243 = 831.0
output_high(DCD_LED);
#endif
|
|
Some people use #if 1 syntax as a way of turning blocks of code on and off. It's an alternative to commenting out. _________________ Read the label, before opening a can of worms. |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Thu Jul 15, 2010 12:33 pm |
|
|
Code: | void get_packet() {
int i;
for(i=0;i<80;i++){ THIS "FOR" IS THE PROBLEM, THE COMPILER GENERATE THIS 2 ERROR:1 improper of a function identifier, 2 expect ;
bte=0xFF;
} | My guess is the error is in the line just before this function. That is, in the part of code not posted here...
The CCS compiler is not always very good in pointing to the real error. |
|
|
icesynth
Joined: 03 Sep 2007 Posts: 32 Location: Edmonton, Alberta
|
|
Posted: Wed May 11, 2011 11:52 pm |
|
|
Agreed, this error is usually caused by a curly bracket missing in the previous function. _________________ Programming for the the real world.
--Chris Burchett
Sylver Technologies Inc. |
|
|
|