写一个stm32f103rct6的按键程序,按键接PC8
时间: 2024-04-25 13:09:20 浏览: 24
#include "stm32f10x.h"
#include "stm32f10x_gpio.h"
#include "stm32f10x_rcc.h"
int main(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOC, &GPIO_InitStructure);
while(1)
{
if(GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_8) == RESET)
{
//按键按下,执行相应操作
}
}
}
相关问题
写一个stm32f103RCT6按键中断程序,按键引脚为PC9
这是一个技术问题,我可以为您提供代码:
``` c
#include "stm32f103rc.h"
void EXTI9_5_IRQHandler(void) {
if (GPIOC->IDR & GPIO_IDR_IDR9) {
// PC9 按键按下
}
// 清除中断标志位
EXTI->PR |= EXTI_PR_PR9;
}
void init_GPIO(void) {
// 使能 GPIOC 时钟
RCC->APB2ENR |= RCC_APB2ENR_IOPCEN;
// PC9 配置为输入模式,上拉输入
GPIOC->CRH &= ~(GPIO_CRH_MODE9 | GPIO_CRH_CNF9);
GPIOC->CRH |= GPIO_CRH_CNF9_1 | GPIO_CRH_MODE9_0;
// 外部中断线 9 配置
EXTI->IMR |= EXTI_IMR_MR9; // 使能线路 9
EXTI->FTSR |= EXTI_FTSR_TR9; // 下降沿触发
NVIC_EnableIRQ(EXTI9_5_IRQn); // 使能 NVIC 中断线 5 至 9
}
int main(void) {
init_GPIO();
while (1) {
// 做一些其它事情,例如读取传感器等
// 进入低功耗模式等待中断
__WFI();
}
}
```
希望对您有所帮助。
写一个stm32f103rct6矩阵键盘程序
好的,我可以回答这个问题。以下是一个简单的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--);
}
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)