diff --git a/Makefile b/Makefile index cf2bde8..835f768 100644 --- a/Makefile +++ b/Makefile @@ -15,12 +15,12 @@ else CC := ablrun sdcc COM := /dev/ttyUSB0 endif - TEMP := $(shell sudo chmod 777 $(COM)) endif # set CC TOOL PACKIHX := packihx CFLAGS := -DUSE_FLOATS=1 +LDFLAGS := --iram-size 0x100 --xram-size 0x400 --code-size 0xffff # set DIR INCDIR = include @@ -38,18 +38,20 @@ OBJ := $(patsubst src/%.c, obj/%.rel, $(SRC)) all: main.hex clean: - -$(RM) obj\* + -$(RM) obj/* $(OBJ):obj/%.rel:src/%.c -$(CC) $(CFLAGS) -I $(INC) -c $^ -o $@ $(TARGET): $(OBJ) - -$(CC) $^ -o $@ + -$(CC) $(LDFLAGS) $^ -o $@ main.hex: $(TARGET) -$(PACKIHX) $(TARGET) > main.hex -flash: +flash: + -sudo chmod 777 $(COM) + -./reset_mcu.sh -stcgal -P stc89 -p $(COM) main.hex #led.bin:led.hex diff --git a/ReadMe.md b/ReadMe.md index 14a1345..eca5758 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -9,6 +9,7 @@ uart_temp是用于8051单片机上的一个项目,用于获取温度,并使 - 仅当温度变化时才会打印 - 支持[SDCC](https://sdcc.sourceforge.net/)编译 - 支持[stcgal](https://github.com/grigorig/stcgal)命令行烧录 +- 支持不断电烧录,发送"RESET!"命令后,软复位单片机,并自动重启。(`stcgal -a -r "./reset_mcu.sh"`的方式无法自动重启,原因未知) - 支持Makefile - 支持Window环境 @@ -44,7 +45,7 @@ uart_temp是用于8051单片机上的一个项目,用于获取温度,并使 minicom -D /dev/ttyUSB0 -b 9600 ``` - > 推荐使用图形化的串口软件:< + > 推荐使用图形化的串口软件:[COMtool](https://github.com/Neutree/COMTool/tree/master) 5. 运行`process.py`解析数据生成图片 diff --git a/reset_mcu.sh b/reset_mcu.sh new file mode 100755 index 0000000..9ea07fa --- /dev/null +++ b/reset_mcu.sh @@ -0,0 +1,29 @@ +#!/bin/bash +#=========================================================================== +# Organization : Individual developer +# Filename : reset_mcu.sh +# Author : Feng Bohan +# Create Time : 02:51:28 2024-07-14 +# Last Modified: 00:17:44 2024-07-15 +# Abstract : +#-------------------------------------------------------------------------- +# Description: +# +#-------------------------------------------------------------------------- +# Modification History: +#-------------------------------------------------------------------------- +# Rev Date Who Description +# --- ---- --- ----------- +# 0.0.01 2024-07-14 Feng Bohan initial version +#=========================================================================== +stty -F /dev/ttyUSB0 speed 9600 cs8 -parenb -cstopb raw -echo -echoe -echok -echoctl -echoke + +echo -e "RESET!" > /dev/ttyUSB0 + + +#说明: +#speed 串口波特率 +#cs8 数据位8位 +#parenb 无校验 +#cstopb 停止位1位 +#查看串口设置: stty -a -F /dev/ttyUSB0 diff --git a/src/main.c b/src/main.c index 90777ec..b684124 100644 --- a/src/main.c +++ b/src/main.c @@ -17,6 +17,35 @@ int HH=0, MM=0, SS=0; int send_tmp = 0; +__sfr __at (0xE7) ISP_CONTR; +#define RESET_PASSWORD_LENGTH 6 +char __xdata reset_password[RESET_PASSWORD_LENGTH] = "RESET"; +char __xdata receice_password[RESET_PASSWORD_LENGTH] = {0}; +/******************************************************************************* +* 函 数 名 : auto_reset +* 函数功能 : 接受到重启命令RESET!后,软复位MCU +* 输 入 : 无 +* 输 出 : 0:检测到重启命令,1:未检测到重启命令 +*******************************************************************************/ +u8 auto_reset(u8 rec_data) +{ + for(u8 i=0;i