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.
Leave a Reply