#include
#define uchar unsigned char
#define uint unsigned int
uchar idata zz[]={oxf1,oxf3,oxf2,oxf6,oxf4,oxfc,oxf8,oxf9};电机正转
uchar idata zz[]={oxf1,oxf9,oxf8,oxfc,oxf4,oxf6,oxf2,oxf3};电机反转
sbit zhengzhuan=p1^0;按下时正转
sbit fanzhuan=p1^1;按下时反转
sbit jiansu=p1^2;按下时减速
sbit jiasu=p1^3;按下时加速
sbit jiting=p3^0;
int count;
int derection ;
int speed;
void init(viod) 定时
{
count=0; 定时函数
TOMD=OX01;
TH0=(65536-speed)/256;
TL0=(65536-speed)%256;
EA=1;
ET0=1
}
void delay0(viod) interrupt 1 using1
{
TH0=(65536-speed)/256;
TL0=(65536-speed)%256;
p2=direction;
count++;
if(count==6);
count=0;
}
void delay(uint aa) 延::
{
uint i;
while(--aa)
{
for(i=0;i<250;i++);
}
}
}
}
void main (void)
{
int cnt;
cnt=0;
speed=40000;
fanzhuan=1;
zhengzhuan=1;
jiansu=1;
jiasu=1
jiting=1
p2=0;初始化继电器的控制端口
init();
while(p2=1) 循环控制 循环控制这一块我不知道怎么写好 你们可以帮我写下吗
{
count++;
delay(20)
TR0=1;
daley(20)
}
while(p2=0)
if(zhengzhuan==0);
{
while(zhengzhuan==0)
cnt++;
}
if(cnt==1)
delay(10);
direction=zz[count];
}
}
}
if(jiasu==0) 加速控制
{
while(jiaau==0)
speed=speed+1000;
if(speed==65000)
break;
}
if(jiansu==0) 减速控制
{
while(jiansu==0)
{speed=speed-1000;
if(speed==0)
break;
}
}
} |