优化代码逻辑

This commit is contained in:
fengbh 2024-07-15 01:22:00 +08:00
parent f8ffa00e00
commit 12fe1b13c7
3 changed files with 35 additions and 28 deletions

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

View File

@ -17,35 +17,7 @@
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
* :

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;
}