Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A lite firmware library for STC8G/STC8H series MCU

License

NotificationsYou must be signed in to change notification settings

IOsetting/FwLib_STC8

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

SDCC Makefile Quick Start

  1. Clone this repository to local file system
# GitHubgit 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. Edit Makefile

Change according to your MCU part

## STC8H1K08 STC8H8K64UMCU                 ?= STC8H1K08MCU_IRAM            ?= 256# 1024, 2048, 3072, 4096, 8192MCU_XRAM            ?= 1024# 8192, 16384, 32768, 65536MCU_CODE_SIZE       ?= 8192

And the SDCC path

TOOCHAIN_PREFIX     ?= /opt/sdcc/sdcc-4.3.0/bin/

And the compile flags

## STC8H1K08 36.864MHzLIB_FLAGS           := __CONF_FOSC=36864000UL \__CONF_MCU_MODEL=MCU_MODEL_STC8H1K08 \__CONF_CLKDIV=0x00 \__CONF_IRCBAND=0x01 \__CONF_VRTRIM=0x1F \__CONF_IRTRIM=0xB5 \__CONF_LIRTRIM=0x00
  1. Compile
make clean; make

PlatformIO Quick Start

  1. Clone this repository to local file system
# GitHubgit 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. Includefw_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
# GitHubgit 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. Includefw_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 fromsdcc 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:

MacroKeil C51SDCC
__BITbit__bit
__DATAdata__data
__IDATAidata__idata
__PDATApdata__pdata
__XDATAxdata__xdata
__CODEcode__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 vectorvoid name (void) __interrupt (vector)
INTERRUPT_USING(name, vector, regnum)void name (void) interrupt vector using regnumvoid 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 IOsettingiosetting@outlook.com

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

About

A lite firmware library for STC8G/STC8H series MCU

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors6


[8]ページ先頭

©2009-2025 Movatter.jp