|
源代码如下:
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
uchar steptabt[]={0x01,0x03,0x02,0x06,0x04,0x0c,0x08,0x09};
uchar steptabf[]={0x09,0x08,0x0c,0x04,0x06,0x02,0x03,0x01};
uint freq,ftim;
uchar num,fx;
sbit key1=P2^0;
sbit key2=P2^1;
sbit key3=P2^2;
void t0isr() interrupt 1
{
TH0=(65536-ftim)/256;
TL0=(65536-ftim)%256;
P1=steptabt[num];
if(fx==0)
{
num++;
num%=8;
}
else
{
if(num==0)num=7;
else num--;
}
}
main()
{
TMOD=0x01;
freq=1/10;
ftim=1000000/2/freq;
TH0=(65536-ftim)/256;
TL0=(65536-ftim)%256;
ET0=1;
EA=1;
while(1)
{
if(key1==0){fx=0;TR0=1;}
if(key2==0){fx=1;TR0=1;}
if(key3==0){TR0=0;}
}
}
|
-
-
电机.zip
55.67 KB, 下载次数: 8, 下载积分: 黑币 -5
|