1
完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
|
|
相关推荐
1个回答
|
|
#include "stm32f10x.h"
#include "uart.h" #define LED GPIO_Pin_8 #define KEY_1_GPIO_CLK RCC_APB2Periph_GPIOA #define KEY_1_GPIO_PORT GPIOA #define KEY_1_GPIO_PIN GPIO_Pin_15 #define KEY_1_EXTI_PORTSOURCE GPIO_PortSourceGPIOA #define KEY_1_EXTI_PINSOURCE GPIO_PinSource15 #define KEY_1_EXTI_LINE EXTI_Line15 #define KEY_1_EXTI_IRQ EXTI15_10_IRQn #define KEY_2_GPIO_CLK RCC_APB2Periph_GPIOC #define KEY_2_GPIO_PORT GPIOC #define KEY_2_GPIO_PIN GPIO_Pin_5 #define KEY_2_EXTI_PORTSOURCE GPIO_PortSourceGPIOC #define KEY_2_EXTI_PINSOURCE GPIO_PinSource5 #define KEY_2_EXTI_LINE EXTI_Line5 #define KEY_2_EXTI_IRQ EXTI9_5_IRQn #define KEY_1_IRQHandler EXTI15_10_IRQHandler #define KEY_2_IRQHandler EXTI9_5_IRQHandler void delay(void) { int i; int j; for(i=0;i<100;i++) { for(j=0;j<100;j++) {} } } void LED_Config(void) { GPIO_InitTypeDef GPIO_InitStructure; // ÆôÓÃGPIO¶ÔÓ¦µÄʱÖÓ RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE); // ÕÒµ½¶ÔÓ¦Òý½Å // GPIOA 8 GPIO_InitStructure.GPIO_Pin=GPIO_Pin_8; // ÅäÖÃΪÊä³öOUTPUT GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP; // SPEED GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; GPIO_Init(GPIOA,&GPIO_InitStructure); // µÍµçƽ GPIO_ResetBits(GPIOA, GPIO_Pin_8); // while(1) //return 0; } uint8_t Key_Scan(GPIO_TypeDef* GPIOx,uint16_t GPIO_Pin) { if(GPIO_ReadInputDataBit(GPIOx,GPIO_Pin)==1) { while(GPIO_ReadInputDataBit(GPIOx,GPIO_Pin)==1); return 1; } else { return 0; } } static void NVIC_Configuration(void) { NVIC_InitTypeDef NVIC_InitStructure; NVIC_InitTypeDef NVIC_InitStructure2; NVIC_InitStructure.NVIC_IRQChannel = KEY_1_EXTI_IRQ; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=1; NVIC_InitStructure.NVIC_IRQChannelSubPriority=1; NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE; NVIC_Init(&NVIC_InitStructure); NVIC_InitStructure2.NVIC_IRQChannel=KEY_2_EXTI_IRQ; NVIC_InitStructure2.NVIC_IRQChannelPreemptionPriority=1; NVIC_InitStructure2.NVIC_IRQChannelSubPriority=1; NVIC_InitStructure2.NVIC_IRQChannelCmd=ENABLE; NVIC_Init(&NVIC_InitStructure2); } void KEY_CPIOConfig(void) { GPIO_InitTypeDef GPIO_InitStructure; EXTI_InitTypeDef EXTI_InitStructure; EXTI_InitTypeDef EXTI_InitStructure5; RCC_APB2PeriphClockCmd(KEY_1_GPIO_CLK|KEY_2_GPIO_CLK,ENABLE); NVIC_Configuration(); GPIO_InitStructure.GPIO_Pin=KEY_1_GPIO_PIN; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING; GPIO_Init(KEY_1_GPIO_PORT,&GPIO_InitStructure); GPIO_EXTILineConfig(KEY_1_EXTI_PORTSOURCE,KEY_1_EXTI_PINSOURCE); EXTI_InitStructure.EXTI_Line= KEY_1_EXTI_LINE; EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Falling; EXTI_InitStructure.EXTI_LineCmd=ENABLE; EXTI_Init(&EXTI_InitStructure); GPIO_InitStructure.GPIO_Pin=KEY_2_GPIO_PIN; GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IN_FLOATING; GPIO_Init(KEY_2_GPIO_PORT,&GPIO_InitStructure); GPIO_EXTILineConfig(KEY_2_EXTI_PORTSOURCE,KEY_2_EXTI_PINSOURCE); EXTI_InitStructure5.EXTI_Line =KEY_2_EXTI_LINE; EXTI_InitStructure5.EXTI_Mode=EXTI_Mode_Interrupt; EXTI_InitStructure5.EXTI_Trigger=EXTI_Trigger_Falling; EXTI_InitStructure5.EXTI_LineCmd=ENABLE; EXTI_Init(&EXTI_InitStructure5); } void KEY_2_IRQHandler(void)//pc5 { delay(); if(EXTI_GetITStatus(KEY_1_EXTI_LINE)!=RESET) { GPIO_SetBits(GPIOA,GPIO_Pin_8); EXTI_ClearITPendingBit(KEY_1_EXTI_LINE); } } void KEY_1_IRQHandler(void)//pa15 { delay(); if(EXTI_GetITStatus(KEY_2_EXTI_LINE)!=RESET) { Usart_SendString( USART1,"key1.2n"); GPIO_ResetBits(GPIOA,GPIO_Pin_8); EXTI_ClearITPendingBit(KEY_2_EXTI_LINE); } } int main(void) { LED_Config(); KEY_CPIOConfig(); while(1) { } return 0; } |
|
|
|
只有小组成员才能发言,加入小组>>
调试STM32H750的FMC总线读写PSRAM遇到的问题求解?
1767 浏览 1 评论
X-NUCLEO-IHM08M1板文档中输出电流为15Arms,15Arms是怎么得出来的呢?
1619 浏览 1 评论
1069 浏览 2 评论
STM32F030F4 HSI时钟温度测试过不去是怎么回事?
724 浏览 2 评论
ST25R3916能否对ISO15693的标签芯片进行分区域写密码?
1673 浏览 2 评论
1935浏览 9评论
STM32仿真器是选择ST-LINK还是选择J-LINK?各有什么优势啊?
727浏览 4评论
STM32F0_TIM2输出pwm2后OLED变暗或者系统重启是怎么回事?
567浏览 3评论
592浏览 3评论
stm32cubemx生成mdk-arm v4项目文件无法打开是什么原因导致的?
551浏览 3评论
小黑屋| 手机版| Archiver| 德赢Vwin官网 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-21 19:54 , Processed in 0.496129 second(s), Total 73, Slave 57 queries .
Powered by 德赢Vwin官网 网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
德赢Vwin官网 观察
版权所有 © 湖南华秋数字科技有限公司
德赢Vwin官网 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号