Parts
AT89S52 8051 microcontroller: pinout, ports, ISP pins and a minimal circuit
By Bulan Sarkar
The AT89S52 has the standard 8051 DIP-40 pinout: Port 1 on pins 1 to 8, RST on 9, Port 3 on 10 to 17, the crystal on 18 and 19, ground on 20, Port 2 on 21 to 28, then PSEN, ALE and EA on 29 to 31, Port 0 on 32 to 39 and VCC on 40. Port 0 is open drain, so its pins need pull-up resistors to drive a high, and EA must be tied to VCC for the chip to run its own flash.
Below: which chip you have, the ratings from the Atmel AT89S52 datasheet (1919D, now hosted by Microchip), what each port does, and a minimal circuit with an 11.0592 MHz crystal and the reset time worked out. The AT89C52 and AT89S51 datasheets cover the substitutes. For a pin-by-pin table of all 40 pins, see our 8051 pin diagram and pin description.
Pinout by package
Top view, notch up: pin 1 (P1.0) top left, pins 1 to 20 down the left side and 21 to 40 back up the right.
Port 0 has no pull-ups of its own. Fit 4.7 to 10 kΩ on P0.0 to P0.7 if you use them as outputs.
Source: Microchip (Atmel) AT89S52 8-bit Microcontroller with 8K Bytes In-System Programmable Flash, p. 2 (40-lead PDIP pin configuration with alternate functions); Microchip (Atmel) AT89S52 8-bit Microcontroller with 8K Bytes In-System Programmable Flash, p. 4 (Port 0 open drain; P1.5, P1.6, P1.7 are MOSI, MISO, SCK for in-system programming); Microchip (Atmel) AT89S52 8-bit Microcontroller with 8K Bytes In-System Programmable Flash, p. 34 (ordering codes AT89S52-24PU and -33PU in the 40P6 0.600 inch PDIP)
Same top view and the same 40 pins; P1.5 to P1.7 carry no ISP function.
Source: Microchip (Atmel) AT89C52 8-bit Microcontroller with 8K Bytes Flash, p. 1 (PDIP pin configuration; "Not Recommended for New Designs. Use AT89S52."); Microchip (Atmel) AT89C52 8-bit Microcontroller with 8K Bytes Flash, p. 3 (pin description: Port 0 open drain, RST high for two machine cycles)
Which one do you have?
A through-hole AT89S52 is marked AT89S52-24PU or AT89S52-33PU. The number is the top clock: 24 MHz on a 4.0 to 5.5 V supply, or 33 MHz on 4.5 to 5.5 V. PU is the 40-pin 0.6 inch PDIP; AU and JU are the 44-lead TQFP and PLCC, which number their pins differently.
The AT89C52 in older kits has the same pins and Timer 2 but no in-system programming, and the AT89S51 is the 4 KB version without Timer 2. Chips from other makers sold as "89S52 compatible" are outside this page: check their own datasheet, above all for how they are programmed.
Absolute maximum ratings
The AT89S52 and AT89C52 datasheets give the same absolute maximums. Where they part company is the working supply: 4.0 to 5.5 V for the S52, 5 V ± 20% for the C52. Run either at 5 V, and treat the 15 mA DC output current as a ceiling, not a working figure: the steady-state limit in the DC table is 10 mA per pin.
| Parameter | AT89S52DIP-40 | AT89C52DIP-40 |
|---|---|---|
| Voltage on any pin | −1.0 V to +7.0 V | −1.0 V to +7.0 V |
| Maximum operating voltage | 6.6 V | 6.6 V |
| DC output current | 15.0 mA | 15.0 mA |
| Operating temperature (absolute) | −55 to +125 °C | −55 to +125 °C |
| Storage temperature | −65 to +150 °C | −65 to +150 °C |
Ports, pin levels and supply current
| Parameter | AT89S52DIP-40 | AT89C52DIP-40 |
|---|---|---|
| Operating supply VCC | 4.0 to 5.5 V (4.5 to 5.5 V for the 33 MHz grade) | 5 V ± 20% |
| Clock | 0 to 33 MHz | 0 to 24 MHz |
| Flash write/erase cycles | 10,000 | 1,000 |
| Programming | serial ISP on P1.5 to P1.7 with RST high, or parallel | parallel programmer only |
| Crystal capacitors C1 = C2 | 30 pF ± 10 pF | 30 pF ± 10 pF |
| Input high, XTAL1 and RST VIH1 | 0.7 VCC min | 0.7 VCC min |
| RST pull-down resistor RRST | 50 to 300 kΩ | 50 to 300 kΩ |
| Output low, ports 1 to 3 VOLIOL = 1.6 mA | 0.45 V max | 0.45 V max |
| Output low, Port 0, ALE, PSEN VOL1IOL = 3.2 mA | 0.45 V max | 0.45 V max |
| Output high, ports 1 to 3 VOHIOH = −60 µA, VCC = 5 V ± 10% | 2.4 V min | 2.4 V min |
| Logical 1 to 0 transition current ITLVIN = 2 V, ports 1 to 3 | −300 µA max | −650 µA max |
| Sink current, steady stateper pin / per port / all pins | 10 mA / 26 mA (P0), 15 mA (P1 to P3) / 71 mA | 10 mA / 26 mA (P0), 15 mA (P1 to P3) / 71 mA |
| Supply current, active ICC12 MHz | 25 mA max | 25 mA max |
| Supply current, power-down ICC | 50 µA max at 5.5 V | 100 µA max at 6 V |
Port 0 (pins 39 to 32) is open drain. It can sink eight TTL loads, but writing a 1 only lets the pin float: there is no pull-up inside unless Port 0 is acting as the external address and data bus. Used as plain I/O it needs a resistor to VCC on every pin.
Ports 1, 2 and 3 have internal pull-ups. A 1 written to the pin makes it an input; a pin pulled low from outside then sources up to 50 µA, and up to 300 µA while it swings through 2 V. The pull-ups are weak: a high output is promised only 2.4 V at 60 µA, so these pins sink current well and source almost none. P1.0 and P1.1 double as Timer 2 inputs, P1.5 to P1.7 carry the ISP signals, Port 2 gives the high address byte for external memory, and Port 3 carries RXD, TXD, INT0, INT1, T0, T1, WR and RD.
ALE (pin 30) pulses at one sixth of the crystal frequency while the chip runs. PSEN (pin 29) is the read strobe for external program memory. EA (pin 31) chooses where code comes from: tied to VCC, the internal flash; tied to ground, external memory from address 0000H.
What it is good for
- Learning the 8051 instruction set and its timers, serial port and interrupts on a chip that sits in a breadboard or ZIF socket.
- 5 V control boards with up to 32 I/O lines: relays through driver transistors, keypads, seven-segment and character LCD displays.
- Keeping an existing 8051 design or lab kit running, since the pinout matches the AT89C52 and AT89S51.
It is the wrong chip for anything new that needs an ADC, PWM hardware, 3.3 V logic or low sleep current. An ATmega328P does all of those in a smaller package.
Worked example: the minimal AT89S52 circuit
A 5 V supply, an 11.0592 MHz crystal, a power-on reset, EA tied high and pull-ups on Port 0: the least the chip needs to run its own program and talk over its serial port.
1. Why 11.0592 MHz. With Timer 2 as the baud generator, the baud rate is the crystal frequency / (32 × N), N being a whole number (p. 15). At 11.0592 MHz, 9600 baud needs N = 36, 19,200 needs 18 and 115,200 needs 3: every one exact. At 12 MHz the nearest N gives 9615 baud for 9600 (+0.16%), 18750 for 19,200 (-2.34%) and 125000 for 115,200 (+8.51%).
2. What it costs. A machine cycle is 12 oscillator periods (p. 12): 1.085 µs at 11.0592 MHz instead of a round 1 µs at 12 MHz. Delay loops need slightly odder counts.
3. Crystal capacitors. The datasheet asks for 30 pF ± 10 pF on each side, so 20 to 40 pF. We use 33 pF.
4. Reset. RST must be high for two machine cycles while the oscillator runs (p. 5): 2.17 µs. The datasheet gives no start-up time for the crystal, so the reset pulse is made far longer. A 10 µF capacitor from VCC to RST and 10 kΩ from RST to ground give τ = 10 kΩ × 10 µF = 100.0 ms. RST reads high above 0.7 VCC = 3.5 V (p. 29), so after power-up it stays high for τ × ln(1 / 0.7) = 35.7 ms.
5. Allow for the internal pull-down. RST has its own 50 to 300 kΩ to ground. At 50 kΩ it sits in parallel with the 10 kΩ, making 8.33 kΩ and a reset of 29.7 ms. Either way that is more than ten thousand times the 2.17 µs minimum.
6. EA and Port 0. EA (pin 31) goes straight to VCC. Port 0 gets a 10 kΩ pull-up per pin; one 9-pin resistor network holds all eight. The lowest value that keeps a low pin inside its 3.2 mA test current is (5 − 0.45) V / 3.2 mA = 1.42 kΩ; 10 kΩ sinks 0.5 mA per pin, 4.0 mA for all eight against the 26 mA port limit.
The RC time constant calculator redoes step 4 for other parts, and the RC time constant lesson explains the curve.
Worked example in numbers
- Reset held high
- 35.7 ms
- Machine cycle
- 1.085 µs
- Port 0 pull-ups
- 8 × 10 kΩ
- ISP clock below
- 691.2 kHz
Tips and checks
- Drive LEDs by sinking: anode to 5 V through a resistor, cathode to the pin, lit on a 0. For eight red LEDs of about 2 V on Port 1, (5 − 2 − 0.45) V / 1.6 mA = 1.59 kΩ, so 1.8 kΩ: 1.4 mA each and 11.3 mA for all 8, inside the 15 mA port limit (Figure 5).
- The 10 mA per-pin limit does not add up across a port. Eight pins at 10 mA would be 80 mA on a port allowed 15. Anything brighter needs a transistor per pin.
- Write a 1 to a pin before reading it as an input, on every port. On Port 0 the input also needs its pull-up, or an open button reads as noise.
- For in-system programming, the programmer holds RST high and clocks SCK below one sixteenth of the crystal: 691.2 kHz at 11.0592 MHz. The 10 µF reset capacitor does not get in the way.
- Put the 100 nF decoupling capacitor across pins 40 and 20 at the chip, and keep the crystal and its two capacitors within a couple of centimetres of pins 18 and 19.
At 10 kΩ, a Port 0 pin charging only its own 10 pF has a time constant of 100 ns. Long wires add capacitance; drop to 4.7 kΩ if edges on a long cable look slow.
Substitutes: AT89S51 and AT89C52
Both share the 40-pin layout. The AT89S51 loses memory and Timer 2; the AT89C52 loses in-system programming and speed.
| Part | Pins | Verdict |
|---|---|---|
| AT89S51 | Same 40 pins | Same pins, same ISP pins and the same 33 MHz limit, but half the flash (4 KB), half the RAM (128 bytes) and no Timer 2. Fine for small programs that never touch T2 or the upper 128 bytes of RAM.Microchip (Atmel) AT89S51 8-bit Microcontroller with 4K Bytes In-System Programmable Flash, p. 1; Microchip (Atmel) AT89S51 8-bit Microcontroller with 4K Bytes In-System Programmable Flash, p. 2 |
| AT89C52 | Same 40 pins | The older part the AT89S52 replaced: same pins, same 8 KB and Timer 2, but 24 MHz at most, 1,000 flash cycles and no ISP, so it needs a parallel programmer. Atmel marked it not recommended for new designs.Microchip (Atmel) AT89C52 8-bit Microcontroller with 8K Bytes Flash, p. 1 |
Bench check: is it running?
- Measure 5 V from pin 40 to pin 20, and 5 V on EA (pin 31).
- RST (pin 9) should jump to 5 V at power-up and fall to near 0 V within a fraction of a second. Stuck high means a shorted capacitor or a missing resistor to ground.
- Put a frequency counter or scope on ALE (pin 30). A running chip shows 1.8432 MHz, one sixth of the crystal. Nothing there means the oscillator is not running or the chip is held in reset (unless the program has turned ALE off).
- Read the signature with the ISP programmer: an AT89S52 answers 1EH, 52H, 06H. A different answer or none at all means wiring, RST not held high, or a different chip.
What we'd do
Use the AT89S52-24PU at 5 V with an 11.0592 MHz crystal and 33 pF capacitors, 10 µF and 10 kΩ on RST, EA tied to VCC, a 10 kΩ network on Port 0 and 100 nF across the supply pins, and program it in circuit through P1.5 to P1.7. Sink LEDs at about 1.4 mA each, put a transistor on anything heavier, and choose a newer chip for new designs that need an ADC or PWM.
Questions people ask
What is the AT89S52 pinout?
Pins 1 to 8 are P1.0 to P1.7, 9 RST, 10 to 17 P3.0 to P3.7, 18 XTAL2, 19 XTAL1, 20 GND, 21 to 28 P2.0 to P2.7, 29 PSEN, 30 ALE, 31 EA, 32 to 39 P0.7 to P0.0 and 40 VCC.
Why does Port 0 need pull-up resistors?
Its outputs are open drain: they can pull a pin low but have nothing to pull it high. Without a resistor to VCC, a pin written to 1 floats. 4.7 to 10 kΩ per pin is the usual fit.
Why is an 11.0592 MHz crystal used with the 8051?
It divides exactly into the standard baud rates. Timer 2 needs a divider of 36 for 9600 baud and 3 for 115,200, both whole numbers; a 12 MHz crystal misses 115,200 by 8.5%.
What does the EA pin do?
It picks the program memory. Tied to VCC the chip runs from its internal 8 KB flash; tied to ground it fetches from external memory. During parallel programming the same pin takes the 12 V programming voltage.
AT89S52 or AT89C52: what is the difference?
Same pins and Timer 2. The S52 programs in circuit through P1.5 to P1.7, runs to 33 MHz and takes 10,000 flash rewrites; the C52 needs a parallel programmer, stops at 24 MHz and is rated for 1,000.
How do you program an AT89S52?
Hold RST high, then send the programming commands on MOSI (P1.5) with the clock on SCK (P1.7), reading back on MISO (P1.6). That is the reverse of an AVR, which holds its reset low while it is programmed.
Buying the AT89S52 in India
The AT89S52-24PU is widely sold by Indian component shops and in 8051 starter kits. Read the full marking: AT89S52 rather than AT89C52 if you plan to program it with an ISP programmer, and check the signature once it is in a socket. Buy the crystal as 11.0592 MHz specifically; 11 MHz and 12 MHz parts look the same. Our guide to buying electronic components in India compares ten online sellers and covers how to spot fakes.
One email a month from the bench
New circuits, lessons, part guides and calculators, on the first Sunday of each month.
Used in these lessons
Lessons that go deeper
Datasheets this page was checked against
- Microchip (Atmel), AT89S52 8-bit Microcontroller with 8K Bytes In-System Programmable Flash (1919D–MICRO–6/08)
- Microchip (Atmel), AT89C52 8-bit Microcontroller with 8K Bytes Flash (0313H–02/00)
- Microchip (Atmel), AT89S51 8-bit Microcontroller with 4K Bytes In-System Programmable Flash (2487D–MICRO–6/08)
Makers revise datasheets. If the copy you download has a newer revision and a number here disagrees with it, the datasheet wins, and we would like to hear about it.