1. 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.
    Dismiss Notice

compiler for c

Discussion in 'Microcontrollers' started by Dr_Doggy, Dec 28, 2011.

  1. DerStrom8

    DerStrom8 Super Moderator Most Helpful Member

    Joined:
    Aug 9, 2010
    Messages:
    5,484
    Likes:
    503
    Location:
    Vermont (GMT-5:00)
    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: Jan 4, 2012
  2. Dr_Doggy

    Dr_Doggy Well-Known Member

    Joined:
    Aug 11, 2007
    Messages:
    1,715
    Likes:
    37
    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......
     
  3. DerStrom8

    DerStrom8 Super Moderator Most Helpful Member

    Joined:
    Aug 9, 2010
    Messages:
    5,484
    Likes:
    503
    Location:
    Vermont (GMT-5:00)
    What exactly does the error say?
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. DirtyLude

    DirtyLude Well-Known Member

    Joined:
    Aug 5, 2003
    Messages:
    1,904
    Likes:
    56
    Location:
    Toronto, Canada

    Post you updated code and the error.
     
  6. Dr_Doggy

    Dr_Doggy Well-Known Member

    Joined:
    Aug 11, 2007
    Messages:
    1,715
    Likes:
    37
    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: Jan 6, 2012
  7. 3v0

    3v0 Coop Build Coordinator Forum Supporter

    Joined:
    Jul 14, 2006
    Messages:
    9,404
    Likes:
    227
    Location:
    OKLAHOMA USA
    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: Jan 6, 2012
  8. Dr_Doggy

    Dr_Doggy Well-Known Member

    Joined:
    Aug 11, 2007
    Messages:
    1,715
    Likes:
    37
    (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:
     

    Attached Files:

    Last edited: Jan 6, 2012
  9. DerStrom8

    DerStrom8 Super Moderator Most Helpful Member

    Joined:
    Aug 9, 2010
    Messages:
    5,484
    Likes:
    503
    Location:
    Vermont (GMT-5:00)
    "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.
     
  10. 3v0

    3v0 Coop Build Coordinator Forum Supporter

    Joined:
    Jul 14, 2006
    Messages:
    9,404
    Likes:
    227
    Location:
    OKLAHOMA USA
    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: Jan 6, 2012
  11. DerStrom8

    DerStrom8 Super Moderator Most Helpful Member

    Joined:
    Aug 9, 2010
    Messages:
    5,484
    Likes:
    503
    Location:
    Vermont (GMT-5:00)
    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 (text):
     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};"
     
  12. DerStrom8

    DerStrom8 Super Moderator Most Helpful Member

    Joined:
    Aug 9, 2010
    Messages:
    5,484
    Likes:
    503
    Location:
    Vermont (GMT-5:00)
    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 (text):
    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.
     
  13. Gobbledok

    Gobbledok Active Member

    Joined:
    Mar 9, 2008
    Messages:
    452
    Likes:
    34
    Location:
    Toowoomba, Australia
    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 (text):

    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 (text):
    INITALISE (LAYER, SECTOR, BLOCK, PAGE);
    And also move your function to after main():
    Code (text):
    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: Jan 6, 2012
  14. DerStrom8

    DerStrom8 Super Moderator Most Helpful Member

    Joined:
    Aug 9, 2010
    Messages:
    5,484
    Likes:
    503
    Location:
    Vermont (GMT-5:00)
    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 (text):

    /* 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: Jan 6, 2012
  15. Gobbledok

    Gobbledok Active Member

    Joined:
    Mar 9, 2008
    Messages:
    452
    Likes:
    34
    Location:
    Toowoomba, Australia
    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. *
     
    Last edited: Jan 6, 2012
  16. Dr_Doggy

    Dr_Doggy Well-Known Member

    Joined:
    Aug 11, 2007
    Messages:
    1,715
    Likes:
    37
    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?
     
  17. Pommie

    Pommie Well-Known Member Most Helpful Member

    Joined:
    Mar 18, 2005
    Messages:
    10,015
    Likes:
    317
    Location:
    Brisbane Australia
    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.
     
  18. misterT

    misterT Well-Known Member Most Helpful Member

    Joined:
    Apr 19, 2010
    Messages:
    2,697
    Likes:
    368
    Location:
    Finland
    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: Jan 7, 2012
  19. edeca

    edeca Active Member

    Joined:
    Apr 8, 2008
    Messages:
    589
    Likes:
    38
    Location:
    England
    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);
     
  20. misterT

    misterT Well-Known Member Most Helpful Member

    Joined:
    Apr 19, 2010
    Messages:
    2,697
    Likes:
    368
    Location:
    Finland
    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 (text):

    if(CSA = 2)
    {
        // This always executes, because "CSA = 2" is always 'true'.
        PORTDbits.D0 = 0;
    }
     
     
    Last edited: Jan 7, 2012
  21. 3v0

    3v0 Coop Build Coordinator Forum Supporter

    Joined:
    Jul 14, 2006
    Messages:
    9,404
    Likes:
    227
    Location:
    OKLAHOMA USA
    This program seems much to complex for the OP's skill level. I say that because he does not know the c operators or how to define or call a function.
     

Share This Page