Compare commits
	
		
			10 Commits
		
	
	
		
			3334d7896c
			...
			ebf06e4b0c
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| ebf06e4b0c | |||
| 12fe1b13c7 | |||
| f8ffa00e00 | |||
| 8a5fbc1319 | |||
| 09dbe975ac | |||
| 859888d7a2 | |||
| d51d81ee90 | |||
| b11383c5bb | |||
| 8ea43ebed0 | |||
| bb92563de2 | 
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -1,3 +1,3 @@
 | 
			
		||||
.vscode/
 | 
			
		||||
obj/*
 | 
			
		||||
uart_temp.hex
 | 
			
		||||
*.hex
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										23
									
								
								Makefile
									
									
									
									
									
								
							
							
						
						
									
										23
									
								
								Makefile
									
									
									
									
									
								
							@@ -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
 | 
			
		||||
flash:
 | 
			
		||||
	-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
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										12
									
								
								ReadMe.md
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								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环境
 | 
			
		||||
@@ -38,8 +39,16 @@ uart_temp是用于8051单片机上的一个项目,用于获取温度,并使
 | 
			
		||||
 | 
			
		||||
4. 打开串口软件,接收来自单片机的数据
 | 
			
		||||
 | 
			
		||||
    串口波特率:9600
 | 
			
		||||
 | 
			
		||||
    ```bash
 | 
			
		||||
    minicom -D /dev/ttyUSB0 -b 9600
 | 
			
		||||
    ```
 | 
			
		||||
 | 
			
		||||
 	> 推荐使用图形化的串口软件:[COMtool](https://github.com/Neutree/COMTool/tree/master)
 | 
			
		||||
 | 
			
		||||
5. 运行`process.py`解析数据生成图片
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    ```bash
 | 
			
		||||
        # 新建虚拟环境
 | 
			
		||||
        virtualenv env
 | 
			
		||||
@@ -48,6 +57,7 @@ uart_temp是用于8051单片机上的一个项目,用于获取温度,并使
 | 
			
		||||
        # 运行脚本
 | 
			
		||||
        python process.py
 | 
			
		||||
    ```
 | 
			
		||||
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
## 更多的信息
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										
											BIN
										
									
								
								SimHei.ttf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								SimHei.ttf
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								img.png
									
									
									
									
									
								
							
							
						
						
									
										
											BIN
										
									
								
								img.png
									
									
									
									
									
								
							
										
											Binary file not shown.
										
									
								
							| 
		 Before Width: | Height: | Size: 20 KiB After Width: | Height: | Size: 26 KiB  | 
@@ -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
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										4495
									
								
								minicom.cap
									
									
									
									
									
								
							
							
						
						
									
										4495
									
								
								minicom.cap
									
									
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										11
									
								
								process.py
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								process.py
									
									
									
									
									
								
							@@ -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,8 +21,13 @@ for line in lines:
 | 
			
		||||
                        timedelta(minutes=int(time_str.split(':')[1])) + \
 | 
			
		||||
                        timedelta(hours=int(time_str.split(':')[0]))
 | 
			
		||||
    temperature = float(temp_str)
 | 
			
		||||
    times.append(time)
 | 
			
		||||
    temperatures.append(temperature)
 | 
			
		||||
    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)
 | 
			
		||||
 | 
			
		||||
# 确保时间序列是排序的
 | 
			
		||||
times.sort()
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										33
									
								
								reset_mcu.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										33
									
								
								reset_mcu.sh
									
									
									
									
									
										Executable 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   
 | 
			
		||||
@@ -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)
 | 
			
		||||
	{
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										28
									
								
								src/public.c
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								src/public.c
									
									
									
									
									
								
							@@ -22,4 +22,32 @@ void delay_ms(u16 ms)
 | 
			
		||||
	u16 i,j;
 | 
			
		||||
	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;
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user