<?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>PROBLEM WITH THE C CODE</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/23940/problem-with-the-c-code</link><description> 
#include&amp;lt;reg51.h&amp;gt; 

 
sfr port= 0x80; 
void main() 
{ port=~port; 
} 

 
This code was successfully compiled...but yu expect the port pins
are complemented only once..But what i experiened when used with a
simulator software, was the port pins get complemented</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: PROBLEM WITH THE C CODE</title><link>https://community.arm.com/thread/135426?ContentTypeID=1</link><pubDate>Fri, 25 Jul 2008 07:58:10 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:0a3c14da-5a08-49c3-bc47-a67537cad05a</guid><dc:creator>doubt that my ISP Al Bradford</dc:creator><description>&lt;p&gt;&lt;p&gt;
All of the previous answers tell you why your code is wrong. But
the reason that your first post is in an infinite loop is beacuse
Keil forces an LJMP to main at the end of your code. This is to
prevent the very problem discribed, that is over running your code
with no possible exit from main. You can only prevent this by
inserting a proper &amp;#39;forever&amp;#39; loop.&lt;br /&gt;
Please read and run some of the sample code in the &amp;#39;Getting Started&amp;#39;
manual. This action is well defined in the manual.&lt;br /&gt;
Bradford&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PROBLEM WITH THE C CODE</title><link>https://community.arm.com/thread/124756?ContentTypeID=1</link><pubDate>Fri, 25 Jul 2008 06:28:44 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:8d7d6b8b-f6d1-4229-b549-e7a017cbd770</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;pre&gt;
while (1) {
    port1 = ~port1;
}
&lt;/pre&gt;

&lt;p&gt;
Why do you think that an infinite loop _around_ the code line that
inverts the pins should not result in constantly toggling pins?&lt;/p&gt;

&lt;p&gt;
What do you think happen if you add an empty infinite loop _after_
you have inverted the port pins once?&lt;/p&gt;

&lt;pre&gt;
int f = 0;
while (1) {
    if (f == 0) port1 = ~port1;
    f++;
}
&lt;/pre&gt;

&lt;p&gt;
What do you think happens when you keep on incrementing f again
and again? What will happen when f reaches the limit for possible
values?&lt;/p&gt;

&lt;p&gt;
By the way - why not post the source code as I do - formatted as
code and not inlined in the text?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PROBLEM WITH THE C CODE</title><link>https://community.arm.com/thread/124753?ContentTypeID=1</link><pubDate>Fri, 25 Jul 2008 06:27:33 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:114f16bd-b3b0-45f0-b0b5-6494fc287d49</guid><dc:creator>clever dick</dc:creator><description>&lt;p&gt;&lt;p&gt;
Think about what happens when f gets bigger than an int...&lt;/p&gt;

&lt;p&gt;
And if you post any more code, put the proper &amp;quot;pre&amp;quot; tags around it
so we can read it easier.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PROBLEM WITH THE C CODE</title><link>https://community.arm.com/thread/114064?ContentTypeID=1</link><pubDate>Fri, 25 Jul 2008 05:46:28 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:24b4d20d-2648-4388-a939-0ca0796a1dfd</guid><dc:creator>priyan ob</dc:creator><description>&lt;p&gt;&lt;p&gt;
Even if i add an infinite loop like&lt;/p&gt;

&lt;p&gt;
while(1)&lt;br /&gt;
{ port1 = ~port1;&lt;br /&gt;
} The same thing happens(actually that was my problem). It means that
i need to make it happen only once. I can do like below&lt;/p&gt;

&lt;p&gt;
int f=0;&lt;br /&gt;
while(1)&lt;br /&gt;
{ if(f==0) port1 = ~port1; f++;&lt;br /&gt;
} This keeps the statement port1= ~port1; happen only once
theoratically.But it doesnt actually.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PROBLEM WITH THE C CODE</title><link>https://community.arm.com/thread/100801?ContentTypeID=1</link><pubDate>Fri, 25 Jul 2008 05:33:07 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:16f9377f-c61c-424b-beb8-1da1592397cf</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
You have already been notified that your expectation that it is ok
to fall out of main() is ok.&lt;/p&gt;

&lt;p&gt;
Since it isn&amp;#39;t, change your code so that it doesn&amp;#39;t end. There are
no OS available to catch you, so add an infinite loop.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PROBLEM WITH THE C CODE</title><link>https://community.arm.com/thread/76415?ContentTypeID=1</link><pubDate>Fri, 25 Jul 2008 05:21:54 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:f8a8e3aa-cbab-421a-b170-28295387a680</guid><dc:creator>priyan ob</dc:creator><description>&lt;p&gt;&lt;p&gt;
Then please help me stating what should be the code for my
need.&lt;br /&gt;
The code should complement the port pins only once. Please help
me.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PROBLEM WITH THE C CODE</title><link>https://community.arm.com/thread/50083?ContentTypeID=1</link><pubDate>Sun, 22 Jun 2008 06:19:39 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:e3897373-fd2d-481a-9805-9599c26e2b80</guid><dc:creator>HansBernhard Broeker</dc:creator><description>&lt;p&gt;&lt;p&gt;
&lt;i&gt;but yu expect the port pins are complemented only once&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
No. We don&amp;#39;t expect that. You do.&lt;/p&gt;

&lt;p&gt;
We have read enough of the documentation, particularly the
tutorials, to know that falling through the end of main() is not
typically something one should do in an embedded C program if one
doesn&amp;#39;t want unexpected things to happen.&lt;/p&gt;

&lt;p&gt;
&lt;i&gt;What could be the wrong?&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;
Your expectations are.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: PROBLEM WITH THE C CODE</title><link>https://community.arm.com/thread/50081?ContentTypeID=1</link><pubDate>Sun, 22 Jun 2008 02:01:56 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:7c234bef-c4a8-41ff-a6cc-c5168580857e</guid><dc:creator>Catcus Blip</dc:creator><description>&lt;p&gt;&lt;p&gt;
priyan,&lt;br /&gt;
first of all, why don&amp;#39;t you place an infinite loop in main?&lt;br /&gt;
second, once your main terminates what happens is compiler dependent
- it might be that your processor repeatedly resets which is the
reason for the behavior you see.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>