Close

The Microcontroller

A project log for Semyon

A small simon game using the 8 pin STC15F104W, written in 8051 assembly using the SDAS(ASXXXX) assembler from the SDCC toolchain.

hummusprinceHummusPrince 10/13/2019 at 20:380 Comments

The hardware is rather simplistic. It consists mainly of 4 LEDs and tactile switches surrounding the MCU. Lets have a look at the chip itself.

The chip itself is part of chinese STCmicro line of 8051 derivative MCUs. It sports a 1T architecture compared to crusty old 12T architecture of the original one, meaning it's much more efficient (though no 8051 is really a 1T machine anyway, so don't expect it to really be 12 times faster).

The MCU comes in DIP8 and SOP8, and should be really cheap - I got mine for 0.27$ for piece in quantity of 10 from aliexpress (DIP8), and I believe you can find it even cheaper. It has 4kB of flash, only 128 bytes of ram without XRAM, 2 timers (the traditional T0 timer but no T1 timer, but rather T2 timer which can't count external interrupt events in hardware), and not even UART, presumably (we might tackle it later).

It also has an internal oscillator which can be calibrated quite accurately to arbitrary values, internal clock dividers and other power control goodies absent from the original. It's brothers look pretty much the same:

It's not much compared to other MCUs in the market, but it's more than plenty to make a simon game - Consider that the original one was implemented on TMS1000 4bit microcontrollers which had 64 nibbles (not bytes!) of ram, 1kB of flash, single level stack and no interrupts at all, and did it successfully.

One sweet thing about most STC micros is that you don't need no special programmer. The programming is made using simple UART. The only thing you need is one of these cheap USB to TTL serial adapters, which you seriously own if you want to do real shit with microcontrollers:


This should be connected to the chip according to the datasheet, as presented below. P3.0 is UART RX output of standard 8051, and so P3.1 is the TX. This makes me suspect even further that the UART peripheral is really there.

I got myself a blink binary to check how well the chip works. Now I only had to download it inside the chip through the serial port. How is it done though?

STC has a utility called STC-ISP which takes care of it for you. It's quite ugly and lots of chinese script can't be parsed in my computer, making parts of the GUI a real mess. It contains many tabs for random stuff, but the only tab that's going to interest us is the code buffer (and maybe one day the EEPROM buffer).

To download the code you should open your binary with 'open code file', take the MCU off, press download and ONLY THEN turn it on. It feels backwards at first, but it's actually good, as the bootloader doesn't need to make boot from power off take so long as bootloaders tend to do.

And it worked! Woohoo!

A better and more thorough overlook for STC can be found on Jay Carlson's website. It's part of a very thorough comparison of simple microcontrollers he made, which I very liked and can recommend to take a look at.

Discussions