Mikro C errors

Thread Starter

abcd3

Joined Feb 12, 2011
9
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.

Rich (BB code):
unsigned short kp, cnt, firstdigit = 0, seconddigit = 0;
int secs = 0;
char txt[6];

// Keypad module connections
char  keypadPort at PORTD;
// End Keypad module connections

// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;

void main() {


     TRISC = 0xFF;            //PORT C IS INPUT FROM INFRARED SENSOR
     TRISA = 0x00;            // PORT A IS OUTPUT TO MOTOR

     cnt = 0;                                 // Reset counter
     Keypad_Init();                           // Initialize Keypad
     Lcd_Init();                              // Initialize Lcd
     Lcd_Cmd(_LCD_CLEAR);                      // Clear display
     Lcd_Cmd(_LCD_CURSOR_OFF);;                 // Cursor off

     int hr = 12, min = 0, time_enter = 0, a = 0;
     int feed_hour[5], feed_min[5], am_pm[5], clock_ampm[1];
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!
 

spinnaker

Joined Oct 29, 2009
7,830
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.

Rich (BB code):
unsigned short kp, cnt, firstdigit = 0, seconddigit = 0;
int secs = 0;
char txt[6];

// Keypad module connections
char  keypadPort at PORTD;
// End Keypad module connections

// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;

void main() {


     TRISC = 0xFF;            //PORT C IS INPUT FROM INFRARED SENSOR
     TRISA = 0x00;            // PORT A IS OUTPUT TO MOTOR

     cnt = 0;                                 // Reset counter
     Keypad_Init();                           // Initialize Keypad
     Lcd_Init();                              // Initialize Lcd
     Lcd_Cmd(_LCD_CLEAR);                      // Clear display
     Lcd_Cmd(_LCD_CURSOR_OFF);;                 // Cursor off

     int hr = 12, min = 0, time_enter = 0, a = 0;
     int feed_hour[5], feed_min[5], am_pm[5], clock_ampm[1];
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!
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.
 

thatoneguy

Joined Feb 19, 2009
6,359
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 ()
 

nerdegutta

Joined Dec 15, 2009
2,684
Rich (BB code):
    Lcd_Cmd(_LCD_CURSOR_OFF);;                 // Cursor off
This lines has double semicolons, but that's ignored by the compiler, I think...:rolleyes:
 

spinnaker

Joined Oct 29, 2009
7,830
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 ()
That is the main reason I said not to make people count lines. And not all of the code is there to boot!
 

Thread Starter

abcd3

Joined Feb 12, 2011
9
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.

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

spinnaker

Joined Oct 29, 2009
7,830
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.
 

Thread Starter

abcd3

Joined Feb 12, 2011
9
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.
nope I just tried splitting them up and still the same annoying errors:confused:
 

spinnaker

Joined Oct 29, 2009
7,830
nope I just tried splitting them up and still the same annoying errors:confused:

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.
 

SgtWookie

Joined Jul 17, 2007
22,230
On this line:
Rich (BB code):
     Lcd_Cmd(_LCD_CURSOR_OFF);;                 // Cursor off
you have two semicolons. Delete one of them.

Then try compiling it again.
 
Last edited:

thatoneguy

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

 

Thread Starter

abcd3

Joined Feb 12, 2011
9
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!
 

Attachments

Thread Starter

abcd3

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


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:
 

thatoneguy

Joined Feb 19, 2009
6,359
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.
 

Thread Starter

abcd3

Joined Feb 12, 2011
9
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.
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
 

thatoneguy

Joined Feb 19, 2009
6,359
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.
 

Thread Starter

abcd3

Joined Feb 12, 2011
9
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
 

Thread Starter

abcd3

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

0 360 Unresolved extern 'LCD_D7' __Lib_Lcd.c
 

thatoneguy

Joined Feb 19, 2009
6,359
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.
 

Thread Starter

abcd3

Joined Feb 12, 2011
9
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
 
Top