Noob XC Question

This forum handles questions and discussions concerning Microchip’s 8-bit compilers, assemblers, linkers and related tools.

Noob XC Question

Postby Dimebag » Fri Jul 11, 2014 6:14 am

Code: Select all
#include <xc.h>
//#include <p18f452.h>


void Main (void)
{
   
}
 


The code output is.
Code: Select all
make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory 'D:/MPLABXProjects/BasicCodeTEST.X'
make  -f nbproject/Makefile-default.mk dist/default/production/BasicCodeTEST.X.production.hex
make[2]: Entering directory 'D:/MPLABXProjects/BasicCodeTEST.X'
"C:\Program Files\Microchip\xc8\v1.32\bin\xc8.exe" --pass1  --chip=18F452 -Q -G  --double=24 --float=24 --emi=wordwrite --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto:auto "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s"    -obuild/default/production/452Test.p1  452Test.c
"C:\Program Files\Microchip\xc8\v1.32\bin\xc8.exe"  --chip=18F452 -G -mdist/default/production/BasicCodeTEST.X.production.map  --double=24 --float=24 --emi=wordwrite --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto:auto "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s"     -odist/default/production/BasicCodeTEST.X.production.elf  build/default/production/452Test.p1     
Microchip MPLAB XC8 C Compiler (Free Mode) V1.32
Part Support Version: 1.32 (A)
Copyright (C) 2014 Microchip Technology Inc.
License type: Node Configuration

:: advisory: (1233) Employing 18F452 errata work-arounds:
:: advisory: (1234)  * Address 4000h boundary
:: advisory: (1234)  * Faulty table reads at -40 degrees C
:: advisory: (1234)  * GOTO instruction at reset vector must be preceded by NOP
:: advisory: (1234)  * Peripherals can misbehave if BSR = 15
:: advisory: (1234)  * DAW instruction may improperly clear CARRY bit
:: advisory: (1234)  * Specifically disable interrupt sources during tblwt instruction
:: advisory: (1234)  * Writes to flash must target opposite side of 4000h boundary
:: warning: (1273) Omniscient Code Generation not available in Free mode
Non line specific message:: error: (1091) main function "_main" not defined
(908) exit status = 1
make[2]: *** [dist/default/production/BasicCodeTEST.X.production.hex] Error 1
make[1]: *** [.build-conf] Error 2
nbproject/Makefile-default.mk:116: recipe for target 'dist/default/production/BasicCodeTEST.X.production.hex' failed
make[2]: Leaving directory 'D:/MPLABXProjects/BasicCodeTEST.X'
nbproject/Makefile-default.mk:75: recipe for target '.build-conf' failed
make[1]: Leaving directory 'D:/MPLABXProjects/BasicCodeTEST.X'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make: *** [.build-impl] Error 2

BUILD FAILED (exit value 2, total time: 5s)


I tried to make the code as basic as possible. I don't understand the errors. Where did I make a mistake?
Dimebag
 
Posts: 109
Joined: Sun Jun 29, 2014 7:51 am
Location: Sydney, Australia

Re: Noob XC Question

Postby ric » Fri Jul 11, 2014 6:17 am

Capital "M" on "Main()".

The only error message is:
Non line specific message:: error: (1091) main function "_main" not defined
Latest test project, an LED matrix display made from one reel of addressable LEDs. here
User avatar
ric
Verified identity
 
Posts: 659
Joined: Sat May 24, 2014 2:35 pm
Location: Melbourne, Australia
PIC experience: Professional 5+ years with MCHP products

Re: Noob XC Question

Postby Dimebag » Fri Jul 11, 2014 6:29 am

I feel a little bit silly now that I didn't think of changing the capital letter M. :( What stupid mistake to make. Thank you Ric
Dimebag
 
Posts: 109
Joined: Sun Jun 29, 2014 7:51 am
Location: Sydney, Australia

Re: Noob XC Question

Postby Dimebag » Fri Jul 11, 2014 1:18 pm

Not sure that this is correct. code was complied completely
Code: Select all
#include <p18f452.h>
#include <xc.h>

//
//Configurations and Fuses
#pragma config  OSC = HS
#pragma config  OSCS = OFF
#pragma config  PWRT = ON
#pragma config  BOR = OFF
#pragma config  BORV = 45
#pragma config  WDT = OFF
#pragma config  WDTPS = 1
#pragma config  CCP2MUX = OFF
#pragma config  STVR = OFF
#pragma config  LVP = OFF
#pragma config  DEBUG = ON
#pragma config  CP0 = OFF
#pragma config  CP1 = OFF
#pragma config  CP2 = OFF
#pragma config  CP3 = OFF
#pragma config  CPB = OFF
#pragma config  CPD = OFF
#pragma config WRT0 = OFF
#pragma config WRT1 = OFF
#pragma config WRT2 = OFF
#pragma config WRT3 = OFF
#pragma config WRTB = OFF
#pragma config WRTC = OFF
#pragma config WRTD = OFF
#pragma config EBTR0 = OFF
#pragma config EBTR1 = OFF
#pragma config EBTR2 = OFF
#pragma config EBTR3 = OFF
#pragma config EBTRB = OFF

//Declare Variables and set values
unsigned Offset = 0;
unsigned Counter = 60;
unsigned Button_Num = 0;
unsigned Select = 30;
//
char i = 0;
char e = 0;
char o = 0;
char h = 0;
char f = 0;

//Statement covering the start up output and input pins of Device.
void main (void)
{
 TRISA = 0x00;
 TRISB = 0x00;
 TRISC = 0x00;
 TRISD = 0x00;
 TRISE = 0x00;
}

//Program set up pins Input/output defined here.
void Initialization (void)
{
}
//running program to jump here
void state (void)
{
}
//subroutine statement here
void  Fivit_1 (void)
{
}
//Extra statements here.
void pivit_2 (void)
{
}

I know I need to read more about this software. I am not sure where in fact the answers are clearly explained. I would like to jump from main() to Initialization(). For future reference, please leave this thread active for beginners like myself. I am thinking that the "void Initialization (void)" should be at the start of the program like "Initialization (void)". I am trying to figure it out, I just have some stubbing blocks atm.
Dimebag
 
Posts: 109
Joined: Sun Jun 29, 2014 7:51 am
Location: Sydney, Australia

Re: Noob XC Question

Postby Tom Maier » Fri Jul 11, 2014 1:33 pm

Dimebag,

You need to drop back and punt (american expression).

There are some good free tutorials on the use of xc8 compiler at the web site of gooligum.com. They are "down-under" (sorry, that's an austrailian expression :D ). Their tutorial uses the low end pic16s, but you will find their explainations about how to develop a C program very informative. They start with the basics and slowly grow the program in functionality and structure, which is what you are inquiring about.
Last edited by Tom Maier on Fri Jul 11, 2014 1:35 pm, edited 1 time in total.
User avatar
Tom Maier
Verified identity
 
Posts: 179
Joined: Mon May 26, 2014 2:37 pm
PIC experience: Professional 5+ years with MCHP products

Re: Noob XC Question

Postby ric » Fri Jul 11, 2014 1:35 pm

Dimebag wrote:...
I know I need to read more about this software. I am not sure where in fact the answers are clearly explained.

These are standard C concepts. Any guide to programming in C should get you started.

I would like to jump from main() to Initialization().

You almost never jump from one place to another in C. You should call the initialization function at the start of your main function.
You also don't jump off to another bit of code after intialisation. Your main running code should be inside the main() function.

There are two basic "styles" of programming.
"Top down" style puts your high level routine first, then your lower level routines later.
C has to see a definition of a function (what parameters it takes etc.) BEFORE you can call that function, so to do "top-down" style, you have to have prototypes of all your functions at the start of the code, or in header files which are included at the start of the code.

The other style is "bottom up", where you put lower level routines first, and then higher level routines later.
That way, you don't need function prototypes, as the compiler has already seen the full definition of each function by the time it gets to a call to that function.

Also, in an embedded environment (i.e. where there is no operating system to return to), you must never let your main() procedure exit.
It is usual to put all your main code inside an endless loop.

Rearranging your code to make it bottom up....
(Note, I have removed the pic specific header file. xc.h includes that for you automatically.)

Code: Select all
#include <xc.h>

//
//Configurations and Fuses
#pragma config  OSC = HS
#pragma config  OSCS = OFF
#pragma config  PWRT = ON
#pragma config  BOR = OFF
#pragma config  BORV = 45
#pragma config  WDT = OFF
#pragma config  WDTPS = 1
#pragma config  CCP2MUX = OFF
#pragma config  STVR = OFF
#pragma config  LVP = OFF
#pragma config  DEBUG = ON
#pragma config  CP0 = OFF
#pragma config  CP1 = OFF
#pragma config  CP2 = OFF
#pragma config  CP3 = OFF
#pragma config  CPB = OFF
#pragma config  CPD = OFF
#pragma config WRT0 = OFF
#pragma config WRT1 = OFF
#pragma config WRT2 = OFF
#pragma config WRT3 = OFF
#pragma config WRTB = OFF
#pragma config WRTC = OFF
#pragma config WRTD = OFF
#pragma config EBTR0 = OFF
#pragma config EBTR1 = OFF
#pragma config EBTR2 = OFF
#pragma config EBTR3 = OFF
#pragma config EBTRB = OFF

//Declare Variables and set values
unsigned Offset = 0;
unsigned Counter = 60;
unsigned Button_Num = 0;
unsigned Select = 30;
//
char i = 0;
char e = 0;
char o = 0;
char h = 0;
char f = 0;

//Program set up pins Input/output defined here.
void Initialization (void)
{
 TRISA = 0x00;
 TRISB = 0x00;
 TRISC = 0x00;
 TRISD = 0x00;
 TRISE = 0x00;
}

//subroutine statement here
void  Fivit_1 (void)
{
}
//Extra statements here.
void pivit_2 (void)
{
}

//Statement covering the start up output and input pins of Device.
void main (void)
{
 Initialization();
 while (1)
 {  //running code goes inside this loop
 }
}
 

(Note, as these are questions about writing C code, I have moved this topic to the "XC8" forum.)
Latest test project, an LED matrix display made from one reel of addressable LEDs. here
User avatar
ric
Verified identity
 
Posts: 659
Joined: Sat May 24, 2014 2:35 pm
Location: Melbourne, Australia
PIC experience: Professional 5+ years with MCHP products

Re: Noob XC Question

Postby Dimebag » Fri Jul 11, 2014 2:43 pm

Very hard to disagree there Ric. I believe I may have a program flow issue as stated before in other posts. I am still working on it. Thank you all.
Dimebag
 
Posts: 109
Joined: Sun Jun 29, 2014 7:51 am
Location: Sydney, Australia

Re: Noob XC Question

Postby Dimebag » Fri Jul 11, 2014 6:35 pm

So its the structure of code that I should be looking at.
There are two basic "styles" of programming.

Design a project in two ways
"Top down" style puts your high level routine first, then your lower level routines later.

and the other

The other style is "bottom up", where you put lower level routines first, and then higher level routines later.

Work in progress.
Dimebag
 
Posts: 109
Joined: Sun Jun 29, 2014 7:51 am
Location: Sydney, Australia


Return to MPLAB XC8

Who is online

Users browsing this forum: No registered users and 7 guests

cron