Understanding the AT89S52’s pin configuration

Thread Starter

@vajra

Joined May 2, 2018
154
I am confused about how to configure ports of AT89S52. It has four I/O ports where in each port contains 8 pins that can be configured as inputs or outputs. It can be configured as input or output depends on logic state.

In order to configure a pin of AT89S52 as an output, it is necessary to send a logic zero (0) to the port pins. In this case, the voltage level at the appropriate pin will be 0.

Similarly, in order to configure a pin of AT89S52 as an input, it is necessary to send a logic one (1) to the port pin. In this case, the voltage level on the appropriate pin will be 5V.

C:
#include <REG51.h>
                
sbit Switch  = P0^1;    //switch connected to P0.1
sbit LED     = P2^0;    //LED connected to p2.0

#define  ON    1
#define  OFF   0

#define  High  1
#define  Low   0

void main (void)
{
       Switch = High;    //Set P0^1 as input pin by making it high
  
       LED = Low;        //Set P2^0 as output pin by making it low

        while(1)
       {
                if(Switch == ON)      //Check switch
                {
                   LED = ON;             // Turn on LED
                }
                else
                {
                     LED = OFF;         // Turn off LED
                }
       }
}
I haven't tested this code. I have doubt on the input & output configuration. Can we set all port in same way

Configure port pin as input
Code:
P0^1 = 1;
P1^1 = 1;
P2^1 = 1;
P3^1 = 1;
Configure port pin as output
Code:
P0^1 = 0;
P1^1 = 0;
P2^1 = 0;
P3^1 = 0;
 

Ian Rogers

Joined Dec 12, 2012
820
In order to configure a pin of AT89S52 as an output, it is necessary to send a logic zero (0) to the port pins. In this case, the voltage level at the appropriate pin will be 0.
You do not need to worry yourself over the output.

As the 8052 has such a basic port hardware, the manufactures suggest writing a 1 to a port BEFORE you apply a high voltage level, if the port is at zero and you apply 5v on the pin...... Pooof!!! no pin left.... If the port is high and 5v is switched... no problem... If the port is high and 0v is applied the internal pullup allows the port to be read as a zero safely..
 

Papabravo

Joined Feb 24, 2006
15,092
The 8051 architecture has what is known as a quasi bi-direction port pin structure. Outputs have an active hard pulldown transistor that will sink a reasonable amount of current: several milliamperes. The have a weak transistor pullup that will source only a small amount of current; maybe 100 micro amperes. An output high can be pulled to a logic low by an external source without damaging the part. This structure predated the true bi-directional port structure on the Motorola and MOS Technology parts of the middle 70's
 

Thread Starter

@vajra

Joined May 2, 2018
154
You do not need to worry yourself over the output..
The code I posted is working. I just tested code by replacing pins. It's also working

Code:
#include <REG51.h>             
sbit Switch  = P2^1;    //switch connected to P2.0
sbit LED     = P1^0;    //LED connected to p1.0
Thank you for response. I understood the pin configuration of 8051
 
Top