[SOLVED] Error 1151 struct or union object designator expected

Status
Not open for further replies.

kasoma

Newbie level 6
Joined
Jul 27, 2011
Messages
12
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,430
Hi all

I am working on source code to display Characters on a 16x2 LCD using a PIC18F4550 microcontroller.
I am using MPLAB IDE with C18 compiler. I am writing my source code and on compiling I get the Error [1151] struct or union object designator expected.

When I looked up the error in the MPLAB CI8 users guide I found this message

"1151: struct or union object designator expected
The member access operators, '.' and '->' require operands of struct/union
and pointer to struct/union, respectively."

I think the library function miss some operands but I don't really know how to include those operands.

Please help me debug this code

Here is the source code

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include <p18cxxx.h>
#pragma config CPUDIV = OSC1_PLL2
#pragma config WDT = OFF
#pragma config LVP = OFF
#pragma config DEBUG = OFF
#pragma config MCLRE = ON
//static bit LCD_RS    @ ((unsigned)&PORTA*8+4)
//static bit LCD_EN    @ ((unsigned)&PORTA*8+5)
#define LCD_RS LATABits.LATB4
#define LCD_EN LATABits.LATB5
//#define LCD_RS LATA.F4
//#define LCD_EN LATA.F5
#define LCD_STROBE ((LCD_EN = 1), (LCD_EN = 0))
 
 
//void lcd_write (unsigned char);
//void lcd_clear (void);
//void lcd_puts(const char * s);
//void lcd_goto(unsigned char pos);
 
void main(void)
{
void lcd_init (void);
LATA = 0x00;
TRISA = 0x00;
LATB = 0x00;
TRISB = 0x00;
 lcd_init();
}
 
void lcd_init(void)
{
    LCD_RS = 0;    // write control bytes
    DelayMs(15);    // power on delay
    PORTB = 0x3;    // attention!
    LCD_STROBE;
    DelayMs(5);
    LCD_STROBE;
 DelayUs(100);
//    LCD_STROBE;
    LCD_EN = 1;
    LCD_EN = 0;
    DelayMs(5);
    PORTB = 0x2;    // set 4 bit mode
    LCD_STROBE;
 DelayUs(40);
    lcd_write(0x28);    // 4 bit mode, 1/16 duty, 5x8 font
    lcd_write(0x08);    // display off
    lcd_write(0x0F);    // display on, blink curson on
    lcd_write(0x06);    // entry mode
}



ON BUILDING THESE ARE THE RESULTS
Code:
Debug build of project `C:\Users\tx2AKE\Documents\PIC\works\display.mcp' started.
Language tool versions: mpasmwin.exe v5.42, mplink.exe v4.40, mcc18.exe v3.40, mplib.exe v4.40
Preprocessor symbol `__DEBUG' is defined.
Sat Mar 10 20:58:22 2012
----------------------------------------------------------------------
Clean: Deleting intermediary and output files.
Clean Warning: File "C:\Users\tx2AKE\Documents\PIC\works\display2.o" doesn't exist.
Clean: Deleted file "C:\Users\tx2AKE\Documents\PIC\works\display.mcs".
Clean: Done.
Executing: "C:\MCC 18\bin\mcc18.exe" -p=18F4450 /i"C:\MCC 18\h" "display.c" -fo="display.o" -D__DEBUG -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-
C:\Users\tx2AKE\Documents\PIC\works\display.c:55:Error [1203] too few arguments in function call
C:\Users\tx2AKE\Documents\PIC\works\display.c:57:Error [1203] too few arguments in function call
C:\Users\tx2AKE\Documents\PIC\works\display.c:67:Error [1151] struct or union object designator expected
C:\Users\tx2AKE\Documents\PIC\works\display.c:67:Error [1151] struct or union object designator expected
C:\Users\tx2AKE\Documents\PIC\works\display.c:69:Error [1151] struct or union object designator expected
C:\Users\tx2AKE\Documents\PIC\works\display.c:69:Error [1151] struct or union object designator expected
C:\Users\tx2AKE\Documents\PIC\works\display.c:70:Warning [2058] call of function without prototype
C:\Users\tx2AKE\Documents\PIC\works\display.c:80:Error [1151] struct or union object designator expected
C:\Users\tx2AKE\Documents\PIC\works\display.c:82:Warning [2058] call of function without prototype
C:\Users\tx2AKE\Documents\PIC\works\display.c:89:Error [1151] struct or union object designator expected
C:\Users\tx2AKE\Documents\PIC\works\display.c:100:Error [1151] struct or union object designator expected
C:\Users\tx2AKE\Documents\PIC\works\display.c:108:Error [1151] struct or union object designator expected
C:\Users\tx2AKE\Documents\PIC\works\display.c:109:Warning [2058] call of function without prototype
C:\Users\tx2AKE\Documents\PIC\works\display.c:111:Error [1151] struct or union object designator expected
C:\Users\tx2AKE\Documents\PIC\works\display.c:111:Error [1151] struct or union object designator expected
C:\Users\tx2AKE\Documents\PIC\works\display.c:112:Warning [2058] call of function without prototype
C:\Users\tx2AKE\Documents\PIC\works\display.c:113:Error [1151] struct or union object designator expected
C:\Users\tx2AKE\Documents\PIC\works\display.c:113:Error [1151] struct or union object designator expected
C:\Users\tx2AKE\Documents\PIC\works\display.c:114:Warning [2058] call of function without prototype
C:\Users\tx2AKE\Documents\PIC\works\display.c:115:Error [1151] struct or union object designator expected
C:\Users\tx2AKE\Documents\PIC\works\display.c:115:Error [1151] struct or union object designator expected
C:\Users\tx2AKE\Documents\PIC\works\display.c:116:Warning [2058] call of function without prototype
C:\Users\tx2AKE\Documents\PIC\works\display.c:118:Error [1151] struct or union object designator expected
C:\Users\tx2AKE\Documents\PIC\works\display.c:118:Error [1151] struct or union object designator expected
C:\Users\tx2AKE\Documents\PIC\works\display.c:119:Warning [2058] call of function without prototype
Halting build on first failure as requested.
----------------------------------------------------------------------
Debug build of project `C:\Users\tx2AKE\Documents\PIC\works\display.mcp' failed.
Language tool versions: mpasmwin.exe v5.42, mplink.exe v4.40, mcc18.exe v3.40, mplib.exe v4.40
Preprocessor symbol `__DEBUG' is defined.
Sat Mar 10 20:58:23 2012
----------------------------------------------------------------------
BUILD FAILED

Anyone who understands what this error wants please help me.

---------- Post added at 06:30 ---------- Previous post was at 06:13 ----------

Please someone give me an idea on what I should do . I am waiting
 
Last edited by a moderator:

[Merged] Error 1151 struct or union object designator expected

EUREKA

Hullo everyone. I have found 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:\MCC18\h . For example, the 18F4550 file includes the following code:

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
Code:
#define rs LATA.F4
#define en LATA.F5
I should use
Code:
# 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
 
Last edited by a moderator:

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…