An Arduino-based programmer for the AT89C2051 chip – part 2

Part 1

Here’s the software necessary to work the programmer board:

Arduino sketch (for Arduino Mega 2560)

PC program See also part 3 with a Python program that runs under Linux

Here’s a screenshot of the program in operation.  It should all be fairly self-explanatory.  Please send me a comment if you have any problems or questions.

89C2051screenshot

Update January 2024. Fixed a slight bug in the Arduino sketch. It only affected the reading of the chip when lock bit 2 (verify disabled) was set. When the lock bit is set, the program cannot be read out of the chip, and when a byte is read, the P1 outputs of the chip just float (high impedance state). After the update, the Arduino sets its pins connected to P1 in the INPUT_PULLUP mode when reading – so in the lock bit set case, all the bytes will read as 0xFF and the chip will be reported to appear empty. Previously, depending on what operations had been carried out before reading, the Arduino inputs could have been in INPUT, rather than INPUT_PULLUP mode – this gave inconsistent readings, usually 0xFE or 0xFC. Anyway, now fixed.

Update January 2021. Thanks to Marco Almeida, who built one of these gadgets, and reported errors when reading a program from the Chip. He solved the problem by reducing the baud rate at which the Arduino communicates with the PC program – previously it was 57600, and Marco reported that he’d had success at 9600. I was able to reproduce the bug at 57600 baud. I don’t know why it worked previously – I think maybe an update to the Arduino release, default optimization settings, etc, pushed it over the edge. Anyway, I found that mine worked reliably at 19200 baud, so I’ve now modified and uploaded both the Arduino Mega sketch, and the PC program to work at that new reduced speed. It’s still plenty fast enough, only taking a couple of seconds to write, read, or verify a program using all the AT89C2051’s flash memory. The download links haven’t changed, but if you installed the programs prior to January 2021, you should probably uninstall your old copy, and update to the current one.

To reliably program a chip, you need to use the Erase function first. I usually erase, then read the chip (to check it’s empty), then load the hex file, write it to the chip, verify, and power down. Very occasionally, I’ll get a verify error, but a second pass through the above sequence has always resulted in success, so far!

You can buy programmers for the AT89C2051 (and other similar chips) on AliExpress for less than twenty dollars, and if you just want to program chips, that’s an easier way to go!


Posted

in

,

by

Tags:

Comments

43 responses to “An Arduino-based programmer for the AT89C2051 chip – part 2”

  1. borya avatar
    borya

    Hi.
    I need a flash AT89C2051 controller for the stereo system. I want to repeat your programmer. Tell me, please, can I replace the transistor BC337 to transistor BC817?

    thanks!
    regard, B

    1. ceptimus avatar
      ceptimus

      Hi borya

      Yes, the BC817 will work well. You can use any general purpose NPN transistors for this project.

  2. borya avatar
    borya

    Thank you. I will try

  3. natraj avatar
    natraj

    Can you send me analog propeller clock source code and circuit diagram using arduino through mail

    1. ceptimus avatar
      ceptimus

      Hi natraj,

      There is a link to download the source code on the page ‘POV source code – part 2’. Here’s a copy of the link:

      http://ceptimus.co.uk/POVclockMain.c

      If you click on that it might just display the source in a window, but you should be able to right-click and ‘save as…’

      All the source is in that one file.

      The YouTube video shows how to connect the Arduino: https://youtu.be/Xy8lKjUCEk8

      Look in the description of that video and there are some links to download the Arduino sketch.

  4. Daniel Denis avatar
    Daniel Denis

    Hi ceptimus, can you send me the PC program source code please… Thanks

    1. ceptimus avatar
      ceptimus

      Hi Daniel

      I never really intended to publish the source code, so it’s not as well structured or well commented as it should be, but here you go.

      PC program source code for AT89C2051Programmer

  5. cesco avatar
    cesco

    Cant make this work reliably. I can read and i can erase “sometimes” but not always. I cannot read signature, i cannot program the chip. The PC program seems quite flaky.

    1. ceptimus avatar
      ceptimus

      Have you measured the voltages produced by the charge pump and the zenner / transistor circuit? Mine seems to work 100% reliable – sorry that you’re having problems with your version.

  6. cesco avatar
    cesco

    I do use external 12V source. I do manually switch from 12V to 5V and back. Only 2 resistor and 1 transistor. The hardware works, i can program the chip.

    I did simplyfy the code and send commands / data with a terminal program now. This works reliably. I use hex2bin to convert the hex to binary, then hterm “send file” to upload the data.

    I think the PC app has some problems.

    1. Vasile avatar
      Vasile

      Thank you very much Ceptimus, works perfectly.

    2. San Zamoyski avatar

      Hi Cesco!
      I was thinking if setting RST to GND is necessary. Do You use only 5V and 12V, without ever setting RST to GND? I’m going to use nano as programmer, so I need to modify somehow ino.
      Can You describe in details how to send binary with some terminal software? Or Your modified ino file.
      I’m working on linux, so PC program won’t propably work…

      Regards!

  7. borya avatar
    borya

    Hi, ceptimus!
    I assembled the programmer according to Your circuit. It seems to be working. I can read the signatures, I can read the controller’s memory (but it’s empty). When I try to download the firmware into the program, I get an error “Line 1 of file does not start with a colon”.
    Can You help me?

    1. borya avatar
      borya

      I think the problem is one hundred firmware in the BIN format. I downloaded the converter, converted it to HEX. Uploaded it to the program. But got the error “hex file extends beyond memory size (2048 bytes)”
      Took another file that weighs 2kB, first was 3kB. converted it to HEX, uploaded to the program. good, there is no error.
      Write it to the chip. Then I read the chip. And I see discrepancies. The FF structures are listed as 7F, there are still discrepancies. Tell me, what’s wrong? Where I was mistaken?

  8. borya avatar
    borya

    I compared two files. There are a lot of mistakes. I can attach the result of the comparison

    1. ceptimus avatar
      ceptimus

      Hi borya,

      If something is being written to the chip, but some bits are missing (e.g. 7F instead of FF), then I would first check the programming voltage while the chip is being programmed. Do you have a voltmeter? The circuit has to provide 5V and 0V to the chip when it is being read normally – and then 12V while programming. The diode capacitor circuit driven by the two Arduino pins should generate more than that – maybe 15V or so – as long as it’s more than 12V that’s fine as the zener diode then regulates it down to 12V. Try to erase the chip back to blank (or use another one if you have one) and try again. If you want to email me the two files, I can try to compare them and see if I can work out what might be going wrong. You can email to ceptimus@ceptimus.co.uk

      If it’s not the programming voltage, another problem might be a bad connection or short on the pins connecting from the twin row of I/O on the Arduino Mega to the pins on the chip. If you disconnect your board from the Arduino and also remove the chip from the programming socket, then you should carefully check that all the connections are as they should be and you don’t have any accidental shorts between adjacent pins.

  9. borya avatar
    borya

    ceptimus, thanks for your reply.
    I wrote to you email

  10. Bogdan avatar
    Bogdan

    hi, I ‘ve maked your programmer but is not giving 12v on reset pin.
    can you help me?

    1. ceptimus avatar
      ceptimus

      Yes, I’ll try. Do you have any sort of oscilloscope available? Or maybe a multimeter that can show frequency as well as volts, etc.?

  11. Shanjaq avatar
    Shanjaq

    Hi, is the Arduino sketch compatible with Arduino Uno or Diecimila or similar “normal” Arduino? I have a ModernDevices RBBB based on ATMega328, and I’m not sure why all parallel programmers I’ve found use the Arduino Mega? Thanks!

    1. ceptimus avatar
      ceptimus

      It’s just that the Mega328 Arduinos don’t have enough free pins to connect to all the pins on the AT89C2051 and still have pins to drive the voltage multiplier and select the programming voltage. Remember that you have to leave pins 0 and 1 free for serial communication with the PC. It is just about possible to get a 328 to do the job as not every pin on the AT89C2051 is needed for programming, and some of the Arduino’s pins could be used for more than one function. It’s a lot easier to do with a Mega 2560, and the layout of the double-row of I/O pins on the 2560 board makes routing the connections to the target AT89C2051 easier.

  12. PANKAJ MAHENDRA PANDIT avatar
    PANKAJ MAHENDRA PANDIT

    Hello sir,
    Thanks for giving us solution for AT89C2051.
    I got one error while uploading hex file, while loading simple hex file it shows error that, Hex file extends beyond memory. But hex file which I trying to upload was blinking led.

  13. LuWi avatar
    LuWi

    This is super. I made little changes for UNO and it works fine!

  14. vik avatar
    vik

    This horror is pumped with 12 volts. Why is it not possible to have a second power supply for 12 and control via a transistor switch from an Arduino pin?
    I also don’t understand what Python does. Well, if the sketch is already loaded into the IDE, then why use Python?

    1. ceptimus avatar

      Certainly you can use a 12V supply if you have one available. There is already a transistor that switches the 12V in my design – it’s just that the 12V comes from the charge pump, which for most users is more convenient than needing a separate 12V supply.
      The reason for the Python (or the C# program) is to allow your main PC to control the Arduino, and transfer hex files that contain AT89C2051 code, to and from the Arduino. The Arduino sketch doesn’t contain the program (8051 code) for the AT89C2051 – the Arduino, with its sketch, is just a tool for programming the target chip – when you change your AT89C2051 code, there’s no need to alter or reupload the Arduino sketch.

  15. r.s.kamath avatar
    r.s.kamath

    exit status 1
    vppinfra/types.h: No such file or directory

    1. ceptimus avatar

      This happened when trying to compile the Arduino sketch in the Arduino IDE?
      Some of the editions of the IDE – especially the ‘app’ ones, are missing some of the header files. If you do an online search for “Arduino types.h” you’ll find you can download it and place it in the folder where the compiler says it’s missing from – in your case vppinfra.
      If you’re able to try a fresh installation of the Arduino IDE, possibly on a different PC, that may be a simpler way. Go for the full installed IDE, not the ‘app’ version.

  16. Phil Karza avatar
    Phil Karza

    I am a little more than a noob but not a pro with the schematic – did you ever make a bom for the parts? I’d like to build this but want to make sure that I order everything at one time. I’m just going to point to point wire it – and it looks like fun.

  17. Allen Bong avatar
    Allen Bong

    Nice project. I am recently playing with 89c4051 and I’d like to make my own programmer for it. Will try this out this weekend…

    Thanks so much.

  18. Freddie Barros avatar
    Freddie Barros

    Hi,

    I am just building the hardware for this, so have not looked at everything so apologies if already explained…

    Could you please explain the purpose of ‘VCC’ on MEGA pin 35 and also AT89C051 pin 20.

    Mega ‘HIGH’ needs to connected to ‘HIGH’ at transistor
    Mega ‘A’ needs to be connected to ‘A at C1…………etc,

    so the ‘VCC’ is confusing! Is this just 5V?

    Thank you – I have already used your UNO nano reader

    1. ceptimus avatar

      The VCC (20) pin on the AT89C2051 is just its power supply – so when it’s in normal operation this would be connected to 5V or whatever voltage supply it’s running from.
      When chips are being programmed, it’s better if the programmer can switch the chip off except when power is actually needed for reading or programming the chip. That way, if you’re programming several chips, one after the other, it’s safer to insert and remove them from the programmer while the programmer is still powered on.
      The AT89C2051 draws very little power from its VCC pin, so the Arduino Mega can easily provide that power from one of its standard digital output pins. The Arduino just switches the pin HIGH to provide power, or LOW to switch the chip off.
      I chose to use pin 35 on the Arduino Mega to do that. I labelled it VCC on the diagram because it has to connect to pin 20 on the AT89C2051 – and that pin has the label VCC on the chip’s datasheet. Sorry that it’s a bit confusing. This VCC is different to the Arduino’s own VCC (5V) pin. I probably should have labelled it with some other name to avoid confusion.
      I put a decoupling capacitor, C2, to ground from that connection, on the diagram, because the AT89C2051 data sheet says that its power supply should be decoupled like that. The Arduino output pin has no problem driving such a small value capacitor. The programmer would probably work fine without that capacitor fitted, but I’ve not tested that.

    2. ceptimus avatar

      The other labels on the diagram, ‘A’, ‘HIGH’, etc., are just a way of drawing the diagram so that there aren’t lots of lines crossing over each other. Any wires on the diagram labelled ‘A’ (there are only two on this diagram) are connected to each other – all the ‘HIGHS’ are connected to each other, and so on.

      1. Freddie Barros avatar
        Freddie Barros

        Thank you again – that makes things clear !!

        have drawn a line from MEGA pin 35 to AT89C2051 pin 20 :-))))

        I will ask another another question to confirm understanding at the top thread level. Thanks

  19. Freddie Barros avatar
    Freddie Barros

    Hi again,

    Please confirm that the purpose of the two transistors are to switch RST/VPP between ‘0V’ and ‘5V’. So when the transistors are not driven RST/VPP reverts to 12V (for programming)?

    Thanks

    1. ceptimus avatar

      Yes, that’s right. The voltage on that pin has to be set at one of three levels – 0V, normal 5V (VCC) level, and 12V for programming a byte to the chip’s flash memory. Toggling between 0V and 5V switches from chip reset to chip normal running, and 12V has to be applied to program each byte to the flash. So the Arduino Mega switches the pin labelled ‘HIGH’ to a high state to make the RST/VPP pin about 5V, or it can switch the pin labelled ‘LOW’ to a high state to pull the RST/VPP pin down close to 0V. When it leaves both the ‘HIGH’ and ‘LOW’ pins in the low state, then neither of the transistors Q1 and Q2 are on, and the RST/VPP pin then rises to the 12V level, supplied by the charge pump voltage multiplier, and regulated by the 12V zener diode.

      1. Freddie Barros avatar
        Freddie Barros

        Thank you yet again…….. I recently bought an AT89C2051 based clock kit and it did not work, so i am determined to find out why :-)).

  20. Freddie avatar
    Freddie

    Hi,

    You already answered my last question a few posts above this. My apologies.
    Thanks

  21. Freddie avatar
    Freddie

    This programmer really works !!!!!

    After a few of rookie mistakes (like leaving MEGA pin 8 connected to RST/VPP) it worked flawlessly!! The pump circuit gave me 18.7 volts, I was so stunned :-)))))). Built on vero/strip board. I note you had test code in the MEGA code for the voltages (commented out).

    Got my £4.99 Clock kit working by reprogramming the original source code from a Github site.

    Thank you !!!!!!!!!

    1. ceptimus avatar

      I’m glad it’s working for you!
      You could now try my alternate firmware for your clock kit – you can always go back to the standard firmware if you don’t like it. Some people have reported that my version keeps better time. I’ve also done some alternate firmware that allows the kit to be used as a stopwatch, rather than a clock. You can find details on my YouTube site, and maybe somewhere in this blog.

  22. Freddie avatar
    Freddie

    Regretfully, my clock kit is the far simpler one using the 4401 AS1-30 4 digit (with seconds) display (not the ‘3-button’ 6 digit one).
    There has been a spate of these where the firmware was actually the ascii file of the firmware and not the compiled version.

    1. ceptimus avatar

      You could likely edit my code to work with it – just don’t connect anything to the two ‘select seconds digit’ outputs. I also did a version for the single button version (still with 6 digits though). There are three versions of that code: one runs it as a stopwatch; one as a 12-hour clock; and one as 24-hour clock. See here: https://youtu.be/QaYYkiHG2Io?si=qoXyOqr_bV_8Pe9J
      I’ll add one of the 4-digit kits to my next Ali Express order, and eventually I’ll post a YouTube and/or blog with code for that version.

  23. Freddie avatar
    Freddie

    I last programmed in assembly on something called the MK14 (pre Sinclair).
    It had a Zilog Z80 cpu.

    I am using the ‘ruthsarian’ (Github) firmware for my version of the clock kit.

    https://youtu.be/OIdR2x1GxLo?si=M9K4elaewqExv2G4

    My longer term plan is to replace the 4 digit LED display with a with a set of 4 x 1 inch high blue displays. Unfortunately the original display (4401) is common cathode and mine are common anode. Only doing because I had the displays spare in my parts drawer :-)))). Thanks

    1. ceptimus avatar

      I’ve built some MK14 emulators, that run on a PIC chip! Not my design – original code was by Karen Orton, but I have made a bigger display for them. See here: https://mccrash-racing.co.uk/philg/picl/picl.htm
      and here: https://youtube.com/shorts/FnLXP4NWFZ8?si=PViA4muQ5Pp1yYZq
      I’ve not done much with them, yet. I’ve been intending to build a NIBL or Nibbler that run the same SC/MP microprocessor (or an emulator on a modern chip) but can run BASIC or an operating system a bit like CPM.
      My clock code is all in C – so no need to delve into assembly language. The SDCC (small device C compiler) is free, and generates decent code for these 8051-based devices.

Leave a Reply to Freddie Barros Cancel reply

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