1. <th id="uou7b"></th>
        2. <tbody id="uou7b"></tbody>
          <tbody id="uou7b"></tbody>
        3. <span id="uou7b"></span>

          <tbody id="uou7b"></tbody>
          <em id="uou7b"></em>

          專注電子技術學習與研究
          當前位置:單片機教程網 >> STM32 >> 瀏覽文章

          STM32之點亮LED燈程序

          作者:佚名   來源:本站原創   點擊數:  更新時間:2014年08月17日   【字體:

           原理圖:

           頭文件及完整例程下載:http://www.wanmei-8.com/f/stm32標準例程庫函數.rar
          程序:

          #include "stm32f10x.h"
           
          GPIO_InitTypeDef GPIO_InitStructure;
          #define LED1_ON GPIO_SetBits(GPIOB, GPIO_Pin_5);  
           //#define LED1_ON GPIO_WriteBit(GPIOB, GPIO_Pin_5, Bit_SET);
           
          #define LED1_OFF GPIO_ResetBits(GPIOB, GPIO_Pin_5); 
          //#define LED1_OFF GPIO_WriteBit(GPIOB, GPIO_Pin_5, Bit_RESET) ; 
           
          #define LED2_ON GPIO_SetBits(GPIOD, GPIO_Pin_6);  
          #define LED2_OFF GPIO_ResetBits(GPIOD, GPIO_Pin_6); 
           
          #define LED3_ON GPIO_SetBits(GPIOD, GPIO_Pin_3);  
          #define LED3_OFF GPIO_ResetBits(GPIOD, GPIO_Pin_3);  
           
          void RCC_Configuration(void);
          void LED_Config(void);
          void Delay(__IO uint32_t nCount);
           
          /****************************************************************************
          * 名    稱:void LED_Config(void)
          * 功    能:LED 控制初始化函數
           

          輸入
          ****************************************************************************/ 
          void LED_Config(void){
            RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOD , ENABLE);
           
            GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;     //LED1  V6   //將V6,V7,V8 配置為通用推挽輸出  
            GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
            GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //口線翻轉速度為50MHz
            GPIO_Init(GPIOB, &GPIO_InitStructure); 
           
            GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6|GPIO_Pin_3; //LED2, LED3 V7 V8
            GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
            GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
            GPIO_Init(GPIOD, &GPIO_InitStructure);
          //  GPIO_Init(GPIOD, &GPIO_InitStructure);
           
            GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13;      //LCD背光控制
            GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
            GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
            GPIO_Init(GPIOD, &GPIO_InitStructure);
            GPIO_ResetBits(GPIOD, GPIO_Pin_13);              //LCD背光關閉
           
          }
           
          /****************************************************************************
          * 名    稱:int main(void)
          * 功    能:主函數
          ****************************************************************************/ 
          int main(void)
          {
            RCC_Configuration();   //系統時鐘配置
            LED_Config();//LED控制配置
            while (1)
            {
            LED1_ON; LED2_OFF; LED3_OFF;//LED1亮  LED2,LED3滅(LED2,LED3 僅V5  V3,V2,V2.1板有)
              Delay(0xAFFFF);
          LED1_OFF; LED2_ON; LED3_OFF;//LED2亮  LED1,LED3滅(LED2,LED3 僅V5  V3,V2,V2.1板有)
          Delay(0xAFFFF);
          LED1_OFF; LED2_OFF; LED3_ON;//LED3亮  LED1,LED2滅(LED2,LED3 僅V5  V3,V2,V2.1板有)
          Delay(0xAFFFF);    
            }
          }
           
          /****************************************************************************
          * 名    稱:void RCC_Configuration(void)
          * 功    能:系統時鐘配置為72MHZ
          * 入口參數:無
          * 出口參數:無
          * 說    明:
          * 調用方法:無 
          ****************************************************************************/ 
          void RCC_Configuration(void)
          {   
            SystemInit();
          }
           
          /****************************************************************************
          * 名    稱:void Delay(__IO uint32_t nCount)
          * 功    能:延時函數
          * 入口參數:無
          * 出口參數:無
          * 說    明:
          * 調用方法:無 
          ****************************************************************************/ 
          void Delay(__IO uint32_t nCount)
          {
             for(; nCount != 0; nCount--);
          }

           

           

          關閉窗口
          日日噜噜夜夜狠狠久久无码区

              1. <th id="uou7b"></th>
              2. <tbody id="uou7b"></tbody>
                <tbody id="uou7b"></tbody>
              3. <span id="uou7b"></span>

                <tbody id="uou7b"></tbody>
                <em id="uou7b"></em>