All Projects → IOsetting → FwLib_STC8

IOsetting / FwLib_STC8

Licence: Apache-2.0 license
A lite firmware library for STC8G/STC8H series MCU

Programming Languages

c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to FwLib STC8

HML FwLib STC89
A lite firmware library for STC micro STC89 series MCU based on SDCC complier | 基於SDCC編譯器實現的針對宏晶微电子(STC Micro)STC89系列單晶片的輕量級固件庫
Stars: ✭ 41 (+28.13%)
Mutual labels:  sdcc, stc-mcu
stc8
#NVJOB STC8 v 3.2 (Custom shader for Unity SpeedTree 8)
Stars: ✭ 17 (-46.87%)
Mutual labels:  stc, stc8
HML FwLib STC12
A lite firmware library for STC12 series MCU
Stars: ✭ 15 (-53.12%)
Mutual labels:  sdcc, stc-mcu
STC15 LIB
用于STC15系列单片机,借鉴STM32库的形式,让官方库更加易于使用。
Stars: ✭ 30 (-6.25%)
Mutual labels:  stc
viking-village-nvjob-sky-water-stc
Unity Viking Village + #NVJOB Water Shader, Dynamic Sky, STC (Demo). Unity Asset.
Stars: ✭ 29 (-9.37%)
Mutual labels:  stc
stm8-bare-min
Tiny peripheral library for STM8 microcontrolles
Stars: ✭ 103 (+221.88%)
Mutual labels:  sdcc
stm8s-sdcc-examples
Example codes using sdcc to target STM8S MCUs.
Stars: ✭ 31 (-3.12%)
Mutual labels:  sdcc
tobutobugirl-dx
An arcade platformer homebrew game for the Game Boy, Game Boy Color and Super Game Boy
Stars: ✭ 58 (+81.25%)
Mutual labels:  sdcc

About

FwLib_STC8 is a lite firmware library for STC8G/STC8H series MCU.

Official Datasheets, User Manuals

Features

  • Compatible with SDCC and Keil C51
  • Optimized for constrained 8-bit MCU resources
  • Readable code for on-chip resources operation
  • Demos for quick start

PlatformIO Quick Start

  1. Clone this repository to local file system
# GitHub
git clone https://github.com/IOsetting/FwLib_STC8.git FwLib_STC8
# or Giteee (for Chinese users)
git clone https://gitee.com/iosetting/fw-lib_-stc8.git FwLib_STC8
  1. Copy(or move) it to your PlatformIO project library, the file structure
├── include
├── lib
│   └── FwLib_STC8
│       ├── demo
│       ├── include
│       └── src
├── src
└── test
  1. Add compile arguments in platformio.ini
build_flags =
    -D__CONF_FOSC=36864000UL                       ;The osc/irc frequency you MCU will be running on
    -D__CONF_MCU_MODEL=MCU_MODEL_STC8H3K32S2       ;change this to your MCU type
    -D__CONF_CLKDIV=0x02                           ;frequency trimming
    -D__CONF_IRCBAND=0x03
    -D__CONF_VRTRIM=0x19
    -D__CONF_IRTRIM=0x28
    -D__CONF_LIRTRIM=0x00
  1. Include fw_hal.h in your code
#include "fw_hal.h"

then it's ready to go.

VS Code Syntax Problem

VS Code doesn't support some of SDCC syntax for Intel 8051 (issue 7146), if you want to eliminate syntax errors in code editor, add a separate env for code editing and add __SDCC_SYNTAX_FIX in build_flags:

build_flags =
    -D__SDCC_SYNTAX_FIX
    -D__CONF_FOSC=36864000UL
    -D__CONF_MCU_MODEL=MCU_MODEL_STC8H3K32S2
    ...

This special env is for code editing only, building and uploading should use the normal env.

Keil C51 Quick Start

  1. Clone this repository to local file system
# GitHub
git clone https://github.com/IOsetting/FwLib_STC8.git FwLib_STC8
# or Giteee (for Chinese users)
git clone https://gitee.com/iosetting/fw-lib_-stc8.git FwLib_STC8
  1. Copy(or move) it to your Keil C51 project directory,
  2. Add it to project through Project -> Manage -> Project Items,
  3. Open project option dialog by clicking Project -> Options for Target ... , switch to C51 tab, and input following content in Preprocessor Symbols -> Define:
__CX51__, __CONF_MCU_MODEL=MCU_MODEL_STC8H3K32S2,__CONF_FOSC=36864000UL

The explanation of these arguments

   __CX51__ This will tell the macros to switch to Keil C51 keywords
   __CONF_MCU_MODEL, change this to your MCU type, please look into FwLib_STC8/include/fw_conf.h for all available types.
   __CONF_FOSC The osc/irc frequency you MCU will be running on. It equals to the frequency this MCU will be trimmed to in STC-ISP.
  1. Include fw_hal.h in your code
#include "fw_hal.h"

then it's ready to go.

Macros

Some macros were introduced for code compatibility with Keil C51 and SDCC.

The naming is from sdcc compiler.h. If you want your code to work with both compilers, you need to stick to these macros instead of the compiler specific keywords:

Here is a list of the macros:

Macro Keil C51 SDCC
__BIT bit __bit
__IDATA idata __idata
__PDATA pdata __pdata
__XDATA xdata __xdata
__CODE code __code
SBIT(name, addr, bit) sbit name = addr^bit __sbit __at(addr+bit) name
SFR(name, addr) sfr name = addr __sfr __at(addr) name
SFRX(addr) (*(unsigned char volatile xdata *)(addr)) (*(unsigned char volatile __xdata *)(addr))
SFR16X(addr) (*(unsigned int volatile xdata *)(addr)) (*(unsigned int volatile __xdata *)(addr))
INTERRUPT(name, vector) void name (void) interrupt vector void name (void) __interrupt (vector)
INTERRUPT_USING(name, vector, regnum) void name (void) interrupt vector using regnum void name (void) __interrupt (vector) __using (regnum)
NOP() nop() __asm NOP __endasm

The definition of these macros can be found in include/fw_reg_base.h

License

Copyright (c) 2021-present IOsetting [email protected]

The FwLib_STC8 is licensed under the permissive Apache 2.0 license, you can use it in both commercial and personal projects with confidence.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].