51单片机开发环境macstc12c5a60s2·

RY-Teach STC12C5A60S2 Mac环境搭建

devcui

devcui

3281 3

1.编辑器

brew cask install visual-studio-code

2.开发平台

3.开发包

4.开发包无 STC12C5A60S2 自定义 board

{
  "build": {
    "f_cpu": "11059200",
    "size_iram": 256,
    "size_xram": 256,
    "size_code": 8192,
    "size_heap": 128,
    "mcu": "stc12c5a60s2",
    "cpu": "mcs51"
  },
  "frameworks": [],
  "upload": {
    "maximum_ram_size": 512,
    "maximum_size": 8192,
    "protocol": "stcgal",
    "stcgal_protocol": "stc12",
    "protocols": [
      "stcgal"
    ]
  },
  "name": "Generic STC12C5A60S2",
  "url": "https://www.stcmicro.com/stc/stc12c5a32s2.html",
  "vendor": "STC"
}

将 json 放入 Users/{YourName}/.platformio/platforms/intel_mcs51/boards 命名为 stc12c5a60s2.json

5.创建项目

首先重启 Vscode,使得 platformIO 重新读取 boards 里的配置文件

6.编写项目

src 下新建 led.c

#include <stc12.h>

#define R P0_2
#define G P0_1
#define B P0_0

void delay_ms(unsigned int s)
{

    unsigned int x;

    for (s; s > 0; s--)
    {
        x = 98;
        while (x--)
            ;
    }
}

void main()
{
    while (1)
    { //主循环

        R = 0xff;
        G = 0xff;
        B = 0xff;

        delay_ms(150);

        for (int i = 0; i < 8; i++)
        {
            R = R << 1;
            G = G << 1;
            B = B << 1;
            delay_ms(150);
        }

        R = 0xff;

        delay_ms(150);

        for (int i = 0; i < 8; i++)
        {
            R = R >> 1;
            G = G >> 1;
            B = B >> 1;
            delay_ms(150);
        }
    }
}

7.编译与烧录

8.效果

9.Question: 关于 stc12.h 文件头的问题

正在研究中,我也不知道怎么才能让其不报错

相关文章

优先推荐同专题、同标签和同作者内容,补足热门文章。

评论 3

登录 后参与评论

评论 3

Hugh
Hugh12月13日 18:33

? ?

ronger
ronger12月14日 08:49

建议再加一个,开发平台内找不到芯片对应的 board,如何查找对应的配置信息

Hugh
Hugh12月14日 13:14

9.Question: 平台自带的SDCC不包含STC的头文件,把最新SDCC的include文件内容复制过去,亲试有效解决。