C18 error [help please :)]

Thread Starter

Jgb5067

Joined Aug 1, 2011
16
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:
Rich (BB code):
#include <p18f4550.h>;
#include <xlcd.h>;
#include <stdio.h>;
#include <stdlib.h>;
#include <delays.h>;

void DelayFor18TCY(void)
void DelayPORXLCD(void)
void DelayXLC(void)

#pragma config FOSC = INTOSC_HS;
#pragma config PWRT = OFF;
#pragma config BOR = OFF;
#pragma config WDT = OFF;
#pragma config MCLRE = OFF;
#pragma config PBADEN = OFF;

char Value[10];
unsigned long i;
unsigned long tot5;
unsigned long tot3;
unsigned long mult3;
unsigned long mult5;
unsigned long total1;
unsigned long tot15;
unsigned long mult15;

rom char Answer[] = "ANSWER = "

//project Euler #1 all multiples of 3 & 5 up to 1000 added
main (void)
{

mult3=0;
mult5=0;
tot3=0;
tot5=0;
tot15=0;
mult15=0;

//multiples of 3 loop
for(i=0; tot3<1000; i++)
{	
mult3 = mult3+tot3;
tot3 = 3*i;
}
//multiples of 5 loop
for(i=0; tot5<1000; i++)
{
mult5 = mult5+tot5;
tot5 = 5*i;
}
//subtract all multiples of 15 only once
for(i=0; tot15<1000; i++)
{
mult15 = mult15+tot15;
tot15=15*i;
}
//total
total1 = mult5+mult3-mult15;
ltoa(total1,Value);
//LCD output
OpenXLCD(2);
SetDDRamAddr(0xB0);
PutrsXLCD(Answer);
SetDDRamAddr(0xC0);
PutsXLCD(Value);
}

// DelayFor18TCY() provides a 18 Tcy delay     
void DelayFor18TCY(void){
for(i=0; i<18; i++){
nop();}
}
// DelayPORXLCD() provides at least 15ms delay 
void DelayPORXLCD(void){
Delay1KTCYx(15);
}
// DelayXLCD() provides at least 5ms delay 
void DelayXLC(void){
Delay1KTCYx(5);
}

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 :)
 

stahta01

Joined Jun 9, 2011
133
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.

Rich (BB code):
Executing: "C:\MCC18\bin\mcc18.exe" -p=18F4550 "main.c" -fo="main.o" -D__DEBUG -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-
H:\SourceCode\MCU\test4\main.c:31:Warning [2068] obsolete use of implicit 'int' detected
H:\SourceCode\MCU\test4\main.c:31:Warning [2103] default startup code expects main function declared as 'void main (void)'
H:\SourceCode\MCU\test4\main.c:65:Warning [2058] call of function without prototype
H:\SourceCode\MCU\test4\main.c:67:Warning [2058] call of function without prototype
H:\SourceCode\MCU\test4\main.c:73:Warning [2058] call of function without prototype
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:

Thread Starter

Jgb5067

Joined Aug 1, 2011
16
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.
 

ErnieM

Joined Apr 24, 2011
8,045
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.
 

Thread Starter

Jgb5067

Joined Aug 1, 2011
16
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:

Rich (BB code):
#include <p18f4550.h>
#include <xlcd.h>
#include <stdio.h>
#include <stdlib.h>
#include <delays.h>
#include <string.h>

#pragma config FOSC = INTOSC_HS
#pragma config PWRT = OFF
#pragma config BOR = OFF
#pragma config WDT = OFF
#pragma config MCLRE = OFF
#pragma config PBADEN = OFF

void main (void);

char Value[10];
unsigned long i;
unsigned long tot5;
unsigned long tot3;
unsigned long mult3;
unsigned long mult5;
unsigned long total1;
unsigned long tot15;
unsigned long mult15;

rom char Answer[] = "ANSWER = ";

//project Euler #1 all multiples of 3 & 5 up to 1000 added
void main (void)
{

char Value[10];
unsigned long i=0;
unsigned long tot5=0;
unsigned long tot3=0;
unsigned long mult3=0;
unsigned long mult5=0;
unsigned long total1=0;
unsigned long tot15=0;
unsigned long mult15=0;

//multiples of 3 loop
	for(i=0; tot3<1000; i++){	
		mult3 = mult3+tot3;
		tot3 = 3*i;
	}
	
//multiples of 5 loop
	for(i=0; tot5<1000; i++){
		mult5 = mult5+tot5;
		tot5 = 5*i;
	}

//subtract all multiples of 15 only once
	for(i=0; tot15<1000; i++){
		mult15 = mult15+tot15;
		tot15=15*i;
	}

//total
	total1 = mult5+mult3-mult15;
	ltoa(total1,Value);

//LCD output
	OpenXLCD(2);
	SetDDRamAddr(0xB0);
	PutrsXLCD(Answer);
	SetDDRamAddr(0xC0);
	PutsXLCD(Value);
}

// DelayFor18TCY() provides a 18 Tcy delay     
void DelayFor18TCY(void)
{
	for(i=0; i<18; i++)
		nop();
}
// DelayPORXLCD() provides at least 15ms delay 
void DelayPORXLCD(void)
{
	Delay1KTCYx(15);
}
// DelayXLCD() provides at least 5ms delay 
void DelayXLC(void)
{
	Delay1KTCYx(5);
}
Rich (BB code):
----------------------------------------------------------------------
Debug build of project `C:\Users\Chuck Norris\Documents\PIC\C18Euler.mcp' started.
Language tool versions: mpasmwin.exe v5.42, mplink.exe v4.40, mcc18.exe v3.40, mplib.exe v4.40
Preprocessor symbol `__DEBUG' is defined.
Sat Aug 20 10:15:09 2011
----------------------------------------------------------------------
Clean: Deleting intermediary and output files.
Clean: Done.
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-
C:\Program Files (x86)\Microchip\mplabc18\v3.40\h\p18f4550.h:10:Error: syntax error
Halting build on first failure as requested.
----------------------------------------------------------------------
Debug build of project `C:\Users\Chuck Norris\Documents\PIC\C18Euler.mcp' failed.
Language tool versions: mpasmwin.exe v5.42, mplink.exe v4.40, mcc18.exe v3.40, mplib.exe v4.40
Preprocessor symbol `__DEBUG' is defined.
Sat Aug 20 10:15:09 2011
----------------------------------------------------------------------
BUILD FAILED
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:

stahta01

Joined Jun 9, 2011
133
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).

Rich (BB code):
Debug build of project `H:\SourceCode\MCU\test4\test4.mcp' started.
Language tool versions: mpasmwin.exe v5.42, mplink.exe v4.40, mcc18.exe v3.40, mplib.exe v4.40
Preprocessor symbol `__DEBUG' is defined.
Sat Aug 20 11:58:05 2011
Rich (BB code):
Clean: Deleting intermediary and output files.
Clean: Deleted file "H:\SourceCode\MCU\test4\test4.mcs".
Clean: Done.
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-
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
MPLINK 4.40, Linker
Device Database Version 1.3
Copyright (c) 1998-2011 Microchip Technology Inc.
Errors    : 0

MP2HEX 4.40, COFF to HEX File Converter
Copyright (c) 1998-2011 Microchip Technology Inc.
Errors    : 0

Loaded H:\SourceCode\MCU\test4\test4.cof.
Tim S.
 
Last edited:

Thread Starter

Jgb5067

Joined Aug 1, 2011
16
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
 

stahta01

Joined Jun 9, 2011
133
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
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:

Thread Starter

Jgb5067

Joined Aug 1, 2011
16
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.
 

stahta01

Joined Jun 9, 2011
133
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".

Rich (BB code):
----------------------------------------------------------------------
Debug build of project `C:\Users\USERNAME\Documents\Test\test4.mcp' started.
Language tool versions: mpasmwin.exe v5.42, mplink.exe v4.40, mcc18.exe v3.40, mplib.exe v4.40
Preprocessor symbol `__DEBUG' is defined.
Sat Aug 20 15:15:59 2011
----------------------------------------------------------------------
Clean: Deleting intermediary and output files.
Clean: Deleted file "C:\Users\USERNAME\Documents\Test\main.o".
Clean: Done.
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-
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
MPLINK 4.40, Linker
Device Database Version 1.3
Copyright (c) 1998-2011 Microchip Technology Inc.
Errors    : 0

MP2HEX 4.40, COFF to HEX File Converter
Copyright (c) 1998-2011 Microchip Technology Inc.
Errors    : 0

Loaded C:\Users\USERNAME\Documents\Test\test4.cof.
----------------------------------------------------------------------
Debug build of project `C:\Users\USERNAME\Documents\Test\test4.mcp' succeeded.
Language tool versions: mpasmwin.exe v5.42, mplink.exe v4.40, mcc18.exe v3.40, mplib.exe v4.40
Preprocessor symbol `__DEBUG' is defined.
Sat Aug 20 15:16:00 2011
----------------------------------------------------------------------
BUILD SUCCEEDED
 

Thread Starter

Jgb5067

Joined Aug 1, 2011
16
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
 
Top