SH-E 879 clock kit stopwatch

I first mentioned these kits about six years ago when I blogged about making this Arduino-based programmer for the AT89C2051 chip.

The kits are still available on eBay, Banggood, AliExpress, … and there are plenty of variations that still use the AT89C2051 chip, but have more (three) push buttons, a buzzer, or only four digits instead of six, and so on. The code presented here could easily be modified to run on any of those. The six-digit clock kit, with three buttons and buzzer, is advertised as having a stopwatch, alarm, etc. built in and less than £4 including shipping at the time of writing, from AliExpress.

But my SH-E 879 kit was a clock only, as far as I could tell, so I wrote some code to be compiled by the excellent free SDCC C compiler to turn it into a stopwatch. SDCC is available on Windows, Linux, and Mac.

For Windows, you can also use the Keil uVision compiler, which is fine for small projects like this. The ‘free’ version of the Keil compiler has a 2K code size limit, which is no problem for the AT89C2051, because it only has 2K of Flash memory. But if you intend to write 8051 code for other 8051-based chips, and might eventually exceed 2K of code, it’s better (in my opinion) to use SDCC from the outset. The very expensive Keil licence is out of reach for hobby programmers, so starting with SDCC saves you having to migrate your code from Keil to SDCC later (the syntax is slightly different). The Keil compiler perhaps optimizes your code slightly better, and allows in-line declaration of variables instead of needing to declare them up at the top of each scope block, but the SDCC is not far behind, and given the price difference, the choice is a no-brainer.

Here’s the source code for the stopwatch, and in the comments there is the command you need to type into a CMD prompt (or terminal window on Linux) to compile and link it. If you just want the hex resulting hex file, it’s here.

If you want to turn your stopwatch back into being a clock, the 12-hour-clock source code is here, and its hex file is here. Should you prefer a 24-hour clock, here is the source, and hex file.






4 responses to “SH-E 879 clock kit stopwatch”

  1. […] wanted to reprogram the chip so I could use the kit as a stopwatch/timer instead of a regular clock.  Of course I could have bought a programmer to do the job, but reading the chip’s data […]

  2. Kellner, Simon avatar
    Kellner, Simon

    Very good article.
    Everything worked wonderfully.
    I used “AT89OVERLORD” and the Adrduino UNO for flashing and reading.
    (And of course also SDCC)
    It’s not 100% accurate, but it’s good enough for my purposes.

  3. ReedB avatar

    Ceptimus, thank you very much for this. The original firmware supplied with the kits I purchased was never accurate to better than a few minutes a month. I tried trimming the crystal to very near 12MHz using an accurate frequency counter and the problem persisted (always slow). Replacing with your firmware (clock12h.c) fixed the problem. I also change the crystal to a TCXO chip and with your firmware I can confirm accuracy is better than +-1 second per month over a 20 degree C temp range.

  4. PeterB avatar

    I shot the Input for the pushbutton.
    So i can program a new chip with your code.
    Thank you

Leave a Reply

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