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:
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......
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
"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.
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};"
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;
}
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.
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**
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
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.
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.
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};"
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);
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;
}