0
\$\begingroup\$

I am designing a simple circuit with AT89S52 micro controller. I set the I/O pins as high and when the switch is pressed will get connected to ground. And in my program I check for I/O pins as 0 and on 0 will set pin 1.5 as high and the LED will glow.

But the pins 2.0 to 2.7 is not working as expected. These pins are always high even the switch is pressed. Kindly check the attached image and suggest me if anything is wrong.

Kindly check my circuit

\$\endgroup\$
  • \$\begingroup\$ Is this a homework question? If not, what is the purpose of R1,R3 and how did you calculate the values? If so, then please show your attempt to answer the question. \$\endgroup\$ – Spehro Pefhany Apr 23 '17 at 12:53
  • \$\begingroup\$ actually I had designed LEDs earlier in those pins. But I forget to remove it later. Well, I am using simple logic like.. if(P0_0 == 0) { P1_5 = 1 } if(P2_0 == 0) { P1_5 = 1 } \$\endgroup\$ – Hari Hara Krishnan Apr 23 '17 at 13:26
  • \$\begingroup\$ @SpehroPefhany, This is not a homework. I am new to electronics. I am learning my self. \$\endgroup\$ – Hari Hara Krishnan Apr 23 '17 at 13:39
  • \$\begingroup\$ @SpehroPefhany, This is not a homework. I am new to electronics. I am learning my self. \$\endgroup\$ – Hari Hara Krishnan Apr 23 '17 at 13:39
  • \$\begingroup\$ The internal pull-ups are something like 50uA so the resistors are at least part of your problem. Follow Tony's suggestions. \$\endgroup\$ – Spehro Pefhany Apr 23 '17 at 13:42
1
\$\begingroup\$

You need to change your circuit and possibly your software.

The I/O pins are the so-named quasi-bidirectional standard for the MCS-51. These have internal pull-ups and open-drain transistors to drive them low. The pin input level can be read directly and there is no distinct 'input mode' or 'output mode'.

Remove R3 and R1. Connect each of your switches across an I/O pin and GND. Now, when a switch is closed, the I/O pin's internal pull-up is shorted to GND and the I/O pin reads logic '0'. When a switch is open, the internal pull-up pulls the pin high and it reads logic '1'.

In your software, write each port's SFR with 0FFh to drive out logic high. Then you can read each port's SFR to get the switch states.

\$\endgroup\$
  • \$\begingroup\$ Hi I removed the resistance. And connected the switch to the ground and the I/O pins to the other end of the switch. Now it is working for Pin 2 But not Pin 0. What could be the issue. I am new to electronics. Kindly help \$\endgroup\$ – Hari Hara Krishnan Apr 23 '17 at 13:27
  • \$\begingroup\$ I initialized the pins as high like this. P0_0 = 0xFF; P0_1 = 0xFF; P0_2 = 0xFF; P0_3 = 0xFF; P0_4 = 0xFF; P0_5 = 0xFF; P0_6 = 0xFF; P0_7 = 0xFF; P2_0 = 0xFF; P2_1 = 0xFF; P2_2 = 0xFF; P2_3 = 0xFF; P2_4 = 0xFF; P2_5 = 0xFF; P2_6 = 0xFF; P2_7 = 0xFF; Then, In my code I used to check like this if(P0_0 == 0) { P1_5 = 1 } if(P2_0 == 0) { P1_5 = 1 } \$\endgroup\$ – Hari Hara Krishnan Apr 23 '17 at 13:29
  • 1
    \$\begingroup\$ Hi @HariHaraKrishnan, I can't debug the whole thing for you in a series of comments - edit your question to add the software or other things if need to. Please know that this site cannot teach you electronics or C on an AT89S52, you'll have to learn that elsewhere. Meanwhile, if P0_0 is a bit, why write 0xFF to it? And why write all P0/P2 bits one at a time? Change to write P0 (not P0_x) with 0xFF, and write P2 with 0xFF. Read datasheet (www.atmel.com/images/doc1919.pdf). P1.5 can't source hi LED current, only sink low current. Connect 5V->1K->LEDA->LEDK->P1.5. On is P1_5=0, off is P1_5=1. \$\endgroup\$ – TonyM Apr 23 '17 at 15:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.