PlatformIO搭配clion或vscode踩坑记录

好吧,我是“颜狗”,⚠keil⚠

缺点就是不支持调试52rc https://docs.platformio.org/en/latest/boards/intel_mcs51/STC89C52RC.html#

image-20230926224013694

sdcc其实有调试工具sdcdb,但我觉得那是一坨shit(难道我的打开方式不对?)

PlatformIO开发51

官方手册 https://docs.platformio.org/page/projectconf.html

platformio.ini教程 https://www.bilibili.com/video/BV16X4y1m7AK/

platformio.ini 能用配置

[platformio]
include_dir = C:\Users\zbx\.platformio\packages\toolchain-sdcc\include
[env:STC89C52RC]
platform = intel_mcs51
board = STC89C52RC
upload_flags =
-p
$UPLOAD_PORT
upload_command = stcgal $UPLOAD_FLAGS $SOURCE

一些博客教程

https://nu-ll.github.io/2021/02/24/PlatformIO%E4%BD%BF%E7%94%A8%E4%B8%AD%E9%81%87%E5%88%B0%E7%9A%84%E5%9D%91/

https://bannirui.github.io/2023/02/28/C51%E5%8D%95%E7%89%87%E6%9C%BA%E5%BC%80%E5%8F%91%E7%8E%AF%E5%A2%83/

刚开始补全不好用改下下面头文件

8052.h

image-20230926220532073

8051.h

image-20230926220553512

愉快补全

image-20230926220702006

keil,sdcc库不同点

Migration Keil 2 SDCC:https://www.infineon.com/dgdl/AP0806510_XC800_Migration_Keil_2_SDCC.pdf?folderId=db3a30431375fb1a01138c57204603bd&fileId=db3a304314dca389011517efc5860d61&ack=t

sdcc manual https://sdcc.sourceforge.net/doc/sdccman.pdf

中断回调函数定义中x标识的是中断号

比如

中断号 含义
0 外部中断0
1 定时器中断0
2 外部中断1
3 定时器中断1
4 串口中断
sdcc keil
头文件 8052.h/8051.h reg52.h/reg51.h
端口控制口定义 #define LED1 P2_0 sbit LED1 = P2 ^ 0;
中断回调定义 void time1() __interrupt(x) {} void time1() interrupt 3 using 2

keil c 的中断
void SerialComm(void ) interrupt 4 ;
{
}

sdcc 的中断
void SerialComm(void) __interrupt 4;
{
}

sdcc 没有_nop()_ , 可用如下自定义宏代替: #define _nop()_ __asm NOP __endasm ps: sdcc里用__asm xxx __endasm来做内联汇编

#define LED P00
LED = 0;

这种宏定义的方式在SDCC中不支持。可以替换为以下方式:

#define LED(x) P00=x
LED(0);

在反转引脚时,不要使用取反(P00 = ~P00),而应该使用非(P00 = !P00)运算;因为 sdcc 会默认进行类型提升,然后进行取反

sdcc简单示例

https://doc.itprojects.cn/0015-zhishi.89c51/index.html#/