打印
[技术问答]

修改LED的GPIO

[复制链接]
577|8
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
bestdesign11|  楼主 | 2021-1-22 14:49 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
您好,想问一下在库中都定义了GPIO_PIN_x,如果在LED的程序中想修改GPIO调用几,就那个口亮,这么修改可以吗?6口,7口的交替闪烁.
        Led_On(6);
        delay_ms(500);
        Led_Off(6);
        delay_ms(500);


        Led_On(7);
        delay_ms(500);
        Led_Off(7);
        delay_ms(500);


在LED_On中做如下修改:
void Led_On(int GPIO_Number)
{
    GPIO_ResetBits(GPIOC, "GPIO_Pin_"&char(GPIO_Number);
}

void Led_Off(int GPIO_Number)
{
    GPIO_SetBits(GPIOC, "GPIO_Pin_"&char(GPIO_Number);
}


编译不通过,如果自己定义调用的GPIO呢?

使用特权

评论回复

相关帖子

沙发
laocuo1142| | 2021-1-22 15:11 | 只看该作者
  GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable, ENABLE);

    /* Configure PA.13 (JTMS/SWDAT), PA.14 (JTCK/SWCLK) and PA.15 (JTDI) as
       output push-pull */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_Init(GPIOA, &GPIO_InitStructure);

    /* Configure PB.03 (JTDO) and PB.04 (JTRST) as output push-pull */
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4;
    GPIO_Init(GPIOB, &GPIO_InitStructure);应该这样初始化吧

使用特权

评论回复
板凳
bestdesign11|  楼主 | 2021-1-22 15:27 | 只看该作者
谢谢楼上,

不能调用哪个,初始化哪个吗?

例如我想调用6,就用void Led_Init(int GPIO_Number);Led_Init(6); 函数中怎么写?

使用特权

评论回复
地板
bestdesign11|  楼主 | 2021-1-22 16:53 | 只看该作者
搞定了,打扰到大家了.因为定义的是无符号整数.所以函数的参数应该是uint16_t

使用特权

评论回复
5
单片小菜| | 2021-2-24 08:07 | 只看该作者
函数的定义尤为重要,特别是变量定义。

使用特权

评论回复
6
xixi2017| | 2021-2-24 17:23 | 只看该作者
你直接操作对应的PIN和GPIO就行了。

使用特权

评论回复
7
玛尼玛尼哄| | 2021-2-25 11:34 | 只看该作者
要看引用的什么。

使用特权

评论回复
8
天意无罪| | 2021-2-26 12:28 | 只看该作者
用宏定义啊就可以解决这个问题啊

使用特权

评论回复
9
Woo0o| | 2021-2-27 23:04 | 只看该作者
宏定义可以~

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

32

主题

234

帖子

1

粉丝