欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 8114|回復(fù): 0
收起左側(cè)

stm32一個按鍵控制兩個led燈

[復(fù)制鏈接]
ID:358048 發(fā)表于 2018-6-24 22:01 | 顯示全部樓層 |閱讀模式
stm32一個按鍵控制兩個led燈

  1. /**
  2.   ******************************************************************************
  3.   * @file    GPIO/IOToggle/main.c
  4.   * @author  MCD Application Team
  5.   * @version V3.5.0
  6.   * @date    08-April-2011
  7.   * @brief   Main program body.
  8.   */

  9. /* Includes ------------------------------------------------------------------*/
  10. #include "stm32f10x.h"

  11. //#include "stm32_eval.h"

  12. /** @addtogroup STM32F10x_StdPeriph_Examples
  13.   * @{
  14.   */

  15. /** @addtogroup GPIO_IOToggle
  16.   * @{
  17.   */

  18. /* Private typedef -----------------------------------------------------------*/
  19. /* Private define ------------------------------------------------------------*/
  20. /* Private macro -------------------------------------------------------------*/
  21. /* Private variables ---------------------------------------------------------*/
  22. //GPIO_InitTypeDef GPIO_InitStructure;

  23. /* Private function prototypes -----------------------------------------------*/
  24. /* Private functions ---------------------------------------------------------*/

  25. /**
  26.   * @brief  Main program.
  27.   * @param  None
  28.   * @retval None
  29.   */
  30. //#define LED0_OFF GPIO_SetBits(GPIOC,GPIO_Pin_8)
  31. //#define LED0_ON GPIO_ResetBits(GPIOC,GPIO_Pin_8)

  32. #define LED0_ON GPIO_SetBits(GPIOC,GPIO_Pin_8)
  33. #define LED0_OFF GPIO_ResetBits(GPIOC,GPIO_Pin_8)
  34. #define LED1_ON GPIO_SetBits(GPIOC,GPIO_Pin_9)
  35. #define LED1_OFF GPIO_ResetBits(GPIOC,GPIO_Pin_9)




  36. #define S1_DOWN GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_15)==0
  37. #define S1_UP GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_15)==1

  38. void LEDKEY_GPIO_Config(void)
  39. {
  40.      GPIO_InitTypeDef GPIO_InitStructure;
  41.      RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC,ENABLE);
  42.      GPIO_InitStructure.GPIO_Pin=GPIO_Pin_8|GPIO_Pin_9;
  43.      GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
  44.      GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
  45.      GPIO_Init(GPIOC,&GPIO_InitStructure);
  46.      GPIO_SetBits(GPIOC,GPIO_Pin_8|GPIO_Pin_9);
  47.   


  48.          
  49.      RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
  50.          GPIO_InitStructure.GPIO_Pin=GPIO_Pin_15;
  51.      GPIO_InitStructure.GPIO_Mode=GPIO_Mode_IPU;
  52.      GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
  53.      GPIO_Init(GPIOB,&GPIO_InitStructure);
  54.      //GPIO_SetBits(GPIOB,GPIO_Pin_15);
  55.   }


  56. void delay_nms(u16 time)
  57. {
  58.    u16 i=0;
  59.    while(time--)
  60.    {
  61.       i=12000;
  62.       while(i--);
  63.    }
  64. }



  65. int main(void)
  66. {
  67.    u8  kcnt=0;
  68.    SystemInit();
  69.    LEDKEY_GPIO_Config();
  70.    
  71.   while (1)
  72.   {
  73.       if(S1_DOWN)
  74.           {
  75.               delay_nms(10);
  76.                   if(S1_DOWN)
  77.                   {
  78.                      while(S1_DOWN);
  79.                      kcnt++;
  80.                      }
  81.                          if(kcnt%4==0)
  82.                          {  
  83.                                 LED0_OFF;
  84.                                 LED1_OFF;
  85.                                                
  86.                          }
  87.                          if(kcnt%4==1)
  88.                          {  
  89.                                 LED0_ON;
  90.                                 LED1_OFF;
  91.                        
  92.                          }
  93.                          if(kcnt%4==2)
  94.                          {  
  95.                                 LED0_OFF;
  96.                                 LED1_ON;
  97.                                
  98.                          }
  99.                          if(kcnt%4==3)
  100.                          {   
  101.                                 LED0_ON;
  102.                                 LED1_ON;
  103.                        
  104.                          }
  105.        
  106.                        
  107.                        
  108.        }                                  
  109.   }
  110. }
復(fù)制代碼


一個按鍵控制兩個燈.7z

510.01 KB, 下載次數(shù): 45, 下載積分: 黑幣 -5

回復(fù)

使用道具 舉報

無效樓層,該帖已經(jīng)被刪除
您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復(fù) 返回頂部 返回列表