打印
[MM32软件]

方向控制初始化假设使用GPIO引脚PA0和PA1

[复制链接]
1648|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
舒伯特玫瑰|  楼主 | 2024-5-31 22:46 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
初始化方向控制引脚(假设使用GPIO引脚PA0和PA1)

void Direction_Control_Init(void) {
    GPIO_InitTypeDef GPIO_InitStructure;

    // 假设方向控制引脚为PA0和PA1
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOA, &GPIO_InitStructure);
}

void Set_Direction(uint8_t direction) {
    if (direction) {
        GPIO_SetBits(GPIOA, GPIO_Pin_0); // 设置方向1
        GPIO_ResetBits(GPIOA, GPIO_Pin_1);
    } else {
        GPIO_ResetBits(GPIOA, GPIO_Pin_0); // 设置方向0
        GPIO_SetBits(GPIOA, GPIO_Pin_1);
    }
}


使用特权

评论回复
沙发
ClarkLLOTP| | 2024-6-3 17:20 | 只看该作者
看着跟st库挺像

使用特权

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

本版积分规则

50

主题

249

帖子

2

粉丝