您的位置 首页 IOT

怎么选用51单片机操控电机的旋转视点?

如何采用51单片机控制电机的旋转角度?-typedefunsignedcharuchar;
typedefunsignedintuint;
typedefunsignedlongulong;
ucharcodebeatCode[8]={
0xE,0xC,0xD,0x9,0xB,0x3,0x7,0x6

typedefunsignedcharuchar;

typedefunsignedintuint;

typedefunsignedlongulong;

ucharcodebeatCode[8]={

0xE,0xC,0xD,0x9,0xB,0x3,0x7,0x6

};

ulongbeats=0;

ucharT0RH=0,T0RL=0;

voidturnMotor(ulongangle){

EA=0;

beats=angle*4076/360;

EA=1;

}

voidsetTImer0(uintms){

ulongtmp;

tmp=11059326/12;

tmp=tmp*ms/1000;

tmp=65536-tmp;

tmp+=28;

T0RL=tmp;

T0RH=tmp>>8;

}

voidinterruptTImer0()interrupt1{

staTIcucharindex=0;

TH0=T0RH;

TL0=T0RL;

if(beats){

uchartmp=P1;

tmp&=0xF0;

tmp|=beatCode[index];

P1=tmp;

index=++index&0x07;

beats–;

}

else{

P1|=0x0F;

}

}

voidmain(){

EA=1;

TMOD=0x01;

setTImer0(2);

TH0=T0RH;

TL0=T0RL;

ET0=1;

TR0=1;

turnMotor(2*360+180);

while(1);

}

下面是运用库函数循环左移完成的:

#include

#include

typedefunsignedcharuchar;

typedefunsignedintuint;

typedefunsignedlongulong;

ulongbeats=0;

ucharT0RH=0,T0RL=0;

voidturnMotor(ulongangle){

EA=0;

beats=angle*4076/360;

EA=1;

}

voidsetTimer0(uintms){

ulongtmp;

tmp=11059326/12;

tmp=tmp*ms/1000;

tmp=65536-tmp;

tmp+=28;

T0RL=tmp;

T0RH=tmp>>8;

}

voidinterruptTimer0()interrupt1{

staticucharbeatCode=0x33;

TH0=T0RH;

TL0=T0RL;

if(beats){

uchartmp=P1;

tmp&=0xF0;

beatCode=_crol_(beatCode,1);

tmp|=beatCode;

P1=tmp;

beats–;

}

else{

P1|=0x0F;

}

}

voidmain(){

EA=1;

TMOD=0x01;

setTimer0(2);

TH0=T0RH;

TL0=T0RL;

ET0=1;

TR0=1;

turnMotor(2*360+180);

while(1);

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/yingyong/iot/347298.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部