ISP programmer for the STC89C51 and STC89C52

I couldn’t find an ISP (programmer) for the STC89C52RC that worked with modern versions of Windows. I found several programmers that work with other chips in the STC range.

I did find one that worked on Windows XP, and with some hacking got it to work with Windows 7; however I had no luck with Windows 10. In any case, it was a Chinese program, and as I don’t read that language, I just had to remember which controls to use.

I also found one that worked under Linux, from the command line.  Using that source code as a guide I figured out how to write my own Windows version.

Image1It’s pretty basic but all you really need.  You select the COM port and the hex file you want to upload.  Connect up to your chip with a 5-volt serial port such as an FTDI (or you can use an Arduino UNO or similar that has a 5V FTDI built-in).

Here’s the video showing how to use the Arduino UNO as a programmer.  Here it’s being used to program a Banggood POV kit which uses an STC89C52RC chip – but you could obviously adapt the Arduino sketch and/or make a wiring harness to work with any STC89 board:

 

Here’s the Arduino sketch when you’re using the UNO as a programmer as shown in the video: Arduino sketch

Edit: the programmer program is now at V0.4 which fixes a few bugs and lets you switch the microcontroller to high speed (6T per machine cycle) or normal speed (12T per machine cycle).

Further Edit (August 2017): the programmer program is now at V0.5, and supports some different STC-chip bootloader firmware versions that previous versions did not.

If you’re not using the Arduino (which powers up the STC chip by itself when it detects activity on the serial port) then press the button to start the upload and then apply power to the target chip.  There’s a progress bar indicator – it takes maybe ten seconds to program the chip.

I’ve tried it on Windows 10 and Windows 7.  I’ve no reason to suspect that it won’t work with other versions of Windows.

Beware the fake Prolific serial chips that come in some USB-serial adapters and some cheap STC89C5x development boards.  I have one of those boards. I found an old version of the driver that let me get the Prolific chip operating as a loop back device – it even worked under Windows 10.  But it’s flaky and doesn’t work for programming the chip.  I found the only way I could get the programmer to work reliably was to cut the tracks leading from the STC chip’s serial port to the Prolific chip and connect an FTDI interface to the STC chip instead.

You may also need to fit a pull-up resistor to the STC’s TxD pin – only try that if you think you’ve connected everything up properly but it’s still not working – something like 10K or 100K should do the trick.  It depends on how much pull-up effect is already present on the RxD line of your serial interface and on the amount of stray capacitance present on your boards and cables.

Here is the link to download the install zip file for the programmer

Update: Ewald Burger (see comments below) encountered problems with the installation that he eventually traced to his AVAST virus scanner.  If you encounter problems with the installation you may want to try temporarily disabling your virus scanner while installing.

Here’s the source code – unzip it to your ‘projects’ folder. It was done using the free version of Visual Studio 2015 source code


Posted

in

,

by

Tags:

Comments

35 responses to “ISP programmer for the STC89C51 and STC89C52”

  1. Ewald Burger avatar
    Ewald Burger

    Hi,

    Thanks for you informative and interesting web site.
    I also built the POV kit from banggood only to find there seems to be no code in the STC chip.

    I tried to install your programmer but run into problems.
    I’m running 64 bit windows 7 here.

    When I double click the Setup.exe, it actually spawns three setup.exe processes and three rundll32.exe processes as well. But nothing seems to occur.
    I waited for a little hour and then tried to kill these processes using task manager, but it was not possible to stop them.
    I had to restart my laptop.
    I also double clicked STC89C5xProgrammer.application but that didn’t seem to work either.
    However after another reboot I found that there was an entry to your programmer in the windows start menu.
    I clicked it and then your programmer did start up.
    It had however no com ports listed.
    After another reboot i was unable to start the programmer again.
    There are eventually three instances of process STC89C5xProgrammer.exe *32 running, but no User interface is visible. Also i see two instances of rundll32.exe and one instance if rundll32.exe *32 running.

    Do you have any suggestions for me to try? Are there any special requirements/assumptions for your program to run?
    Thanks for any help in advance,

    Ewald

  2. ceptimus avatar
    ceptimus

    Hi Ewald,

    Did you copy the contents of the zip file to somewhere on your PC before running the install program? I’ve seen strange things like that happen when you just click on the setup program from inside the zip ‘view’.

    I recommend removing all the traces of the STC programmer you can find on your PC – try the ‘remove programs’ from control panel and uninstall the STCprogrammer… if it’s there. Also look in your program files and program files (x86) folders and delete any folders named STCprogrammer…

    Then open the zip file again, but this time, drag the folder inside it to your desktop. Then close the zip file view and open the STC… folder on your desktop and click on the setup program in there. It should only take a few seconds. I’ve installed it on Windows 7 and Windows 10 PCs – and both 32-bit and 64-bit versions of Windows 7.

    Let me know if you are still having problems and I’ll try to think of some other things to try.

  3. Ewald Burger avatar
    Ewald Burger

    Hello there,

    Thanks for your quick response, I was only a little late reading it 🙂
    Sure, I did unzip the file to my hard drive before running the setup.

    Nonetheless I followed your advice and removed the STCprogrammer using “remove software”. Then I downloaded the zip again from your web site and this time extracted it to the desktop like you did.
    Unfortunately running setup.exe has the same affect as before. Task manager shows three occurences of setup.exe *32 (but only one rundll32.exe *32) and there is no GUI visible.
    Killing these processes using task manager does not work.

    I see that the date of the files in your zip is very recent (2015-12-24) is it possible for me to get an earlier version to check if this is some unforseen side effect in the most recent version?
    All help is appreciated.

    Kind regards,

    Ewald

    1. ceptimus avatar
      ceptimus

      I’ve put a 64-bit-specific version up to try. Let me know if that works. Failing that, I can send you the source code to try – have you used Microsoft Visual Studio before? It’s free nowadays.

  4. Ewald Burger avatar
    Ewald Burger

    Hello,

    Thanks for your help so far. Unfortunately it is still not working, same symptoms. I have Developper Studio 2013 installed. If you could provide me the source code i’ll try and compile it myself to see how that turns out.
    Thanks again.

    Ewald

  5. Ewald Burger avatar
    Ewald Burger

    Hello again,

    Success! I used msconfig to start my laptop in diagnostic mode. Then i was able to successfully install the programmer software and also to load your clock software to the LED board. It is fascinating to see it all work!

    I am still curious whats biting your programmer application on my machine, I will try to figure that out.
    I have one more question. Are you willing to share your clock source code? It would certainly help to experiment further with this fun and fascinating board.

    By the way I saw another “DIY Rotating LED Kit POV Welding Kit Upgraded Version” on Banggood, you might as well be interested in.
    Seems a lot easier to build and there is quite some info available although most is in Chinese of course….
    Kind regards,

    Ewald

    1. ceptimus avatar
      ceptimus

      Great news that you’ve got it going! What programming hardware did you use to connect it up?

      I’ve put the (Windows) source code up. It might need tweaking a bit to work with the slightly older version of Visual Studio – I’ve not tried that. If you do figure out why the files created by the VS2015 ‘deploy solution’ were causing trouble on your machine, let me know – maybe there is a better way of deploying it that will make it easier for others.

      Yes, I ordered the ‘enhanced’ kit a week or so ago but it’s not arrived yet. It’s still using a chip based on the ancient 8051 architecture but it has a lot more I/O and works a lot faster: instead of needing 12 cycles of the crystal per instruction (or 6 which the 89C52 chip does in ‘fast’ mode) it only needs one cycle. And it doesn’t even need a crystal as it has a fairly stable clock built in to the chip… not accurate enough for good timekeeping but it has a separate real time clock so that’s even better as it will still keep time when it’s powered down.

      I’ll look into posting the ‘8051’ source code for the project. You’ll need a suitable cross compiler. The Keil one is the easiest to use but the free version is restricted to 2K of code size. That’s plenty to get it working as a clock, but when I added the second row of scrolling text I ran out of room…

  6. Ewald Burger avatar
    Ewald Burger

    Hello Ceptimus,

    I used the Arduino and your sketch to upload the clock SW to the led board, not sure if that answers your question?
    I might as well order the enhanced kit. It looks fancy enough to spend some time with. Yesterday, I searched for some X-compiler and ended up with installing MCU 8051 IDE on Ubuntu. Seems quite sophisticated. It is a long time ago I did programming on an MCS51 chip though 😉

    I have compiled your source code in VS2013. It complains about missing a certificate and about the solution using .NET Framework 4.5.2 that it says is not installed on my computer.
    To solve the certificate issue, I simply created a new test certificate.
    Concerning the framework version issue, VS offered two solutions: 1) change target to framework 4.5 or 2) download framework 4.5.2.

    I choose Option 1) and it built and ran without any problems from within VS. I tried a debug as well as a release build and both work fine.
    However when I try to execute the program by double clicking the generated .exe I end up with the same problem scenario as before.

    I then decided to check what .NET Framework versions are installed on my machine, and according to the registry, I do have version 4.5.2 installed! Just to be sure, I reinstalled FW 4.5.2 (repair), and started over again with your source code, but again it. Omplains about the FW version.

    It seems there is something messed up in my SW-configuration. I am currently in the process of uninstalling many older versions of VS and all the bits and pieces that surround it aand then will try to install VS2015 community to see if it then all works.
    But this is time consuming and I actually should go to bed now 🙂

    Thanks again for your support!

    Ewald

  7. Ewald Burger avatar
    Ewald Burger

    Hi Martin,

    Here is a short update:
    I have installed VS2015, but that did not solve the issues executing the built .exe.

    After some more experiments I however discovered that the problems seem to be caused by my virus scanner (AVAST). When I stop the virus scanner, I can execute the built .exe without problems!

    Regards,

    Ewald

    1. ceptimus avatar
      ceptimus

      Ahh! Thanks for that research. I’ll update the post to include that information in case other people using AVAST encounter similar problems.

  8. gthmpic avatar
    gthmpic

    Hi,Ewald.
    I recommend you to use stc-isp,
    It is an official ISP programmer for the STC89C52RC.
    The newest version is 6.85,and it could switch English version,it also worked on Win 7,Win 8/8.1,even Win 10.
    It could be found at stcmcu,called”STC15新ISP软件v6.85I”.

    1. ceptimus avatar
      ceptimus

      I think Ewald has my version working now. I’ve tried the one you recommend. I got a virus warning from my ISP when visiting the stcmcu site, but I ignored that and downloaded and installed the stc-isp V6.85I. It does appear to be mostly in English, but I couldn’t get it to work with my STC89 chips – whenever I try the ‘Check MCU’ button it says, “Checking target MCU … Download failed ! (6.85I) Please using the newest software !”

  9. Ewald Burger avatar
    Ewald Burger

    Hi gthmpic and Martin,

    Indeed I got Martin’s programmer with Arduino working although it sometimes takes several tries before it will actually program the CPU. Disconnecting and reconnecting the Arduino often seems to help.
    I have the impression sometimes during the start-up of the STC-board program execution of the STC-program starts, including changing output pins connected to Rx and Tx before it enters programming mode. Maybe that causes some weird character in the Arduino’s serial buffer or so that makes it hang.

    I have not tried the programmer gthmpic suggests but am afraid I will experience the same issues as Martin does. Will give it a try though and let you guys know my findings.

    Ewald

  10. Ewald Burger avatar
    Ewald Burger

    Hello,

    Tonight I found some time to play with the STC-ISP SW gthmpic recommended. As Martin I also got some warnings about a banned phishing site. After some hesitation, like Martin I decided to ignore the warnings and downloaded the 6.85I version…

    I used a USB to serial converter (Seeed studio UartSBee v4.0) to connect to the 4 pins on the LED-board’s ISP- header.
    I set the min/max baud rate to 9600 bps and tried the Check MCU.
    That resulted in a message “Checking target MCU…” that never finishes…

    I finally got that working by disconnecting the LED-board from the USB-Serial converter, then hitting the “Check MCU” button and then reconnecting the board. I think the issue is that when the board is already powered (through the USB-serial converter), the application program is already running and the STC89C52RC will not enter the ISP-mode.

    I than tried to program the board with a simple program that every second toggles all output ports (i.e. all LED’s) on the board between 0x55 and 0xAA using the same technique of disconnecting the board first, hitting the “Download/Program” button and then reconnecting the board. It however usually takes several attempts before programming starts, but eventually I was able to succesfully program the board.

    That’s all folks, good night!

    Ewald

  11. Derek avatar

    Your uploader worked well for me on a Win7 Home Edition PC. The STC89C52 was the inexpensive YL-39 development board with onboard PL2303HX USB to serial device.

    The .hex file from BASCOM worked at the first attempt.

    Note that I tried unsuccessfully to install your uploader on an old Win XP laptop. Seems that the necessary .Net components will not install on XP.

    Thanks for the good application.

  12. farhad avatar
    farhad

    hi
    why stc89c51 doesn’t have any lock bit?
    how i can protect my program to read?
    tnks

    1. ceptimus avatar
      ceptimus

      Your have to reset (to zero) the ISPEN bit (bit 7) in the register ISP_CONTR (ISP/IAP Control Register). This globally disables all ISP functions (read, write, and erase). This protects your program from read, but also locks the chip against any further writes – which is not something you’d want to do while you’re still developing. This is documented in the chip datasheet.

  13. farhad avatar
    farhad

    Hello,
    Thanks for your fast response.
    I reset ISPEN (to zero) from ISP_CONTR ,but i still enable program my micro using stc_isp .that happen because boot loader (F/W) change it during the boot.
    I think this is not the right solution to protect my program to read.

  14. ceptimus avatar
    ceptimus

    Ah, yes I think you’re right. I looked through the documentation and it looks as though you have to set an option bit to enable or disable the BSL (boot strap loader) in the same way that the ‘high speed mode’ bit is set. The BSL is controlled by the ~BSLD bit (bit 2) while the high speed mode bit (~CPU6T) is bit 0.

    I chose not to support setting/clearing that bit in my program as it seems too dangerous to me – once you’ve turned off the BSL then you can’t make further changes to the program yourself – so if you find a bad bug in STC code then the chip is effectively bricked.

    The best source of information is to look for stcgal – you’ll find it on github and in the documents folder you can see the stc89-options.txt file.

    Here’s the link (but this may go out of date so use a search if it doesn’t work): https://github.com/grigorig/stcgal/blob/master/doc/stc89-options.txt

    and here’s the section (which probably won’t be formatted properly in this comment, so look at the original document):

    In STC89 series, there is only a single MCS byte.

    MCS0
    ----

    MSB 7 6 5 4 3 2 1 0 LSB
    ~WDEN XRAM ALE OSCG ~EERE ~BSLD 0 ~CPU6T

    ~WDEN := watchdog enable after power-on-reset
    XRAM := enable access to internal XRAM
    ALE := enable ALE pin function (otherwise, it's just regular GPIO)
    OSCG := high oscillator gain
    ~EREE := enable eeprom erase next time MCU is programmed
    ~BSLD := enable BSL pin detect; i.e. BSL is only enabled if P1.0/P1.1
    (or others, depends on MCU model) are held low on POR.
    ~CPU6T := enable double speed (6T cycles instead of 12T cycles) mode

    I don’t really want to change my code to support altering this (~BSLD) bit, as testing it will likely brick my chips and I don’t want to risk that. You could alter my source code yourself or probably easier would be to use stcgal itself which does support setting/clearing ALL the option bits and it works great under linux – but I don’t know how easy it might be to get going under Windows.

  15. Daniel avatar
    Daniel

    Hi, i have a problem with the programmer. I can’t read the chip info and i can’t upload the hex file. It seems like the programmer doesn’t find my chip. Could you please help me?

    P.S. I’m italian, sorry if i made some grammar mistake.

  16. Sivaguru Mudaliar avatar
    Sivaguru Mudaliar

    Hi, ceptimus… I got it to work on the first try. Thanks for providing your programmer software. It was difficult to get the official STC ISP to work. I have tried all the versions up to the 6.86 with no results. They all get stuck at “Checking the cpu….” stage. I have loaded programs on STC89C51RC and STC89C52RC without problems.
    Again thanks for providing the software and easy to understand explanation on how to use the program.
    The power to the CPU must be interrupted to make the bootloader to work. Resetting the CPU only does not work.

  17. Bao Phan avatar
    Bao Phan

    Hi, can we read the code inside chip by this board? I want to read code from STC89C52RC but did not know how to do. Thanks!

    1. ceptimus avatar
      ceptimus

      It is not possible to read code (or EEPROM data) from an STC chip using STC’s bootloader protocols. This is considered a security feature by STC. There is no known workaround at this time.

      1. Bao Phan avatar
        Bao Phan

        Thank you!

  18. Lajos avatar
    Lajos

    Hi, ceptimus. The STC89C52RC can’t use external program memory over internal
    program memory (from 02000H)(PSEN not presents) . Is this an option, or what?
    EA pin also not works. STC is allways in internal access.What can i do?
    Thanks,
    Lajos

    1. ceptimus avatar
      ceptimus

      You have to set the EXTRAM bit in the AUXR register. There is a description in the data sheet – page 22 in my version from here: http://www.stcmicro.com/datasheet/STC89C51RC-en.pdf

      1. Lajos avatar
        Lajos

        Thank you for your response. EXTRAM bit control the internal RAM availability 00-FFH, but unfortunately
        the external PROGRAM memory area is still unavailable – page 21 in your datasheet. For example an external flash as code memory works with an AT89C52 over address 01FFFH, and when EA is low 00000-0FFFFH.

  19. Pavel avatar
    Pavel

    Hi, I have one procesor STC89C52 (not RC) with internal program (inside in this procesor) and I need transfer this program to new empty procesors. Do you help me? Is this possible copy inside program from one procesor to new (empty) procesor? According of your writing,it is impossible (the chip can be closed, or closed is) I think. Very thanks for help. Sorry for my english, Im from Czech republic. 🙂

    1. ceptimus avatar
      ceptimus

      Hi Pavel,

      As far as I know, it’s not possible to read code (or EEPROM) using the STC chip’s bootloader protocols. STC claim this to be a “security feature.”
      I don’t think there is any way to do it. Sorry.

      1. Pavel avatar
        Pavel

        Hi Ceptimus. Very thanks for reply. Bye 🙂

  20. Pavel avatar
    Pavel

    Hi, wants anybody some procesors STC89C52 and SRC89C52RC? I have ca. 15pcs. I won’t be need this chips already. I send this free.

    1. Pavel Kalina avatar
      Pavel Kalina

      Ok, if anybody want some chips, send me request to viburnum@volny.cz 😉

  21. Nguyen Anh Tuan avatar
    Nguyen Anh Tuan

    Thank you so much! You’s literally saved my life, sir. I’ve bought a STC89C52 board with built-in CH340 USB to COM. After ONE DAY long searching and trying various method to program this chip (eh, using STC-ISP, PROG ISP …) without success!!!
    Your software and your methods work totally fine, and very simple UI, that what I need. Thank you again, sir!

  22. Andrew Lynch avatar
    Andrew Lynch

    Hi
    Thank you for this great program! I was using stcgal and was experimenting with various programs. I managed to get the STC89C52RC to stop responding to stcgal and it would not erase so I could regain control and start over. I tried your program and was able to access the STC89C52RC and then load a simple LED blinker program. Once that was working, I was then able to get stcgal to get status chip status again and then successfully erase it.

    Now my STC89C52RC seems to be back to factory default which is what I wanted so I can continue experimenting. Thank you!

    PS, would you please add an “erase” function? I know we can’t read from the STC89C52RC by design, but it would be handy to regain control the STC89C52RC and reset to factory defaults. Otherwise, if you get a runaway program, you can effectively lose the part — which I almost did.

  23. Andrew Lynch avatar
    Andrew Lynch

    Hi
    I was thinking about the STC89C52RC more and realized probably we do not need to add an erase function to the program but if you would include an 8KB file of all FF values and “program” the Flash with it. That should wipe out any remaining crud left in memory and bring the Flash back to a pristine state.

    Likewise, a small program to reset all the EEPROM values back to factory defaults would be useful in case a runaway program corrupted values there unintentionally. There are probably limits to what can be done but just reset what can be done. Some “bricking” events are probably unrecoverable it is affects security bits, etc.

    Then people could use your program to bring their damaged parts back from the broken bin and reuse them. Maybe only some can be fixed but better those that can be save don’t spend the rest of eternity in a landfill rotting away.

    Thanks

Leave a Reply

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