Skip to content
Snippets Groups Projects
Commit efc8bebe authored by kevin's avatar kevin 🎱
Browse files

完成,可以通过ADC防止堵转卡死

parent 04dddf88
No related branches found
No related tags found
No related merge requests found
No preview for this file type
This diff is collapsed.
This diff is collapsed.
my_main.c:43:6:Send_to_595 24 static
my_main.c:76:6:display 16 static
my_main.c:141:6:mymain 24 static
my_main.c:44:6:Send_to_595 24 static
my_main.c:77:6:display 16 static
my_main.c:142:6:mymain 40 static
......@@ -19,8 +19,9 @@
#define KEY2 HAL_GPIO_ReadPin(KEY3_GPIO_Port, KEY3_Pin)
#define KEY3 HAL_GPIO_ReadPin(KEY4_GPIO_Port, KEY4_Pin)
struct button key1,key2,key3,key4;
struct button key1,key2,key3,key4,overload;
extern ADC_HandleTypeDef hadc;
const char d_num_data[2][10]=
{
{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f},
......@@ -141,9 +142,10 @@ long countdown_set=15000;
void mymain()
{
uint32_t runtime=0,move=0;
uint8_t mode=0;
uint16_t adc;
uint8_t mode=0,overload_mode=0;
uint16_t adc,adc_times=0;
uint32_t adc_l;
uint16_t overload_times=0;
MOTA(0);
MOTB(0);
HC595_DCK(0);
......@@ -159,6 +161,7 @@ void mymain()
while(1)
{
switch(mode)
{
case 0:
......@@ -172,6 +175,10 @@ void mymain()
mode=1;
}
HAL_ADC_Start(&hadc);
HAL_ADC_GetValue(&hadc);
HAL_ADC_Stop(&hadc);
dis_buff.d_num[0]=((countdown/100)%10);
dis_buff.d_num[1]=((countdown/100)%10);
dis_buff.d_num[2]=((countdown/100)%10);
......@@ -202,7 +209,7 @@ void mymain()
dis_buff.dot2=0;
dis_buff.dot3=0;
dis_buff.dot4=0;
overload_times=0;
if(key2.code!=0)
{
mode=2;
......@@ -249,10 +256,19 @@ void mymain()
mode=3;
countdown=countdown_set-countdown;
}
if(key4.code!=0)
if(key4.code<0)
{
mode=1;
}
if(overload.code!=0)
{
overload_times+=1;
}
if(overload_times>2)
{
overload_mode=2;
mode=5;
}
break;
case 3:
MOTB(0);
......@@ -284,10 +300,19 @@ void mymain()
mode=2;
countdown=countdown_set-countdown;
}
if(key4.code!=0)
if(key4.code<0)
{
mode=1;
}
if(overload.code!=0)
{
overload_times+=1;
}
if(overload_times>2)
{
overload_mode=3;
mode=5;
}
break;
case 4:
//setting mode
......@@ -324,6 +349,45 @@ void mymain()
dis_buff.d_num[1]=dis_buff.d_num[1]==0?255:dis_buff.d_num[1];
dis_buff.dot3=1;
break;
case 5:
//overload
MOTB(0);
MOTA(0);
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?255:dis_buff.d_num[1];
dis_buff.dot3=1;
dis_buff.led_err=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;
}
......@@ -352,7 +416,23 @@ void mymain()
dis_buff.led_run=1;
}
}
HAL_ADC_Start(&hadc);
adc_l+=HAL_ADC_GetValue(&hadc);
adc_times+=1;
HAL_ADC_Stop(&hadc);
if(adc_times==32)
{
adc=adc_l>>5;
adc_times=0;
adc_l=0;
}
if(adc>600)
{
GEI_BUTTON_CODE(&overload,1);
}else
{
GEI_BUTTON_CODE(&overload,0);
}
GEI_BUTTON_CODE(&key1,KEY1);
GEI_BUTTON_CODE(&key2,KEY2);
GEI_BUTTON_CODE(&key3,KEY3);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment