Code Monkey home page Code Monkey logo

hml_fwlib_stc12's Introduction

HML_FwLib_STC12

GitHub repo size GitHub GitHub tag (latest by date)

关于

HML_FwLib_STC12(Hardware Middle Layer Firmware Library for STC12) 是面向STC12系列单片机的C语言封装库, STC12系列单片机是宏晶公司的产品, 发布于2007年. 这个系列的型号有STC12C5A60S2, STC12C5A56S2等, STC12系列是STC89,STC90,STC11系列的后继型号, 相对于早期型号增加了ADC, PCA, SPI和PWM等片内外设. 更多的细节可以查看官方介绍, STC12C5Axx Datasheet. STC12是使用经典引脚布局的最后一个系列, 从STC15系列开始使用了新的引脚布局.

这个封装库是HML_FwLib_STC11项目的一个分支(在此感谢原开发团队), 在其基础上对STC12的寄存器定义做了调整和适配, 对新增的硬件外设ADC, PWM, UART2, SPI等增加了对应的库方法, 并增加了对应的代码示例.

HML_FwLib_STC12 与其它 HML 封装库一样, 将MCU的片上资源进行包装并提供便捷的编程接口, 让开发者可以在项目中以类似STM32的编程方式, 快捷使用 ADC, GPIO, IAP, PCA, TIM, UART, EXTI, 电源管理以及看门狗等片上资源.

特性

  • 基于 SDCC compiler
  • (几乎)完整覆盖 STC12 系列 MCU 的片上资源
  • GPL-3.0 开源协议
  • 丰富的代码例子供开发参考, 有立即可用的MAX7219, nRF24L01, DS1302, DS12C887, TM1650参考代码

封装库支持的功能列表

Peripheral Description Status
extended bus Intel 8080 bus receiver/transmitter supported
ADC A/D conversion supported
EXTI extern interrupt supported
GPIO I/O peripheral supported
IAP in application programming supported
PCA 16-bit capture/compare and 8-bit PWM supported
PWR power management supported
RCC reset & clock control supported
SPI full-duplex, high-speed serial peripheral interface supported
TIM timer supported
UART universal asynchronous receiver/transmitter supported
WDT watchdog supported

如何使用

请查看WIKI, 里面详细介绍了命令行方式和IDE界面方式的安装和使用.

需要的环境

开发

文件结构

HML_FwLib_STC12
├─doc          # 文档
├─example      # 使用封装库的代码例子
├─inc          # 封装库的头文件(*.h)
├─obj          # 编译过程中产生的文件
├─src          # 封装库的源代码(*.c)
├─usr          # 项目代码及 makefile
├─library.json # 用于PlatformIO集成的库结构定义文件
├─LICENSE      # 授权
├─README.md    # 本文件
└─VERSION      # 版本

编译参数

使用本封装库时需要开发者配置的参数

__CONF_COMPILE_xxx (用于条件编译)

为了节约有限的片内资源, 开发者可以修改conf.h中的__CONF_COMPILE_xxx用于选择参与编译的部分, 从而减小最终产生的.hex文件大小. 例如如果只用到GPIO模块, 可以只启用__CONF_COMPILE_GPIO. 因为一些模块的编译依赖于其他模块, 例如__CONF_COMPILE_RCC依赖于__CONF_COMPILE_UTIL, 启用前者时必须也启用后者, 否则编译会失败.

__CONF_FRE_CLKIN

用于标记时钟源的频率, 在conf.h中定义

__CONF_MCU_MODEL

标记目标单片机型号, 在conf.h中定义

示例代码及编译

usr下有一个文件名为test.c的示例文件, 您可以修改其中的代码后在命令行下输入 make, 这时会执行Makefile中定义的过程完成编译. 另外, 可以输入make help查看编译选项.

使用 PlatformIO + VS Code 进行开发

PlatformIO 是 VS Code 的一个扩展, 用于嵌入式项目的开发. 在开发STC12项目时, HML_FwLib_STC12可以作为库直接引用. 下面是一个典型的PlatformIO项目目录结构:

|--include
|--lib
|  |
|  |--HML_FwLib_STC12
|  |  |--docs
|  |  |--examples
|  |  |--inc
|  |  |--src
|  |  |- library.json
|  |
|  |--Other_Libraries
|
|- platformio.ini
|--src
   |- main.c

编译和烧录的工具都由PlatformIO自动安装和管理, 需要在platformio.ini中配置相应的编译参数

  • -D__CONF_FRE_CLKIN, 必填, 用于指定晶振频率
  • -D__CONF_MCU_MODEL, 必填, 用于指定单片机型号
  • upload_speed and upload_flags, 选填, 用于ISP提速

配置示例

[env:stc12c5a56s2]
platform = intel_mcs51
board = stc12c5a56s2
build_flags =
    -D__CONF_FRE_CLKIN=11059200
    -D__CONF_MCU_MODEL=MCU_MODEL_STC12C5A56S2
upload_speed = 115200
upload_flags =
    -b$UPLOAD_SPEED

附录

STC单片机版本历史

时间 版本
2004 STC89
2007 STC90 STC10 STC11 STC12
2010 STC15
2014 IAP15
2017 STC8F/STC8A/STC8G/STC8H

hml_fwlib_stc12's People

Contributors

iosetting avatar mcu-zhishan-iot avatar weilunfong avatar zhongliguo avatar zsiothsu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

hml_fwlib_stc12's Issues

[DOC] 建议wiki中的 #安装sdcc 新增【二进制安装】子章节

若用户不选择使用流行的apt-get或yum命令安装,无非为如下两点原因:

  • 编译环境无法直接联网;
  • 可用的软件源中没有期望版本的软件包。

编译安装方式对于大部分用户来说并不友好,因为:

  • 环境甚至没有预装HOSTCC,例如gcc、clang等;
  • 构建过程中可能存在依赖缺失的问题,sdcc编译器本身即依赖boost c++;
  • 编译命令有时需根据自身环境与需要进行调整才能正常构建;
  • 卸载、更新与多版本共存的操作较为麻烦;

此时,若采用二进制方式,仅需将与运行环境相匹配的软件包解压至一个合适的路径下(通常为/opt),加以少量的环境变量配置即可运行软件;此外,由于软件的安装路径取决于解压路径,因此可以很轻松地通过修改环境变量PATH以切换不同版本的编译器,这也是usr/env.sh文件编写的初衷,其内容形式参考了yocto工程模板。多版本sdcc共存安装参考路径如下:

/opt
 + --- sdcc
        + --- sdcc-4.1.0
        + --- sdcc-3.6.0

sdcc官方提供了主流的amd64平台的二进制安装包,参见Small Device C Compiler - Browse /sdcc-linux-amd64 at SourceForge.net,将其中的压缩包解压并添加bin目录至环境变量PATH中即可运行。

望采纳!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.