<?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>Reading Pins</title><link>https://community.arm.com/developer/tools-software/tools/f/keil-forum/36913/reading-pins</link><description> Dear All, 
 
I&amp;#39;ve tried to read the pin of Port1 , but i failed . 
I should write one to it right ? , how do i read a one again ? 
If i tried to write the following code,it works without checking the status of the pin 
 
Port1_3=1; 
if(Port1_3==1) 
</description><dc:language>en-US</dc:language><generator>Telligent Community 10</generator><item><title>RE: Reading Pins</title><link>https://community.arm.com/thread/141624?ContentTypeID=1</link><pubDate>Tue, 09 May 2006 16:55:18 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:0ceb2297-5b37-45cb-ae9d-d4ec71eb145e</guid><dc:creator>Juna Adam</dc:creator><description>&lt;p&gt;thanks erik.&lt;br /&gt;
&lt;br /&gt;
I tried to use this code and it works in the simulator, could you tell me what&amp;#39;s ur opinion about it ? :&lt;br /&gt;
void main (void)&lt;br /&gt;
{&lt;br /&gt;
pin_4=1;&lt;br /&gt;
&lt;br /&gt;
while(1)&lt;br /&gt;
{&lt;br /&gt;
while (pin_4 !=1)&lt;br /&gt;
{&lt;br /&gt;
P2=0xFF;&lt;br /&gt;
DELAY_LOOP_Wait(90);&lt;br /&gt;
if ( pin_4==1)&lt;br /&gt;
{&lt;br /&gt;
p++;&lt;br /&gt;
if  ( p==5)&lt;br /&gt;
{&lt;br /&gt;
P2=0x00;&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reading Pins</title><link>https://community.arm.com/thread/149179?ContentTypeID=1</link><pubDate>Tue, 09 May 2006 16:14:34 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:c9b940bd-69de-41da-810e-7b4ebaf0b9b3</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;&lt;i&gt;&amp;quot; ... its supposed to be ... &amp;quot;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
1st law of programming: the compiler will do what you &lt;i&gt;&lt;b&gt;tell&lt;/b&gt;&lt;/i&gt; it to do; it will not attempt to second-guess what you actually &lt;i&gt;&lt;b&gt;wanted&lt;/b&gt;&lt;/i&gt; it to do!!&lt;br /&gt;
&lt;br /&gt;
So, if you actually write&lt;pre&gt;sbit P1_3=P1^3;

if ( P1_3==1)
{
   // execute ...
}&lt;/pre&gt;does it work?&lt;br /&gt;
&lt;br /&gt;
As Erik says, &amp;quot;P1_3&amp;quot; is a pretty meaningless name - in a real program, you should certainly choose something that&amp;#39;s actually descriptive;eg,&lt;pre&gt;sbit door_open = P1^3;

if ( door_open )
{
   // execute ...
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reading Pins</title><link>https://community.arm.com/thread/138203?ContentTypeID=1</link><pubDate>Tue, 09 May 2006 15:13:38 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:115b2920-9310-4254-9bf5-a698301e841f</guid><dc:creator>erik  malund</dc:creator><description>&lt;p&gt;&lt;i&gt;its supposed to be&lt;br /&gt;
sbit P1_3=P1^3;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
NO, do not use Px.y in code, only in definitions.  use something like&lt;br /&gt;
sbit    SBG_P1_USB_SSI  = 0x96; // USB SSI&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
a surefire way (TCON as an example):&lt;br /&gt;
&lt;br /&gt;
  sbit    SB_TCON_TF1    = 0x8F;&lt;br /&gt;
  sbit    SB_TCON_TR1    = 0x8E;&lt;br /&gt;
  sbit    SB_TCON_TF0    = 0x8D;&lt;br /&gt;
  sbit    SB_TCON_TR0    = 0x8C;&lt;br /&gt;
  sbit    SB_TCON_IE1    = 0x8B;&lt;br /&gt;
  sbit    SB_TCON_IT1    = 0x8A;&lt;br /&gt;
  sbit    SB_TCON_IE0    = 0x89;&lt;br /&gt;
  sbit    SB_TCON_IT0    = 0x88;&lt;br /&gt;
&lt;br /&gt;
This avoid ALL confusion.  I like to remove confusion, that keeps me more productive.&lt;br /&gt;
&lt;br /&gt;
I find using SB_TCON_ in the definitions very helpful (a global search on TCON gives all uses whether bit set ot SFR load) but, if you find that distasteful, the method works with any naming convention.&lt;br /&gt;
&lt;br /&gt;
Erik&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reading Pins</title><link>https://community.arm.com/thread/130046?ContentTypeID=1</link><pubDate>Tue, 09 May 2006 14:31:15 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:3494d347-6c79-41f7-9653-a95127dc9160</guid><dc:creator>Juna Adam</dc:creator><description>&lt;p&gt;sorry am newbie :-&lt;br /&gt;
&lt;br /&gt;
its supposed to be&lt;br /&gt;
sbit P1_3=P1^3;&lt;br /&gt;
&lt;br /&gt;
if ( P1_3==1)&lt;br /&gt;
{&lt;br /&gt;
// execute ...&lt;br /&gt;
}&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reading Pins</title><link>https://community.arm.com/thread/123237?ContentTypeID=1</link><pubDate>Tue, 09 May 2006 12:24:22 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:01643915-2938-4d24-a478-8956eeb60c95</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;You are using the &amp;#39;^&amp;#39; incorrectly!&lt;br /&gt;
&lt;br /&gt;
&lt;pre&gt;if ( P1^3==1)&lt;/pre&gt;Here it has the ANSI standard meaning.&lt;br /&gt;
&lt;br /&gt;
If you want the Keil-specific meaning, you can only do that as part of an &lt;b&gt;sbit&lt;/b&gt; or &lt;b&gt;bit&lt;/b&gt; definition&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.keil.com/support/man/docs/c51/c51_le_sbit.htm"&gt;http://www.keil.com/support/man/docs/c51/c51_le_sbit.htm&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://www.keil.com/support/man/docs/c51/c51_le_bitaddrobj.htm"&gt;http://www.keil.com/support/man/docs/c51/c51_le_bitaddrobj.htm&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
I think Keil must&amp;#39;ve done this deliberately to catch our newbies - it caught me out the first time!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reading Pins</title><link>https://community.arm.com/thread/112089?ContentTypeID=1</link><pubDate>Tue, 09 May 2006 10:16:37 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:7f882652-0451-467c-abf6-c300bf5bab6b</guid><dc:creator>Juna Adam</dc:creator><description>&lt;p&gt;Thanks Andy ,&lt;br /&gt;
If the externally-applied signal is 1, you read 1&lt;br /&gt;
&lt;br /&gt;
yea ,that&amp;#39;s what i need , but when writting if ( test pin ==1) in Keil C51 the next expression is executed whatever happens .. there&amp;#39;s no checking occurs&lt;br /&gt;
e.g&lt;br /&gt;
if ( P1^3==1)&lt;br /&gt;
{&lt;br /&gt;
P2=0x00; // P2 will be zeros in&lt;br /&gt;
//the simulator , cuz P1^3 is initially&lt;br /&gt;
//set to 1 , so how do i check then for&lt;br /&gt;
// a 1 again ??&lt;br /&gt;
}&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reading Pins</title><link>https://community.arm.com/thread/98071?ContentTypeID=1</link><pubDate>Tue, 09 May 2006 06:06:36 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:dbf2a803-eb8c-47a4-a42b-952da7041142</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;You just read it.&lt;br /&gt;
&lt;br /&gt;
If the externally-applied signal is 1, you read 1; it it&amp;#39;s zero, you read zero.&lt;br /&gt;
&lt;br /&gt;
Think about this:&lt;br /&gt;
The standard 8051 IO ports &amp;amp; pins don&amp;#39;t have direction registers (unlike some other processors).&lt;br /&gt;
The output &amp;quot;latch&amp;quot; has to be set to something, and that can only be 0 or 1&lt;br /&gt;
So, which are you going to choose - will it be 0, or will it be 1?&lt;br /&gt;
&lt;br /&gt;
What would happen if you chose 0?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reading Pins</title><link>https://community.arm.com/thread/74022?ContentTypeID=1</link><pubDate>Tue, 09 May 2006 03:28:18 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:f89f3007-916b-44b0-89f8-6901524a499a</guid><dc:creator>Juna Adam</dc:creator><description>&lt;p&gt;thanks ,&lt;br /&gt;
Neil Kurzman&lt;br /&gt;
yes , i mean P1^3.&lt;br /&gt;
&lt;br /&gt;
Andy , thanks , i read them but i still didnt figure out how can i read an input 1 on the pin :(.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reading Pins</title><link>https://community.arm.com/thread/46031?ContentTypeID=1</link><pubDate>Tue, 09 May 2006 01:02:52 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:93590f59-235e-486f-ad2f-661a05d77d07</guid><dc:creator>Andy Neil</dc:creator><description>&lt;p&gt;Look at the description of the port operation in chapter 3 of the so-called &amp;quot;bible&amp;quot; for the 8051:&lt;br /&gt;
&lt;br /&gt;
Chapter 3 - 80C51 Family Hardware Description:&lt;br /&gt;
&lt;a href="http://www.semiconductors.philips.com/acrobat/various/80C51_FAM_HARDWARE_1.pdf" target="_blank"&gt;http://www.semiconductors.philips.com/acrobat/various/80C51_FAM_HARDWARE_1.pdf&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Page 3 describes what happens when you write a &amp;#39;1&amp;#39; to a port bit; now think about what happens when an external circuit tries to force that to &amp;#39;0&amp;#39; or &amp;#39;1&amp;#39;...&lt;br /&gt;
&lt;br /&gt;
The so-called &amp;quot;bible&amp;quot; is absolutely fundamental to your understanding of the 8051 and its derivatives; the other 2 chapters are:&lt;br /&gt;
&lt;br /&gt;
Chapter 1 - 80C51 Family Architecture:&lt;br /&gt;
&lt;a href="http://www.semiconductors.philips.com/acrobat/various/80C51_FAM_ARCH_1.pdf" target="_blank"&gt;http://www.semiconductors.philips.com/acrobat/various/80C51_FAM_ARCH_1.pdf&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Chapter 2 - 80C51 Family Programmer&amp;#39;s Guide and Instruction Set:&lt;br /&gt;
&lt;a href="http://www.semiconductors.philips.com/acrobat/various/80C51_FAM_PROG_GUIDE_1.pdf" target="_blank"&gt;http://www.semiconductors.philips.com/acrobat/various/80C51_FAM_PROG_GUIDE_1.pdf&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
You should download these, familiarise yourself with their content, and keep them constantly to hand for reference!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Reading Pins</title><link>https://community.arm.com/thread/46030?ContentTypeID=1</link><pubDate>Tue, 09 May 2006 00:48:02 GMT</pubDate><guid isPermaLink="false">dd9e70c8-6d3c-4c71-b136-2456382a7b5c:a0e40d01-f829-4fa9-92cf-aa49ad90c17d</guid><dc:creator>Neil Kurzmam</dc:creator><description>&lt;p&gt;What is the definition of &amp;quot;Port1_3&amp;quot;&lt;br /&gt;
Port 1 is P1&lt;br /&gt;
Port 1 bit 3 is P1^3&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>