The AT89C51 is Atmel’s version of the 8051. The original 8051 series (also known as MCS-51) designed by Intel was discontinued in 1996. More than 20 major companies still produce their variants of the 8051 or other uC using 8051’s IP cores. Atmel’s version of the 8051 is the most popular one out there. You are most likely using this to study right now.
The only difference between the original 8051’s architecture and the AT89c51’s architecture is that the latter has 4KB of on-chip programmable flash memory. This allows for faster development since the flash memory can be erased in a few seconds. Although, you will need an external programmer/burner that supports flash memory to program it.
Where can I buy an external programmer for the AT89c51?
- You can buy this programmer. It supports a wide variety of chips so you can use it for a lot of other projects. Very versatile and useful.
- Or you can just get an 8051 development board.
In this article, we will just discuss all the functions of the 40 pins that you can see protruding out the sides of the AT89C51 and everything else that you can physically see when you hold your microcontroller.
You don’t have to memorize the pin locations (unless you are taking an exam that requires you to). You will almost always have the datasheet on hand when working on actual projects. The purpose of discussing the pins and their functions is to understand what the microcontroller is capable of doing. It might not give you the complete picture of all the functionalities at first, but it is a great place to start from. Once you go through the architecture and internal structure, the picture will get clearer. Similarly, once you start getting acquainted with more microcontrollers, you will be able to predict the internal architecture to some extent by just looking at the pin configuration.
Pin configuration of the AT89C51 and the function of each pin
Port 0 (P0.0/AD0 to P0.7/AD7)
- It can be used as a simple 8-bit bidirectional input/output port. What that essentially means is that you can connect any input device like a sensor or any output device like an LED to any of these pins.
- Or it can be used as a bidirectional lower address byte and data bus for connecting to external memory. Whenever the microcontroller needs to access external program/data memory, the lower byte of the 16-bit address is generated by Port 0 (If 34FF H were the hex address of the external memory, FF would be generated by Port 0)
- It does not have internal pull-up resistors. You’ll have to manually connect pull-up resistors if you want to use the port pins as output. In general, a pull-up resistor is required to make sure that the input line to an electronic logic gate does not get short-circuited and has a stable value.
Port 1 (P1.0 to P1.7)
- Most basic port of all. No dual function. It can be used as an 8-bit bidirectional I/O port.
- It has internal pull-ups, so no need to connect any resistors manually.
- It is an input port by default (i.e., on reset). Alternatively, you can write 1 (FF H) to all pins to set it as an input port.
- It can be used as a simple 8-bit bidirectional input/output port like Port 0 and Port 1.
- Or it can be used as a bidirectional higher address byte and data bus for connecting to external memory. Whenever the microcontroller needs to access external program/data memory, the higher byte of the 16-bit address is generated by Port 2 (If 34FF H were the hex address of the external memory, FF would be generated by Port 0 and 34 would be generated by Port 2)
- Upon Reset, it will be configured as an input port by default. Alternatively, just as with Port 1, you can write FF H to all pins.
Port 3 (P3.0 to P3.7; Pins have alternative functions too)
- Together with the three ports mentioned above, Port 3 makes up the fourth 8-bit bidirectional I/O port.
- It has internal pull-up resistors like Port 1 and Port 2. On;y Port 0 doesn’t have any internal pull-ups.
- It is an input port by default or can be made one by writing 1 to all pins.
- Interestingly, the pins of Port 3 have dual functions. When they are not being used as input or output ports, they can perform several nifty applications, as shown in the table below. We will take a detailed look into these alternate functions in succeeding articles.
|P3.0||RXD||Serial data input|
|P3.1||TXD||Serial data output|
|P3.4||T0||External Timer Input 0|
|P3.5||T1||External Timer Input 1|
|P3.6||External Data Memory Write Pulse|
|P3.7||External Data Memory Read Pulse|
An interesting fact about these ports is that they are bit addressable along with being byte-addressable.
This is the pin that will save you when you are confused, don’t know what the heck is going on, or just want to clear register memory to start afresh. Send a high pulse for at least two machine cycles through this tiny metal pin, and you will wipe the registers and set all ports to their default configurations. Nifty.
ALE stands for Address Latch Enable. In AT89C51, the lower 8 bits of the 16-bit address bus are multiplexed with the data bus. To separate these 8 bits, the ALE pin is kept high. It is an output pin that is used when we are connecting to external extra memory chips.
Program Store Enable
If we are going to use an external memory chip to store the program (the code), then this pin, which is an output pin, is connected to the pin of the external memory chip. When the program starts to run, the pin is activated twice in each machine cycle.
EA stands for external access enable. It is used with pin to access external memory. When we wish to access the code stored in an external memory chip, the pin should be connected to GND. If we wish to access the on-chip program memory, then it should be connected to Vcc.
XTAL1 and XTAL2
XTAL 1 is an input pin, and XTAL2 is an output pin. The 8051 has an on-chip oscillator, which requires an external clock signal to run. This clock signal can be supplied via
- A crystal oscillator – A crystal oscillator of the same frequency (or less) as that of the on-chip oscillator is connected with 22pF capacitors between XTAL 1 and XTAL 2.
- External clock/frequency source – If something else, like a TTL oscillator, is used, then it should be connected just to XTAL1 and XTAL2 should be left open.