Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

syntax error using Mplab c18

Status
Not open for further replies.

bethel

Newbie level 4
Joined
Sep 26, 2017
Messages
6
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
71
Hi,
i got a problem with my project..
I get a syntax error while compiling the program on mplab c18 , same program was compiled in another c program compiler and hex code generated but I only have access to
mplab c18.... can i get help to get the program compiled to hex file
 

I get a syntax error while compiling the program on mplab c18

This question is for guessing what error is this ? If you are new in programming, have a look at the log which accompanies the error message, and see what line is referred, and to which command.
 

Here is the program

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Keypad module connections
char  keypadPort at PORTB;
// End Keypad module connections
 
// LCD module connections
sbit LCD_RS at LATC4_bit;
sbit LCD_EN at LATC5_bit;
sbit LCD_D4 at LATC0_bit;
sbit LCD_D5 at LATC1_bit;
sbit LCD_D6 at LATC2_bit;
sbit LCD_D7 at LATC3_bit;
 
sbit LCD_RS_Direction at TRISC4_bit;
sbit LCD_EN_Direction at TRISC5_bit;
sbit LCD_D4_Direction at TRISC0_bit;
sbit LCD_D5_Direction at TRISC1_bit;
sbit LCD_D6_Direction at TRISC2_bit;
sbit LCD_D7_Direction at TRISC3_bit;
// End LCD module connections
 
#define HEATER PORTD.RD0
#define FAN PORTD.RD1
#define ENTER 15
#define CLEAR 13
#define ON 1
#define OFF 0
 
void main() {
  unsigned short kp,Txt[14];
  unsigned short Temp_Ref ;      //  Reference Temperature
  unsigned char inTemp;
  unsigned int temp;
  float mV, ActualTemp;
  
  Keypad_Init();                           // Initialize Keypad
  ANSELC = 0;                              // Configure PORTC as digital I/O
  ANSELB = 0;                              // Configure PORTB as digital I/O
  ANSELD = 0;                              // Configure PORTD as digital I/O
  TRISA0_bit = 1;                          //Configure AN0 (RA0) as input
  TRISC = 0;                               //PORTC are outputs (LCD)
  TRISD0_bit=0;                            //RD0 is output (Heater)
  TRISD1_bit=0;                            //RD1 is output (Fan)
  
  Lcd_Init();                              // Initialize LCD
  Lcd_Cmd(_LCD_CLEAR);                     // Clear display
  Lcd_Cmd(_LCD_CURSOR_OFF);                // Cursor off
  Lcd_Out(1, 4, "Automatic");
  Lcd_Out(2, 2, "Temp Control");
  delay_ms(2000);                          //2s delay
  
  HEATER = OFF;
  FAN = OFF;
 
  //ON startup, read the Referance Temperature from the Keypad
        START:
       Lcd_Cmd(_LCD_CLEAR);                     // Clear display
       Lcd_Out(1, 1, "Enter Temp Ref");
       Temp_Ref=0;
        Lcd_Out(2, 1, "Temp Ref: ");
        while(1)
        {
         do
         kp = Keypad_Key_Click();             // Store key code in kp variable
         while (!kp);
         if ( kp == ENTER )break;
         if (kp > 3 && kp < 8) kp = kp-1;
         if (kp > 8 && kp < 12) kp = kp-2;
         if (kp ==14)kp = 0;
         if ( kp == CLEAR )goto START;
         Lcd_Chr_Cp(kp + '0');
         Temp_Ref =(10*Temp_Ref) + kp;
       }
      Lcd_Cmd(_LCD_CLEAR);                     // Clear display
      Lcd_Out(1, 1, "Temp Ref: ");
      intToStr( Temp_Ref,Txt);         //Convert to String
      inTemp=Ltrim(Txt);
       Lcd_Out_CP(inTemp);                  //Display Ref Temp
      Lcd_Out(2, 1, "Press # to Cont.");
      //Wait until # is pressed
      kp =0;
      while(kp!=ENTER)
      {
         do
           kp = Keypad_Key_Click();             // Store key code in kp variable
         while(!kp);
      }
       Lcd_Cmd(_LCD_CLEAR);              // Clear display
       
   Lcd_Out(1, 1, "Temp Ref: ");
   Lcd_Chr(1,15,223);                  // Different LCD displays have different
                                     //   char code for degree
  Lcd_Chr(1,16,'C');                  // Display "C" for Celsius
   //Program loop
  while(1) {
     //Display Referance Temperature and Actual Temperature
     temp = ADC_Read(0);               //Read temperature from AN0
     mV = temp * 5000.0/1024.0;        //Convert to mV
     ActualTemp = mV/10.0 ;              // Convert to degrees Celcius
     intToStr( Temp_Ref,Txt);         //Convert to String
     inTemp=Ltrim(Txt);
     //Lcd_Out(1, 1, "Temp Ref: ");
     Lcd_Out(1, 11, inTemp);        //Display Ref Temp
     Lcd_Out(2, 1, "Temp= ");
     FloatToStr(ActualTemp,Txt);         //Convert to string
     Txt[4] = 0;
     Lcd_Out(2,7,Txt);
     Lcd_Out(2,12,"   ");
 
      //Compare ref temp with actual emp
      if (Temp_Ref >  ActualTemp)  //If Temp Ref is less than actual Temp, Switch ON Heater
      {
      HEATER = ON,
      FAN = OFF;
      }
       if (Temp_Ref <  ActualTemp)  //If Temp Ref is greater than actual Temp, Switch ON Fan
      {
      HEATER = OFF,
      FAN = ON;
      }
      if (Temp_Ref ==  ActualTemp)  //If Temp Ref is equal to actual Temp, Switch OFF Fan and Heater
      {
      HEATER = OFF,
      FAN = OFF;
      }
      Delay_ms(10000);        //Wait 10 s then repeat
  }
}

 
Last edited by a moderator:

*WILD* guess, but do you have all of the required headers at the start of each code file?
If the code will compile with another compiler then that compiler may not need an include file that the C18 compiler does.
Susan
 

Yes I did put the header and other necessary files in place. I tried compiling a smaller code and it worked. Though it's my first time using c18 compiler

- - - Updated - - -

This question is for guessing what error is this ? If you are new in programming, have a look at the log which accompanies the error message, and see what line is referred, and to which command.

Yes I have it's actually refering to line two and if I comment out line two, line 6 to 18 becomes the challenge.
 

You are trying to compile a code written for mikroC with C18. That doesn't work. The mikroC specific C extension have to be replaced by C standard compatible constructs understood by C18. Review the C18 manual how SFR accesses (e.g. to port bits) can be coded.
 
  • Like
Reactions: bethel

    bethel

    Points: 2
    Helpful Answer Positive Rating
'at' and 'sbit' are not part of the C language, they are part of MicroC but I don't think any other compiler will understand them.

instead of "sbit LCD_RS at LATC4_bit;" use "#define LCD_RS LATC,4;"

instead of "char keypadPort at PORTB;" try "#define keypadport PORTB". I do not use MicroC so it may be necessary to further qualify the 'char' type for keypadport.

Brian.
 
  • Like
Reactions: bethel

    bethel

    Points: 2
    Helpful Answer Positive Rating
Microchip compilers have already structures with port bit definitions in their processor specific include files. Best way is to understand the intended syntax, e.g. by studying example projects shipped with the compiler or from Microchip application library.
 
  • Like
Reactions: bethel

    bethel

    Points: 2
    Helpful Answer Positive Rating
I have corrected the syntax as advised by betwixt, those lines are fine now the challenge lies on line 35,36,37....... Attached here is the error message I now get from the c18 compiler.

(Error/warning message)
Preprocessor symbol `__DEBUG' is defined.
Wed Sep 27 05:40:26 2017
----------------------------------------------------------------------
Make: The target "C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.o" is out of date.
Executing: "C:\Program Files (x86)\Microchip\mplabc18\v3.47\bin\mcc18.exe" -p=18F4550 "incubat.c" -fo="incubat.o" -D__DEBUG -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-
MPLAB C18 3.47 (evaluation)
Copyright 2000-2011 Microchip Technology Inc.
Days remaining until evaluation becomes feature limited: 55

WARNING: Running the compiler in extended mode will not be supported when the evaluation becomes feature limited.

C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.c:37:Warning [2058] call of function without prototype
C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.c:38:Error [1105] symbol 'ANSELC' has not been defined
C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.c:38:Error [1101] lvalue required
C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.c:39:Error [1105] symbol 'ANSELB' has not been defined
C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.c:39:Error [1101] lvalue required
C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.c:40:Error [1105] symbol 'ANSELD' has not been defined
C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.c:40:Error [1101] lvalue required
C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.c:41:Error [1105] symbol 'TRISA0_bit' has not been defined
C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.c:41:Error [1101] lvalue required
C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.c:42:Error [1105] symbol 'TRISC' has not been defined
C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.c:42:Error [1101] lvalue required
C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.c:43:Error [1105] symbol 'TRISD0_bit' has not been defined
C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.c:43:Error [1101] lvalue required
C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.c:44:Error [1105] symbol 'TRISD1_bit' has not been defined
C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.c:44:Error [1101] lvalue required
C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.c:46:Warning [2058] call of function without prototype
C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.c:47:Error [1105] symbol '_LCD_CLEAR' has not been defined
C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.c:47:Warning [2058] call of function without prototype
C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.c:48:Error [1105] symbol '_LCD_CURSOR_OFF' has not been defined
C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.c:48:Warning [2058] call of function without prototype
C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.c:49:Warning [2058] call of function without prototype
C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.c:50:Warning [2058] call of function without prototype
C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.c:51:Warning [2058] call of function without prototype
C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.c:53:Error [1105] symbol 'PORTD' has not been defined
C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.c:53:Error [1151] struct or union object designator expected
C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.c:53:Error [1101] lvalue required
C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.c:54:Error [1105] symbol 'PORTD' has not been defined
C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.c:54:Error [1151] struct or union object designator expected
C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.c:54:Error [1101] lvalue required
C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.c:58:Error [1105] symbol '_LCD_CLEAR' has not been defined
C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.c:58:Warning [2058] call of function without prototype
C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.c:59:Warning [2058] call of function without prototype
C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.c:61:Warning [2058] call of function without prototype
C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.c:65:Warning [2058] call of function without prototype
C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.c:72:Warning [2058] call of function without prototype
C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.c:75:Error [1105] symbol '_LCD_CLEAR' has not been defined
C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.c:75:Warning [2058] call of function without prototype
C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.c:76:Warning [2058] call of function without prototype
C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.c:77:Warning [2058] call of function without prototype
C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.c:78:Warning [2058] call of function without prototype
C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.c:79:Warning [2058] call of function without prototype
C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.c:80:Warning [2058] call of function without prototype
C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.c:86:Warning [2058] call of function without prototype
C:\Users\iroabueke bethel\Desktop\New folder (3)\incubat.c:89:Error [1105] symbol '_LCD_CLEAR' has not been defined
Halting build on first failure as requested.
----------------------------------------------------------------------
Debug build of project `C:\Users\iroabueke bethel\Desktop\New folder (3)\incubator.mcp' failed.
Language tool versions: mpasmwin.exe v5.54, mplink.exe v5.00, mcc18.exe v3.47, mplib.exe v5.00
Preprocessor symbol `__DEBUG' is defined.
Wed Sep 27 05:40:28 2017
----------------------------------------------------------------------
BUILD FAILED
 
Last edited by a moderator:

There are HD44780 internal MikroC driver are used. You have to attach it as external library if you with to use it.
 

"has not been defined" is the clue. The listed names are either not the standard Microchip register names or are commands to the LCD.
Go through the list and pick out the lines ending with that message then somewhere near the other 'define' lines, add your own definitions in the same way as you did to clear the earlier errors.

The basic problem is MikroC uses it's own non-standard additions to the C language which makes any programs written in it unrecognizable to other compilers. However, the main commands should still be the same if you #define the missing names. Almost certainly the _LCD_ defines are just the command numbers to send to the LCD to perform the function.

I'm not sure if you can add the MikroC LCD library to Microchip code. You can add most libraries but for the reasons already mentioned, it may not work.

Ignore the 'WARNING' near the top, it's just saying you are still in the free trial period before the optimizations are turned off and you have to buy a license to restore them.

Brian.
 

I believe he able to find HD44780 library himself. May be the most popular topic in whole internet after mr.Putin offcause.
 

I have tried both solutions given above by betwixt and easyrider83 to fix the error but haven't succeeded yet. please I'd appreciate if you give me a little example on how to resolve the issue. am quite a novice in coding programs
 

Replacing the pin definitions with #define should fix most of the problems.

The "...function without prototype" errors are telling you a function is called that doesn't seem to exist or is present more than once in different forms. Because you have since recompiled, the original error report is now out of date so it doesn't help us any longer, you need to post a new one.

I would guess the remaining issues are to do with "LCD_" instructions which are calls to a pre-built MikroC library routine. There is no direct equivalent in MCC18 but they can be written in just a few lines of code. Probably the easiest way to do it is to look at the code produced by MikroC and rewrite it as a new function in your program, otherwise look at the data sheet for the HD44780 which tells you exactly what to do. LCD drivers are very simple, all the hard work is done on the LCD itself.

Brian.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top