欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
我這個可以控制步進電機的開始、暫停、正轉、反轉、加速、減速嗎? 求幫助
[打印本頁]
作者:
2523472815
時間:
2020-3-1 13:27
標題:
我這個可以控制步進電機的開始、暫停、正轉、反轉、加速、減速嗎? 求幫助
#include"reg52.h"
#include"intrins.h"
typedef unsigned int u16;
typedef unsigned char u8;
#define GPIO_MOTOR P1;//定義步進電機的IO口
u8 code FFW[8]={0xf4,0xf5,0xf1,0xf9,0xf8,0xfa,0xf2,0xf6}; // 電機正轉
u8 code FFZ[8]={0xf2,0xfa,0xf8,0xf9,0xf1,0xf5,0xf4,0xf6}; //電機反轉
u8 Speed=0;
u8 direction=0;
u8 receiveData='0';
void UsartConfiguration(); //函數的聲明
void Motor();
void delay(u16 i)
{
while(i--);
}
void main()
{
UsartConfiguration();
Speed=180;
while(1)
{
if(receiveData=='1') //串口接收到'1',電機正轉
{
direction=1;
receiveData='0';
}
if(receiveData=='2') //串口接收到'2',電機反轉
{
direction=2;
receiveData='0';
}
if(receiveData=='3') // 串口接收到'3',電機暫停
{
P1=0;
receiveData='0';
}
if(receiveData=='4') //串口接收到'4',電機開始
{
P1=1;
receiveData='0';
}
if(receiveData=='5') //串口接收到'5',電機加速
{
Speed=20;
receiveData='0';
Speed=+180;
}
if(receiveData=='6') //串口接收到'6',電機減速
{
Speed=-20;
receiveData='0';
Speed=+180;
}
}
Motor();
direction=0;
}
void UsartConfiguration()
{
SCON=0X50; //波特率是4800
TMOD=0X20;
PCON=0X80;
TH1=0XF3;
TL1=0XF3;
ES=1;
EA=1;
TR1=1;
}
void Usart() interrupt 4
{
receiveData=SBUF;//出去接收到的數據
RI = 0;
SBUF=receiveData;
while(!TI);
TI=0;//清除接收中斷標志位
}
void Motor()
{
u8 i;
for(i=0;i<8;i++)
{
if(direction==1)
{
P1=FFW[i];
}
if(direction==2)
{
P1=FFZ[i];
}
delay(Speed);
}
}
復制代碼
歡迎光臨 (http://www.raoushi.com/bbs/)
Powered by Discuz! X3.1