
I wasn't intending to do any more projects with 8051 family chips, but I still had some 8 pin STC15F104W MCUs bought cheap in a moment of weakness. Now the price is higher; interesting how yesteryear's technology actually becomes more expensive after they have been superseded. They have 4 kB flash memory and 128 B RAM. What to do with them?
With only 6 I/O pins possibilities are fewer. The idea came of making a thermometer and humidity meter using AHT30 sensors. I also have a handful of Inchdigit modules that I made but hadn't found a use for. I2C for the sensor takes 2 pins, the TM1637 interface takes 2 pins, leaving 2 pins for buttons of which only one is needed if the meter has only two modes, temperature and humidity. There is no hardware I2C support so that will have to be bitbanged. The two timers suffice for providing a tick for driving the firmware timing and generating a 5 µs delay for the bitbanging. Fortunately display multiplexing is handled by the TM1637 so no display glitches happen during updates from the sensor.
I repurposed bits of 8051 code from previous projects and whipped up the firmware. Using fixed point arithmetic for converting the sensor readings allowed me to avoid expensive (in code size) floating point operations, and still display one decimal digit. The code came in at just over 2.5 kB so there's room for more functionality but more display area is needed.
I used a couple of state machines in the guise of Protothreads, one to handle the button debouncing and the other to handle the sequencing of reading the sensor.
The code contains two variants selected by a #define. The prototyping version runs on a 40-pin STC89C52 descendant of the 8051 in the QX-mini-51. The STC15F MCUs will be flashed using this adaptor.
This project is just maker practice for me and impractical. If you want a cost-effective thermometer and humidity meter, just buy one of these.
I've added a link to the firmware sources at Github. Note that this hasn't been tested with STC15F104W MCUs yet; I need to order a PCB to go on the back of the Inchdigit displays. After that I'll assemble the units and foist them on unsuspecting friends. 🤣 Stay tuned.
Ken Yap
romaindurocher
tinu
alberto nunez
Ted