I have a very simple code, but when I compile I keep getting syntax errors. Unfortunatly, the MPLAB does not tell you anything but that there is a syntax error. I’ve been trying to debug it, and it seems to be either the “void Autonomous_1()” line, or the IF loop. It seems like it should work, and multiple people have checked it and agreed. Does anybody see something that I’m not? It’s so simple, I don’t understand why it won’t work. Thanks.
pwm01 = 254;
pwm02 = 254;
pwm01 = 127;
pwm02 = 127;
Can you give us the error message from the compiler? It would help greatly with the debugging. Even the line number will help. Do you have Autonomous_1 and Autonomous_2 defined in a header? If so, what do those lines look like? If you’re having trouble getting something to compile that looks like it should, take out enough code to get it to at least compile. Then slowly add the code back in and you’ll know where the problem is.
Is that the code exactly as it appears in your file? If so, why isn’t the IF statement inside a function?
what’s the code before the if statement? You don’t have an ending bracket like you are closing a function.
I’m using this with the Edubot, I’m putting it in user_routines.c where it says to add your own code. The MPLAB compiler doesnt tell me anything other than “Error: syntax error” and it points at the space between where it closes the first IF loop, and where it says “void Autonomous_1()”. I did try the method Mike said with taking some code out and adding it back. It seems to be the “void Autonomous_1()” and “void Autonomous_2()” lines. Do we have to have them defined in a header? If so, where and how… because I haven’t done that.? Thanks!
well the most obvious problem is that you are trying do define function inside of functions. This is illegal. Put the declaration outside of any other functions. Things will work if you put the functions at the end of the code.
a better idea is this
----------------------------- edit --------------------------------
One good prectice is to put as much of any new code as possible in seperate files from the default IFI code and oly modify when need be. This makes code more portabe and keeps related things in one place. If you do this be sure to include your new files in whatever other files reference them. Also be sure to include whatever files your code references. Btw to create a new file and add it to a project, first create the file and save it with the appropriate file extention. this is not enough. if must then be added to the project file. the command to do this is on the project menu.
Also, while it is not mandatory in all compilers, it is a good idea to prototype your functions. This lets the compiler know what kind of arguments will be passed to them. In your case nothing is passed. add these lines(also outside of any other functions):
That was the problem. Thanks for the help!