按钮驱动
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* button.c
|
||||
*
|
||||
* Created on: Sep 18, 2021
|
||||
* Author: wuwenfeng
|
||||
*/
|
||||
|
||||
#include "button.h"
|
||||
|
||||
void GEI_BUTTON_CODE(struct button *bt,uint8_t in)
|
||||
{
|
||||
#define t 250
|
||||
bt->code=0;
|
||||
if(in==1)
|
||||
{
|
||||
if(bt->lock==0)
|
||||
{
|
||||
if(HAL_GetTick()<bt->time+t)
|
||||
{
|
||||
bt->times++;
|
||||
bt->time=HAL_GetTick();
|
||||
bt->lock=1;
|
||||
|
||||
}else
|
||||
{
|
||||
bt->times=1;
|
||||
bt->time=HAL_GetTick();
|
||||
bt->lock=1;
|
||||
}
|
||||
|
||||
}
|
||||
if(bt->lock==1)
|
||||
{
|
||||
if(HAL_GetTick()>bt->time+t)
|
||||
{
|
||||
bt->code=255;
|
||||
bt->times=255;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(in==0)
|
||||
{
|
||||
if(bt->lock==1)
|
||||
{
|
||||
if(bt->code==255)
|
||||
{
|
||||
|
||||
}else
|
||||
{
|
||||
bt->code=bt->times;
|
||||
}
|
||||
bt->lock=0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* button.h
|
||||
*
|
||||
* Created on: Sep 18, 2021
|
||||
* Author: wuwenfeng
|
||||
*/
|
||||
|
||||
#ifndef BUTTON_H_
|
||||
#define BUTTON_H_
|
||||
|
||||
#include "main.h"
|
||||
|
||||
struct button
|
||||
{
|
||||
uint16_t code;
|
||||
uint8_t lock;
|
||||
uint32_t time;
|
||||
uint16_t times;
|
||||
};
|
||||
|
||||
void GEI_BUTTON_CODE(struct button *bt,uint8_t in);
|
||||
|
||||
#endif /* BUTTON_H_ */
|
||||
@@ -5,6 +5,7 @@
|
||||
* Author: wuwenfeng
|
||||
*/
|
||||
#include "my_main.h"
|
||||
#include "button.h"
|
||||
|
||||
#define HC595_DCK(x) HAL_GPIO_WritePin(HC595_DCK_GPIO_Port, HC595_DCK_Pin, x);
|
||||
#define HC595_RCK(x) HAL_GPIO_WritePin(HC595_RCK_GPIO_Port, HC595_RCK_Pin, x);
|
||||
@@ -13,6 +14,13 @@
|
||||
#define MOTA(x) HAL_GPIO_WritePin(MOTA_GPIO_Port, MOTA_Pin, x);
|
||||
#define MOTB(x) HAL_GPIO_WritePin(MOTB_GPIO_Port, MOTB_Pin, x);
|
||||
|
||||
#define KEY1 HAL_GPIO_ReadPin(KEY1_GPIO_Port, KEY1_Pin)
|
||||
#define KEY2 HAL_GPIO_ReadPin(KEY2_GPIO_Port, KEY2_Pin)
|
||||
#define KEY3 HAL_GPIO_ReadPin(KEY3_GPIO_Port, KEY3_Pin)
|
||||
#define KEY4 HAL_GPIO_ReadPin(KEY4_GPIO_Port, KEY4_Pin)
|
||||
|
||||
struct button key1,key2,key3,key4;
|
||||
|
||||
const char d_num_data[2][10]=
|
||||
{
|
||||
{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f},
|
||||
@@ -134,6 +142,7 @@ void mymain()
|
||||
HC595_SCK(0);
|
||||
|
||||
|
||||
|
||||
while(1)
|
||||
{
|
||||
if(HAL_GetTick()>runtime)
|
||||
@@ -154,6 +163,11 @@ void mymain()
|
||||
dis_buff.led_run=rand()%2;
|
||||
}
|
||||
|
||||
GEI_BUTTON_CODE(&key1,KEY1);
|
||||
GEI_BUTTON_CODE(&key2,KEY2);
|
||||
GEI_BUTTON_CODE(&key3,KEY3);
|
||||
GEI_BUTTON_CODE(&key4,KEY4);
|
||||
|
||||
display();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user