Compare commits

...

10 Commits

Author SHA1 Message Date
ebf06e4b0c 优化获取波特率的方式 2024-07-15 01:34:57 +08:00
12fe1b13c7 优化代码逻辑 2024-07-15 01:22:00 +08:00
f8ffa00e00 up 2024-07-15 01:02:36 +08:00
8a5fbc1319 优化获取COM口的逻辑 2024-07-15 01:01:03 +08:00
09dbe975ac 增加不断电下载功能 2024-07-15 00:48:18 +08:00
859888d7a2 更加通用 2024-07-14 01:16:44 +08:00
d51d81ee90 add 串口工具 2024-07-13 15:54:33 +08:00
b11383c5bb update 2024-07-07 19:02:36 +08:00
8ea43ebed0 update 2024-01-15 22:00:02 +08:00
bb92563de2 add filter 2024-01-15 21:59:32 +08:00
12 changed files with 2412 additions and 2208 deletions

2
.gitignore vendored
View File

@ -1,3 +1,3 @@
.vscode/
obj/*
uart_temp.hex
*.hex

View File

@ -15,12 +15,15 @@ else
CC := ablrun sdcc
COM := /dev/ttyUSB0
endif
TEMP := $(shell sudo chmod 777 $(COM))
endif
# set uart baudrate
BAUD := 9600
# set CC TOOL
PACKIHX := packihx
CFLAGS := -DUSE_FLOATS=1
LDFLAGS := --iram-size 0x100 --xram-size 0x400 --code-size 0xffff
# set DIR
INCDIR = include
@ -35,23 +38,27 @@ OBJ := $(patsubst src/%.c, obj/%.rel, $(SRC))
.PHONY: all clean
all: uart_temp.hex
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 $@
uart_temp.hex: $(TARGET)
-$(PACKIHX) $(TARGET) > uart_temp.hex
main.hex: $(TARGET)
-$(PACKIHX) $(TARGET) > main.hex
flash:
-stcgal -P stc89 -p $(COM) uart_temp.hex
-sudo chmod 777 $(COM)
-./reset_mcu.sh $(COM) $(BAUD)
-stcgal -P stc89 -p $(COM) main.hex
com:
-minicom -D $(COM) -b $(BAUD)
#led.bin:led.hex
# objcopy -I ihex -O binary led.hex led.bin

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环境
@ -38,6 +39,14 @@ uart_temp是用于8051单片机上的一个项目用于获取温度并使
4. 打开串口软件,接收来自单片机的数据
串口波特率9600
```bash
minicom -D /dev/ttyUSB0 -b 9600
```
> 推荐使用图形化的串口软件:[COMtool](https://github.com/Neutree/COMTool/tree/master)
5. 运行`process.py`解析数据生成图片
```bash
@ -48,6 +57,7 @@ uart_temp是用于8051单片机上的一个项目用于获取温度并使
# 运行脚本
python process.py
```
![数据图片](./img.png)
## 更多的信息

BIN
SimHei.ttf Normal file

Binary file not shown.

BIN
img.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 26 KiB

View File

@ -7,8 +7,15 @@
typedef unsigned int u16;
typedef unsigned char u8;
// 用于自动重启的变量
__sfr __at (0xE7) ISP_CONTR;
#define RESET_PASSWORD_LENGTH 6
extern char __xdata reset_password[RESET_PASSWORD_LENGTH];
extern char __xdata receice_password[RESET_PASSWORD_LENGTH];
void delay_10us(u16 ten_us);
void delay_ms(u16 ms);
u8 auto_reset(u8 rec_data);
#endif

File diff suppressed because it is too large Load Diff

View File

@ -7,7 +7,7 @@ from pylab import mpl
mpl.rcParams["font.sans-serif"] = ["SimHei"]
# 初始化一个起始日期这里假设是今天凌晨0点
start_date = datetime.now().replace(hour=0, minute=0, second=0, microsecond=0)
start_date = datetime.now().replace(hour=20, minute=21, second=0, microsecond=0)
with open('minicom.cap', 'r') as file:
lines = file.readlines()
@ -21,6 +21,11 @@ for line in lines:
timedelta(minutes=int(time_str.split(':')[1])) + \
timedelta(hours=int(time_str.split(':')[0]))
temperature = float(temp_str)
if len(temperatures) > 0:
pre_temp = temperatures[-1]
else:
pre_temp = temperature
if pre_temp-0.5 < temperature < pre_temp+0.5:
times.append(time)
temperatures.append(temperature)

33
reset_mcu.sh Executable file
View File

@ -0,0 +1,33 @@
#!/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
#===========================================================================
if [ "$#" -ne 2 ]; then
echo "错误此脚本需要且仅需要2个参数, 作为COM口号和波特率。"
exit 1 # 使用非零状态码退出表示异常
fi
stty -F $1 speed $2 cs8 -parenb -cstopb raw -echo -echoe -echok -echoctl -echoke
echo -e "RESET!" > $1
#说明:
#speed 串口波特率
#cs8 数据位8位
#parenb 无校验
#cstopb 停止位1位
#查看串口设置: stty -a -F /dev/ttyUSB0

View File

@ -17,6 +17,7 @@
int HH=0, MM=0, SS=0;
int send_tmp = 0;
/*******************************************************************************
* : main
* :
@ -57,7 +58,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 +77,7 @@ void uart(void) __interrupt (4) //串口通信中断函数
SBUF=rec_data; //将接收到的数据放入到发送寄存器
while(!TI); //等待发送数据完成
TI=0; //清除发送完成标志?
auto_reset(rec_data);
}
if(TI)
{

View File

@ -23,3 +23,31 @@ void delay_ms(u16 ms)
for(i=ms;i>0;i--)
for(j=110;j>0;j--);
}
/*******************************************************************************
* : auto_reset
* : RESET!MCU
* :
* : 0:1:
*******************************************************************************/
char __xdata reset_password[RESET_PASSWORD_LENGTH] = "RESET";
char __xdata receice_password[RESET_PASSWORD_LENGTH] = {0};
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;
}

3
test.py Normal file
View File

@ -0,0 +1,3 @@
import matplotlib
print(matplotlib.matplotlib_fname())
print(matplotlib.get_cachedir())