Mikro C errors

Discussion in 'Programmer's Corner' started by abcd3, Feb 12, 2011.

  1. abcd3

    Thread Starter New Member

    Feb 12, 2011
    9
    0
    Hello everyone. I'm new to programming with Mikro C and I'm trying to write code for a PIC16F877A that will operate a dog feeder.

    Code ( (Unknown Language)):
    1.  
    2. unsigned short kp, cnt, firstdigit = 0, seconddigit = 0;
    3. int secs = 0;
    4. char txt[6];
    5.  
    6. // Keypad module connections
    7. char  keypadPort at PORTD;
    8. // End Keypad module connections
    9.  
    10. // LCD module connections
    11. sbit LCD_RS at RB4_bit;
    12. sbit LCD_EN at RB5_bit;
    13. sbit LCD_D4 at RB0_bit;
    14. sbit LCD_D5 at RB1_bit;
    15. sbit LCD_D6 at RB2_bit;
    16. sbit LCD_D7 at RB3_bit;
    17.  
    18. sbit LCD_RS_Direction at TRISB4_bit;
    19. sbit LCD_EN_Direction at TRISB5_bit;
    20. sbit LCD_D4_Direction at TRISB0_bit;
    21. sbit LCD_D5_Direction at TRISB1_bit;
    22. sbit LCD_D6_Direction at TRISB2_bit;
    23. sbit LCD_D7_Direction at TRISB3_bit;
    24.  
    25. void main() {
    26.  
    27.  
    28.      TRISC = 0xFF;            //PORT C IS INPUT FROM INFRARED SENSOR
    29.      TRISA = 0x00;            // PORT A IS OUTPUT TO MOTOR
    30.  
    31.      cnt = 0;                                 // Reset counter
    32.      Keypad_Init();                           // Initialize Keypad
    33.      Lcd_Init();                              // Initialize Lcd
    34.      Lcd_Cmd(_LCD_CLEAR);                      // Clear display
    35.      Lcd_Cmd(_LCD_CURSOR_OFF);;                 // Cursor off
    36.  
    37.      int hr = 12, min = 0, time_enter = 0, a = 0;
    38.      int feed_hour[5], feed_min[5], am_pm[5], clock_ampm[1];
    39.  
    This is just the beginning of my code, but I believe from the errors I'm receiving if I solve it the rest of my code will work. Here are the error messages

    36 315 Invalid expression dog_feedtest.c
    34 402 ; expected, but 'int' found dog_feedtest.c
    36 424 '}' expected ';' found dog_feedtest.c

    Also I have one more error which I don't understand.

    80 371 Specifier needed dog_feedtest.c

    What does "Specifier needed" mean? I know this is not the best place to post this question, but I've already posted on mikro C forum and it's taking wayyy too long for a response so I'm trying to get help as quick as possible, from anywhere possible. So your help would be greatly appreciated!
     
  2. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,866
    988
    Mark which lines are causing which problems. Please don't expect people to count the lines of code. if you asked the question the same way on the Mikro C forum, it could be why you are not getting an answer.
     
  3. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    The lines posted don't match the lines mentioned by the errors.

    34 402 ; expected, but 'int' found dog_feedtest.c //forgot ; to terminate previous line
    36 424 '}' expected ';' found dog_feedtest.c // Didn't close a code block with }, looks like main ()
     
  4. nerdegutta

    Moderator

    Dec 15, 2009
    2,514
    784
    Code ( (Unknown Language)):
    1.     Lcd_Cmd(_LCD_CURSOR_OFF);;                 // Cursor off
    2.  
    This lines has double semicolons, but that's ignored by the compiler, I think...:rolleyes:
     
  5. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,866
    988
    That is the main reason I said not to make people count lines. And not all of the code is there to boot!
     
  6. abcd3

    Thread Starter New Member

    Feb 12, 2011
    9
    0
    I didn't post the entire code because I'm not that efficient yet in programming in C so right now the code is over 3000 lines long :eek: I don't need efficient I just need it to work so I can continue the rest of my project. but I did take out the extra comma and recompiled it but still the same error messages. I numbered the lines too so it will be easier.

    Code ( (Unknown Language)):
    1.  
    2. unsigned short kp, cnt, firstdigit = 0, seconddigit = 0;  //1
    3. int secs = 0;   //2
    4. char txt[6];   //3
    5.                    //4
    6. // Keypad module connections  //5
    7. char  keypadPort at PORTD;    //6
    8. // End Keypad module connections   //7
    9.                        //8
    10. // LCD module connections       //9
    11. sbit LCD_RS at RB4_bit;          //10
    12. sbit LCD_EN at RB5_bit;          //11
    13. sbit LCD_D4 at RB0_bit;          //12
    14. sbit LCD_D5 at RB1_bit;         //13
    15. sbit LCD_D6 at RB2_bit;         //14
    16. sbit LCD_D7 at RB3_bit;         //15
    17.                                         //16
    18. sbit LCD_RS_Direction at TRISB4_bit;   //17
    19. sbit LCD_EN_Direction at TRISB5_bit;   // 18
    20. sbit LCD_D4_Direction at TRISB0_bit;   //19
    21. sbit LCD_D5_Direction at TRISB1_bit;   //20
    22. sbit LCD_D6_Direction at TRISB2_bit;   //21
    23. sbit LCD_D7_Direction at TRISB3_bit;   //22
    24.                                        // 23
    25. void main() {                  //24
    26.                                   //25
    27.                                   //26
    28.      TRISC = 0xFF;            //PORT C IS INPUT FROM INFRARED SENSOR//27
    29.      TRISA = 0x00;            // PORT A IS OUTPUT TO MOTOR   //28
    30.                                  //29
    31.      cnt = 0;                                 // Reset counter     //30
    32.      Keypad_Init();                           // Initialize Keypad   //31
    33.      Lcd_Init();                              // Initialize Lcd        //32
    34.      Lcd_Cmd(_LCD_CLEAR);                      // Clear display   //33
    35.      Lcd_Cmd(_LCD_CURSOR_OFF);                 // Cursor off    //34
    36.                            //35
    37.      int hr = 12, min = 0, time_enter = 0, a = 0;         //36
    38.      int feed_hour[5], feed_min[5], am_pm[5], clock_ampm[1];    //37
    39.  
    I hope this makes it easier for you.

    36 315 Invalid expression dog_feedtest.c ---- this corresponds with line 36
    34 402 ; expected, but 'int' found dog_feedtest.c --- corresponds with 34
    36 424 '}' expected ';' found dog_feedtest.c --- line 36 again

    thanks for the quick replies also, I appreciate it!
     
  7. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,866
    988
    Your problem might be here

    int hr = 12, min = 0, time_enter = 0, a = 0; //36
    int feed_hour[5], feed_min[5], am_pm[5], clock_ampm[1];

    At least in C18, you cannot mix declarations within your code. They need to go at the top of your function. I am not sure about Mikro C.
     
  8. abcd3

    Thread Starter New Member

    Feb 12, 2011
    9
    0
    nope I just tried splitting them up and still the same annoying errors:confused:
     
  9. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,866
    988

    If by splitting up, you mean :

    int hr = 12;
    int min = 0;
    int time_enter = 0;
    int a = 0; //36


    Then I did not say anything about that. I said declarations need to be placed at the top of the function before any code.

    Also it could be that mikro C does not like assignment on declaration within a function.
     
  10. SgtWookie

    Expert

    Jul 17, 2007
    22,182
    1,728
    On this line:
    Code ( (Unknown Language)):
    1.      Lcd_Cmd(_LCD_CURSOR_OFF);;                 // Cursor off
    you have two semicolons. Delete one of them.

    Then try compiling it again.
     
    Last edited: Feb 12, 2011
  11. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    The first one is also missing a semicolon terminating the line before it, possibly several if a comment block is above it (the "; expected")

    The "}" expected means that not all of your { match }, adding extras randomly will most likely hork the program. { and } are used in pairs to denote code blocks, so make sure every { has a matching } in the correct spot, you may have left one out in a while loop, leaving main() without a closing }, so adding a } to the end of the code would make all that code "inside" the loop you forgot to add it to.

    Try running your code through Src CodeColorizer That will color-highlight your code (paste ALL 3000 lines) and missing parts will jump out at you.

    To be honest, I'm not sure how you ended up with three thousand lines of code for a first app, unless there is a lot of "patching together" existing code. You should also get a "lint" tool, which goes through code and spits out all of the syntax errors in a more readable format than a compiler. Talk to google about an "Online C Code Lint"

    The output of the colorizer (NOT a lint tool) looks like this (from your first post):
    Code ( (Unknown Language)):
    1.  
    2. [FONT=Arial][SIZE=2][COLOR=#cccccc] 1: [/COLOR]unsigned [COLOR=RED][B]short[/B][/COLOR] kp[SIZE=+1][COLOR=BLUE][B],[/B][/COLOR][/SIZE] cnt[SIZE=+1][COLOR=BLUE][B],[/B][/COLOR][/SIZE] firstdigit [SIZE=+1][COLOR=BLUE]=[/COLOR][/SIZE] [COLOR=BROWN]0[/COLOR][SIZE=+1][COLOR=BLUE][B],[/B][/COLOR][/SIZE] seconddigit [SIZE=+1][COLOR=BLUE]=[/COLOR][/SIZE] [COLOR=BROWN]0[/COLOR][SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]
    3. [COLOR=#eeeeee] 2: [/COLOR][COLOR=RED][B]int[/B][/COLOR] secs [SIZE=+1][COLOR=BLUE]=[/COLOR][/SIZE] [COLOR=BROWN]0[/COLOR][SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]
    4. [COLOR=#eeeeee] 3: [/COLOR][COLOR=RED][B]char[/B][/COLOR] txt[SIZE=+1][COLOR=BLUE][B][[/B][/COLOR][/SIZE][COLOR=BROWN]6[/COLOR][SIZE=+1][COLOR=BLUE][B]][/B][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]
    5. [COLOR=#eeeeee] 4: [/COLOR]
    6. [COLOR=#cccccc] 5: [/COLOR][COLOR=GREEN][I]// Keypad module connections
    7. [COLOR=#eeeeee] 6: [/COLOR][/I][/COLOR][COLOR=RED][B]char[/B][/COLOR]  keypadPort at PORTD[SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]
    8. [COLOR=#eeeeee] 7: [/COLOR][COLOR=GREEN][I]// End Keypad module connections
    9. [COLOR=#eeeeee] 8: [/COLOR][/I][/COLOR]
    10. [COLOR=#eeeeee] 9: [/COLOR][COLOR=GREEN][I]// LCD module connections
    11. [COLOR=#cccccc]10: [/COLOR][/I][/COLOR]sbit LCD_RS at RB4_bit[SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]
    12. [COLOR=#eeeeee]11: [/COLOR]sbit LCD_EN at RB5_bit[SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]
    13. [COLOR=#eeeeee]12: [/COLOR]sbit LCD_D4 at RB0_bit[SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]
    14. [COLOR=#eeeeee]13: [/COLOR]sbit LCD_D5 at RB1_bit[SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]
    15. [COLOR=#eeeeee]14: [/COLOR]sbit LCD_D6 at RB2_bit[SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]
    16. [COLOR=#cccccc]15: [/COLOR]sbit LCD_D7 at RB3_bit[SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]
    17. [COLOR=#eeeeee]16: [/COLOR]
    18. [COLOR=#eeeeee]17: [/COLOR]sbit LCD_RS_Direction at TRISB4_bit[SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]
    19. [COLOR=#eeeeee]18: [/COLOR]sbit LCD_EN_Direction at TRISB5_bit[SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]
    20. [COLOR=#eeeeee]19: [/COLOR]sbit LCD_D4_Direction at TRISB0_bit[SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]
    21. [COLOR=#cccccc]20: [/COLOR]sbit LCD_D5_Direction at TRISB1_bit[SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]
    22. [COLOR=#eeeeee]21: [/COLOR]sbit LCD_D6_Direction at TRISB2_bit[SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]
    23. [COLOR=#eeeeee]22: [/COLOR]sbit LCD_D7_Direction at TRISB3_bit[SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]
    24. [COLOR=#eeeeee]23: [/COLOR]
    25. [COLOR=#eeeeee]24: [/COLOR][COLOR=RED][B]void[/B][/COLOR] main[SIZE=+1][COLOR=BLUE][B]([/B][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B])[/B][/COLOR][/SIZE] [SIZE=+1][COLOR=BLUE][B]{[/B][/COLOR][/SIZE]
    26. [COLOR=#cccccc]25: [/COLOR]
    27. [COLOR=#eeeeee]26: [/COLOR]
    28. [COLOR=#eeeeee]27: [/COLOR]     TRISC [SIZE=+1][COLOR=BLUE]=[/COLOR][/SIZE] 0xFF[SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]            [COLOR=GREEN][I]//PORT C IS INPUT FROM INFRARED SENSOR
    29. [COLOR=#eeeeee]28: [/COLOR][/I][/COLOR]     TRISA [SIZE=+1][COLOR=BLUE]=[/COLOR][/SIZE] [COLOR=PINK]0x00[/COLOR][SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]            [COLOR=GREEN][I]// PORT A IS OUTPUT TO MOTOR
    30. [COLOR=#eeeeee]29: [/COLOR][/I][/COLOR]
    31. [COLOR=#cccccc]30: [/COLOR]     cnt [SIZE=+1][COLOR=BLUE]=[/COLOR][/SIZE] [COLOR=BROWN]0[/COLOR][SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]                                 [COLOR=GREEN][I]// Reset counter
    32. [COLOR=#eeeeee]31: [/COLOR][/I][/COLOR]     Keypad_Init[SIZE=+1][COLOR=BLUE][B]([/B][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B])[/B][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]                           [COLOR=GREEN][I]// Initialize Keypad
    33. [COLOR=#eeeeee]32: [/COLOR][/I][/COLOR]     Lcd_Init[SIZE=+1][COLOR=BLUE][B]([/B][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B])[/B][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]                              [COLOR=GREEN][I]// Initialize Lcd
    34. [COLOR=#eeeeee]33: [/COLOR][/I][/COLOR]     Lcd_Cmd[SIZE=+1][COLOR=BLUE][B]([/B][/COLOR][/SIZE]_LCD_CLEAR[SIZE=+1][COLOR=BLUE][B])[/B][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]                      [COLOR=GREEN][I]// Clear display
    35. [COLOR=#eeeeee]34: [/COLOR][/I][/COLOR]     Lcd_Cmd[SIZE=+1][COLOR=BLUE][B]([/B][/COLOR][/SIZE]_LCD_CURSOR_OFF[SIZE=+1][COLOR=BLUE][B])[/B][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]                 [COLOR=GREEN][I]// Cursor off
    36. [COLOR=#cccccc]35: [/COLOR][/I][/COLOR]
    37. [COLOR=#eeeeee]36: [/COLOR]     [COLOR=RED][B]int[/B][/COLOR] hr [SIZE=+1][COLOR=BLUE]=[/COLOR][/SIZE] [COLOR=BROWN]12[/COLOR][SIZE=+1][COLOR=BLUE][B],[/B][/COLOR][/SIZE] min [SIZE=+1][COLOR=BLUE]=[/COLOR][/SIZE] [COLOR=BROWN]0[/COLOR][SIZE=+1][COLOR=BLUE][B],[/B][/COLOR][/SIZE] time_enter [SIZE=+1][COLOR=BLUE]=[/COLOR][/SIZE] [COLOR=BROWN]0[/COLOR][SIZE=+1][COLOR=BLUE][B],[/B][/COLOR][/SIZE] a [SIZE=+1][COLOR=BLUE]=[/COLOR][/SIZE] [COLOR=BROWN]0[/COLOR][SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]
    38. [COLOR=#eeeeee]37: [/COLOR]     [COLOR=RED][B]int[/B][/COLOR] feed_hour[SIZE=+1][COLOR=BLUE][B][[/B][/COLOR][/SIZE][COLOR=BROWN]5[/COLOR][SIZE=+1][COLOR=BLUE][B]][/B][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B],[/B][/COLOR][/SIZE] feed_min[SIZE=+1][COLOR=BLUE][B][[/B][/COLOR][/SIZE][COLOR=BROWN]5[/COLOR][SIZE=+1][COLOR=BLUE][B]][/B][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B],[/B][/COLOR][/SIZE] am_pm[SIZE=+1][COLOR=BLUE][B][[/B][/COLOR][/SIZE][COLOR=BROWN]5[/COLOR][SIZE=+1][COLOR=BLUE][B]][/B][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B],[/B][/COLOR][/SIZE] clock_ampm[SIZE=+1][COLOR=BLUE][B][[/B][/COLOR][/SIZE][COLOR=BROWN]1[/COLOR][SIZE=+1][COLOR=BLUE][B]][/B][/COLOR][/SIZE][SIZE=+1][COLOR=BLUE][B];[/B][/COLOR][/SIZE]
    39. [/SIZE][/FONT]

     
    abcd3 likes this.
  12. abcd3

    Thread Starter New Member

    Feb 12, 2011
    9
    0
    I just tried placing the declarations outside of the function. It did clear the errors, but it brought different ones with it. I also removed the double ;; so it is now only one. I've attached a copy of my source code. If anyone can try and go through it and observe the errors themselves and help me that would be awesome! everything in the program is pretty repetitive, so once you figured out one section you pretty much figured it all out. They have necessary comments made in them to make it easier. It's for a PIC16F877A and the project is for a dog feeder. I'm not looking for efficiency or anything like that. I just want the errors I have to go away, because I'm almost confident the rest of the program should be ok so I can actually go about and build my circuit. thanks for your help!
     
  13. abcd3

    Thread Starter New Member

    Feb 12, 2011
    9
    0

    Will do! I told you, I'm not really that efficient in coding so I tend to take the long way to do things. but right now I could careless if it's long, I just want it to work:confused:
     
  14. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    I've looked at it..

    You need to define variables inside the main function, not outside of functions.

    Declare variables at top of function.

    sbit isn't defined

    LCD_* functions are not defined.

    You can't define "keypad at PORTD", it needs to be int keypad@PORD.2 or similar (see help file).

    For every error on the build, in the red at the bottom, double click on it and the cursor will jump to the line where the error is.

    Too many for me to fix quickly, sorry.
     
    abcd3 likes this.
  15. abcd3

    Thread Starter New Member

    Feb 12, 2011
    9
    0
    THANK YOU SO MUCH YOU HAVE NO IDEA! Turns out I forgot to add the prototype functions to the program. I appreciate it, now I just have to fix the other errors and I'm home free! :D
     
  16. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    Glad to help. During my perusal, there are many "simpler ways" of doing the same thing you are trying, probably cutting the code in half or more.

    Use the case statement instead of many if's, index arrays instead of comparing, stuff like that.
     
  17. abcd3

    Thread Starter New Member

    Feb 12, 2011
    9
    0
    thanks for the tip. I'm going to try and find easier ways to cut the code in half. I only have one semester of C++ in me so I've yet to take notice in the easier ways to do stuff, but I'm getting it.... slowly

    switch statement is a good idea though I'm going to try that instead of the if's
     
  18. abcd3

    Thread Starter New Member

    Feb 12, 2011
    9
    0
    you wouldn't happen to know what this error message means do you?:

    0 360 Unresolved extern 'LCD_D7' __Lib_Lcd.c
     
  19. thatoneguy

    AAC Fanatic!

    Feb 19, 2009
    6,357
    718
    LCD_D7 is not defined/declared to an address in your other files that are included.

    Is the LCD routine made for 4 bit communication? Take a look the functioning LCD example to get the code for working with the LCD.
     
  20. abcd3

    Thread Starter New Member

    Feb 12, 2011
    9
    0
    it is made for 4 bit communication.. but I don't understand what that might have to do with the errors? I have the LCD library included in my program
     
Loading...