lzyor 发表于 2024-4-6 08:56:30

分享一个免插件的VSCode开发sdcc-51方法

默认情况下vscode并不能支持sdcc的扩展语法,但是可以配置简单忽略这些对语义没有影响的扩展关键词。

在打开的目录下新建: .vscode/c_cpp_properties.json
{
    "configurations": [
      {
            "name": "sdcc",
            "compilerPath": "/usr/bin/sdcc",
            "intelliSenseMode": "linux-gcc-x64",
            "cStandard": "c23",
            "cppStandard": "gnu++17",
            "defines": [
                "__sfr=unsigned char",
                "__sbit=int",
                "__at(a)= ",
                "__data= ",
                "__xdata= ",
                "__interrupt n= ",
                "__using= "
            ]
      }
    ],
    "version": 4
}
这样默认的C/C++插件就不会报错了。

假定目录结构:
-/

-bin
-src
-inc
入口在src/main.c

简单编写一个makefile:
# Makefile template for stc8h projects using SDCC

# Compiler and linker flags
CFLAGS = -mmcs51 --std-sdcc2x --model-large --opt-code-speed \
               --code-size 0xffff --xram-size 0x2000

# Define the compiler and the linker
# CC = sdcc
CC := $(if $(shell echo $$SDCC_PATH),$(shell echo $$SDCC_PATH),sdcc)

# Define the project directories
SRCDIR = src
INCDIR = inc
BINDIR = bin

# Define the target name
TARGET = $(BINDIR)/main.ihx
ENTRY = main.c

# Define the C source and header files
SRC := $(filter-out $(SRCDIR)/$(ENTRY), $(wildcard $(SRCDIR)/*.c))
OBJ = $(SRC:$(SRCDIR)/%.c=$(BINDIR)/%.rel)
INC = -I$(INCDIR)

# Define the phony targets
.PHONY: all clean

# Default target
all: $(TARGET)

# Link the object files into the final binary
$(TARGET): $(OBJ) $(SRCDIR)/$(ENTRY)
        $(CC) $(CFLAGS) $(INC) -o $(TARGET) $^
        @cat $(BINDIR)/main.mem

# Compile the source files into object files
$(BINDIR)/%.rel: $(SRCDIR)/%.c
        @mkdir -p $(@D)
        $(CC) $(CFLAGS) $(INC) -c $< -o $@

# Clean up the build files
clean:
        rm -f ./$(BINDIR)/*


用 make clean && make 就能完成大部分开发了。



lzyor 发表于 2024-4-6 08:58:42

可能缺少一些功能,但是这样配置所有vscode都能正常编辑/编译工程代码,可以在分享工程时避免一些兼容问题。

aorey@126.com 发表于 2024-4-27 22:47:13

有sdcc的stc8h的库吗?

oldcat 发表于 2024-4-28 10:30:47

aorey@126.com 发表于 2024-4-27 22:47
有sdcc的stc8h的库吗?

有的,这两个都可以





aorey@126.com 发表于 2024-4-28 10:53:56

oldcat 发表于 2024-4-28 10:30
有的,这两个都可以

用这个头文件跑官方的函数库和示例不成功.

oldcat 发表于 2024-4-29 23:24:47

aorey@126.com 发表于 2024-4-28 10:53
用这个头文件跑官方的函数库和示例不成功.

我用的就是这俩,都可以成功运行,你用是有报错还是?

这个是串口1打印芯片id的,你试试

aorey@126.com 发表于 2024-4-30 13:13:35

oldcat 发表于 2024-4-29 23:24
我用的就是这俩,都可以成功运行,你用是有报错还是?

这个是串口1打印芯片id的,你试试


方便加v吗 ?

oldcat 发表于 2024-5-5 16:39:40

aorey@126.com 发表于 2024-4-30 13:13
方便加v吗 ?

你发我吧

qsuwwww 发表于 2024-5-11 14:02:29

非常实用{:4_197:}这样是不是用ipad也能写STC项目的代码了?
页: [1]
查看完整版本: 分享一个免插件的VSCode开发sdcc-51方法