计算机小混子 2022-11-18 02:47 采纳率: 100%
浏览 16
已结题

stm32电机和流水灯的仿真跑不出来

LED.c

#include "stm32f10x.h"                  // Device header
#include "Delay.h"
void LED_Init(void)
{
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);//打开GPIOA时钟
    GPIO_InitTypeDef GPIO_InitStructure;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//推挽输出
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1|GPIO_Pin_2;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOB, &GPIO_InitStructure);
    GPIO_Write(GPIOB, ~0x000B);
}


void LED_LSD()
{
        GPIO_Write(GPIOB, ~0x0001);    //0000 0000 0000 0001
        Delay_ms(60000);
        GPIO_Write(GPIOB, ~0x0002);    //0000 0000 0000 0010
        Delay_ms(60000);
        GPIO_Write(GPIOB, ~0x008);    //0000 0000 0000 0100
        Delay_ms(60000);
}


Key.c

#include "stm32f10x.h"                  // Device header
#include "Delay.h"

void Key_Init(void)
{
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);//打开GPIOA时钟
    
    GPIO_InitTypeDef GPIO_InitStructure;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;//上拉输入
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2|GPIO_Pin_3;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOB, &GPIO_InitStructure);
}

uint8_t Key_GetNum(void)
{
    uint8_t KeyNum = 0;
    if (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_0) == 1)//检测是否被按下
    {
        Delay_ms(100);//消抖
        while (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_0) == 1);
        Delay_ms(100);
        KeyNum = 1;
    }
    if (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_1) == 2)
    {
        Delay_ms(100);
        while (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_1) == 2);
        Delay_ms(100);
        KeyNum = 2;
    }
    if (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_2) == 3)
    {
        Delay_ms(100);
        while (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_2) == 3);
        Delay_ms(100);
        KeyNum = 3;
    }
    return KeyNum;
}



motor.c

#include "stm32f10x.h"                  // Device header


void Motor_Init(void)
{
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);//打开GPIOB时钟
    
    GPIO_InitTypeDef GPIO_InitStructure;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;//推挽输出
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOC, &GPIO_InitStructure);
    GPIO_SetBits(GPIOC, GPIO_Pin_0);
    GPIO_SetBits(GPIOC, GPIO_Pin_1);
}


void SetZhengZhuan()
{
    GPIO_SetBits(GPIOC, GPIO_Pin_0);
    GPIO_ResetBits(GPIOC, GPIO_Pin_1);

}
void SetFanZhuan()
{
    GPIO_ResetBits(GPIOC, GPIO_Pin_0);
    GPIO_SetBits(GPIOC, GPIO_Pin_1);
}

void SetTingZhi()
{
    GPIO_ResetBits(GPIOC, GPIO_Pin_0);
    GPIO_ResetBits(GPIOC, GPIO_Pin_1);

}


main.c

#include "stm32f10x.h"                  // Device header
#include "Delay.h"
#include "OLED.h"
#include "Key.h"
#include "LED.h"
#include "motor.h"
uint16_t num = 0;
uint16_t key;
int main(void)
{
    LED_LSD();
    Key_Init();//独立按键初始化
    LED_Init();//LED初始化
    while (1)
    {
        LED_LSD();//流水灯
        key = Key_GetNum(); //扫描按键是否被按下,如果按下返回键码

        if(key)//如果按键被按下
        {
            switch(key)
            {
                case 1:
                    SetZhengZhuan();
                    break;

                case 2:
                    SetFanZhuan();
                    break;

                case 3:
                    SetTingZhi();
                    break;
            
            }

        }
        
    }
    
}


仿真图连线

img

  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 11月26日
    • 创建了问题 11月18日

    悬赏问题

    • ¥15 C++识别堆叠物体异常
    • ¥15 音量自动减小啦!日历自动翻页
    • ¥15 微软硬件驱动认证账号申请
    • ¥15 有人知道怎么在R语言里下载Git上的miceco这个包吗
    • ¥15 GPT写作提示指令词
    • ¥20 如何在cst中建立这种螺旋扇叶结构
    • ¥20 根据动态演化博弈支付矩阵完成复制动态方程求解和演化相图分析等
    • ¥20 关于DAC输出1.000V对分辨率和精度的要求
    • ¥15 华为超融合部署环境下RedHat虚拟机分区扩容问题
    • ¥15 哪位能做百度地图导航触点播报?