欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
STM32 4X4矩形鍵盤代碼
[打印本頁]
作者:
LHM
時間:
2019-7-25 09:58
標題:
STM32 4X4矩形鍵盤代碼
有空做了一個4X4的矩陣鍵盤
單片機源程序如下:
#include "key.h"
#include "Systick.h"
uint8_t Key_Number=0,column=0;
//行做輸出低電平,列讀取電平
void KEY_L_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APBxPeriphClockCmd (RCC_APB2Periph_GPIOx,ENABLE);
//列
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING; //浮空輸入
GPIO_InitStructure.GPIO_Pin=KEY_L0_GPIO_PIN;
GPIO_Init(KEY_L0_PORN,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=KEY_L1_GPIO_PIN;
GPIO_Init(KEY_L1_PORN,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=KEY_L2_GPIO_PIN;
GPIO_Init(KEY_L2_PORN,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=KEY_L3_GPIO_PIN;
GPIO_Init(KEY_L3_PORN,&GPIO_InitStructure);
//行
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP; //推挽輸出
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin=KEY_R0_PIN;
GPIO_Init(KEY_R0_PORN,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=KEY_R1_PIN;
GPIO_Init(KEY_R1_PORN,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=KEY_R2_PIN;
GPIO_Init(KEY_R2_PORN,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=KEY_R3_PIN;
GPIO_Init(KEY_R3_PORN,&GPIO_InitStructure);
}
//列做輸出高電平,行讀取電平
void KEY_R_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APBxPeriphClockCmd (RCC_APB2Periph_GPIOx,ENABLE);
//列
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP; //推挽輸出
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin=KEY_L0_GPIO_PIN;
GPIO_Init(KEY_L0_PORN,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=KEY_L1_GPIO_PIN;
GPIO_Init(KEY_L1_PORN,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=KEY_L2_GPIO_PIN;
GPIO_Init(KEY_L2_PORN,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=KEY_L3_GPIO_PIN;
GPIO_Init(KEY_L3_PORN,&GPIO_InitStructure);
//行
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING; //浮空輸入
GPIO_InitStructure.GPIO_Pin=KEY_R0_PIN;
GPIO_Init(KEY_R0_PORN,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=KEY_R1_PIN;
GPIO_Init(KEY_R1_PORN,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=KEY_R2_PIN;
GPIO_Init(KEY_R2_PORN,&GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin=KEY_R3_PIN;
GPIO_Init(KEY_R3_PORN,&GPIO_InitStructure);
}
void Keyboard_Scanning (void)
{
KEY_L_Init(); //行做輸出低電平,列讀取電平
L_KEY_R0; //各行輸出低電平
L_KEY_R1;
L_KEY_R2;
L_KEY_R3;
if(KEY_L0==0)column=1; //如果第一列讀到低電平
if(KEY_L1==0)column=2; //如果第二列讀到低電平
if(KEY_L2==0)column=3; //如果第三列讀到低電平
if(KEY_L3==0)column=4; //如果第四列讀到低電平
if(column==1) //如果第一列讀到低電平
{
KEY_R_Init(); //列做輸出高電平,行讀取電平
H_KEY_L0; //第一列輸出高電平
SysTick_Delay_us(5);
if(KEY_R0==1)Key_Number=1; //第一行
if(KEY_R1==1)Key_Number=2; //第二行
if(KEY_R2==1)Key_Number=3; //第三行
if(KEY_R3==1)Key_Number=4; //第四行
}
if(column==2) //如果第二列讀到低電平
{
KEY_R_Init();
H_KEY_L1; //第二列輸出高電平
SysTick_Delay_us(5);
if(KEY_R0==1)Key_Number=5;
if(KEY_R1==1)Key_Number=6;
if(KEY_R2==1)Key_Number=7;
if(KEY_R3==1)Key_Number=8;
}
if(column==3) //如果第三列讀到低電平
{
KEY_R_Init();
H_KEY_L2; //第三列輸出高電平
SysTick_Delay_us(5);
if(KEY_R0==1)Key_Number=9;
if(KEY_R1==1)Key_Number=10;
if(KEY_R2==1)Key_Number=11;
if(KEY_R3==1)Key_Number=12;
}
if(column==4) //如果第四列讀到低電平
{
KEY_R_Init();
H_KEY_L3; //第四列輸出高電平
SysTick_Delay_us(5);
if(KEY_R0==1)Key_Number=13;
if(KEY_R1==1)Key_Number=14;
if(KEY_R2==1)Key_Number=15;
if(KEY_R3==1)Key_Number=16;
}
column=0; //列標記清零
}
復制代碼
所有資料51hei提供下載:
4x4矩形鍵盤.7z
(182.31 KB, 下載次數: 22)
2019-7-25 16:35 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
作者:
admin
時間:
2019-7-25 16:35
本帖需要重新編輯補全電路原理圖,源碼,詳細說明與圖片即可獲得100+黑幣(帖子下方有編輯按鈕)
歡迎光臨 (http://m.raoushi.com/bbs/)
Powered by Discuz! X3.1