查看: 1595|回复: 0

【GoKit试用体验】LED使用

[复制链接]
  • TA的每日心情
    奋斗
    2023-7-6 08:48
  • 签到天数: 169 天

    连续签到: 1 天

    [LV.7]常住居民III

    发表于 2015-12-30 17:24:52 | 显示全部楼层 |阅读模式
    分享到:
    LED的使用就是GPIO电平的变化,那么先看一下原理图
    捕获.PNG
    可以看到这几个LED使用到的GPIO口分别是:PB1、PB11PB14PB15
    自己的头文件
    1. #define LED3(a) if (a)
    2. GPIO_SetBits(GPIOB,GPIO_Pin_11);

    3. else

    4. GPIO_ResetBits(GPIOB,GPIO_Pin_11)

    5. #define LED2(a) if (a)

    6. GPIO_SetBits(GPIOB,GPIO_Pin_14);
    7. else
    8. GPIO_ResetBits(GPIOB,GPIO_Pin_14)


    9. #define LED1(a) if (a)

    10. GPIO_SetBits(GPIOB,GPIO_Pin_15);

    11. else

    12. GPIO_ResetBits(GPIOB,GPIO_Pin_15)
    13. #efine digitalHi(p,i) {p->BSRR=i;}
    14. #define digitalLo(p,i) {p->BRR =i;}
    15. #define digitalToggle(p,i) {p->ODR ^=i;}

    16. #define LED1_TOGGLE digitalToggle(GPIOB,GPIO_Pin_15)
    17. #define LED1_OFF digitalHi(GPIOB,GPIO_Pin_15)
    18. #define LED1_ON digitalLo(GPIOB,GPIO_Pin_15)

    19. #define LED2_TOGGLE digitalToggle(GPIOB,GPIO_Pin_14)
    20. #define LED2_OFF digitalHi(GPIOB,GPIO_Pin_14)
    21. #define LED2_ON digitalLo(GPIOB,GPIO_Pin_14)
    22. #define LED3_TOGGLE digitalToggle(GPIOB,GPIO_Pin_11)
    23. #define LED3_OFF digitalHi(GPIOB,GPIO_Pin_11)
    24. #define LED3_ON digitalLo(GPIOB,GPIO_Pin_11)


    25. void LED_GPIO_Config(void);
    复制代码
    main函数
    1. #include "stm32f10x.h"
    2. #include "led.h"

    3. void Delay( unsigned int nCount);

    4. int main(void)
    5. {
    6.         GPIO_InitTypeDef GPIO_InitStructure;
    7.         RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOB, ENABLE);     
    8.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
    9.         GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;   
    10.         GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    11.         GPIO_Init(GPIOB, &GPIO_InitStructure);
    12.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14;
    13.         GPIO_Init(GPIOB, &GPIO_InitStructure);   
    14.         GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
    15.         GPIO_Init(GPIOB, &GPIO_InitStructure);   
    16.         GPIO_ResetBits(GPIOB, GPIO_Pin_11|GPIO_Pin_14|GPIO_Pin_15);

    17.          while (1){

    18.                 LED1( 1 );
    19.                 Delay(100000);
    20.                 LED1( 0 );
    21.                 LED2( 1 );
    22.                 Delay(100000);
    23.                 LED2( 0 );
    24.                 LED3( 1 );
    25.                 Delay(100000);
    26.                 LED3( 0 );

    27.         }

    28. }



    29. void Delay(unsigned int  nCount)  //简单的延时函数
    30. {
    31.         for(; nCount != 0; nCount--);
    32. }
    复制代码
    但是LED亮的顺序好像不对啊。是不是板子画错了。

    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /2 下一条



    手机版|小黑屋|与非网

    GMT+8, 2024-4-26 15:10 , Processed in 0.102954 second(s), 16 queries , MemCache On.

    ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.