前言
本文主要介绍了,基于stm32单片机的电机驱动,在proteus仿真电路中,控制电机的正转、反转以及停止转动。
一、代码部分
#include "stm32f10x.h"
int main(void)
{
void Delay();
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,ENABLE); //使能时钟
GPIO_InitTypeDef GPIO_TypeStructure; //定义结构体变量
GPIO_TypeStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 |GPIO_Pin_4 |GPIO_Pin_5; //配置引脚
GPIO_TypeStructure.GPIO_Mode = GPIO_Mode_Out_PP; //选择工作模式 通用推挽输出
GPIO_TypeStructure.GPIO_Speed = GPIO_Speed_50MHz; //选择输出最大速度 50MHz
GPIO_Init(GPIOA,&GPIO_TypeStructure); //初始化GPIOA
while(1)
{
GPIO_Write(GPIOA,0x0012); //正转
Delay();
GPIO_Write(GPIOA,0x0011); //反转
Delay();
GPIO_Write(GPIOA,0x0013); //停止转动