“优化了一下”

This commit is contained in:
2021-11-05 10:21:32 +08:00
parent a4d76b0005
commit 7a4c0b2aba
6 changed files with 2126 additions and 2161 deletions
+74 -122
View File
@@ -16,41 +16,6 @@ struct button key1,key2,key3,key4;
config_setting config;
#define set_filtering_times 50
struct
{
//ADC_HandleTypeDef *device;
int filtering_times;
unsigned long adc_filtering[2];
int adc_value[2];
}ADCC;
struct
{
uint32_t moto_run;
int pwm_run;
char moto1a;
char moto1b;
char moto2a;
char moto2b;
char moto1a_;
char moto1b_;
char moto2a_;
char moto2b_;
}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;
//}
//send data to 959
void Sand_Byte_to_595_2(uint8_t h)
@@ -74,7 +39,7 @@ void Sand_Byte_to_595_2(uint8_t h)
HC595_RCK(1);
HC595_RCK(0);
}
void hc2_sever()
void HC595_control_server()
{
char h=0;
if(dis_buff.led_run==1)
@@ -101,61 +66,50 @@ void hc2_sever()
}
//motor cool start
void moto_server()
void Motoer_control_server()
{
if(HAL_GetTick()>moto.moto_run)
{
moto.moto_run=HAL_GetTick()+10;
if(moto.moto1a!=moto.moto1a_)
moto.moto_run=HAL_GetTick()+10; //set the index follow delay
if(moto.moto1a>moto.moto1a_)
{
if(moto.moto1a>moto.moto1a_)
{
moto.moto1a_++;
}
if(moto.moto1a<moto.moto1a_)
{
moto.moto1a_--;
}
moto.moto1a_++;
}
if(moto.moto1b!=moto.moto1b_)
if(moto.moto1a<moto.moto1a_)
{
if(moto.moto1b>moto.moto1b_)
{
moto.moto1b_++;
}
if(moto.moto1b<moto.moto1b_)
{
moto.moto1b_--;
}
moto.moto1a_--;
}
if(moto.moto2a!=moto.moto2a_)
if(moto.moto1b>moto.moto1b_)
{
if(moto.moto2a>moto.moto2a_)
{
moto.moto2a_++;
}
if(moto.moto2a<moto.moto2a_)
{
moto.moto2a_--;
}
moto.moto1b_++;
}
if(moto.moto2b!=moto.moto2b_)
if(moto.moto1b<moto.moto1b_)
{
if(moto.moto2b>moto.moto2b_)
{
moto.moto2b_++;
}
if(moto.moto2b<moto.moto2b_)
{
moto.moto2b_--;
}
moto.moto1b_--;
}
if(moto.moto2a>moto.moto2a_)
{
moto.moto2a_++;
}
if(moto.moto2a<moto.moto2a_)
{
moto.moto2a_--;
}
if(moto.moto2b>moto.moto2b_)
{
moto.moto2b_++;
}
if(moto.moto2b<moto.moto2b_)
{
moto.moto2b_--;
}
}
moto.pwm_run++;
if(moto.pwm_run==10)
{
@@ -289,20 +243,16 @@ void my_code()
{
uint32_t runtime=0,move=0;
uint8_t mode=1;
long countdown=1000;
long countdown_set=15000;
char moto_in1,moto_in2;
uint16_t moto_in1_pp=0,moto_in2_pp=0;
char moto_sw_buff1,moto_sw_buff2;
uint16_t moto_sw_buff1_pp=0,moto_sw_buff2_pp=0;
HT1621_Init();
r480_init();
config.begin=0;
AT24CXX_Read(32,(char *)&config,sizeof(config_setting));
if(config.begin!=0xab||check_need_reset())
AT24CXX_Read(EEPROM_BEGIN_ADD,(char *)&config,sizeof(config_setting));
if(config.begin!=CONFIG_EFF_CODE||check_need_reset())
{
mode=0;
r480.key=0;
@@ -354,14 +304,15 @@ void my_code()
}
if(r480.key==0xd7)
{
config.begin=0xab;
config.begin=CONFIG_EFF_CODE;
config.key_code[0]=r480.add[0];
config.key_code[1]=r480.add[1];
config.countdown_set=15000;
r480.key=0;
r480.add[0]=0;
r480.add[1]=0;
mode=1;
AT24CXX_Write(32,(char *)&config,sizeof(config_setting));
AT24CXX_Write(EEPROM_BEGIN_ADD,(char *)&config,sizeof(config_setting));
}
break;
@@ -397,7 +348,7 @@ void my_code()
if(key2.code!=0)
{
mode=2;
countdown=countdown_set;
countdown=config.countdown_set;
moto.moto1a=10;
moto.moto1b=0;
moto.moto2a=10;
@@ -410,7 +361,7 @@ void my_code()
moto.moto2a=0;
moto.moto2b=10;
mode=3;
countdown=countdown_set;
countdown=config.countdown_set;
}
if(key1.code!=0)
{
@@ -445,7 +396,7 @@ void my_code()
if(key3.code!=0)
{
mode=3;
countdown=countdown_set-countdown;
countdown=config.countdown_set-countdown;
moto.moto1a=0;
moto.moto1b=10;
moto.moto2a=0;
@@ -456,13 +407,13 @@ void my_code()
mode=1;
}
if(ADCC.adc_value[1]>400||(moto_in1==1&&READ_MOT_IN1==0))
if(ADCC.adc_value[1]>400||(moto_sw_buff1==1&&READ_MOT_IN1==0))
{
//overload_times=0;
moto.moto1a=0;
moto.moto1b=0;
}
if(ADCC.adc_value[0]>400||(moto_in2==1&&READ_MOT_IN2==0))
if(ADCC.adc_value[0]>400||(moto_sw_buff2==1&&READ_MOT_IN2==0))
{
moto.moto2a=0;
moto.moto2b=0;
@@ -494,7 +445,7 @@ void my_code()
if(key2.code!=0)
{
mode=2;
countdown=countdown_set-countdown;
countdown=config.countdown_set-countdown;
moto.moto1a=10;
moto.moto1b=0;
moto.moto2a=10;
@@ -504,13 +455,13 @@ void my_code()
{
mode=1;
}
if(ADCC.adc_value[1]>400||(moto_in1==1&&READ_MOT_IN1==0))
if(ADCC.adc_value[1]>400||(moto_sw_buff1==1&&READ_MOT_IN1==0))
{
//overload_times=0;
moto.moto1a=0;
moto.moto1b=0;
}
if(ADCC.adc_value[0]>400||(moto_in2==1&&READ_MOT_IN2==0))
if(ADCC.adc_value[0]>400||(moto_sw_buff2==1&&READ_MOT_IN2==0))
{
//overload_times2=0;
moto.moto2a=0;
@@ -531,25 +482,26 @@ void my_code()
dis_buff.dot4=1;
}
countdown-=100;
if(countdown<0)
{
mode=1;
}
if(key2.code<0){countdown_set+=1000;countdown=10000;}
if(key3.code<0){countdown_set-=1000;countdown=10000;}
if(key2.code<0){config.countdown_set+=1000;countdown=10000;}
if(key3.code<0){config.countdown_set-=1000;countdown=10000;}
}
if(key2.code>0){countdown_set+=100;countdown=10000;}
if(key3.code>0){countdown_set-=100;countdown=10000;}
if(countdown_set<100){countdown_set=100;}
if(countdown_set>60000){countdown_set=60000;}
if(key2.code>0){config.countdown_set+=100;countdown=10000;}
if(key3.code>0){config.countdown_set-=100;countdown=10000;}
if(config.countdown_set<100){config.countdown_set=100;}
if(config.countdown_set>60000){config.countdown_set=60000;}
if(key4.code!=0){mode=1;}
dis_buff.d_num[3]=(countdown_set/100)%10;
dis_buff.d_num[2]=(countdown_set/1000)%10;
dis_buff.d_num[1]=((countdown_set/10000)%10);
if(key4.code!=0||countdown<0)
{
mode=1;
AT24CXX_Write(EEPROM_BEGIN_ADD,(char *)&config,sizeof(config_setting));
}
dis_buff.d_num[3]=(config.countdown_set/100)%10;
dis_buff.d_num[2]=(config.countdown_set/1000)%10;
dis_buff.d_num[1]=((config.countdown_set/10000)%10);
dis_buff.d_num[1]=dis_buff.d_num[1]==0?16:dis_buff.d_num[1];
@@ -595,28 +547,28 @@ void my_code()
dis_buff.button_flag[2]=0;
dis_buff.button_flag[3]=0;
if(moto_in1!=READ_MOT_IN1)
if(moto_sw_buff1!=READ_MOT_IN1)
{
moto_in1_pp++;
if(moto_in1_pp==100)
moto_sw_buff1_pp++;
if(moto_sw_buff1_pp==100)
{
moto_in1_pp=0;
moto_in1=READ_MOT_IN1;
moto_sw_buff1_pp=0;
moto_sw_buff1=READ_MOT_IN1;
}
}
if(moto_in2!=READ_MOT_IN2)
if(moto_sw_buff2!=READ_MOT_IN2)
{
moto_in2_pp++;
if(moto_in2_pp==100)
moto_sw_buff2_pp++;
if(moto_sw_buff2_pp==100)
{
moto_in2_pp=0;
moto_in2=READ_MOT_IN2;
moto_sw_buff2_pp=0;
moto_sw_buff2=READ_MOT_IN2;
}
}
HT1621_Display_GetButton();
hc2_sever();
moto_server();
HC595_control_server();
Motoer_control_server();
}
}