Programming the AT89S52 with Arduino (and avrdude)


The AT89S52 microcontroller from the Atmel family is a popular and versatile microcontroller utilized in many embedded system applications. While there are many ways to program this microcontroller, one of the most innovative methods involves using an Arduino board as a programmer in conjunction with the 'avrdude' software.

The AT89S52 is an 8-bit microcontroller with 8KB of flash programmable and erasable read-only memory (PEROM). It comes with 32 I/O lines, three 16-bit timer/counters, a six-vector two-level interrupt architecture, and a full-duplex serial port, making it suitable for a wide range of applications.

Why Use Arduino?

Using an Arduino board as a programmer for the AT89S52 offers several advantages:

Cost-Effective

No need to invest in expensive dedicated programmers.

Accessibility

Most developers already have an Arduino board on hand.

Flexibility

The Arduino environment is open-source and adaptable for various tasks.

Software Setup

Installing avrdude

Avrdude is an open-source tool that allows for communication with microcontrollers through a programmer.

To install in Linux:

sudo apt-get install avrdude 

To install in windows:

Download .zip file and extract in your C drive.

Set this directory path in System or User Environment variables.

Arduino Setup:

  • Open the Arduino IDE.
  • Select Arduino Comm Port
  • Go to Examples-> ArduinoISP-> Open this sketch, compile it, and upload it to your Arduino.
  • Close the Arduino Ide.

Setting Up the Hardware

Components Required

  1. AT89S52 Microcontroller
  2. Arduino board (Uno or Nano recommended)
  3. Breadboard and jumper wires
  4. 11.0592 MHz crystal oscillator
  5. Two 22pF capacitors
  6. 10uF capacitor and 10k resistor

Connection

  • Connect the XTAL1 and XTAL2 pins of the AT89S52 to the crystal oscillator.
  • Connect the two 22pF capacitors from each leg of the crystal to the ground.
  • Reset the AT89S52 by connecting a 10k resistor from the Reset pin to VCC and a 10uF capacitor from the Reset pin to Ground.
  • Connect the MOSI, MISO, SCK, and RESET pins of the Arduino to the appropriate pins of the AT89S52.

Programming the AT89S52

  1. Launch the Command Prompt or Terminal.
  2. Execute the following command:(Replace you hex file path with at89s52.hex and your Arduino COMM Port with COM14)
C:\avrdude>avrdude -c stk500v1 -b 19200 -p at89s52 -P COM14 -U flash:w:at89s52.hex:a


avrdude: AVR device initialized and ready to accept instructions
avrdude: device signature = 0x1e5206 (probably 89S52)
avrdude: Note: flash memory has been specified, an erase cycle will be performed.
         To disable this feature, specify the -D option.
avrdude: erasing chip

avrdude: processing -U flash:w:at89s52.hex:i
avrdude: reading input file at89s52.hex for flash
         with 74 bytes in 2 sections within [0, 0x846]
avrdude: writing 74 bytes flash ...
Writing | ################################################## | 100% 1.80 s
avrdude: 74 bytes of flash written
avrdude: verifying flash memory against at89s52.hex
Reading | ################################################## | 100% 0.61 s
avrdude: 74 bytes of flash verified

avrdude done.  Thank you. 
Loading...

Search