<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.arm.com/utility/feedstylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Assign name to pin</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/16491/assign-name-to-pin</link><description> Hi all, 
I searched the forum before starting 
this thread, but I couldn&amp;#39;t find a 
satifying answer to my question. 
 
here&amp;#39;s my question: 
I&amp;#39;m using keil uVision2 and the EZ-USB FX 
dev kit. This kit has 6 IO ports on it. 
I want to assign a name to</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: Assign name to pin</title><link>https://community.arm.com/thread/110746?ContentTypeID=1</link><pubDate>Thu, 12 Feb 2004 10:46:45 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:af55f122-e7fa-49c6-8303-47bae919adf4</guid><dc:creator>Drew Davis</dc:creator><description>&lt;p&gt;&lt;i&gt;It is pity that C51 does not handle bit-fields efficiently&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Few compilers handle C bitfields efficiently.  Given my bad experiences with that, plus the fact that bitfields are under-specified* and thus not very portable, I&amp;#39;ve learned to avoid their use entirely and just use bitwise operators instead.&lt;br /&gt;
&lt;br /&gt;
The Keil sbit mechanism is one of those low-level 8051 architecture adaptations.  Since only the occasional SFR and a few bytes of memory are bit-addressable, it really wouldn&amp;#39;t do as a mechanism for general bitfields.&lt;br /&gt;
&lt;br /&gt;
(* Common snags: The order of bitfields in a word is not standardized, and varies from compiler to compiler.  Despite the fact that bitfields are specifically &amp;quot;int&amp;quot;, whether or not a value with the high bit set is negative is implementation-dependent, so it&amp;#39;s risky to use some tests on a bitfield or pass them as parameters.  Standard C insists that bitfields are always an int wide, even if you declare only one bit, though most decent embedded compiler lets you declare them in ints of various sizes as an extension.)&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Assign name to pin</title><link>https://community.arm.com/thread/96112?ContentTypeID=1</link><pubDate>Thu, 12 Feb 2004 09:48:25 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:f538d506-ae37-4fbc-9e81-2c30f988afdd</guid><dc:creator>Jon Ward</dc:creator><description>&lt;p&gt;&lt;i&gt;It is pity that C51 does not handle bit-fields efficiently and did not make this the normal way of defining an SFR that has bit-fields (as opposed to the totally non-C sbit extensions.&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
Back in the heyday of the 8051 (which was the mid 80&amp;#39;s according to Intel) the Intel ASM-51 Assembler and PL/M-51 Compiler were the standard development tools.&lt;br /&gt;
&lt;br /&gt;
When Keil started making C compilers for the 8051 a decisiiiion had to be made as to how SFRs and bits and that kind of stuff were to be handled.  We decided to use the same nomenclature as PL/M-51 (which is similar to pascal).  That&amp;#39;s where sfr and sbit came from.  At the time, these were the &amp;quot;standard&amp;quot; way of doing things.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Jon&lt;/b&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Assign name to pin</title><link>https://community.arm.com/thread/72280?ContentTypeID=1</link><pubDate>Thu, 12 Feb 2004 06:49:39 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:57031bf7-67eb-4bcf-b15d-3c9cd2ef509c</guid><dc:creator>Graham Cole</dc:creator><description>&lt;p&gt;&lt;i&gt;&lt;pre&gt;
#define D0 OUTB.0
main()
{
    D0 = 1;
}
&lt;/pre&gt;
I get 2 errors:&lt;br /&gt;
error C141: syntax error near &amp;#39;.0&amp;#39;&lt;br /&gt;
error C213: left side of asn-op not an lvalue&lt;br /&gt;
&lt;br /&gt;
As far as I remember I used this code in&lt;br /&gt;
a previous project, and it worked. But now it doesn&amp;#39;t :(&lt;br /&gt;
&lt;/i&gt;&lt;br /&gt;
I don&amp;#39;t think your code could ever have worked in C, maybe you were thinking of assembler. In C &amp;quot;.&amp;quot; is the member operator and OUTB is not a structure.&lt;br /&gt;
&lt;br /&gt;
If OUTB is bit addressable then you can define an &lt;b&gt;sbit&lt;/b&gt; address for bit zero.&lt;br /&gt;
&lt;br /&gt;
The next most obvious method of setting or clearing an individual bit is to use masks as follows:&lt;br /&gt;
&lt;pre&gt;
#define D0_BIT_MASK 0x01
main()
{
    BOUT = BOUT | DO_BIT_MASK;
}
&lt;/pre&gt;
Or, you can define a bit-field structure something like the following (untested).&lt;br /&gt;
&lt;pre&gt;
main()
{
    data struct
    {
        unsigned char d0:1;
        unsigned char padding:7;
    } bout _at_ 0xXX;

    bout.d0 = 1;
}
&lt;/pre&gt;
Both the mask and bit-field methods will do a read-update-write. If BOUT is an SFR, you need to be sure that this is OK.&lt;br /&gt;
&lt;br /&gt;
In general, masks are frequently used in C code. This is partly because they are portable whereas C does not specify the order of fields in a bit-field structure.&lt;br /&gt;
&lt;br /&gt;
However, bit-field structures are a much more natural and elegant way of doing things. It is pity that C51 does not handle bit-fields efficiently and did not make this the normal way of defining an SFR that has bit-fields (as opposed to the totally non-C &lt;b&gt;sbit&lt;/b&gt; extensions.&lt;br /&gt;
&lt;br /&gt;
I understand that Keil have some long-term plans to address this issue. There is an old thread on this subject here: &lt;a href="http://www.keil.com/forum/docs/thread1291.asp"&gt;http://www.keil.com/forum/docs/thread1291.asp&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Assign name to pin</title><link>https://community.arm.com/thread/41707?ContentTypeID=1</link><pubDate>Thu, 12 Feb 2004 05:28:29 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:63f36a66-1a32-4f87-a8ea-7142a00aac8b</guid><dc:creator>John Donaldson</dc:creator><description>&lt;p&gt;&amp;quot;anyone who knows what goes wrong?&amp;quot;&lt;br /&gt;
&lt;br /&gt;
Bad memory, I think!&lt;br /&gt;
&lt;br /&gt;
Are you sure that OUTB is bit addressable?&lt;br /&gt;
&lt;br /&gt;
Stefan&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Assign name to pin</title><link>https://community.arm.com/thread/41706?ContentTypeID=1</link><pubDate>Thu, 12 Feb 2004 05:25:38 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:fb136094-d912-43da-8483-5b1d1efd6be1</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;b&gt;sbit&lt;/b&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>