This tutorial aims to explain the fundamentals of 8051 micro-controller family which are essential to understand for the beginners. We will first go through the history of 8051 family and its members. After that, we will understand the features of AT89S52 and functions of all pins. At the end, we will cover up the basic requirements of 8051 such as power supply, crystal circuit, reset circuit and pull up resistor on Port0 etc.
In 1980, Intel Corporation introduced the first micro-controller INTEL 8051A in the market. It was a 40 pin IC with DIP (Dual in Line Package) and 8 bit architecture which means all the registers associated with 8051 are of 8 bits (1 byte). Later on other manufactures such as Motorola, Philips, Atmel etc. were allowed to make their own versions with additional functionality sharing the same architecture, registers, pin out etc. This lead to a great tech war and various companies came up with ICs having different features making a huge family of controllers known as 8051 family.
All the members of 8051 shares the features which were incorporated in INTEL 8051A IC but they might have different set of additional features. From the family of 8051, we will consider AT89S52 IC from Atmel Incorporation. From now on-wards we will use 8051 to indicate a controller of 8051 family but always keep in mind that 8051 itself is not a controller but it is a controller family.
8051 controller has 40 pins from which 32 pins are available as GPIO (General Purpose Input/Output Pins). These 32 pins has been divided into 4 groups known as Ports. They are named as Port0, Port1, Port2 and Port3 which are accessed as P0, P1, P2 and P3 respectively. Remaining 8 pins are used for power supply, crystal pins, External access, ALE, PSEN and reset. Let’s understand the features of AT89S52, importance of all pins and basic hardware connections first.
Features of AT89S52
- Compatible with MCS®-51 Products
- 8K Bytes of In-System Programmable (ISP) Flash Memory (Endurance: 10,000 Write/Erase Cycles)
- 0V to 5.5V Operating Range
- Fully Static Operation: 0 Hz to 33 MHz
- Three-level Program Memory Lock
- 256 x 8-bit Internal RAM
- 32 Programmable I/O Lines
- Three 16-bit Timer/Counters
- Eight Interrupt Sources
- Full Duplex UART Serial Channel
- Low-power Idle and Power-down Modes
- Interrupt Recovery from Power-down Mode
- Watchdog Timer
- Dual Data Pointer
- Power-off Flag
- Fast Programming Time
- Flexible ISP Programming (Byte and Page Mode)
- Green (Pb/Halide-free) Packaging Option
Pin out of 8051 is as shown below. Four ports are named as P0, P1, P2 and P3. All pins can be used as GPIO. All port pins except Port0 has inbuilt pull-up resistor. On reset all pins are input pins by default. Some pins can perform alternate functions also. Let’s understand the functions of all pins.
Vcc (Pin40) and GND (Pin20)
Power supply for any circuit is as important as oxygen for humans. 8051 needs power supply in the range of 4V to 5.5V for its operation.
We have assumed input as 230, 50 Hz AC mains supply. Block Diagram for 5V DC power supply is as follows.
Circuit diagram for 5V DC supply is as shown below.
It is an active high input pin. To reset the controller, we need to hold reset pin at high logic for minimum two machine cycles. This is done with the help of a capacitor and resistor network.Whenever the capacitor is discharged and power supply is available, capacitor will start charging and provides logic high to reset pin. When capacitor is charged, it blocks DC and reset pin gets logic 0. A resistor is connected with capacitor to make sure that charging time of capacitor is higher than two machine cycle. This is known as power on reset.
When we want to reset the controller manually, a switch connected in parallel with the capacitor has to be pressed. When we press the switch, capacitor discharges and on release of switch it starts charging. Thus reset signal is applied when we release the switch.
It also plays an important role for ISP.
Circuit Diagram for Reset Circuit
XTAL1 (Pin 18) & XTAL2 (Pin 19)
Every micro-controller needs a square wave pulse of suitable frequency for its operation. This pulse controls the execution speed of the controller. Two pins (XTAL1 & XTAL2) has been provided for the connection of crystal oscillator. Both pins has to be connected to a ground through a capacitor of 33pf. Speed of execution depends upon the crystal oscillator connected between pins XTAL1 and XTAL2. However we cannot connect crystal of higher than the maximum frequency range of 8051 which is 33MHz.
Circuit Diagram for Crystal Oscillator
Pins 1 to 8 has been dedicated as Port1. INTEL 8051A had Port1 as GPIO only. Later on Timer/Counter 2 input pin (P1.0) and Timer/Counter trigger pin 2 (P1.1) has been added for AT89S52. Pins MOSI –Master out Slave in (P1.5), MISO- Master out Slave in (P1.6) and SCK- Serial Clock (P1.7) has been provided for SPI- Serial Peripheral Interface Protocol communication. This is also used for ISP- In System Programming.
Pins 10-17 has been dedicated as Port3. Although this port can be used as GPIO but it has a lot more tasks to be performed.
Pins P3.0 (RxD- Serial Input) and P3.1 (TxD-Serial Output) forms a full duplex UART (Universal Asynchronous Receive and Transmit) communication port. 8051 architecture based controllers from Philips such as P89V51RD2 uses this port for ISP-In System Programming.
P3.2 and P3.3 are for external interrupt0 and external interrupt1 respectively.
P3.4 and P3.5 are input pins for Timer/Counter 0 and Timer/Counter 1 respectively.
P3.6 (External memory data write strobe) and P3.7 (External memory data read strobe) are used for external memory interface.
Now as you can see, P3 can perform various tasks, we should not use that as GPIO unless we run out of the pins.
Pins 21 to 28 has been dedicated as Port2. It also acts as a higher order address bus when external memory has been interfaced with 8051.
Pins 32 to 39 has been dedicated as Port0. It also acts as a lower order address bus as well as data bus when external memory has been interfaced with 8051. But major difference is in the construction of this port. All ports except Port0 has in built pull-up resistors but Port0 is an open drain. When we want to utilize Port0 as GPIO, we need to connect external pull up resistor with port.
Circuit Diagram for Pull Up resistor on Port0
PSEN (Pin 29)
PSEN stands for Program store enable which is an output pin which is used for programming.
ALE (Pin 30)
It is an output pin which is used to differentiate working of Port0 as either address or data bus. When this pin is high (in first T clock of Machine read machine cycle), Port0 acts as a lower address data bus and when the ALE output is low, Port0 acts as a data bus.
EA (Pin 31)
8051 has on-chip memory. We can also interface external memory with 8051 and store the program in external memory. EA (External Access) pin is used to select the memory. When this pin is at high logic, internal memory is selected. 8051 family has some memory-less controller such as 8031. For this controller, EA pin has to be connected with ground. For remaining controllers, EA pin has to be connected with Vcc.
UART is one of the protocol generally used to communicate with various peripherals such as Zigbee, Bluetooth, GSM, GPS, RFID etc. 8051 micro-controllers from NXP (Philips) such as P89V51RD2BN uses the UART for loading the program inits memory. P3.0 is the receiver pin of 8051 while P3.1 is used to transmit data. These pins are TTL compatible which means logic 0 is 0V and logic 1 is 5V. However PCs(and some peripherals like GSM etc.) works with RS232 voltage standard which considers logic0 as +3 Vto +23V and logic1 is -3V to -23V. MAX232 IC with 4 external capacitors (or MAX233 IC without capacitors) can convert voltage of TTL to RS232 and vice versa.
Connection for UART with 8051 is as shown.
So now we can start experimenting with 8051. Let’s combine all circuits explained above and make a schematic which is given below.