hi there, i have struct with the problem.I'm writing a code for DS12887,And typedef two structures in the header file.It is normal before writing a function. But now the error C141. I am more confused. Ask for The help Header file:
#include <stdio.h> #include <absacc.h> typedef struct { ...... }stTimeStr; typedef struct { ...... }stDsStatus; void InitaliseDS(stTimeStr* stClkTime,stTimeStr* stAlmTime); void SetClkTime(stTimeStr* stClkTime); void SetAlmTime(stTimeStr* stAlmTime); void GetDSStatus(stDsStatus* stStat);
C Source file:
#include <stdio.h> #include <absacc.h> #include "DS12887.h" void InitaliseDS(stTimeStr* stClkTime,stTimeStr* stAlmTime) { ...... } void SetClkTime(stTimeStr* stClkTime) { ...... } void InitaliseDS(stTimeStr* stClkTime,stTimeStr* stAlmTime) { ...... } void GetDSStatus(stDsStatus* stStat) { ...... } void GetDSStatus(stDsStatus* stStat) { ...... }
The message tells you that the error is near 'stTimeStr'
There are 11 occurrences of 'stTimeStr' in the code you posted - so which one(s), exactly, is it complaining about?
Also note that near 'stTimeStr' usually means, "somewhere before 'stTimeStr'" - so it's useless to post code with text removed!!
Here is the wrong report
typedef struct { ...... }stTimeStr; typedef struct { ...... }stDsStatus;
My compiler complains about the dots...
Seriously take the code and run it through a different compiler and see if it gives more specific errors.
Don't try to sanitize the code by selective editing, it doesn't help with identifying the real issue. Rename the variables to something generic if that is the problem with showing the code.
You could discuss with the people who wrote the code originally.
Errors tend to compound, work backward from the current location looking for syntax errors, or put an #if 0/#endif around it to see if the error moves or changes.
Sorry,Here is the complete source code: ds12887.h
#include <stdio.h> #include <absacc.h> #include "ComUnit.h" #define RDADDR XBYTE[0xfb04] #define WR1ADDR XBYTE[0xfb01] #define WR0ADDR XBYTE[0xfb00] /************** definitions unique to high-speed micros **************/ //sfr CKCON = 0x8e; /***************************** Defines ********************************/ #define CLK_SECS XBYTE[0xfb00] /* time, date & alarm regs */ #define CLK_SECS_ALM XBYTE[0xfb01] #define CLK_MINS XBYTE[0xfb02] #define CLK_MINS_ALM XBYTE[0xfb03] #define CLK_HRS XBYTE[0xfb04] #define CLK_HRS_ALM XBYTE[0xfb05] #define CLK_DOW XBYTE[0xfb06] #define CLK_DOM XBYTE[0xfb07] #define CLK_MON XBYTE[0xfb08] #define CLK_YR XBYTE[0xfb09] #define REGA XBYTE[0xfb0a] #define REGB XBYTE[0xfb0b] #define REGC XBYTE[0xfb0c] #define REGD XBYTE[0xfb0d] #define CLK_CENTTURY XBYTE[0xfb32] //#define REG4A XBYTE[0xfb4a] //#define REG4B XBYTE[0xfb4b] #define RS2 0x0f #define RS4 0x0e #define RS8 0x0d #define RS16 0x0c #define RS32 0x0b #define RS64 0x0a #define RS128 0x09 #define RS256 0x08 #define RS512 0x07 #define RS1024 0x06 #define RS2048 0x05 #define RS4096 0x04 #define RS8192 0x03 #define VRT 0x80 #define E32K 0x40 #define DVX 0x01 #define C887 0x02 #define VRT_SET 0x04 #define VRT2_SET 0x08 #define VLDMDL 0x10 #define CRCSEROK 0x20 typedef struct { byte_1 ucSECS; byte_1 ucMINS; byte_1 ucHRS; byte_1 ucWEEK; byte_1 ucDAY; byte_1 ucMON; byte_1 ucYR; byte_1 ucCENT; }stTimeStr; typedef struct { byte_1 ucStatsBit; byte_1 ucSeletWord; }stDsStatus; void InitaliseDS(stTimeStr* stClkTime,stTimeStr* stAlmTime); void SetClockTime(stTimeStr* stClkTime); void SetAlarmTime(stTimeStr* stAlmTime); void GetDSStatus(stDsStatus* stStat);
ds12887.c
#include <stdio.h> /* Prototypes for I/O functions */ #include <absacc.h> /* needed to define xdata addresses */ #include "DS12887.h" #include "ComUnit.h" //Initialization DS12C887 void InitaliseDS(stTimeStr* stClkTime,stTimeStr* stAlmTime) { REGA = 0xad; REGB = 0xa6; if(stClkTime->ucSECS > 0x80) return; else SetClkTime(stClkTime); if(stAlmTime->ucSECS > 0x80) return; else SetAlmTime(stAlmTime); } //Set Clock Time void SetClkTime(stTimeStr* stClkTime) { } //Set Alarm Time void SetAlmTime(stTimeStr* stAlmTime) { } //Get DS12C887 Status WORD & BIT/ void GetDSStatus(stDsStatus* stStat) { byte_1 uStatus = 0x00; byte_1 ucTemp = 0x00; //Read Select Switch ucTemp = REGA; ucTemp = ucTemp & 0x7f; stStat->ucSeletWord = ucTemp; //Read Status Bit On REG B ucTemp = ucTemp | ((REGB& 0x07)<<1); stStat->ucStatsBit = stStat->ucStatsBit | ucTemp; ucTemp = REGC & 0xf0; //Read Status Bit On REG C stStat->ucStatsBit = ucTemp; }
error C141: syntax error near 'stTimeStr' error C141: syntax error near 'stDsStatus' is there:
typedef struct { byte_1 ucSECS; byte_1 ucMINS; byte_1 ucHRS; byte_1 ucWEEK; byte_1 ucDAY; byte_1 ucMON; byte_1 ucYR; byte_1 ucCENT; }stTimeStr; typedef struct { byte_1 ucStatsBit; byte_1 ucSeletWord; }stDsStatus;
I'm Sorry, the above has been posted on the source code. Can you ask if the correct typedef structure declares, How style should be this code?
What & where is the definition of byte_1 ?
Sorry,"byte_1" is a macro definition in other header file.
#define byte_1 unsigned char #define byte_2 unsigned short int #define byte_3 unsigned long int #define byte_4 unsigned long
"byte_1" macro definition in ComUnit.h file.
just as a test change
typedef struct { byte_1 ucSECS; byte_1 ucMINS; byte_1 ucHRS; byte_1 ucWEEK; byte_1 ucDAY; byte_1 ucMON; byte_1 ucYR; byte_1 ucCENT; }stTimeStr;
to
typedef struct { unsigned char ucSECS; unsigned char ucMINS; unsigned char ucHRS; unsigned char ucWEEK; unsigned char ucDAY; unsigned char1 ucMON; unsigned char ucYR; unsigned char ucCENT; }stTimeStr;
I have a strong feeling what it could be, but need the result of the above change to tell
Good morning....thanks for your help....... I'm try change code as this tip....chang "byte_1" to "unsigned char".Like this:
typedef struct { unsigned char ucSECS; unsigned char ucMINS; unsigned char ucHRS; unsigned char ucWEEK; unsigned char ucDAY; unsigned char ucMON; unsigned char ucYR; unsigned char ucCENT; }stClockTime; typedef struct { unsigned char ucSECS; unsigned char ucMINS; unsigned char ucHRS; }stAlarmTime; typedef struct { unsigned char ucStatsBit; unsigned char ucSeletWord; }stDsStatus;
But......But did not work...... It's so strange ........
Does C51 insist on having a tag for the struct declaration ... ?
so,i feel very strange, If i chang code like this,then no error:
#include <stdio.h> #include <absacc.h> #include "../ComUnit/ComUnit.h" #define RDADDR XBYTE[0xfb04] #define WR1ADDR XBYTE[0xfb01] #define WR0ADDR XBYTE[0xfb00] /************** definitions unique to high-speed micros **************/ //sfr CKCON = 0x8e; /***************************** Defines ********************************/ #define CLK_SECS XBYTE[0xfb00] /* time, date & alarm regs */ #define CLK_SECS_ALM XBYTE[0xfb01] #define CLK_MINS XBYTE[0xfb02] #define CLK_MINS_ALM XBYTE[0xfb03] #define CLK_HRS XBYTE[0xfb04] #define CLK_HRS_ALM XBYTE[0xfb05] #define CLK_DOW XBYTE[0xfb06] /*Day For Week*/ #define CLK_DOM XBYTE[0xfb07] /*Day For Mouth*/ #define CLK_MON XBYTE[0xfb08] #define CLK_YR XBYTE[0xfb09] #define REGA XBYTE[0xfb0a] #define REGB XBYTE[0xfb0b] #define REGC XBYTE[0xfb0c] #define REGD XBYTE[0xfb0d] #define CLK_CENTTURY XBYTE[0xfb32] #define RS2 0x0f #define RS4 0x0e #define RS8 0x0d #define RS16 0x0c #define RS32 0x0b #define RS64 0x0a #define RS128 0x09 #define RS256 0x08 #define RS512 0x07 #define RS1024 0x06 #define RS2048 0x05 #define RS4096 0x04 #define RS8192 0x03 #define VRT 0x80 #define E32K 0x40 #define DVX 0x01 #define C887 0x02 #define VRT_SET 0x04 #define VRT2_SET 0x08 #define VLDMDL 0x10 #define CRCSEROK 0x20 //Order Day For Week:Sun,Mon,Tue,Wed,Thu,Fri,Sat0 typedef struct { unsigned char ucSECS; unsigned char ucMINS; unsigned char ucHRS; unsigned char ucWEEK; unsigned char ucDAY; unsigned char ucMON; unsigned char ucYR; unsigned char ucCENT; }stClockTime; typedef struct { unsigned char ucSECS; unsigned char ucMINS; unsigned char ucHRS; }stAlarmTime; typedef struct { unsigned char ucStatsBit; unsigned char ucSeletWord; }stDsStatus; //Initialization DS12C887 void InitaliseDS(stTimeStr* stClkTime,stTimeStr* stAlmTime) { REGA = 0xad; REGB = 0xa6; if(stClkTime->ucSECS > 0x80) return; else SetClkTime(stClkTime); if(stAlmTime->ucSECS > 0x80) return; else SetAlmTime(stAlmTime); } //Set Clock Time void SetClkTime(stTimeStr* stClkTime) { } //Set Alarm Time void SetAlmTime(stAlarmTime* stAlmTime) { } //Get DS12C887 Status WORD & BIT/ void GetDSStatus(stDsStatus* stStat) { byte_1 uStatus = 0x00; byte_1 ucTemp = 0x00; ucTemp = REGA; ucTemp = ucTemp & 0x7f; stStat->ucSeletWord = ucTemp; ucTemp = ucTemp | ((REGB& 0x07)<<1); stStat->ucStatsBit = stStat->ucStatsBit | ucTemp; ucTemp = REGC & 0xf0; stStat->ucStatsBit = ucTemp; }
have a look at the file with byte1 defined (BTW I do NOT like your byte2=int, an int is not a byte) I will bet dollars to doughnuts there is an #if or #ifdef that disables the byte1 deinition
Sorry - what, exactly, did you change?