wulin 发表于 2024-3-17 12:01
按键硬件消抖是很简单的事,通常用1K电阻和104电容组成低通滤波器即可。但从楼主描述来看不像是按键延时 ...
void show(){
OLED_ShowCH(0,0,"");
sprintf((char*)buff,":%2d %d",timekaishi,isMan);
OLED_ShowCH(16*6, 0, (u8*)buff);
if(isbf==0){
OLED_ShowCH(0,2,"··");
}else{
OLED_ShowCH(0,2,"·");
}
}
void tip(){
beep=0;
delay_mss(500);
beep=1;
}
void fasong(){
}
void set_mima(u8 a,u8 b){
u8 j;
OLED_ShowCH(0,0,"");
sprintf((char*)buff,"%d",a);
OLED_ShowCH(0, 2, (u8*)buff);
for (j = 0; j < b; j++) {
OLED_ShowCH(16*j,4,"*");
}
}
void passwords(){
u8 key,i;
u8 indexs=0,n=1;
u8 values=0,result=0;
static char mima[6];
static char mima_a[]={1,2,3,4,5,7};
while(n){
key=KEY_Scan(0);
if(key){
switch(key){
case 1:
mima[indexs]=values;
indexs++;
if(indexs>=6){
//
for (i = 0; i < 6; i++) {
if(mima!=mima_a){
result=1;
break;
}
}
n=0;
OLED_Clear();
if(result){
//§°
OLED_ShowCH(0,0,"§°");
tip();
}else{
OLED_ShowCH(0,0,"");
weizhi();
delay_mss(2000);
}
OLED_Clear();
break;
}
break;
case 2:
if(values<9)values++;
break;
case 3:
if(values!=0)values--;
break;
default:
break;
}
}
if(n)set_mima(values,indexs);
}
}
void panduan(){
if(timekaishi==21 && isMan && isbf){
//±¨
isbaojing=1;
}else{
isbaojing=0;
}
}
void IC_test ( void )
{
u8 ensure,n,key,statuess,t;
char cStr [ 30 ];
uint8_t ucArray_ID [ 4 ]; /*ó·IC¨àUID(IC¨ò)*/
uint8_t ucStatusReturn; /*·× */
static uint8_t ucLineCount = 0;
char *strx;
while ( 1 )
{
if(hongwai==1)
{
gTime=0; // ìò°20±
}
if(gTime>5*2){ //gTime20
gTime=5*2; //ò°gTime20±ó
isMan=0; // 10ì
}
if(gTime<5*2){
isMan=1; //
}
key=KEY_Scan(0);
switch(key){
case 3:
//
break;
case 1:
if(isbf){
isbf=0;
}else{
isbf=1;
}
break;
case 2:
OLED_Clear();
//
passwords();
break;
}
show();
panduan();
/*°¨*/
if ( ( ucStatusReturn = PcdRequest ( PICC_REQALL, ucArray_ID ) ) != MI_OK )
/*§°°¨*/
ucStatusReturn = PcdRequest ( PICC_REQALL, ucArray_ID );
if ( ucStatusReturn == MI_OK )
{
/*·×¨±à¨÷×÷·§±·úá×÷*/
if ( PcdAnticoll ( ucArray_ID ) == MI_OK )
{
sprintf ( cStr, "The Card ID is: %02X%02X%02X%02X",
ucArray_ID [ 0 ],
ucArray_ID [ 1 ],
ucArray_ID [ 2 ],
ucArray_ID [ 3 ] );
sprintf(buffid,"CardID:%02X%02X%02X%02X",ucArray_ID [ 0 ],ucArray_ID [ 1 ],ucArray_ID [ 2 ],ucArray_ID [ 3 ]);
OLED_Clear();
OLED_ShowCH(0, 2, (u8*)buffid);
delay_mss(2000);
sprintf(buffid,"%02X%02X%02X%02X",ucArray_ID [ 0 ],ucArray_ID [ 1 ],ucArray_ID [ 2 ],ucArray_ID [ 3 ]);
strx=strstr((const char*)buffid,(const char*)"83FA6C9D");//·CSQ
OLED_Clear();
if(strx){
OLED_ShowCH(0,4,"±");
weizhi();
delay_mss(1000);
}else{
OLED_ShowCH(0,4,"±§°");
tip();
}
delay_mss(1000);
OLED_Clear();
}
}
}
}
int main(void)
{
u8 t;
extern const u8 BMP1[];
HZ= GB16_NUM();
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //èNVIC·×é2:22ì
delay_init(); //±
USART2_Init_Config(9600); //wifi
TIM3_Int_Init(4999,7199);
LED_Init();
KEY_Init();
OLED_Init(); //OLED
OLED_Clear(); //OLED
delay_ms(10);
OLED_Init(); //OLED
OLED_Clear(); //OLED
OLED_ShowCH(0,4,"init..");
RC522_Init ();
PcdReset ();
/*è¤×÷·*/
M500PcdConfigISOType ( 'A' );
OLED_Clear();
while(1)
{
/*IC¨ì */
IC_test ();
}
}
//ù×
short CharArrayToNumber( char *p_pBuff, int p_iSize )
{
u8 i;
if ( NULL != p_pBuff && p_iSize > 0 && p_iSize <= 8 )
{
short ulRet = 0;
p_iSize -= 1;
for ( i = 0; i <= p_iSize; ++i)
{
ulRet |= ((short)(p_pBuff)) << ((p_iSize - i) << 2);
}
return ulRet;
}
else
{
return 0;
}
}
void USART2_IRQHandler(void) //1·ò
{
u8 Res,ss;
char datas[2];
if(USART_GetITStatus(USART2, USART_IT_RXNE) != RESET)
{
Res =USART_ReceiveData(USART2); //
USART_ClearFlag(USART2,USART_FLAG_RXNE);
if(Res=='1'){
weizhi();
}
}
}
//¨±÷3·ò
void TIM3_IRQHandler(void) //TIM3
{
if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET) //ìéTIM3ü·ú·
{
TIM_ClearITPendingBit(TIM3, TIM_IT_Update ); //TIMxü±ê
count++;
gTime++;
if(count==2){
count=0;
if(timekaishi!=21){
timekaishi++;
}
if(isbaojing){
beep=~beep;
}else{
beep=1;
}
}
}
} |