AT89c51 GPIO interfacing

Thread Starter

Chetan_Jadhav

Joined Mar 2, 2017
52
Hi there,
I have just read the theory about internal architecture of 8051 I/O ports.
According to theory P1 to P3 should be HIGH if they are to be used as input ports.Because if PORTS are LOW then the internal mosfet will always hold pin status as low (Refer the attached diagram )and cant be changed ...making it useless as an input port.
so I tried to test this condition, I made Port1 LOW... connected an active HIGH switch to P1.0 pin and read the pin status after pressing switch and found it high.
and now I am pretty much confused about how it is becoming high and how things are going on inside? please help me to understand it.
here is my assembly code. I have also attached the simulation result (I found same results on hardware too) and PORT internal structure.

Code:
]org 0
mov p1,#0x00 ; [B]PORT 1 intentionally made 00 so internal MOSFET is now active and 'should not' allow PORT pin to be high by switch[/B]
REP:
jnb p1.0,$ ;wait here till switch is not pressed (please refer the schematic for connections )
lcall delay
mov a,p1 ;Read PORT1 to Accumulator
mov p2,a ;show contents of accumulator to PORT2()
sjmp REP
delay:
mov r3,#1
XYZ:
mov r1,#255
ABC:
mov r0,#255
djnz r0,$
djnz r1,ABC
djnz r3,XYZ
RET
end
Mod edit: code tags - JohnInTX
 
Last edited by a moderator:

ronsimpson

Joined Oct 7, 2019
2,985
According to theory P1 to P3 should be HIGH if they are to be used as input ports..........................
I made Port1 LOW... connected an active HIGH switch to P1.0 pin and read the pin status after pressing switch and found it high.
Change to "I made Port1 HIGH... connected and pull down switch to the pin. ……"
 

JohnInTX

Joined Jun 26, 2012
4,787
Change to "I made Port1 HIGH... connected and pull down switch to the pin. ……"
+1. The reason you are seeing the switch pull the LOW output high is that the MOSFET on the port still has some resistance when it is on. The power supply is more than capable of supplying enough current to drive the pin high across this resistance. It also can destroy the MOSFET. Not recommended.
 

MrChips

Joined Oct 2, 2009
30,706
Don't wire a switch directly between Vcc and a GPIO, ever.
Use a resistor (1k - 10kΩ) in series with the switch to limit the current.
 

Thread Starter

Chetan_Jadhav

Joined Mar 2, 2017
52
+1. The reason you are seeing the switch pull the LOW output high is that the MOSFET on the port still has some resistance when it is on. The power supply is more than capable of supplying enough current to drive the pin high across this resistance. It also can destroy the MOSFET. Not recommended.
Thanks a lot ... finally I got my doubt solved.
 

Thread Starter

Chetan_Jadhav

Joined Mar 2, 2017
52
Hi,
I have made an AT89S52 board on zero pcb ( the schematic is shown in the attachment)and burned the below code in controller.
The problem is PORT 0 is always HIGH(0XFF). all the other ports are showing expected result(0XAA). I have tried keeping Pin PSEN both HIGH and LOW but nothing worked.
I have also checked resister pack connections and the resistance between port pins and VCC. it is also correct.
PORT 2 has the same kind of res pack and same connections and its working fine, so what could be wrong with PORT 0?
Any kind of help is appreciated.
Thanks!!!
Code:
org 0
mov a,#0xaa
mov P0,a
mov P1,a
mov P2,a
mov P3,a

sjmp $
end
89s52.png
 
Last edited:

Thread Starter

Chetan_Jadhav

Joined Mar 2, 2017
52
PSEN/ is an output and should not be connected to +5V.
EA/ should be connected to +5V to enable internal program memory.
Other than that, it looks OK.
ok now I disconnected the PSEN from vcc and dumped the same code but even then the problem remains.
by the way I checked voltages at PSEN = 5V , ALE=1.5V , EA=5V.
so what is causing the problem?
 

JohnInTX

Joined Jun 26, 2012
4,787
Sorry. I don't know.

Does the assembler give any errors or warnings?
You might look at the list file to see if the correct hex instruction codes are being generated.
The accumulator is usually specified as 'A'. Are you sure that the lower case is defined?
 

Thread Starter

Chetan_Jadhav

Joined Mar 2, 2017
52
Sorry. I don't know.

Does the assembler give any errors or warnings?
You might look at the list file to see if the correct hex instruction codes are being generated.
The accumulator is usually specified as 'A'. Are you sure that the lower case is defined?
Hi,
sorry but I just found out that my chip was faulty with PORT 0 . Now I changed the chip and everything is working as expected.
Thanks for the help.
 
Top