<?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>Pin reading Problem with at89c2051</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/31382/pin-reading-problem-with-at89c2051</link><description> 
i use at89c2051 micro controller there is a problem with reading
the pin value after declaring pin 1(input pin)......controller gives
wrong execution... 

 
i already declare pin as a input pin i also place meaningfull part
of code.. 

 
 i also do</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: Pin reading Problem with at89c2051</title><link>https://community.arm.com/thread/107514?ContentTypeID=1</link><pubDate>Wed, 19 Feb 2014 07:46:07 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:f0c66434-db5f-4344-bf69-3af6e98dc3ef</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
But some interesting things here:&lt;/p&gt;

&lt;pre&gt;
 if(AUTO==ON)
  {event=0;}
else if(AUTO==OFF)
  {event=1;}
&lt;/pre&gt;

&lt;p&gt;
You do an assign to &amp;quot;event&amp;quot; that is never used for anything.&lt;/p&gt;

&lt;p&gt;
Next thing - you treat &amp;quot;AUTO&amp;quot; as if it was a variable that can
take more than two states. ON or OFF or something else.&lt;/p&gt;

&lt;p&gt;
And you do two reads of AUTO which mean that a toggle of AUTO
while you read it can actually result in your code neither setting
event=0 nor event=1.&lt;/p&gt;

&lt;pre&gt;
while(1)
{
  if(AUTO==ON)
  {LED1=ON;}
   else if(AUTO==OFF)
  {LED2=ON;}
}
&lt;/pre&gt;

&lt;p&gt;
&lt;br /&gt;
You have no code line anywhere in your loop that assigns LED1=OFF.
And no line that assigns LED2=OFF.&lt;/p&gt;

&lt;p&gt;
And here too, you do two reads which means the state decision
isn&amp;#39;t atomic. And you treat the AUTO pin as potentially having more
than two states.&lt;/p&gt;

&lt;p&gt;
You haven&amp;#39;t documented how LED1 and LED2 are connected - it isn&amp;#39;t
really obvious that&lt;br /&gt;
LED1=ON (nonzero) actually means a lit LED. Note that it is more
common to let processor pins sink current, so a high pin means the
LED is off, and a low pin means current goes from VCC through a
current-limiting resistor, through the LED and then into the
processor pin and down to ground. Lots of microcontrollers can sink
way more current than they can source.&lt;/p&gt;

&lt;p&gt;
Have you looked at how much current your processor pins can
actually source? Or do you help them by having an external pull-up
resistor intended to supply the actual LED current and then have the
processor pin short the LED?&lt;/p&gt;

&lt;p&gt;
Another thing people forgets to think about: What state does the
processor pins have when the processor is in reset state? Are the
LED:s (or maybe relays or whatever is connected) expected to be
active when the processor is in the reset state?&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Pin reading Problem with at89c2051</title><link>https://community.arm.com/thread/117493?ContentTypeID=1</link><pubDate>Wed, 19 Feb 2014 06:45:00 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:e93da4c7-da7b-4a67-b9e9-319870f80e76</guid><dc:creator>shailesh patel</dc:creator><description>&lt;p&gt;&lt;p&gt;
yes per, i also not like such a code...which only turn on
led......and also not like code which turn on led wrongly without
taking care of pin reading value.....and that&amp;#39;s why i posted a
problem.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Pin reading Problem with at89c2051</title><link>https://community.arm.com/thread/81717?ContentTypeID=1</link><pubDate>Wed, 19 Feb 2014 06:42:48 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:5205d91d-db75-4ccc-95ee-e9bb5c456aee</guid><dc:creator>shailesh patel</dc:creator><description>&lt;p&gt;&lt;p&gt;
yes, there are many lines but it is a short part of
debugging....this code is created to analyze controller function or
execution...which is nearly same....as main code.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Pin reading Problem with at89c2051</title><link>https://community.arm.com/thread/107512?ContentTypeID=1</link><pubDate>Wed, 19 Feb 2014 06:01:09 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:ba30ab0c-5027-4958-9858-ff9188da5555</guid><dc:creator>ImPer Westermark</dc:creator><description>&lt;p&gt;&lt;p&gt;
I don&amp;#39;t much like code that can turn on a LED but not turn it off.
Or who can turn off a LED but not turn it on.&lt;/p&gt;

&lt;p&gt;
Somehow, I feel there is a logic error introduced somewhere in the
thought process.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Pin reading Problem with at89c2051</title><link>https://community.arm.com/thread/81719?ContentTypeID=1</link><pubDate>Wed, 19 Feb 2014 05:27:45 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:fad8fa84-2afd-4069-93cb-5f0a5d16ce80</guid><dc:creator>Jeff Mulhoon</dc:creator><description>&lt;p&gt;&lt;p&gt;
Very simple code. You could try it in the uVision simulator.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Pin reading Problem with at89c2051</title><link>https://community.arm.com/thread/62584?ContentTypeID=1</link><pubDate>Wed, 19 Feb 2014 04:45:04 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:af54a1b1-3265-40b4-861e-5c83a6202b72</guid><dc:creator>Kevin Broeker</dc:creator><description>&lt;p&gt;&lt;p&gt;
Sorry. Your program is too complex for me to understand.&lt;/p&gt;

&lt;p&gt;
I think there are too many lines of code in your function.&lt;/p&gt;
&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>