新聞中心

EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > 直流電機(jī)正反轉(zhuǎn)及調(diào)速控制

直流電機(jī)正反轉(zhuǎn)及調(diào)速控制

作者: 時(shí)間:2016-11-18 來(lái)源:網(wǎng)絡(luò) 收藏
#include

#define uint unsigned int
#define uchar unsigned char
sbit rl=P3^0;//正反轉(zhuǎn)按鍵
sbit add=P3^1;//增速按鍵
sbit sub=P3^2;//減速按鍵
sbit stop=P3^3;//電機(jī)停止按鍵
sbit pwmh=P1^0;//PWMH輸出
sbit pwml=P1^1;//1正/0反轉(zhuǎn)
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;}
}
}

本文引用地址:http://m.butianyuan.cn/article/201611/315950.htm

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


//=========================
void intc()
{n=50;//設(shè)定電機(jī)初始轉(zhuǎn)速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;}
}
//=======================================



評(píng)論


技術(shù)專(zhuān)區(qū)

關(guān)閉