您的位置 首页 新能源

直流电机正回转及调速操控

#includereg51.h>#defineuintunsignedint#defineucharunsignedcharsbitrl=P3^0;//正反转按键sbitadd=P3^1;//增

#include

#define uint unsigned int
#define uchar unsigned char
sbit rl=P3^0;//正回转按键
sbit add=P3^1;//增速按键
sbit sub=P3^2;//减速按键
sbit stop=P3^3;//电机中止按键
sbit pwmh=P1^0;//PWMH输出
sbit pwml=P1^1;//1正/0回转
uchar num1,num2,flag1,flag2,flag3;
uint aa,bb,n;
void delay(uint z);
void monitor();
void intc();
void keyscan();
//======================
void main()
{
intc();
while(1)
{
keyscan();
if(flag3==0)
{if(flag1==0)
pwml=1;
else
pwml=0;}
if(flag3==1)
{pwmh=1;pwml=1;}
}
}

//===================
void delay(uint z)
{
uint x;
uchar y;
for(x=0;xfor(y=0;y<100;y++);
}

//=========================
void intc()
{n=50;//设定电机初始转速10MS方波;
TMOD=0x01;
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
ET0=1;
EA=1;
TR0=1;
}
//========================
void keyscan()
{
if(rl==0)
delay(10);
if(rl==0)
{
while(!rl);
flag1++;
if(flag1>1)
flag1=0;
}
if(add==0)
delay(10);
if(add==0)
{
while(!add);
n++;
if(n>100)
n=100;
}
if(sub==0)
delay(10);
if(sub==0)
{
while(!sub);
if(n<2)
n=1;
else
n–;
}
if(stop==0)
delay(10);
if(stop==0)
{
while(!stop);
flag3=1;
pwmh=1;
pwml=1;
}
}

//==========================
//==========第二种改动PWM波的办法======
void timer0() interrupt 1
{
TH0=(65536-10000)/256;
TL0=(65536-10000)%256;
num1++;
if(num1 pwmh=1;
else
pwmh=0;
if(num1>100)
{num1=0;flag2=1;}
}
//=======================================

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

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

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

微信扫一扫关注我们

返回顶部