注册会员
- 积分
- 81
- 威望
- 143
- 贡献
- 28
- 兑换币
- 0
- 注册时间
- 2011-11-13
- 在线时间
- 0 小时
|
1单片机电机驱动程序
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
uchar num,High_num=1000,Low_num=3000;
sbit pulse=P1^7;
sbit UP=P1^3;
sbit DOWN=P1^4;
sbit reversal=P2^3;
sbit foreward=P2^4;
void delayms(uint xms)
{
uint i,j;
for(i=xms;i>0;i--)
for(j=110;j>0;j--);
}
void keyscan()
{
if(UP==0)
{
delayms(10);
if(UP==0)
{
num++;
if(num>4)
num=0;
while(UP==0);
}
}
if(DOWN==0)
{
delayms(10);
if(DOWN==0)
{
if(num!=0)
num--;
else
num=0;
while(DOWN==0);
}
}
}
void dispose()
{
switch(num)
{
case 0:
High_num=500;
Low_num=500;
break;
case 1:
High_num=100;
Low_num=300;
break;
case 2:
High_num=200;
Low_num=200;
break;
case 3:
High_num=300;
Low_num=100;
break;
case 4:
High_num=400;
Low_num=500;
break;
}
} |
|