Redefinition error due to typdef enum and pic header file. Defining AN1 to AN12 in two different header files - wont build
HI All,
I have a MPLAB 8 project which I have imported over to MPLAB X IDE. I've managed to change some of the C Standard settings to get it down to just one repeated error now which is:
../source/kADC.h:31:5: error: redefinition of 'AN1' C:/Program Files/Microchip/MPLABX/v5.45/packs/Microchip/PIC18Fxxxx_DFP/1.2.26/xc8\pic\include\proc\pic18f2321.h:6105:41: note: previous definition is here extern volatile __bit AN1 __at(0x7C01); // @ (0xF80 * 8 + 1)
I think it is due to a typedef enum redefining the AN's as well as them being defined in the PICS header file.
in kADC.h
typedef enum ADC_CHANNEL_ENUM
{
AN0 = 1,
AN1,
AN2,
AN3,
AN4,
AN8,
AN9,
AN10,
AN11,
AN12,
NO_READING
} ADCChannelEnum;
in pic18f2321.h
extern volatile __bit AN0 __at(0x7C00); // @ (0xF80 * 8 + 0)
#define AN0_bit BANKMASK(PORTA), 0
// PORTA<AN1>
extern volatile __bit AN1 __at(0x7C01); // @ (0xF80 * 8 + 1)
#define AN1_bit BANKMASK(PORTA), 1
// PORTB<AN10>
extern volatile __bit AN10 __at(0x7C09); // @ (0xF81 * 8 + 1)
#define AN10_bit BANKMASK(PORTB), 1
// PORTB<AN11>
extern volatile __bit AN11 __at(0x7C0C); // @ (0xF81 * 8 + 4)
#define AN11_bit BANKMASK(PORTB), 4
// PORTB<AN12>
extern volatile __bit AN12 __at(0x7C08); // @ (0xF81 * 8 + 0)
#define AN12_bit BANKMASK(PORTB), 0
// PORTA<AN2>
extern volatile __bit AN2 __at(0x7C02); // @ (0xF80 * 8 + 2)
#define AN2_bit BANKMASK(PORTA), 2
any help would be appreciated .
If you don't have to use
ADC_CHANNEL_ENUM
outside of your kADC.c file, move your enum definition into your kADC.c file so that the enum definition becomes private. This way you can prevent the redefinition errors.But if you have to use
ADC_CHANNEL_ENUM
outside of your kADC.c file, then you'll have to change the names i.e.; instead ofAN0
useANLG0
.Another way to prevent this, is not a preferrable way which implies to not include xc or pic18f2321 headers. This makes all the convenient hardware specific definitions unavailable to your project, resulting to be more inconvenient for you.
As far as I see, you haven't used any
ADC_CHANNEL_ENUM
in the main file, but I don't know whether you have more files in your project and use that enum in them (you can specify if any so). Then you can consider the making the enum definition private to kADC.c file.Go ahead and try one of the options above to see which would best fit for your case.