Hi Donald,
I am trying to re-clarify the concept of __sfr and __sbit.

The statement '__sfr __at 0x9A MY_SFR' means that a new SFR is
declared at 0x9A which is identified by the name MY_SFR in this
program.

However, this does not mean that MY_SFR.0 or MY_SFR_0 can be used to
access the 'bit 0' of MY_SFR. To access that you need __sbit provided
that location is bit-addressable. 0x9A is not a bit-addressable. So
you cannot access the individual bits of this SFR.

To define a bit-addressable register, the address must end with 0 or
8. Thus I can define a bit addressable register at 0xC0. But still
then I have to define each bit of that SFR explicitly. Look at the
following code:

__sfr __at 0xC0 MY_BITADDRESSABLE_SFR;
__sbit __at 0xC0 MY_BITADDRESSABLE_SFR_0;
__sbit __at 0xC1 MY_BITADDRESSABLE_SFR_1;
__sbit __at 0xC2 MY_BITADDRESSABLE_SFR_2;
__sbit __at 0xC3 MY_BITADDRESSABLE_SFR_3;
__sbit __at 0xC4 MY_BITADDRESSABLE_SFR_4;
__sbit __at 0xC5 MY_BITADDRESSABLE_SFR_5;
__sbit __at 0xC6 MY_BITADDRESSABLE_SFR_6;
__sbit __at 0xC7 MY_BITADDRESSABLE_SFR_7;

Sometime the individual bits are given special name. Then the above
code changes to:
__sfr __at 0xC0 MY_BITADDRESSABLE_SFR
__sbit __at 0xC0 SPECIAL_0
__sbit __at 0xC1 SPECIAL_1
__sbit __at 0xC2 SPECIAL_2
__sbit __at 0xC3 SPECIAL_3
__sbit __at 0xC4 SPECIAL_4
__sbit __at 0xC5 SPECIAL_5
__sbit __at 0xC6 SPECIAL_6
__sbit __at 0xC7 SPECIAL_7

If you include <8051.h>, it already defines most of the SFR and SBIT
of 8051 architecture. So that you don't have to re-write them.

As far as PSW_1 is concerned, it has a special name called 'F1'. How
do I know this? Well:

1) Search PSW in 8051.h. The statement looks like '__sfr __at (0xD0)
PSW' which means it is at a location 0xD0.
2) Search of '__sbit __at (0xD0)' and find the following lines:
__sbit __at (0xD0) P
__sbit __at (0xD1) F1
__sbit __at (0xD2) OV
__sbit __at (0xD3) RS0
__sbit __at (0xD4) RS1
__sbit __at (0xD5) F0
__sbit __at (0xD6) AC
__sbit __at (0xD7) CY
So now I know PSW_0 is called P, PSW_1 is called F1, PSW_2 is called
OV and so on. So to set the 5-th bit of PSW, use RS1 = 1. not PSW_4 =
1.


The sfr and sbit keywords are SDCC specific. So it is a good practice
to add '__' (underscore underscore) prefix with them, just like other
SDCC keywords, e.g. __bit, __data, __idata, __code, __xdata,
__critical, __reentrant etc. Omitting this, new versions of sdcc
generate deprecation warnings.

Cheers.
Krish



On Wed, Mar 23, 2011 at 8:04 AM, duck donal <tangtao87657...@gmail.com> wrote:
> Hi roelof,
>    Thanks for your help!
>    I run what you modify code in my pc,It can be compiled successfully!
>    However I have some questions to this code.
>    1.What you use library files(p89lpc938.h) seems not the standard 51
> library files.Does that mean I can subsitute this library for standard
> 51 library?
>
>    2.You have no statements about P1_0/P1_7,Does that mean,the codes which
> have been compiled with SDCC don't need the statements of sfr or sbit?
>    3.I've tried another simple code(newpp.c) as what you told me,but the
> sdcc give me such a error:newpp.c:error 20:Undefined identifier 'PSW_1'
>       the code as follow:
>       #include <AT89X51.H>
>        sfr f_wren=0xf1;
>        sfr f_pp=0xf2;
>        sfr f_wr_adrH=0xf3;
>        sfr f_wr_adrM=0xf4;
>        sfr f_wr_adrL=0xf5;
>        sfr f_wr_dataH=0xf6;
>        sfr f_wr_dataM1=0xf7;
>        sfr f_wr_dataM2=0xf8;
>        sfr f_wr_dataL=0xf9;
>        sfr f_rw=0xfa;
>        sfr f_work=0xfb;
>        main()
>        {
>
>        f_wren=0x06;
>        f_pp=0x02;
>        f_wr_adrH=0x00;
>        f_wr_adrM=0x02;
>        f_wr_adrL=0x00;
>        f_wr_dataH=0x12;
>        f_wr_dataM1=0x34;
>        f_wr_dataM2=0x56;
>        f_wr_dataL=0x78;
>        f_rw=0x01;
>        f_work=0x01;
>        while(PSW_1==0)
>           f_work=0x00;
>        }o
>       I use PSW.1 instead of PSW_1,the SDCC give me a syntax error: token ->
> '.1';column 11
>       So,what should be done on this code?
>       4.I'm interesting in the SDCC compile internal,but manual is not very
> detailed to the introduction of the internal
>          so,could u give me some material,such as SDCC compile flow,Whether
> the SDCC have intermediate language,what is the difference between SDCC with
> GCC
>
>      Thanks!
>       Donald
> 2011/3/22 roelof 't Hooft <roel...@itholland.nl>
>>
>> On Tue, 2011-03-22 at 10:02 +0800, duck donal wrote:
>> > Hi All,
>> > I'm a newbie for sdcc.
>> > A few days ago, I was in use of SDCC, ran into a problem.
>>
>> > So,what is the solutions?To modify the program?How to do it?
>> > Or modify the sdcc?
>>
>> Hi Donald,
>>
>> Here is your example code back, I modified it a bit to
>> have it succesfully compile with sdcc.
>> As opposed to arm-elf-gcc sdcc does not need or use the
>> return at the end of a program, embedded programs usually
>> never return and stay in a while(1) loop forever :-)
>>
>> #include <p89lpc938.h>
>>
>> void main(void)
>> {
>>        unsigned char j;
>>        unsigned int i;
>>
>>        while(1)
>>        {
>>                P1_7 = 1;
>>                while(P1_7 == 0)
>>                {
>>                        for(i = 1; i <= 500; i++)
>>                        {
>>                                P1_0 = !P1_0;
>>                                for(j = 0; j <= 50; j++)
>>                                {
>>                                }
>>                        }
>>                        for(i = 1; i <= 250; i++)
>>                        {
>>                                P1_0 = !P1_0;
>>                                for(j = 0; j <= 100; j++)
>>                                {
>>                                }
>>                        }
>>                }
>>        }
>> }
>>
>> roelofh@baywatch:~/tangtao$ sdcc tang.c
>> roelofh@baywatch:~/tangtao$ ll
>> total 196
>> -rw-r--r-- 1 roelofh domainusers 13302 2011-03-22 10:48 tang.asm
>> -rw-r--r-- 1 roelofh domainusers   333 2011-03-22 10:48 tang.c
>> -rw-r--r-- 1 roelofh domainusers   620 2011-03-22 10:48 tang.ihx
>> -rw-r--r-- 1 roelofh domainusers   215 2011-03-22 10:48 tang.lnk
>> -rw-r--r-- 1 roelofh domainusers 35446 2011-03-22 10:48 tang.lst
>> -rw-r--r-- 1 roelofh domainusers 34876 2011-03-22 10:48 tang.map
>> -rw-r--r-- 1 roelofh domainusers  1129 2011-03-22 10:48 tang.mem
>> -rw-r--r-- 1 roelofh domainusers  6201 2011-03-22 10:48 tang.rel
>> -rw-r--r-- 1 roelofh domainusers 35446 2011-03-22 10:48 tang.rst
>> -rw-r--r-- 1 roelofh domainusers 47706 2011-03-22 10:48 tang.sym
>> roelofh@baywatch:~/tangtao$ sdcc -v
>> SDCC : mcs51 3.0.1 #6066 (23 Nov 2010) (Linux)
>>
>> You will find the header files in /usr/local/share/sdcc/include/mcs51/
>> Please have a look at them and include the one you need for your
>> processor. I have included a random one for example.
>>
>> roelof
>>
>>
>>
>>
>> ------------------------------------------------------------------------------
>> 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
>
>

------------------------------------------------------------------------------
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

Reply via email to