Microcontroller › PIC › Error 1151 struct or union object designator expected › EUREKA! Hullo everyone. I got
EUREKA!
Hullo everyone. I got the cause of the error [1151] struct or union object designator expected.
The naming of the ports was not inline with the names used in the C18 header files.
The C18 compiler provides a header file with definitions for ports and pins for each microcontroller it supports. The default
directory for these files is C:MCC18h . For example, the 18F4550 file includes the following code:
extern volatile near unsigned char PORTB;
extern volatile near union {
struct {
unsigned RB0:1;
unsigned RB1:1;
unsigned RB2:1;
unsigned RB3:1;
unsigned RB4:1;
unsigned RB5:1;
unsigned RB6:1;
unsigned RB7:1;
};
struct {
unsigned INT0:1;
unsigned INT1:1;
unsigned INT2:1;
};
struct {
unsigned :5;
unsigned PGM:1;
unsigned PGC:1;
unsigned PGD:1;
};
} PORTBbits;
This code shows the various ways of addressing PORT B pins. For example, they can be addressed as a byte by PORTB, or
as individual pins by the union PORTBbits using PORTBbits.RB0 through PORTBbits.RB7. When set up as interrupts, pins
0-2 should be accessed as PORTBbits.INT0 through PORTBbits.INT2.
therefore instead of
#define rs LATA.F4
#define en LATA.F5
I should use
# define rs PORTAbits.RB4
#define en PORTAbits.RB5
Do you understand that? I ‘ve learnt that when programming you don’t need to figit. just relax and do things without panicing.
Thank you