Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

compiler for c

Status
Not open for further replies.
no thats just a chunk, and /*wait*/ is waiting to be replaced with a command....

prototypes? is that what a subroutine is? I moved it up, but the error followed it, and all that is before it is another similar bracket, and both brackets have corresponding brackets?

i trimmed that snip so it has only one sub and one main, could you set it up just to get this first sub goin, just so i can template the rest? I updated the sample so there is only one sub and one main

Ok, one problem with that one is that you have a prototype within the main function. You need to put the prototypes before "main".

Anyway, I think you'll get the error "Error [1302] old style function declarations not supported" if you have a prototype but never call it. That might be your problem. Remember, to call the function by saying "functionName();" (It may look a little different if you're passing a value into it--you'll set it up like "functionName(input_value)".

Try putting in a line to call the function and get back to us then.

Oh, and yes, a function is basically the same as a subroutine. You set up the prototype (the program for the function) above "main" with the program you want to execute. You call it by putting the line (like what I mentioned earlier) into "main". It will look something like this:

/*prototype*/

void myFunction(void)
{
function code;
}

/*main function*/

void main(void)
{
myFunction();
}
 
Last edited:
ok, i did it like that, but i am still gettting a error on my first function at the last bracket, this is despite weather the main function is there or not......
 
What exactly does the error say?
 
well it is that error 1302, but its not getting to my other subs, much less to the subs(or main) that have the call, it is occurring on the line with the final bracket





void INSTRUCT (DATAVALUES)
{
for (COUNTS2=1;COUNTS2<8;COUNTS2=COUNTS2+1)
{
/*Rotate DATAVALUES Left*/
if (ANUMBER = 1)
PORTDbits.RD3 = 1; /*STATUSC*/
else
{
PORTDbits.RD3 = 0;
}
PORTDbits.RD2 = 1;
PORTDbits.RD2 = 0;
}
return(0);
}

(even without the return line)
 
Last edited:
Two things come to mind.

If the } the error points to is on the last line in the filetry adding a blank line or two after it.

Could you mave a mismatched number of { and }
if you use code tags it preserves the code's formatting like this
[ CODE]
your code
[ /CODE]

but with no space between the [ and C. and [ and /
 
Last edited:
(it also happens when i use a sub where there are no subs in it)

and i have tripple checked for mismatched brackets, or misplaced semicolons

and when i put extra blank lines the error follows the last bracket for the sub

(also what do i press on the keyb to get an OR operator??)

HERE IS FULL THING:
 

Attachments

  • SAMPLE.txt
    3.3 KB · Views: 152
Last edited:
"Error [1302] old style function declarations not supported"

Apparently you're declaring your functions incorrectly. It looks like it might be this part:

void INITALISE (LAYER, SECTOR, BLOCK, PAGE)

Also, you have a while(PORTDbits.RD7 = 0). When you're testing a bit, you should have a '==', not just a '='. That part wouldn't cause the problem, but check your function declaration.
 
It sounds like the blank line fixed the first error which was keeping you from seeing what you are seeing now.

regarding

void INITALISE (LAYER, SECTOR, BLOCK, PAGE)

you need to specify data types for LAYER SECTOR BLOCK and PAGE

Logical or is || bitwise or is |
Logical and is && bitwise and is &
 
Last edited:
By the way, I was just looking at the code you sent the other day. It has a function that I didn't see in the one you just posted. It looks like this:

Code:
 void FLER (SECTORA, BLOCKA, PAGEA)
{
	for (CSA=1;CSA<3;CSA=CSA+1)
	{
		/*' D1=CS1 ;D0=CS2; C3=CS3 ; B2=DIN ; D2=CLK D.3=DOUT ; B1=WP */
		if (CSA = 1) PORTDbits.RD1 = 0;
		if (CSA = 2) PORTDbits.RD0 = 0;
		if (CSA = 3) PORTCbits.RC3 = 0;
		INSTRUCT (6);
		PORTDbits.D1 = 1;
		PORTDbits.D0 = 1;
		PORTCbits.C3 = 1;
		if (CSA = 1) PORTDbits.D1 = 0;
		if (CSA = 2) PORTDbits.D0 = 0;
		if (CSA = 3) PORTCbits.C3 = 0;
		INSTRUCT (216);
		INSTRUCT (SECTORA);
		INSTRUCT (BLOCKA);
		INSTRUCT (PAGEA);
		PORTDbits.RD1 = 1;
		PORTDbits.RD0 = 1;
		PORTCbits.RC3 = 1;
	}
									/*     wait one second */
}

all of your ifs nee the '=='. Also, I think you need '{}' around the parts where you set the port bits if the condition is true. For example, "if (CSA = 2) PORTDbits.D0 = 0;" Should be if (CSA = 2) {PORTDbits.D0 = 0};"
 
Ok, sorry for three posts in a row, but I think I found the problem. You declare the functions as:

void INITALISE(short, short, short, short);
void FLER (short, short, short);
void FLWR (short, short, short);

Insteady, you should put the code in them to create prototypes, like this:

Code:
void INITIALISE(short, short, short, short)
{
      code for function 'INITIALISE'
}


From there, when you call the function, you say:

INITIALISE(inval1, inval2, inval3, inval4);

I think that's the problem. The way you have it now is the "old style function declaration" that they speak of.
 
Ok, sorry for three posts in a row, but I think I found the problem. You declare the functions as:

void INITALISE(short, short, short, short);
void FLER (short, short, short);
void FLWR (short, short, short);

Insteady, you should put the code in them to create prototypes, like this:

Hi DerStrom,

Sorry to butt in, but the function prototype declares the functions name, arguments and return types while omitting the function body. The Function Prototypes are correct as written above.

Just a quick, simple example:

Code:
int function(int n);            // Function Prototype

int main(void){                 // Calling function
    int temp = function(100);
}

int function(int n){            // Called function
    return n*20;
}


Have a read here.


Doggy, I would place a function prototype before main():
Code:
INITALISE (LAYER, SECTOR, BLOCK, PAGE);

And also move your function to after main():
Code:
int main(void){
}

INITALISE (LAYER, SECTOR, BLOCK, PAGE){
}

You can also put your function prototypes in a header which you include before main().
 
Last edited:
Gobbledok, I've always seen it the other way around. The prototype is made up of the name of the function with all the different data types, and includes the code for that function. The function is called later on by typing the function name, and in parentheses any values you want to pass into the function. That's how I've always done it.

I may very well be wrong that what the OP did was incorrect, but what I describe definitely works, as it is the only way I ever do it.

Code:
/* Prototype */

int myFunction(int)
{
     X=X+1;
     return X;
}

/* Main code */

void main(void)
{
     myFunction(X);
}

In that example, int X gets passed into the function, which adds 1 and returns the new value.
 
Last edited:
Hi DerStrom,

Just had a bit of a read and turns out either way is correct so I apologise to anybody for any confusion. If the function is after main(), then it needs a prototype. If the function is before main(), then no prototype needed. **broken link removed**
 
Last edited:
OKAY well i think i got it going anyway but i wonder, how does it know which variable to use (int,int,int,int) <--these values go in to CSA,SECTOR,BLOCK,PAGE, but how does it know to go to the right variable?



however I have now run in to this error:

F:\Documents and Settings\Administrator\My Documents\mplab\firstone\first1.c:664:Error [1000] token too large, exceeds YYLMAX

what is that, time to shorten my code?
 
I think that error is due to a limitation of C18, it can't handle very long paths. Try moving your projects to somewhere like F:\Projects.

The way the compiler knows what variables to use is because it compiles twice. First time it only needs to know the size of the variables, hence why prototypes are needed, the second time it knows what variables to use.

Mike.
 
If the function is after main(), then it needs a prototype. If the function is before main(), then no prototype needed.

To be precise, if the function is after the point where it is called, then it needs a prototype. Good practice is to always use a prototype (declaration). Interrupt routines do not need a prototype, because they are not actually never called in the code (usually).

Anyway, there are so many things going wrong with doggy's C that I suggest you first try to forget BASIC, and find a good C-tutorial and take your time reading it.
 
Last edited:
Also, I think you need '{}' around the parts where you set the port bits if the condition is true. For example, "if (CSA = 2) PORTDbits.D0 = 0;" Should be if (CSA = 2) {PORTDbits.D0 = 0};"

This bit is incorrect.

It is a matter of style whether you include braces for a 1 line block after a conditional or loop construct. The same as while(1); or for(int n=0; n<=255; n++) dance(n);
 
This bit is incorrect.

Bad thing to call "good programming style" incorrect. I always use braces with conditional code segments.. even if they are only one line. What easily happens is that you add a line of code, but forget to add braces. That kind of bug is really difficult to find.

This kind of bug is also very difficult to spot:
Code:
if(CSA = 2)
{
    // This always executes, because "CSA = 2" is always 'true'.
    PORTDbits.D0 = 0;
}
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top