<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          stm32學(xué)習(xí)之六

          作者: 時(shí)間:2016-12-03 來(lái)源:網(wǎng)絡(luò) 收藏
          EXTI按鍵中斷:

          EXTI中斷:
          注意:
          1、EXTI中斷是一種外部中斷,需要配置相關(guān)的管理中斷器件的。
          2、如果是事件中斷,是不需要配置管理這個(gè)寄存器的。
          3、著重注意這種關(guān)系:EXTI寄存器與NVIC寄存器的關(guān)系,就是這個(gè)!!!

          寫(xiě)出的程序如下:
          由于是中斷驅(qū)動(dòng),因此必須配置中斷控制器。
          首先是:
          exit.h中斷頭文件:
          #ifndef _EXIT_H
          #define _EXIT_H
          #include "stm32f10x.h"
          void NVIC_Configure(void);
          void Exit_Configure(void);

          本文引用地址:http://www.ex-cimer.com/article/201612/325176.htm


          #endif
          然后是:
          exit.c中斷程序配置信息:
          #include "exit.h"

          void NVIC_Configure()
          {

          NVIC_InitTypeDef NVIC_InitStructure;
          NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
          NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn;
          NVIC_InitStructure.NVIC_IRQChannelCmd =ENABLE;
          NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0;
          NVIC_InitStructure.NVIC_IRQChannelSubPriority=1;
          NVIC_Init ( &NVIC_InitStructure);
          }

          void Exit_Configure()
          {
          EXTI_InitTypeDef EXTI_InitStructure;
          GPIO_InitTypeDef GPIO_InitStructure;
          RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE| RCC_APB2Periph_AFIO,ENABLE);

          NVIC_Configure();

          GPIO_InitStructure.GPIO_Pin=GPIO_Pin_5;
          GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPD;
          GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;

          GPIO_Init(GPIOE,&GPIO_InitStructure);

          GPIO_SetBits(GPIOC,GPIO_Pin_5);


          GPIO_EXTILineConfig ( GPIO_PortSourceGPIOE, GPIO_PinSource5);
          EXTI_InitStructure.EXTI_Line=EXTI_Line5;
          EXTI_InitStructure.EXTI_LineCmd=ENABLE;
          EXTI_InitStructure.EXTI_Mode=EXTI_Mode_Interrupt;;
          EXTI_InitStructure.EXTI_Trigger=EXTI_Trigger_Falling;
          EXTI_Init(&EXTI_InitStructure) ;

          }


          需要特別注意幾個(gè)配置信息。

          然后是led.h:
          #ifndef _LED_H
          #define _LED_H
          #include "stm32f10x.h"

          #define ON 1
          #define OFF 0

          #define LED1(a) if (a)
          GPIO_ResetBits(GPIOC,GPIO_Pin_3);
          else
          GPIO_SetBits(GPIOC,GPIO_Pin_3)
          #define LED2(a) if (a)
          GPIO_ResetBits(GPIOC,GPIO_Pin_4);
          else
          GPIO_SetBits(GPIOC,GPIO_Pin_4)
          #define LED3(a) if (a)
          GPIO_ResetBits(GPIOC,GPIO_Pin_5);
          else
          GPIO_SetBits(GPIOC,GPIO_Pin_5)
          void LED_GPIO_Config(void);


          #endif

          接著是:led.c

          #include "led.h"
          void LED_GPIO_Config(void)
          {
          GPIO_InitTypeDef GPIO_InitStructure;
          RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);

          GPIO_InitStructure.GPIO_Pin=GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5;
          GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_OD;
          GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;

          GPIO_Init(GPIOC,&GPIO_InitStructure);

          GPIO_SetBits(GPIOC,GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5);
          }

          然后是,中斷主函數(shù):
          /******************** (C) COPYRIGHT 2013**************************
          * 文件名 :main.c
          * 描述 :用3.5.0版本建的工程模板。
          * 實(shí)驗(yàn)平臺(tái):野火STM32開(kāi)發(fā)板
          * 庫(kù)版本 :ST3.5.0
          *
          * 作者 :wit_yuan
          * 版本 : v1.0
          * 時(shí)間 : 2013年4月27日
          **********************************************************************************/
          #include "stm32f10x.h"
          #include "led.h"
          #include "SysTick.h"
          #include "key.h"
          #include "exit.h"
          /*
          * 函數(shù)名:main
          * 描述 : 主函數(shù)
          * 輸入 :無(wú)
          * 輸出 : 無(wú)
          */
          int main(void)
          {
          LED_GPIO_Config();
          //SysTick_Init();
          //key_Init();
          Exit_Configure();
          while(1)
          {

          }

          }

          在程序執(zhí)行之后,只要開(kāi)啟了中斷,那么就會(huì)在按鍵按下后,觸發(fā)中斷!

          中斷服務(wù)程序如下:
          void EXTI9_5_IRQHandler(void)
          {
          if(EXTI_GetITStatus(EXTI_Line5) != RESET) //確保是否產(chǎn)生了EXTI Line中斷
          {
          // LED1 取反
          GPIO_WriteBit(GPIOC, GPIO_Pin_3,
          (BitAction)((1-GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_3))));
          EXTI_ClearITPendingBit(EXTI_Line5); //清除中斷標(biāo)志位
          }
          }


          小結(jié):
          寫(xiě)stm32的程序總體上看來(lái)是比較簡(jiǎn)單的,但是要注意一些比較細(xì)節(jié)的東西。



          關(guān)鍵詞: stm32EXTI按鍵中斷

          評(píng)論


          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();