完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
|
STM32F103ZET6的学习:中断函数的应用(程序及电路图如下)》》
#include "stm32f10x.h" #define key GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_13) char sj; void qjInit() //初始化 { GPIO_InitTypeDef GPIO_InitStruct; EXti_InitTypeDef EXTI_InitStruct; NVIC_InitTypeDef NVIC_InitStruct; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);//开IOC时钟 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOF,ENABLE);//开IOF时钟 GPIO_InitStruct.GPIO_Mode=GPIO_Mode_IPU; GPIO_InitStruct.GPIO_Pin=GPIO_Pin_13; GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz; GPIO_Init(GPIOC,&GPIO_InitStruct); //IO初始化 GPIO_InitStruct.GPIO_Mode=GPIO_Mode_Out_PP; GPIO_InitStruct.GPIO_Pin=GPIO_Pin_6; GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz; GPIO_Init(GPIOF,&GPIO_InitStruct); //IO初始化 GPIO_ResetBits(GPIOF,GPIO_Pin_6); RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);//开复用时钟 GPIO_EXTILineConfig(GPIO_PortSourceGPIOC,GPIO_PinSource13);//中断映射 EXTI_InitStruct.EXTI_Mode=EXTI_Mode_Interrupt; EXTI_InitStruct.EXTI_Trigger=EXTI_Trigger_Falling; EXTI_InitStruct.EXTI_Line=EXTI_Line13; EXTI_InitStruct.EXTI_LineCmd=ENABLE; EXTI_Init(&EXTI_InitStruct);//中断参数配置 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//中断优先级分组 NVIC_InitStruct.NVIC_IRQChannelCmd=ENABLE; NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority=2; NVIC_InitStruct.NVIC_IRQChannelSubPriority=2; NVIC_InitStruct.NVIC_IRQChannel=EXTI15_10_IRQn; NVIC_Init(&NVIC_InitStruct);//中断优先级配置 } void delay(char x) //延时 { int i,j; for(i=0;i } void EXTI15_10_IRQHandler(void) //中断函数 { delay(10); if(key==0) { sj++; if(sj==1) GPIO_SetBits(GPIOF,GPIO_Pin_6); if(sj==2) { GPIO_ResetBits(GPIOF,GPIO_Pin_6); sj=0; } } EXTI_ClearITPendingBit(EXTI_Line13);//清除中断标志位 } int main(void) { qjInit(); while(1); //等待中断 } 电路图下载:
EM-STM3210E电路图 .pdf
(120.99 KB, 下载次数: 5
)
|
|
|
相关推荐
|
|
311 浏览 0 评论
446 浏览 0 评论
455 浏览 0 评论
456 浏览 0 评论
飞凌嵌入式ElfBoard-文件I/O的深入学习之存储映射I/O
774 浏览 0 评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-12 06:18 , Processed in 0.582140 second(s), Total 73, Slave 53 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖