增加不断电下载功能

This commit is contained in:
fengbh 2024-07-15 00:48:18 +08:00
parent 859888d7a2
commit 09dbe975ac
4 changed files with 71 additions and 5 deletions

View File

@ -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:
-sudo chmod 777 $(COM)
-./reset_mcu.sh
-stcgal -P stc89 -p $(COM) main.hex
#led.bin:led.hex

View File

@ -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
```
> 推荐使用图形化的串口软件:<<https://github.com/Neutree/COMTool/tree/master>
> 推荐使用图形化的串口软件:[COMtool](https://github.com/Neutree/COMTool/tree/master)
5. 运行`process.py`解析数据生成图片

29
reset_mcu.sh Executable file
View File

@ -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

View File

@ -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<RESET_PASSWORD_LENGTH-1;i++)
{
receice_password[i] = receice_password[i+1];
}
receice_password[RESET_PASSWORD_LENGTH-1] = rec_data;
for(u8 i=0;i<RESET_PASSWORD_LENGTH-1;i++)
{
if(receice_password[i]!= reset_password[i])
{
return 1;
}
}
ISP_CONTR = 0x60; //软件复位并切换到系统ISP监控程序区开始执行程序
return 0;
}
/*******************************************************************************
* : main
* :
@ -57,7 +86,11 @@ void main(void)
if(send_tmp == 1) {
send_tmp = 0;
printf("%02d:%02d:%02d temp = %.1f\r\n", HH, MM, SS, temp_value/10.0);
// for(u8 i=0;i<RESET_PASSWORD_LENGTH;i++) {
// printf("i=%0d, %C[%x] = %C[%x] is %0d\r\n", i, reset_password[i], reset_password[i], receice_password[i], receice_password[i],receice_password[i]!= reset_password[i]);
// }
}
}
}
@ -72,6 +105,7 @@ void uart(void) __interrupt (4) //串口通信中断函数
SBUF=rec_data; //将接收到的数据放入到发送寄存器
while(!TI); //等待发送数据完成
TI=0; //清除发送完成标志?
auto_reset(rec_data);
}
if(TI)
{