完成度大概98.99%

This commit is contained in:
2021-10-25 21:02:24 +08:00
parent 39a9350cd1
commit 1b84ff76e5
7 changed files with 7126 additions and 7007 deletions
+1 -1
View File
@@ -55,7 +55,7 @@ void AT24CXX_WriteOneByte(uint16_t WriteAddr,uint8_t DataToWrite)
IIC_Send_Byte(DataToWrite); //发送字节
IIC_Wait_Ack();
IIC_Stop();//产生一个停止条件
HAL_Delay(1);
}
+184 -126
View File
@@ -12,7 +12,7 @@
#include "eeprom.h"
extern ADC_HandleTypeDef hadc;
struct button key1,key2,key3,key4,overload;
struct button key1,key2,key3,key4,overload,overload2;
config_setting config;
@@ -45,12 +45,12 @@ struct
}moto;
uint8_t Read_Ds()
{
change_io_function(HC595_DLK_GPIO_Port,HC595_DLK_Pin,1);
if(READ_HC595_DCK){return 0;}else{return 1;}
//return READ_HC595_DCK;
}
//uint8_t Read_Ds()
//{
// change_io_function(HC595_DLK_GPIO_Port,HC595_DLK_Pin,1);
// if(READ_HC595_DCK){return 0;}else{return 1;}
// //return READ_HC595_DCK;
//}
//send data to 959
void Sand_Byte_to_595_2(uint8_t h)
@@ -251,12 +251,47 @@ void HT1621_Display_GetButton(void)
}
char check_need_reset()
{
char a=0;
change_io_function(MOT_IN1_GPIO_Port, MOT_IN1_Pin,1);
change_io_function(MOT_IN2_GPIO_Port, MOT_IN2_Pin,0);
MOT_IN2(0);
if(READ_MOT_IN1==0)
{
MOT_IN2(1);
if(READ_MOT_IN1==1)
{
change_io_function(MOT_IN1_GPIO_Port, MOT_IN1_Pin,0);
change_io_function(MOT_IN2_GPIO_Port, MOT_IN2_Pin,1);
MOT_IN1(0);
if(READ_MOT_IN2==0)
{
MOT_IN1(1);
if(READ_MOT_IN2==1)
{
a=1;
}
}
}
}
change_io_function(MOT_IN1_GPIO_Port, MOT_IN1_Pin,1);
change_io_function(MOT_IN2_GPIO_Port, MOT_IN2_Pin,1);
return a;
}
void my_code()
{
uint32_t runtime=0,move=0;
uint8_t mode=6,overload_mode=0;
uint8_t mode=1;
uint16_t overload_times=0;
uint16_t overload_times2=0;
long countdown=1000;
long countdown_set=15000;
@@ -264,10 +299,13 @@ void my_code()
HT1621_Init();
r480_init();
config.begin=18;
AT24CXX_Write(8,(char *)&config,sizeof(config_setting));
config.begin=1;
AT24CXX_Read(8,(char *)&config,sizeof(config_setting));
config.begin=0;
AT24CXX_Read(16,(char *)&config,sizeof(config_setting));
if(config.begin!=0xab||check_need_reset())
{
mode=0;
r480.key=0;
}
while(1)
@@ -296,27 +334,32 @@ void my_code()
{
case 0:
//Startup
if(HAL_GetTick()>move)
if(HAL_GetTick()>runtime)
{
move=HAL_GetTick()+100;
countdown-=100;
if(countdown<0)
runtime+=1000;
if(dis_buff.led_run==1)
{
mode=1;
dis_buff.led_run=0;
dis_buff.dot4=1;
dis_buff.d_num[0]=16;
}else
{
dis_buff.led_run=1;
dis_buff.dot4=0;
dis_buff.d_num[0]=10;
}
dis_buff.d_num[0]=((countdown/100)%10);
dis_buff.d_num[1]=((countdown/100)%10);
dis_buff.d_num[2]=((countdown/100)%10);
dis_buff.d_num[3]=((countdown/100)%10);
dis_buff.dot1=countdown>>3;
dis_buff.dot2=countdown>>4;
dis_buff.dot3=countdown>>5;
dis_buff.dot4=countdown>>6;
}
if(r480.key==0xd7)
{
config.begin=0xab;
config.key_code[0]=r480.add[0];
config.key_code[1]=r480.add[1];
r480.key=0;
r480.add[0]=0;
r480.add[1]=0;
mode=1;
AT24CXX_Write(16,(char *)&config,sizeof(config_setting));
}
break;
@@ -354,9 +397,17 @@ void my_code()
{
mode=2;
countdown=countdown_set;
moto.moto1a=10;
moto.moto1b=0;
moto.moto2a=10;
moto.moto2b=0;
}
if(key3.code!=0)
{
moto.moto1a=0;
moto.moto1b=10;
moto.moto2a=0;
moto.moto2b=10;
mode=3;
countdown=countdown_set;
}
@@ -367,10 +418,7 @@ void my_code()
}
break;
case 2:
moto.moto1a=10;
moto.moto1b=0;
moto.moto2a=10;
moto.moto2b=0;
if(HAL_GetTick()>move)
{
move=HAL_GetTick()+100;
@@ -397,6 +445,10 @@ void my_code()
{
mode=3;
countdown=countdown_set-countdown;
moto.moto1a=0;
moto.moto1b=10;
moto.moto2a=0;
moto.moto2b=10;
}
if(key4.code!=0)
{
@@ -406,17 +458,23 @@ void my_code()
{
overload_times+=1;
}
if(overload2.code!=0)
{
overload_times2+=1;
}
if(overload_times>2)
{
overload_mode=2;
mode=5;
overload_times=0;
moto.moto1b=0;
}
if(overload_times2>2)
{
overload_times2=0;
moto.moto2b=0;
}
break;
case 3:
moto.moto1a=0;
moto.moto1b=10;
moto.moto2a=0;
moto.moto2b=10;
if(HAL_GetTick()>move)
{
move=HAL_GetTick()+100;
@@ -442,6 +500,10 @@ void my_code()
{
mode=2;
countdown=countdown_set-countdown;
moto.moto1a=10;
moto.moto1b=0;
moto.moto2a=10;
moto.moto2b=0;
}
if(key4.code!=0)
{
@@ -451,10 +513,19 @@ void my_code()
{
overload_times+=1;
}
if(overload2.code!=0)
{
overload_times2+=1;
}
if(overload_times>2)
{
overload_mode=3;
mode=5;
overload_times=0;
moto.moto1b=0;
}
if(overload_times2>2)
{
overload_times2=0;
moto.moto2b=0;
}
break;
case 4:
@@ -494,102 +565,89 @@ void my_code()
break;
case 5:
//overload
moto.moto1a=0;
moto.moto1b=0;
moto.moto2a=0;
moto.moto2b=0;
dis_buff.led_run=1;
overload_times=0;
dis_buff.d_num[3]=(countdown/100)%10;
dis_buff.d_num[2]=(countdown/1000)%10;
dis_buff.d_num[1]=((countdown/10000)%10);
dis_buff.d_num[1]=dis_buff.d_num[1]==0?16:dis_buff.d_num[1];
dis_buff.dot3=1;
if(key4.code!=0){mode=1;}
// case 5:
// //overload
// moto.moto1a=0;
// moto.moto1b=0;
// moto.moto2a=0;
// moto.moto2b=0;
// dis_buff.led_run=1;
// overload_times=0;
// dis_buff.d_num[3]=(countdown/100)%10;
// dis_buff.d_num[2]=(countdown/1000)%10;
// dis_buff.d_num[1]=((countdown/10000)%10);
// dis_buff.d_num[1]=dis_buff.d_num[1]==0?16:dis_buff.d_num[1];
// dis_buff.dot3=1;
// if(key4.code!=0){mode=1;}
//
// if(key2.code!=0)
// {
// mode=2;
// if(overload_mode==2)
// {
//
// }else
// {
// countdown=countdown_set-countdown;
// }
//
// }
// if(key3.code!=0)
// {
// mode=3;
// if(overload_mode==3)
// {
//
// }else
// {
// countdown=countdown_set-countdown;
// }
//
// }
//
// break;
if(key2.code!=0)
{
mode=2;
if(overload_mode==2)
{
}else
{
countdown=countdown_set-countdown;
}
}
if(key3.code!=0)
{
mode=3;
if(overload_mode==3)
{
}else
{
countdown=countdown_set-countdown;
}
}
break;
case 6:
//stady mode
//config.begin=0xab;
//EEPROM_WRITE_BATY(16,(char *)&config,sizeof(config_setting));
//mode=0;
if(HAL_GetTick()>runtime)
{
runtime+=1000;
if(dis_buff.led_run==1)
{
dis_buff.led_run=0;
dis_buff.dot4=1;
}else
{
dis_buff.led_run=1;
dis_buff.dot4=0;
}
}
dis_buff.d_num[3]=(config.begin)%10;
dis_buff.d_num[2]=(config.begin/10)%10;
dis_buff.d_num[1]=(config.begin/100)%10;
dis_buff.d_num[0]=(config.begin/1000)%10;
break;
}
if(ADCC.adc_value[0]>600||ADCC.adc_value[1]>600)
if(ADCC.adc_value[0]>600)
{
GEI_BUTTON_CODE(&overload,1);
}else
{
GEI_BUTTON_CODE(&overload,0);
}
switch(r480.key)
if(ADCC.adc_value[1]>600)
{
case 0xd7:
dis_buff.button_flag[0]=1;
break;
case 0xdb:
dis_buff.button_flag[1]=1;
break;
case 0xdd:
dis_buff.button_flag[2]=1;
break;
case 0xde:
dis_buff.button_flag[3]=1;
break;
GEI_BUTTON_CODE(&overload2,1);
}else
{
GEI_BUTTON_CODE(&overload2,0);
}
r480.key=0;
if(r480.add[0]==config.key_code[0]&&r480.add[1]==config.key_code[1])
{
switch(r480.key)
{
case 0xd7:
dis_buff.button_flag[0]=1;
break;
case 0xdb:
dis_buff.button_flag[1]=1;
break;
case 0xdd:
dis_buff.button_flag[2]=1;
break;
case 0xde:
dis_buff.button_flag[3]=1;
break;
}
}
r480.key=0;
r480.add[0]=0;
r480.add[1]=0;
GEI_BUTTON_CODE(&key1,dis_buff.button_flag[0]);
GEI_BUTTON_CODE(&key2,dis_buff.button_flag[1]);
GEI_BUTTON_CODE(&key3,dis_buff.button_flag[2]);
+6
View File
@@ -19,6 +19,12 @@ void my_code();
#define HC595_SCK2(x) HAL_GPIO_WritePin(HC595_SLK2_GPIO_Port, HC595_SLK2_Pin, x)
#define READ_HC595_DCK HAL_GPIO_ReadPin(HC595_DLK_GPIO_Port,HC595_DLK_Pin)
#define MOT_IN1(x) HAL_GPIO_WritePin(MOT_IN1_GPIO_Port, MOT_IN1_Pin, x)
#define MOT_IN2(x) HAL_GPIO_WritePin(MOT_IN2_GPIO_Port, MOT_IN2_Pin, x)
#define READ_MOT_IN1 HAL_GPIO_ReadPin(MOT_IN1_GPIO_Port, MOT_IN1_Pin)
#define READ_MOT_IN2 HAL_GPIO_ReadPin(MOT_IN2_GPIO_Port, MOT_IN2_Pin)
typedef struct
{
char begin;