写一个stm32f103rct6矩阵键盘程序
时间: 2023-04-03 09:04:05 浏览: 126
好的,我可以回答这个问题。以下是一个简单的stm32f103rct6矩阵键盘程序:
#include "stm32f10x.h"
void GPIO_Configuration(void);
void Delay(__IO uint32_t nCount);
int main(void)
{
GPIO_Configuration();
while (1)
{
if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0) == 0)
{
GPIO_SetBits(GPIOB, GPIO_Pin_0);
Delay(0xFFFFF);
GPIO_ResetBits(GPIOB, GPIO_Pin_0);
}
if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_1) == 0)
{
GPIO_SetBits(GPIOB, GPIO_Pin_1);
Delay(0xFFFFF);
GPIO_ResetBits(GPIOB, GPIO_Pin_1);
}
if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_2) == 0)
{
GPIO_SetBits(GPIOB, GPIO_Pin_2);
Delay(0xFFFFF);
GPIO_ResetBits(GPIOB, GPIO_Pin_2);
}
if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_3) == 0)
{
GPIO_SetBits(GPIOB, GPIO_Pin_3);
Delay(0xFFFFF);
GPIO_ResetBits(GPIOB, GPIO_Pin_3);
}
}
}
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
void Delay(__IO uint32_t nCount)
{
for(; nCount != 0; nCount--);
}