Using usbasp and avrdude to program 89s52


I’m working on a project that requires the use of an 89s52. Well, it requires a 8051 footprint compatible part but I want In-System-Programability (ISP). So I need to be able to program the 89s52.

The cheap options for programming 89s52 parts are not that well documented on the web. More important, I already have a usbasp. Google’ing hints that it should be possible to program these guys with a usbasp, but there is lots of conflicting information.


Well, it is possible, but it requires some adjustments to the usbasp firmware and some additions to avrdude’s conf. The setup I’m describing is this post is one I’ve used to successfully program an 89s52 and an ATMega328p. Hopefully, no existing functionality is lost.

The firmware here has my changes.

I also have it here untar’ed:

This is my avrdude.conf file:


What did I do?

I started with the information here: In particular, it contains a link to a version of usbasp firmare that should work, but I wasn’t able to get it to work. I can’t really say I tried super hard. The issue I had was the it seemed incompatible with recent avrdude versions. Given my new familiarity with the firmware quoted, it should work.

Anyway, the modified firmware was done on top of the original 2005 firmware. I took that diff and applied it to the most recent 2011 version. This process was pretty educational. There are a bunch of statements out there that are misleading, so I’ll try to dispell some of the. To be clear, I take no credit for any of the changes. I just merged to latest and tweaked a wee bit. The main point is that the version posted here works for me using avrdude 5.10 and a cheap ebay usbasp on 89s52 and ATMega328p. This the command I used:

 avrdude -c usbasp  -p 8052 -b 200 -U flash:w:blink.hex:i

It’s just the reset signal. One common statement that’s made is about how the 89s52 (and all other 8051 parts) reset signal is active high whereas most modern microcontrollers are active low. While this is true, it’s not enough to invert reset. There are several other ways that the usbasp assumes it’s dealing with normal AVR parts that also have to be addressed.

Is anyone out there? The most important trick that these modifications add is a stronger dependency on calling out to the part: "are you an AVR part?" Silence. Ok are you an 89s part? These calls are referred to as "Program Enable" in the datasheets and they are done differently between the two familes. In particular, AVR parts respond on the third byte. 89S parts respond on the 4th. Also, the responses are different. Again, the usbasp knows what it’s calling out to and it’s expecting a certain response. No amount of inverting changes that. It’s a neat trick though. Flash reset, try AVR call/response. Try flashing reset again (this time active high) and try 89S. I could imagine extending this trick further for other products that support serial programming

Change programming assumptions. Once this call/response process matches a product family, the usbasp will know what it’s dealing with and apply the proper assumptions; ones that are appropriate to that part. All of that can be taken into account.

  • Read and write are a bit different. The address component of a read/write instruction is shifted over one. sort of.
  • AVR parts can be programmed using the hardware serial support. usbasp can communicate with this or it has a software implementation. The 89S52 I tried it with didn’t seem to like the hardware way, but software works well.


usbasps can be purchased off of ebay for less than $4 delivered to American doors. You really can’t beat that. I suggest getting more than one. You can use one to program the other, but more interesting, you could reprogram them to do non-flash programming functions. Two or three AA batteries and you have a 4 I/O microcontroller. I haven’t tried this yet, but $4 is certainly less than Arduinos cost. Puts them in "Jelly Bean Part" territory.

I think this is potentially one of my more useful blog posts. If you find it helpful, please do comment and let me know. I’d be curious to hear what projects folks are working on.






11 thoughts on “Using usbasp and avrdude to program 89s52”

  1. It’s an intriguing looking board but but at $199, it seems expensive.

    I’ve worked with the old serial cable based mindstorms and it’s very nice. I would guess that the NX update is a great buy. That’s the direction I would go.

  2. thanks dude,,,,,,,for this post,,,,,really helpful…i also visited the same post & has same problems………now its done ……..thanks ………

  3. I tried your firmware hoping that since it could program the 89S52 it could also program the 89S4051. The firmware caused the LED’s to quit working on the USBASP programmer (bought on email, very common (LC Soft Technology).

    Reprogrammed with the “standard” hex file and programmers were revived (except for one, which I think is more a failure at the uC level than any firmware).

    Thanks for your efforts and maybe one day I can find the magical hex file that will allow me to program the 89S4051.

  4. I know this post is from 5 years ago but I’m hoping you might have an answer as I’ve search and searched. As you said there is a lot of conflicting information. I’m trying to use an USBASP with AVRDUDE to program a AT89S8252. From my understanding it’s an odd ball. A 8051 based chip with eeprom and ISP. My main issue is trying to access the eeprom. I’m pretty sure it’s an issue with the AVRDUDE config file but I haven’t figured it out. Any help would be much appreciated!

    1. Hi Jon,
      looking at the datasheets, I see some similarities between your part and the one I used (89s52). Our parts both want RST to be high. I believe that’s controlled in the function (of usbasp) ispConnect. The 328p used in many arduinos wants low. My part and the 328p have 4 byte programming codes but return a 0x53, mine on the 4th byte, 328 on the third (though you have to read the text to know that “the second byte (0x53), will echo back when issuing the third byte of the Programming Enable”. Your datasheet has no mention of 0x53 though is does mention that you should use the 89s53 but sadly, its programming interface is the 4 byte one, also with no mention of 0x53. Not all hope is lost, however, the important part of usbasp code is isp.c which weighs in at only 335 lines. Note that in order to update firmware on usbasp, you need a second one, or an arduino. Pretty simple though. Just connect the two with the ribbon and set the jumper of the one being programmed.
      Hope that helps, and thanks for commenting. It’s good to know that folks out there read my blog.

  5. Hi Miles,

    I came across your blog because I searched for a way to program an AT89S52 with a USBASP. Your blog seemed exactly what I was looking for. So I took one of my USBASPs and flashed your modified firmware (main.hex from usbasp.2012-07-20_89s52.tgz) onto it. I connected the lines MISO, MOSI, SCK, and RST from the USBASP to the AT89S52 (as reset circuit I used a 10uF between +5V and RST and a 10kOhm between RST and GND – is this correct?). I also connected a 4MHz quartz with 33pF caps and verified that the oscillator is working (with an oscilloscope). Also I connected the AT89S52 /EA VPP (pin31) to +5V. I added the entries for the AT89S52/AT89S51 (from your avrdude.conf) to my avrdude.conf (I tried avrdude versions 5.1 and 6.1).
    However, I am not successful to get a connection to my AT89S52; I get the following with
    this command line: avrdude -p 8052 -c usbasp -b 200 -t
    avrdude: error: programm enable: target doesn’t answer. 1
    avrdude: initialization failed, rc=-1
    The same error occurs when I try to actually flash the AT89S52 with
    avrdude -p 8052 -c usbasp -b 200 -U flash:w:a.hex:i
    My USBASP with your modified firmware is working OK when flashing AVRs, however (I tried a ATMEGA8 so far).
    I am obviously missing something, maybe you can help me nailing down my problem.
    Thanks in advance,


    1. It’s been a long time since I’ve worked with the at89s2; grain of salt needed.

      If I recall correctly, my version of the firmware needed to mess with the RST and I want to say that this kept normal devices (at89s2 is the outlier) from programming. Since you say that the atmega8 works, I wonder if you’ve successfully programmed your programmer. Again, I’m going from memory.

      Do look at the other comments to this post. There are some details in there on how to debug the programming process. There are a couple parts of the datasheet that, if you understand them, give valuable context to getting this to work. When I initially did this work, I wrote a simple arduino bitbaning thing to get the at89s2 to say “hello, you want to program me”. You send it a code and it responds with a specific other code.

      Just doing that gave me the knowledge I needed to understand the usbasp firmware (which is actually pretty simple).

      Hope that helps. Either way, it’s nice knowing that someone out there is reading, and perhaps benefitting from, some of my posts.

      1. Hi Miles,

        thanks for replying.
        I am actually sure that I flashed my USBasp correctly with your firmware, because when I try to program a AT89S52 the RST line does what it is supposed to do with a AT89S52, i.e. it is pulled HIGH when trying to communicate with the MCU (checked with oscilloscope). However, my AT89S52 doesn’t respond at all: I checked the MISO line with my oscilloscope: there is no activity whatsoever (there is plenty of activity on the MOSI line when the USBasp tries to communicate). I have the feeling that the AT89S52 chips I have are somehow locked or otherwise not programmable, even though the quartz is oscillating – I got these chips cheaply via ebay from China. I guess I have to get some AT89S52 from a reputable source and try again…

        Thanks and regards,


      2. Hi Miles,

        I finally figured it out: the trick is to use the correct reset circuit. In my case it was sufficient to only use a 10 kOhm from GND to the RST-Input of the AT89S52, i.e. omitting the 10 uF I had in before (everything else is like in my first post from October 10th) – maybe this also helps others struggeling with programming the AT89S52. Now I can program the AT89S52 using your modified firmware for the USBASP and avrdude – thanks a lot for making the firmware and source available!



Leave a Reply

Your email address will not be published. Required fields are marked *