I am struggling to figure out why I am keep getting this error. The purpose of the code / project is taking an analogue value and converting it to digital value which represents a temperature sensor. Also, I have BCD switches but once I show the code it will be clear that it is some small mistake or syntax maybe, but I can't find it. Any help appreciated.
This is the error message:
Error at file ../main.c line 100 column 45: (255) not a member of the struct/union ""
Error at file ../main.c line 100 column 48: (182) illegal conversion between types
int -> volatile union S380
Error at file ../main.c line 101 column 45: (255) not a member of the struct/union ""
Error at file ../main.c line 101 column 48: (182) illegal conversion between types
make: *** [main.p1] Error 1
int -> volatile union S380
This is where the error appears.
void main(void){
InitPorts();
InitADC();
while(1){
int SetTemp = Bcd_SW_AB (Read_SwitchB(), Read_SwitchA());
DispTemp(Rd_ADC());
if(Rd_ADC() < (SetTemp - 1)){RLED = 1;}
if(Rd_ADC() > (SetTemp 1)){RLED = 0;}
}
}
[Error at file ../main.c line 100 column 45: (255) not a member of the struct/union ""]
if(Rd_ADC() < (SetTemp - 1)){RLED = 1;}
[ Error at file ../main.c line 101 column 45: (255) not a member of the struct/union ""]
if(Rd_ADC() > (SetTemp 1)){RLED = 0;}
This is the complete code:
#include <xc.h>
#define RLED LATCbits.LATA0
#define GLED LATCbits.LATA1
//Defining pins on bcd switch A
#define a1 PORTBbits.RB0
#define a2 PORTBbits.RB1
#define a4 PORTBbits.RB2
#define a8 PORTBbits.RB3
//Defining pins on bcd switch B
#define b1 PORTBbits.RB4
#define b2 PORTBbits.RB5
#define b4 PORTBbits.RB6
#define b8 PORTBbits.RB7
void InitPorts(void){
ANSA0 = 1; // Set pin to analog
TRISA0 = 1; // Set pin to input
ANSELB = 0; // Set Port B to digital
TRISB = 1; // Set port B to input
ANSELC = 0 ; // Set Port C to digital
TRISC = 0; // Set Pins to output
ANSD0 = 0; //Set pin to digital
TRISD0 = 0; //Set pin to output
ANSD1 = 0; //Set pin to digital
TRISD1 = 0; //Set pin to output
}
void InitADC (void){
ADCON0bits.CHS = 0; //Channel 0
ADCON1bits.PVCFG = 0; // Vref = Vdd
ADCON1bits.NVCFG = 0; //-Vref = Vss
ADCON2bits.ADFM = 1; //10-bit operation
ADCON2bits.ACQT = 0b0000010; //4 Tad
ADCON2bits.ADCS = 7; //Frc
ADCON0bits.ADON = 1; //Osc = on
}
int Rd_ADC(void){
int Result;
ADCON0bits.GODONE = 1;
while (ADCON0bits.GODONE);
Result =(((ADRESH <<6) | (ADRESL>>2))/2.56);
return Result;
}
void DispTemp( int BinVal){
int Bcd[2];
Bcd[0] = BinVal ;
BinVal /= 10;
Bcd[1] = BinVal % 10;
BinVal /= 10;
LATC = Bcd[0];
LATCbits.LATC4 = 1;
LATCbits.LATC4 = 0;
LATC = Bcd[1];
LATCbits.LATC5 = 1;
LATCbits.LATC5 = 0;
}
int Read_SwitchA(void){
int total = 0;
if (a1) {total =1;}
if (a2) {total =2;}
if (a4) {total =4;}
if (a8) {total =8;}
return total;
}
int Read_SwitchB(void){
int total = 0;
if (b1) {total =1;}
if (b2) {total =2;}
if (b4) {total =4;}
if (b8) {total =8;}
return total*10;
}
int Bcd_SW_AB(int Read_SwitchB, int Read_SwitchA){
int total = Read_SwitchB Read_SwitchA;
return total;
}
void main(void){
InitPorts();
InitADC();
while(1){
int SetTemp = Bcd_SW_AB (Read_SwitchB(), Read_SwitchA());
DispTemp(Rd_ADC());
if(Rd_ADC() < (SetTemp - 1)){RLED = 1;}
if(Rd_ADC() > (SetTemp 1)){RLED = 0;}
}
}
CodePudding user response:
With reference to this macro definition ...
#define RLED LATCbits.LATA0
, this error ...
Error at file ../main.c line 100 column 45: (255) not a member of the struct/union ""
... referencing this line of code ...
if(Rd_ADC() < (SetTemp - 1)){RLED = 1;}
... seems to be saying that the type of LATCbits
is an untagged structure or union type that does not have any member named LATA0
.
It is plausible that the "illegal conversion" errors just cascade from the "not a member" error, such that they do not indicate a separate issue.
CodePudding user response:
Thanks guys, I found the mistake. Thanks, @ryyker for letting me know I should recheck my spelling, and thanks to @jabberwocky for putting my focus on LATCbits where to mistype was.
So LATCbits is a register on the pic microcontroller and I initially defined the LEDs to be on LATC and later changed it for them to be on LATD and never changed my code.
This was the part that had to change:
form this(wrong) :
#define RLED LATCbits.LATA0
#define GLED LATCbits.LATA1
to this(correct):
#define RLED LATDbits.LATD0
#define GLED LATDbits.LATD1
for anyone you wants to see the correct code:
#include <xc.h>
#define RLED LATDbits.LATD0
#define GLED LATDbits.LATD1
//Defining pins on bcd switch A
#define a1 PORTBbits.RB0
#define a2 PORTBbits.RB1
#define a4 PORTBbits.RB2
#define a8 PORTBbits.RB3
//Defining pins on bcd switch B
#define b1 PORTBbits.RB4
#define b2 PORTBbits.RB5
#define b4 PORTBbits.RB6
#define b8 PORTBbits.RB7
void InitPorts(void){
ANSA0 = 1; // Set pin to analog
TRISA0 = 1; // Set pin to input
ANSELB = 0; // Set Port B to digital
TRISB = 1; // Set port B to input
ANSELC = 0 ; // Set Port C to digital
TRISC = 0; // Set Pins to output
ANSD0 = 0; //Set pin to digital
TRISD0 = 0; //Set pin to output
ANSD1 = 0; //Set pin to digital
TRISD1 = 0; //Set pin to output
}
void InitADC (void){
ADCON0bits.CHS = 0; //Channel 0
ADCON1bits.PVCFG = 0; // Vref = Vdd
ADCON1bits.NVCFG = 0; //-Vref = Vss
ADCON2bits.ADFM = 1; //10-bit operation
ADCON2bits.ACQT = 0b0000010; //4 Tad
ADCON2bits.ADCS = 7; //Frc
ADCON0bits.ADON = 1; //Osc = on
}
int Rd_ADC(void){
int Result;
ADCON0bits.GODONE = 1;
while (ADCON0bits.GODONE);
Result =(((ADRESH <<6) | (ADRESL>>2))/2.56);
return Result;
}
void DispTemp( int BinVal){
int Bcd[2];
Bcd[0] = BinVal ;
BinVal /= 10;
Bcd[1] = BinVal % 10;
BinVal /= 10;
LATC = Bcd[0];
LATCbits.LATC4 = 1;
LATCbits.LATC4 = 0;
LATC = Bcd[1];
LATCbits.LATC5 = 1;
LATCbits.LATC5 = 0;
}
int Read_SwitchA(void){
int total = 0;
if (a1) {total =1;}
if (a2) {total =2;}
if (a4) {total =4;}
if (a8) {total =8;}
return total;
}
int Read_SwitchB(void){
int total = 0;
if (b1) {total =1;}
if (b2) {total =2;}
if (b4) {total =4;}
if (b8) {total =8;}
return total*10;
}
int Bcd_SW_AB(int Read_SwitchB, int Read_SwitchA){
int total = Read_SwitchB Read_SwitchA;
return total;
}
void main(void){
InitPorts();
InitADC();
while(1){
int SetTemp = Bcd_SW_AB (Read_SwitchB(), Read_SwitchA());
DispTemp(Rd_ADC());
if(Rd_ADC() < (SetTemp - 1)){RLED = 1;}
if(Rd_ADC() > (SetTemp 1)){RLED = 0;}
}
}