|
STC15W408AS library 0.18.0
|
A lightweight C Hardware Abstraction Layer (HAL) and register definition library for STC15 series microcontrollers (specifically optimized for STC15W408AS and MCS51/8051-compatible devices) using the SDCC (Small Device C Compiler) toolchain.
The STC15 HAL provides hardware abstractions for the STC15W408AS microcontroller series. Due to the strict flash and RAM constraints of 8051 microcontrollers, most HAL routines are implemented as efficient C macros that expand directly in-place to minimize call overhead and eliminate runtime function call penalty. Supporting modules for tick/frequency conversions and mathematical tables are compiled into a compact static library (stc15hal.lib).
Add the library to your platformio.ini configuration file:
Alternatively, you can depend directly on a GitHub release tag or branch:
Include the include/ directory in your compiler header search paths and link against stc15hal.lib (built from src/).
You can directly read and modify Special Function Registers (SFRs) by including <STC15Fxx.h>:
The HAL macros offer descriptive names, bitmask operations, and automated register setup:
| Module | Header | Description | Maturity |
|---|---|---|---|
| Chip ID | chip_id.h | Read unique 7-byte hardware ID from MCU ROM | Ready |
| Delay | delay.h | Accurate millisecond and microsecond delays | Ready |
| CPU Frequency | frequency.h | Master clock prescaler & clock output to pins (P5.4, P1.6) | Ready |
| Interrupts | interrupt.h | Global/peripheral interrupt enable, priority, INT0/INT1 triggers | Ready |
| Power Management | power_management.h | Idle mode, Power-Down mode, Wake-Up timer, Low-voltage detection | Ready |
| Reset | reset.h | Software system reset to AP or IAP | Ready |
| Timer 0 | timer0_mode*.h | Modes 0, 1, 2, 3 in 1T/12T, sync delays, async interrupts, ms/ticks conversions | Ready |
| Timer 2 | timer2_mode0.h | Mode 0 (16-bit auto-reload) in 1T/12T, baud generator, sync/async | Ready |
| Counters | counter*.h | External event counter on Timer0 (Modes 0-3) and Timer2 (Mode 0) | Ready |
| UART1 | uart.h, uart1_*.h | Modes 0, 1 (Timer2 1T/12T), 2, 3; stdio integration (putchar, printf_tiny) | Ready |
| Watchdog Timer | wdt.h | Hardware watchdog prescaler, enable, and feed | Ready |
| GPIO | gpio.h | Port modes (quasi-bidirectional, push-pull, input-only, open-drain) & pin access | Ready |
| EEPROM / IAP | eeprom.h | Read byte, write byte/array, and sector erase via IAP registers | Ready |
| ADC | adc.h | 10-bit analog-to-digital converter (sync blocking and async interrupt modes) | Ready |
| Comparator | comparator.h | On-chip analog voltage comparator | Initial Support |
| PCA / CCP | pca.h | 16-bit counter, compare/capture, high-speed toggle output, 8/7/6-bit PWM | Initial Support |
| SPI | spi.h | Master & slave, 3 pin groups, 4 clock dividers, CPOL/CPHA modes, sync & async | Initial Support |
| Bit Operations | bits.h | Fast bit set, clear, toggle, and test macros | Ready |
See examples subfolder.
Flashing can be done using stcgal:
When prompted by stcgal, power-cycle the target MCU board to initiate ISP flashing.
Ensure the following tools are installed:
Configure the build using the SDCC toolchain file:
Build the HAL static library, all examples, and utilities:
View the build summary & firmware sizes:
During the build, cmake_examples_build_summary.py automatically generates a table of compiled .hex files and memory usage (FLASH/ROM, IDATA, XDATA). You can view the summary with:
Build Doxygen documentation:
Flash an example directly:
The project includes custom build scripts located in platformio_build/:
compile_lib.py: Compiles the core STC15 HAL library.compile_examples.py: Compiles all examples and outputs a firmware size summary.compile_utils.py: Builds standalone utilities.doxygen.py: Generates Doxygen HTML docs.To run the full PlatformIO build pipeline:
The repository includes utilities located in utils/:
utils/memory_dumpercmake --build build --target mem_dumpcmake --build build --target flash_mem_dumputils/csv2hexThis project is licensed under the [Apache License 2.0](LICENSE).