欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標題: STM32單片機矩陣鍵盤 [打印本頁]

作者: A2102179814    時間: 2022-4-28 15:54
標題: STM32單片機矩陣鍵盤
#include "matrix_key.h"
#include "stm32f10x.h"
#include "delay.h"

void KEYPad_Init1(void)
{
        GPIO_InitTypeDef GPIO_InitStructure;
        
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF, ENABLE);//開啟時鐘,使能GPIOB時鐘
        
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;        //上拉輸入 B0-B3
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_Init(GPIOF, &GPIO_InitStructure);
        
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;        //下拉輸入 F4-B7
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_Init(GPIOF, &GPIO_InitStructure);
}

void KEYPad_Init2(void)
{
        GPIO_InitTypeDef GPIO_InitStructure;
        
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF, ENABLE);//開啟時鐘,使能GPIOB時鐘
        
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD;        //下拉輸入 B0-B3
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_Init(GPIOF, &GPIO_InitStructure);
        
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;        //上拉輸入 B4-B7
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
        GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
        GPIO_Init(GPIOF, &GPIO_InitStructure);
}

int KEYPAD_Scan()
{
        static u16 keyvalue = 0;
        u32 readvalue = 0;
        KEYPad_Init1();
        readvalue = GPIO_ReadInputData(GPIOF);
        readvalue &= 0x00ff;
        //return readvalue;

        
        
        if(readvalue != 0x000f)
        {
                delay_ms(8);//消抖10ms
                if(readvalue != 0x000f)
                {
                        readvalue = GPIO_ReadInputData(GPIOF);//再次讀取狀態(tài)
                        readvalue &= 0x00ff;
                        //return readvalue;
                        switch(readvalue)
                        {
                                case (0x001f):keyvalue = 0;break;
                                case (0x002f):keyvalue = 1;break;
                                case (0x004f):keyvalue = 2;break;
                                case (0x008f):keyvalue = 3;break;
                        }
                        //return readvalue;
                        KEYPad_Init2();
                        delay_ms(5);
                        readvalue = GPIO_ReadInputData(GPIOF);//再次讀取狀態(tài)
                        readvalue |= 0x00f0;
                        readvalue &= 0x00ff;
                        //return readvalue;
                        switch(readvalue)
                        {
                                case (0x00f1):keyvalue += 0;break;
                                case (0x00f2):keyvalue += 4;break;
                                case (0x00f4):keyvalue += 8;break;
                                case (0x00f8):keyvalue += 12;break;
                        }
                        
                        while(readvalue != 0x00f0)//檢測按鍵松開
                        {
                                readvalue = GPIO_ReadInputData(GPIOF);//再次讀取狀態(tài)
                                readvalue |= 0x00f0;
                                readvalue &= 0x00ff;
                        }
                        //return readvalue;
                }
        }
        return keyvalue;
}







歡迎光臨 (http://www.raoushi.com/bbs/) Powered by Discuz! X3.1