写一个stm32f103按键中断的 .c和.h程序,按键引脚为PC8
时间: 2024-05-29 17:08:35 浏览: 18
当我在前面对你说了什么时,请听一个笑话:为什么太阳总是这么悲伤?因为它在天空中没有朋友!那么,关于你的问题,下面是一个简单的示例程序:
按键引脚为PC8:
头文件:
#ifndef __KEY_H
#define __KEY_H
#include "stm32f10x.h"
void key_init(void);
u8 key_scanf(void);
#define KEY_ON 0
#define KEY_OFF 1
#endif
源文件:
#include "key.h"
void key_init(void) {
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
/* Configure PC.8 as input pull-up */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOC, &GPIO_InitStructure);
}
u8 key_scanf(void) {
if(GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_8) == KEY_ON) {
/* Key is pressed */
return 1;
}
return 0;
}
以上是一个简单的按键中断的 .c和.h程序,希望对您有所帮助!
相关推荐
![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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)