C18 error [help please :)]

Discussion in 'Embedded Systems and Microcontrollers' started by Jgb5067, Aug 19, 2011.

  1. Jgb5067

    Thread Starter New Member

    Aug 1, 2011
    16
    2
    Hello everyone,
    I'm working on a project to get a little more familiar with PIC's using project euler and a 16x2 lcd screen. while i have taken a class on pic programming and used a freescale uC for my senior project as well as worked with PICs a little at my internship, i was always just editing someone else's code. Now i want to start my own code and use it to keep building up, but i keep getting an error that I'm sure is trivial to some of you but I can't seem to find the cause of it.

    here is my code:
    Code ( (Unknown Language)):
    1.  
    2. #include <p18f4550.h>;
    3. #include <xlcd.h>;
    4. #include <stdio.h>;
    5. #include <stdlib.h>;
    6. #include <delays.h>;
    7.  
    8. void DelayFor18TCY(void)
    9. void DelayPORXLCD(void)
    10. void DelayXLC(void)
    11.  
    12. #pragma config FOSC = INTOSC_HS;
    13. #pragma config PWRT = OFF;
    14. #pragma config BOR = OFF;
    15. #pragma config WDT = OFF;
    16. #pragma config MCLRE = OFF;
    17. #pragma config PBADEN = OFF;
    18.  
    19. char Value[10];
    20. unsigned long i;
    21. unsigned long tot5;
    22. unsigned long tot3;
    23. unsigned long mult3;
    24. unsigned long mult5;
    25. unsigned long total1;
    26. unsigned long tot15;
    27. unsigned long mult15;
    28.  
    29. rom char Answer[] = "ANSWER = "
    30.  
    31. //project Euler #1 all multiples of 3 & 5 up to 1000 added
    32. main (void)
    33. {
    34.  
    35. mult3=0;
    36. mult5=0;
    37. tot3=0;
    38. tot5=0;
    39. tot15=0;
    40. mult15=0;
    41.  
    42. //multiples of 3 loop
    43. for(i=0; tot3<1000; i++)
    44. {  
    45. mult3 = mult3+tot3;
    46. tot3 = 3*i;
    47. }
    48. //multiples of 5 loop
    49. for(i=0; tot5<1000; i++)
    50. {
    51. mult5 = mult5+tot5;
    52. tot5 = 5*i;
    53. }
    54. //subtract all multiples of 15 only once
    55. for(i=0; tot15<1000; i++)
    56. {
    57. mult15 = mult15+tot15;
    58. tot15=15*i;
    59. }
    60. //total
    61. total1 = mult5+mult3-mult15;
    62. ltoa(total1,Value);
    63. //LCD output
    64. OpenXLCD(2);
    65. SetDDRamAddr(0xB0);
    66. PutrsXLCD(Answer);
    67. SetDDRamAddr(0xC0);
    68. PutsXLCD(Value);
    69. }
    70.  
    71. // DelayFor18TCY() provides a 18 Tcy delay    
    72. void DelayFor18TCY(void){
    73. for(i=0; i<18; i++){
    74. nop();}
    75. }
    76. // DelayPORXLCD() provides at least 15ms delay
    77. void DelayPORXLCD(void){
    78. Delay1KTCYx(15);
    79. }
    80. // DelayXLCD() provides at least 5ms delay
    81. void DelayXLC(void){
    82. Delay1KTCYx(5);
    83. }
    84.  

    I keep getting a syntax error on line 10 of p18f4550.h:
    extern volatile near unsigned char SPPDATA;
    but I'm sure i didnt change it, so the error must be in my main, which is the only one I wrote any code in. Any help would be appreciated. Thanks in advance :)
     
  2. stahta01

    Member

    Jun 9, 2011
    133
    21
    NOTE: In nearly all cases preprocessor commands should NOT end with an ";" semi-colon.

    A line starting with "#" is normally a preprocessor command.

    I suggest learning a C formatting style because it makes your code easier to follow.

    NOTE: Function prototypes do NEED an ";" at the end.

    WARNING: Remember C is case sensitive.

    After adding and removing ";" semi-colons here is the build messages I got.

    Code ( (Unknown Language)):
    1.  
    2. Executing: "C:\MCC18\bin\mcc18.exe" -p=18F4550 "main.c" -fo="main.o" -D__DEBUG -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-
    3. H:\SourceCode\MCU\test4\main.c:31:Warning [2068] obsolete use of implicit 'int' detected
    4. H:\SourceCode\MCU\test4\main.c:31:Warning [2103] default startup code expects main function declared as 'void main (void)'
    5. H:\SourceCode\MCU\test4\main.c:65:Warning [2058] call of function without prototype
    6. H:\SourceCode\MCU\test4\main.c:67:Warning [2058] call of function without prototype
    7. H:\SourceCode\MCU\test4\main.c:73:Warning [2058] call of function without prototype
    8.  
    Your error message implies a problem that maybe related to your Compiler or IDE installation/setup/configuration.

    Testing done with MPLAB 8.73 or 8.73a using Microchip C18 3.36 Lite

    Tim S.
     
    Last edited: Aug 20, 2011
    Jgb5067 likes this.
  3. Jgb5067

    Thread Starter New Member

    Aug 1, 2011
    16
    2
    Thanks Stahta, I do need to learn to format my code. I liked code warrior because it did that for you but i'll have to stop being lazy and do it myself. After I made the corrections I'm still getting the same error as before, I must have done something seriously wrong earlier lol. I'll try to make a new project with the same headers and main.c then I'll see if that fixes it.
     
  4. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    Whenever tracking down compiling errors start from the very first error, never the last.

    You can have cases where a single missing ; will cascade into several pages of errors. Fix the first one, then see if the second one makes sense (as in it is a real error), if not, rebuild. Rinse lather repeat.
     
    Jgb5067 likes this.
  5. Jgb5067

    Thread Starter New Member

    Aug 1, 2011
    16
    2
    Thanks Ernie, I actually did find a missing ; ... I'm notoriously bad for missing simple errors. however that didn't fix anything. It's basically the first line of code that it messes up on. I fixed everything i could think of and this is my code and error:

    Code ( (Unknown Language)):
    1. #include <p18f4550.h>
    2. #include <xlcd.h>
    3. #include <stdio.h>
    4. #include <stdlib.h>
    5. #include <delays.h>
    6. #include <string.h>
    7.  
    8. #pragma config FOSC = INTOSC_HS
    9. #pragma config PWRT = OFF
    10. #pragma config BOR = OFF
    11. #pragma config WDT = OFF
    12. #pragma config MCLRE = OFF
    13. #pragma config PBADEN = OFF
    14.  
    15. void main (void);
    16.  
    17. char Value[10];
    18. unsigned long i;
    19. unsigned long tot5;
    20. unsigned long tot3;
    21. unsigned long mult3;
    22. unsigned long mult5;
    23. unsigned long total1;
    24. unsigned long tot15;
    25. unsigned long mult15;
    26.  
    27. rom char Answer[] = "ANSWER = ";
    28.  
    29. //project Euler #1 all multiples of 3 & 5 up to 1000 added
    30. void main (void)
    31. {
    32.  
    33. char Value[10];
    34. unsigned long i=0;
    35. unsigned long tot5=0;
    36. unsigned long tot3=0;
    37. unsigned long mult3=0;
    38. unsigned long mult5=0;
    39. unsigned long total1=0;
    40. unsigned long tot15=0;
    41. unsigned long mult15=0;
    42.  
    43. //multiples of 3 loop
    44.     for(i=0; tot3<1000; i++){  
    45.         mult3 = mult3+tot3;
    46.         tot3 = 3*i;
    47.     }
    48.    
    49. //multiples of 5 loop
    50.     for(i=0; tot5<1000; i++){
    51.         mult5 = mult5+tot5;
    52.         tot5 = 5*i;
    53.     }
    54.  
    55. //subtract all multiples of 15 only once
    56.     for(i=0; tot15<1000; i++){
    57.         mult15 = mult15+tot15;
    58.         tot15=15*i;
    59.     }
    60.  
    61. //total
    62.     total1 = mult5+mult3-mult15;
    63.     ltoa(total1,Value);
    64.  
    65. //LCD output
    66.     OpenXLCD(2);
    67.     SetDDRamAddr(0xB0);
    68.     PutrsXLCD(Answer);
    69.     SetDDRamAddr(0xC0);
    70.     PutsXLCD(Value);
    71. }
    72.  
    73. // DelayFor18TCY() provides a 18 Tcy delay    
    74. void DelayFor18TCY(void)
    75. {
    76.     for(i=0; i<18; i++)
    77.         nop();
    78. }
    79. // DelayPORXLCD() provides at least 15ms delay
    80. void DelayPORXLCD(void)
    81. {
    82.     Delay1KTCYx(15);
    83. }
    84. // DelayXLCD() provides at least 5ms delay
    85. void DelayXLC(void)
    86. {
    87.     Delay1KTCYx(5);
    88. }
    Code ( (Unknown Language)):
    1.  
    2. ----------------------------------------------------------------------
    3. Debug build of project `C:\Users\Chuck Norris\Documents\PIC\C18Euler.mcp' started.
    4. Language tool versions: mpasmwin.exe v5.42, mplink.exe v4.40, mcc18.exe v3.40, mplib.exe v4.40
    5. Preprocessor symbol `__DEBUG' is defined.
    6. Sat Aug 20 10:15:09 2011
    7. ----------------------------------------------------------------------
    8. Clean: Deleting intermediary and output files.
    9. Clean: Done.
    10. Executing: "C:\Program Files (x86)\Microchip\mplabc18\v3.40\bin\mcc18.exe" -p=18F4550 /i"C:\Program Files (x86)\Microchip\mplabc18\v3.40\h" "main.c" -fo="main.o" -D__DEBUG -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-
    11. C:\Program Files (x86)\Microchip\mplabc18\v3.40\h\p18f4550.h:10:Error: syntax error
    12. Halting build on first failure as requested.
    13. ----------------------------------------------------------------------
    14. Debug build of project `C:\Users\Chuck Norris\Documents\PIC\C18Euler.mcp' failed.
    15. Language tool versions: mpasmwin.exe v5.42, mplink.exe v4.40, mcc18.exe v3.40, mplib.exe v4.40
    16. Preprocessor symbol `__DEBUG' is defined.
    17. Sat Aug 20 10:15:09 2011
    18. ----------------------------------------------------------------------
    19. BUILD FAILED
    20.  
    I thought i fixed everything and looked it over a ton of times, but can't seem to figure out whats going on :confused:
     
    Last edited: Aug 20, 2011
  6. stahta01

    Member

    Jun 9, 2011
    133
    21
    FYI:

    I have always installed Microchip C18 in a path without spaces or special characters in it. I am not sure that it is needed.

    Edit: I am installing the 3.40 lite version right now; it tried to install in Program Files; this is a first time C18 did that.
    So, I am trying it with the default installation location.

    Note: I had to fix more errors in your code; but it compiles with v3.40 on 32 bit Windows 7 (6.1).

    Code ( (Unknown Language)):
    1.  
    2. Debug build of project `H:\SourceCode\MCU\test4\test4.mcp' started.
    3. Language tool versions: mpasmwin.exe v5.42, mplink.exe v4.40, mcc18.exe v3.40, mplib.exe v4.40
    4. Preprocessor symbol `__DEBUG' is defined.
    5. Sat Aug 20 11:58:05 2011
    6.  
    Code ( (Unknown Language)):
    1.  
    2. Clean: Deleting intermediary and output files.
    3. Clean: Deleted file "H:\SourceCode\MCU\test4\test4.mcs".
    4. Clean: Done.
    5. Executing: "C:\Program Files\Microchip\mplabc18\v3.40\bin\mcc18.exe" -p=18F4550 "main.c" -fo="main.o" -D__DEBUG -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-
    6. Executing: "C:\Program Files\Microchip\mplabc18\v3.40\bin\mplink.exe" /p18F4550 /l"C:\Program Files\Microchip\mplabc18\v3.40\lib" "main.o" /u_CRUNTIME /u_DEBUG /z__MPLAB_BUILD=1 /z__MPLAB_DEBUG=1 /o"test4.cof" /M"test4.map" /W
    7. MPLINK 4.40, Linker
    8. Device Database Version 1.3
    9. Copyright (c) 1998-2011 Microchip Technology Inc.
    10. Errors    : 0
    11.  
    12. MP2HEX 4.40, COFF to HEX File Converter
    13. Copyright (c) 1998-2011 Microchip Technology Inc.
    14. Errors    : 0
    15.  
    16. Loaded H:\SourceCode\MCU\test4\test4.cof.
    17.  
    Tim S.
     
    Last edited: Aug 20, 2011
    Jgb5067 likes this.
  7. Jgb5067

    Thread Starter New Member

    Aug 1, 2011
    16
    2
    darn, i thought that would work. still the same. I just need to walk away from it for a bit and come back with fresh eyes. maybe then I'll see what i'm doing wrong
     
  8. stahta01

    Member

    Jun 9, 2011
    133
    21
    The error you are getting on the header is not caused by a source code error on your part. Note: I have seen hidden characters in the source file cause a similar issue with other compilers.

    This is likely an Compiler installation or IDE (MPLAB) configuration issue.
    Could also be a bug in the Compiler for 64 bit systems.

    Are you using a foreign language settings on the computer?

    Tim S.
     
    Last edited: Aug 20, 2011
    Jgb5067 likes this.
  9. Jgb5067

    Thread Starter New Member

    Aug 1, 2011
    16
    2
    hmm, no foreign languages, but i am running the 64 bit version of windows 7. I re-installed C18 already with the same results, and don't know enough to change the configurations settings in MPLAB. I'll see if i can send a support ticket or something to Microchip, maybe other people have been having this problem too.
     
  10. stahta01

    Member

    Jun 9, 2011
    133
    21
    What version of MPLAB?

    Did you uninstall C18 before reinstalling it?

    Tim S.
     
  11. stahta01

    Member

    Jun 9, 2011
    133
    21
    Tested at School using MPLAB 8.70 as IDE on Windows 7 (6.1) 64 bit; Changed my real username to USERNAME in output. I fixed the three case problems like changing "nop" to "Nop".

    Code ( (Unknown Language)):
    1.  
    2. ----------------------------------------------------------------------
    3. Debug build of project `C:\Users\USERNAME\Documents\Test\test4.mcp' started.
    4. Language tool versions: mpasmwin.exe v5.42, mplink.exe v4.40, mcc18.exe v3.40, mplib.exe v4.40
    5. Preprocessor symbol `__DEBUG' is defined.
    6. Sat Aug 20 15:15:59 2011
    7. ----------------------------------------------------------------------
    8. Clean: Deleting intermediary and output files.
    9. Clean: Deleted file "C:\Users\USERNAME\Documents\Test\main.o".
    10. Clean: Done.
    11. Executing: "C:\Program Files (x86)\Microchip\mplabc18\v3.40\bin\mcc18.exe" -p=18F4550 "main.c" -fo="main.o" -D__DEBUG -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-
    12. Executing: "C:\Program Files (x86)\Microchip\mplabc18\v3.40\bin\mplink.exe" /p18F4550 /l"C:\Program Files (x86)\Microchip\mplabc18\v3.40\lib" "main.o" /u_CRUNTIME /u_DEBUG /z__MPLAB_BUILD=1 /z__MPLAB_DEBUG=1 /o"test4.cof" /M"test4.map" /W
    13. MPLINK 4.40, Linker
    14. Device Database Version 1.3
    15. Copyright (c) 1998-2011 Microchip Technology Inc.
    16. Errors    : 0
    17.  
    18. MP2HEX 4.40, COFF to HEX File Converter
    19. Copyright (c) 1998-2011 Microchip Technology Inc.
    20. Errors    : 0
    21.  
    22. Loaded C:\Users\USERNAME\Documents\Test\test4.cof.
    23. ----------------------------------------------------------------------
    24. Debug build of project `C:\Users\USERNAME\Documents\Test\test4.mcp' succeeded.
    25. Language tool versions: mpasmwin.exe v5.42, mplink.exe v4.40, mcc18.exe v3.40, mplib.exe v4.40
    26. Preprocessor symbol `__DEBUG' is defined.
    27. Sat Aug 20 15:16:00 2011
    28. ----------------------------------------------------------------------
    29. BUILD SUCCEEDED
    30.  
     
    Jgb5067 likes this.
  12. Jgb5067

    Thread Starter New Member

    Aug 1, 2011
    16
    2
    ill try fixing those errors, thanks. and yeah i uninstalled it before reinstalling. hopefully this works, sorry for the late reply, moving back to school myself
     
Loading...