Microcontroller 51 / STC89C52 / STC51 / STC89 / STC12 / Intel MCS-51


I have recently bought this board, because it was cheap and had a display that you can just plug in.
It is called STC89/STC12 Demo Board. Link here.

Now, I would like to program it using C++ and PlatformIO. It is sold as “Arduino compatible” (in other shop) but so far I was only able to find some really old information about older version of the chip that allegedly supports only some strange version of C that needs it’s own compiler called SDCC. However, I managed to create a project in PlatformIO using these settings:

platform = intel_mcs51
board = stc89c52rc

Problem is, it won’t compile. It says:

'CC' is not recognized as an internal or external command,
operable program or batch file.

The sketch I’m trying to compile looks like this:

#include <reg51.h>       // old header from SDCC
#include "STC89xx.h"     // Official header from STC-ISP for STC89xx

void main()


The header files don’t even exist. I have installed the required Intel MCS-51 (8051) platform though.

So my questions are: Is there a way to make it work? Is it really Arduino-compatible? Can I use C++ instead of C? How do I make it work? Am I missing something about the project settings? Thank you very much for any helpful advice.

Not reproducable. With the same platformio.ini and a main.c of

#include <reg51.h>       // old header from SDCC
//#include "STC89xx.h"     // Official header from STC-ISP for STC89xx

int main() {
  return 0;

it gives

>pio run -v
Processing stc89c52rc (platform: intel_mcs51; board: stc89c52rc)
CONFIGURATION: https://docs.platformio.org/page/boards/intel_mcs51/stc89c52rc.html
PLATFORM: Intel MCS-51 (8051) 1.2.2 > Generic STC89C52RC
HARDWARE: STC89C52RC 11MHz, 512B RAM, 8KB Flash
 - tool-stcgal 1.104.0 (1.4)
 - toolchain-sdcc 1.30804.10766 (3.8.4)
LDF: Library Dependency Finder -> http://bit.ly/configure-pio-ldf
LDF Modes: Finder ~ chain, Compatibility ~ soft
Framework incompatible library C:\Users\Maxi\.platformio\lib\MCCI LoRaWAN LMIC library_ID5774
Framework incompatible library C:\Users\Maxi\.platformio\lib\Nextion_ID37
Framework incompatible library C:\Users\Maxi\.platformio\lib\dcf77_xtal_ID1482
Found 0 compatible libraries
Framework incompatible library C:\Users\Maxi\.platformio\lib\esp32ModbusRTU_ID5876
Scanning dependencies...
More details about "Library Compatibility Mode": https://docs.platformio.org/page/librarymanager/ldf.html#ldf-compat-mode
No dependencies
Building in release mode
sdcc -o .pio\build\stc89c52rc\src\main.rel -c --std-sdcc11 --opt-code-size --peep-return -mmcs51 -DF_CPU=11059200 -DHEAP_SIZE=128 -DPLATFORMIO=40400 -Iinclude -Isrc src\main.c
In file included from src\main.c:1:
C:/Users/Maxi/.platformio/packages/toolchain-sdcc/bin/../include/mcs51/reg51.h:32:2: warning: #warning This file (reg51.h) is obsolete, use one appropriate for your harware!
C:/Users/Maxi/.platformio/packages/toolchain-sdcc/bin/../include/mcs51/reg51.h:33:2: warning: #warning Falling back to include <8052.h>
sdcc -o .pio\build\stc89c52rc\firmware.hex -mmcs51 --iram-size 256 --xram-size 256 --code-size 8192 --out-fmt-ihx .pio\build\stc89c52rc\src\main.rel -L.pio\build\stc89c52rc
MethodWrapper(["checkprogsize"], [".pio\build\stc89c52rc\firmware.hex"])
Advanced Memory Usage is available via "PlatformIO Home > Project Inspect"
Flash: [          ]   1.3% (used 106 bytes from 8192 bytes)
Internal RAM layout:

      0 1 2 3 4 5 6 7 8 9 A B C D E F

















0-3:Reg Banks, T:Bit regs, a-z:Data, B:Bits, Q:Overlay, I:iData, S:Stack, A:Absolute

Stack starts at: 0x08 (sp set to 0x07) with 248 bytes available.

No spare internal RAM space left.

Other memory:

   Name             Start    End      Size     Max

   ---------------- -------- -------- -------- --------

   PAGED EXT. RAM                         0      256

   EXTERNAL RAM                           0      256

   ROM/EPROM/FLASH  0x0000   0x0069     106     8192
============================= [SUCCESS] Took 1.42 seconds =============================

What IDE are you using? What’s the result of a Verbose Build or pio run -v?

Does exist in C:\Users\<user>\.platformio\packages\toolchain-sdcc\include\mcs51.

I don’t see this being included by the SDCC by default? You should be able to copy-paste this external file from GitHub - znhocn/stc-header: STC header for SDCC (Small Device C Compiler) into the include/ though.

Thank you for such quick response! My problem was, I named the file main.cpp. Renaming it to main.c worked. I then downloaded the header file from the github and it compiled!

Is it possible to use C++ and Arduino with this board? I tried these settings

platform = intel_mcs51
board = stc89c52rc
framework = arduino

lib_deps =
  Adafruit ST7735 and ST7789 Library

But I got this

> Executing task: platformio.exe run <

Processing stc89c52rc (platform: intel_mcs51; board: stc89c52rc; framework: arduino)
Verbose mode can be enabled via `-v, --verbose` option
CONFIGURATION: https://docs.platformio.org/page/boards/intel_mcs51/stc89c52rc.html
PLATFORM: Intel MCS-51 (8051) 1.2.2 > Generic STC89C52RC
HARDWARE: STC89C52RC 11MHz, 512B RAM, 8KB Flash
Error: This board doesn't support arduino framework!
 - tool-stcgal 1.104.0 (1.4) 
 - toolchain-sdcc 1.30804.10766 (3.8.4)
================================================================================================== [FAILED] Took 0.65 seconds ==================================================================================================
The terminal process terminated with exit code: 1

Should I give up and stick to plain C?

I don’t think this is possible due to:

  1. SDCC is the Small Devices C Compiler. It cannot handle C++. Therefore another compiler must be found thaht can compile C++ for the Intel MCS51 / Intel 8051 target platform. After some quick google searches I didn’t come up with anything…
  2. An Arduino Core for this microcontroller platform (STC89 or general MCS51) must be provided. Again a quick google search has turned up nothing.
  3. Memory requirements. You’d have to do some extremely clever programming to fit the Arduino APIs in such a tiny amount of flash and RAM. External libraries are used to a minimum of like 2KB RAM when coming from an Arduino Uno, but 0.5KB RAM are… restricting. If a display library attempts to allocate a framebuffer for the display, it’s already over.

Either this is false advertising (they e.g. meant “arduino-style form factor” or “thing that looks like an Arduino”) or my above two points are fundamentally wrong. Do you have any link to that claim, or even better, compiler and Arduino core links?

Nevertheless, I did find some example C programs for the board targeted for SDCC:

The “128xRGBx128 1.44” display" might be something like https://www.waveshare.com/1.44inch-lcd-hat.htm with a ST7735S over SPI. Since the microcontroller doesn’t even SPI you’d have to bit-bang it – or use the UART peripheral in some 8-bit shift register mode.

The Arduino part was an advertising trick… It says:

51 MCU Minimum System Board STC12C5A60S2 STC89C52 Learning Development Board MCU UART with 2 Serial Port Geekcreit for Arduino - products that work with official Arduino boards

I haven’t even received the right display. The one they sent me has same size but the pins are different so I’ve decided to use it with a different board. I was just curious how to make this one work. I should be able to start with what you told me.

Again, thanks a lot for your explanation. I will check out the links too.