0

I am new to microchip family. i had tried out the below program,

#include<pic.h> 
#include <stdio.h>
__CONFIG(0x1932);
void main() 
{ 
TRISA=0x00;
 PORTA=0x01; 
PORTA=0x02; 
PORTA=0x04; 
PORTA=0x08; 
PORTA=0x10;
 PORTA=0x20; 
PORTA=0x40; 
}    

But i get the error:

Error [237] C:\Users\mathishara\Desktop\project_mplab\alternative.c; 9. function "_main" redefined.

What should I do.

ArK
  • 18,824
  • 63
  • 101
  • 135
  • You are missing information to get a complete answer. What compiler are you using? Which version of that compiler are you using? What optimizations are active during compilation? Post the complete compilation output, redefined errors often have another line like previously defined here. – Mathieu L. Jun 08 '16 at 13:46

2 Answers2

1

Main should be defined as

int main(void)

Any function that takes no parameters should have void as its parameter list.

See main() function in C and What should main() return in C and C++? for further discussion. For embedded applications, the "normal" parameters list int main(int argc, char *argv[]) don't make much sense, so void is fine.

Community
  • 1
  • 1
EBlake
  • 657
  • 7
  • 14
0

This error can occur if:

  1. the function definition doesn't match its prototype

For example

int fun_prot();     /* the function prototype is missing the parameter - "int" */

int fun_prot(int a)
{
    ...
}
  1. if the function has more than one defintion in the same module

Function overloading is illegal in C and will trigger a redfinition error. For example:

int twice(int a)
{
    return a*2;
}

long twice(long a)      /* only one prototype & definition of twice can exist and this will trigger a redifinition error */
{
    return a*2;
}
Cyclops
  • 100
  • 5