Hi Donald, The keyword 'sbit' is used to define special function bits, much like the keyword 'sfr' for the special function registers. The good news is that most of the SFRs in 8051 are already defined in <8051.h> Thus to set the 4th bit of PORT-2 to 0, use the following code:
#include <8051.h> void main (void) { P2_3 = 0; // P2_0 is the first bit of port 2 } This is not standard C. Thus Keil and SDCC may follow different conventions. Krish 2011/3/22 duck donal <tangtao87657...@gmail.com>: > Hi All, > I'm a newbie for sdcc. > A few days ago, I was in use of SDCC, ran into a problem. > > Program (bee.c) is very simple, as follows: > #include<reg51.h> > #include<stdio.h> > sbit P10=P1^0; > sbit P17=P1^7; > int main(void) > { > unsigned char j; > unsigned int i; > while(1){ > P17=1; > while(P17==0) > { > for(i=1;i<=500;i++) > { > P10=~P10; > for(j=0;j<=50;j++); > } > for(i=1;i<=250;i++) > { > P10=~P10; > for(j=0;j<=100;j++); > } > } > } > return 0; > } > My compiler option was sdcc -mmcs51 bee.c > But SDCC gave me such an error message : bee.c:3:error 2:Initializer > element is not constant > > bee.c:4:error 2:Initializer element is not constant > It means the expression: sbit P10=P1^0 was wrong. > I used keil C running the program,it compiled successfully,no > errors,no warnings. > Later,I got other programs to compile with SDCC.I found that where > there is sbit instructions, there is error 2:Initializer element is not > constant > But keil C still can compile successfully. > So,what is the solutions?To modify the program?How to do it? Or modify > the sdcc? > thanks! > Donald > > ------------------------------------------------------------------------------ > Enable your software for Intel(R) Active Management Technology to meet the > growing manageability and security demands of your customers. Businesses > are taking advantage of Intel(R) vPro (TM) technology - will your software > be a part of the solution? Download the Intel(R) Manageability Checker > today! http://p.sf.net/sfu/intel-dev2devmar > _______________________________________________ > Sdcc-user mailing list > Sdcc-user@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/sdcc-user > > ------------------------------------------------------------------------------ Enable your software for Intel(R) Active Management Technology to meet the growing manageability and security demands of your customers. Businesses are taking advantage of Intel(R) vPro (TM) technology - will your software be a part of the solution? Download the Intel(R) Manageability Checker today! http://p.sf.net/sfu/intel-dev2devmar _______________________________________________ Sdcc-user mailing list Sdcc-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sdcc-user