One HAL head file: /**********************************/ #ifndef __HAL_H__ #define __HAL_H__ #define DATA_BUS P0 // sbit MCU_TXD = P1^0; // sbit MCU_RXD = P1^1; // sbit MCU_NC = P1^2; sbit D12_A0 = P1^3; sbit MCU_INT1 = P1^4; // sbit MCU_RST = P1^5; sbit WR_N = P1^6; sbit RD_N = P1^7; sbit LED1 = P3^0; sbit LED2 = P3^1; #define A0_COMMAND D12_A0=1 #define A0_DATA D12_A0=0 #define DATABUS_READ(x) DATA_BUS = 0xFF; D12_RD_N = 0; x = DATA_BUS; D12_RD_N = 1 #define DATABUS_WRITE(x) D12_WR_N = 0; DATA_BUS = x; D12_WR_N = 1 #define DISABLE EA=0 #define ENABLE EA=1 #endif /**********************************/ While compiling, it is reported that on every C file containing the head file: ERROR C231:'D12_A0' redifinition ERROR C231:'WR_N' redifinition ERROR C231:'RD_N' redifinition No other place in the project define these three, I have searched for within but no discovery. If i rem all definitions but these three in this head file, nothing change. If i merely rem these three and left others untouch, no compiling error any more.
Had u include this header file in ur project? If so, u should disable it from target build by unchecking a "Include in target build" & "Always build" checkboxes in options of this header file or by simply excluding this file from project (in this way the header file will be referenced only by "#include" directive).
The problem is that you have initialized variable definitions in a header file. That's never going to work, independent of this being on Keil C51 --- it's a generic C issue. Those variables will have to become 'extern sbit ...' declarations, and then you'll need one source file that actually has the initialized definitions.
"The problem is that you have initialized variable definitions in a header file." Not quite!
sbit D12_A0 = P1^3; sbit MCU_INT1 = P1^4; sbit WR_N = P1^6; sbit RD_N = P1^7;
Thanks,Alex. You reminded me a detailed issue on development.
It's strange in that if I use other lines of definition "sbit xxx = yyy", no compiling error reports. The problem is only on the back of these three lines.
Therefore, my resolution is not to use sbit-definition but use P1 directively. The better thing is that I can confine the manipulation of P1 in macro definition in one place. However, I am still confused with the discrimenativeness of the compiler. Any suggestion is still appreciated.
Try looking at the preprocessor listing - that will show you the file after all the header inclusions & macro expansions (which is what the compiler actually sees). It may become clearer then...
Hi, Your problem may be because the 'header file is being processed more than once'. Try this link:- http://www.keil.com/support/docs/834.htm Mark.
"Your problem may be because the 'header file is being processed more than once'." The preprocessor listing, as previously suggested, would confirm whether or not this is the case.
the '=' sign is not an assignment Of course not. Nor did I claim it was, or did I?. It's an initializer. And that's exactly the problem. You can never have more than one initializer for the same object in the entire project.
Hi,Andrew. Your advice is really directive. I have tried to see global marco definiton by "View->source browser" manu_item in Uv2.Howerver, if I did not compile the code successfully, I can not have a look on the definiton. That means if there is an error in code, i can not have a check. Is any way else to look the list that you said?
Thanks,Mark. It's quite similar mistake, but I don't take it as the same case. The sbit definition is a special address maping and the error report is generated at the early stage of compiling while compiler is checking GLOBAL marco definiton. In contrast, the variant definiton check is at the late stage of compiling while compiler is doing scope check of variants. In different file or different place of the same file, the same marco can be define with different value. Variant can not be redefine. By the way, I can not accept the method that that post mentioned. It will make maintanence more difficult as it was before the ifndef-def-endif appear.
By the way, I can not accept the method that that post mentioned. It will make maintanence more difficult as it was before the ifndef-def-endif appear. For easier maintenance you may use the following approach: In your C code files place a definition like
#define SENSORS_MODULE
#ifndef SENSORS_H #define SENSORS_H #ifdef _DECL #undef _DECL #endif #ifdef SENSORS_MODULE #define _DECL #else #define _DECL extern #endif _DECL UI16 GetVoltage(); _DECL UI8 ui8_SomeVariable; #endif // SENSORS_H
"I have tried to see global marco definiton by "View->source browser" manu_item in Uv2.Howerver, if I did not compile the code successfully, I can not have a look on the definiton." True - that's why I suggested that you use the preprocessor listing. "Is any way else to look the list that you said?" The preprocessor listing usually has a .i filetype; you enable it on the 'Listings' tab in the Project options.