|
#include
#define uchar unsigned char
#define uint unsigned int
uchar flag=0;
uchar flad=0;
uchar flau=0;
uchar flav=0;
sbit P20=P2^0;
uint key=0;
uint th0l,th0h,tl0l,tl0h;
uint th1l,th1h,tl1l,tl1h;
void delay(uint n)
{
uint i,j;
for(i=0;i
for(j=0;j<123;j++);
}
void init()
{
TMOD=0x11;
TH1=0x3c;
TL1=0xb0;
TH0=0xfc;
TL0=0x18;
ET1=1;
ET0=1;
TR1=1;
TR0=1;
EA=1;
P20=1;
key=0;
}
void rupt1()interrupt 3
{
if(!flav)
{
P21=0;
TH1=th1h;
TL1=th1l;
}
else
{
P21=1;
TH1=tl1h;
TL1=tl1l;
}
flav=!flav;
}
void rupt0()interrupt 1
{
if(!flag)
{
P20=1;
TH0=th0h;
TL0=th0l;
}
else
{
P20=0;
TH0=tl0h;
TL0=tl0l;
flad=0;
}
flag=!flag;
}
void main()
{
init();
do{
if(!flad)
{
switch(key)
{
case(7): th0h=0xfc;th0l=0xe0;tl0h=0xb5;tl0l=0x00; flad=1;break;//0.8ms
case(6): th0h=0xfc;th0l=0x7c;tl0h=0xb5;tl0l=0x64; flad=1;break; //0.9ms
case(5): th0h=0xfc;th0l=0x18;tl0h=0xb5;tl0l=0xc8; flad=1;break; //1.0ms
case(4): th0h=0xfb;th0l=0xb4;tl0h=0xb6;tl0l=0x2c; flad=1;break; //1.1ms
case(3): th0h=0xfb;th0l=0x50;tl0h=0xb6;tl0l=0x90; flad=1;break; //1.2ms
case(2): th0h=0xfa;th0l=0xec;tl0h=0xb6;tl0l=0xf4; flad=1;break; //1.3ms
case(1): th0h=0xfa;th0l=0x88;tl0h=0xb7;tl0l=0x58; flad=1;break; //1.4ms
case(0): th0h=0xfa;th0l=0x24;tl0h=0xb7;tl0l=0xbc; flad=1;break; //1.5ms
case(11): th0h=0xf9;th0l=0xc0;tl0h=0xb8;tl0l=0x20; flad=1;break; //1.6ms
case(12): th0h=0xf9;th0l=0x5c;tl0h=0xb8;tl0l=0x84; flad=1;break; //1.7ms
case(13): th0h=0xf8;th0l=0xf8;tl0h=0xb8;tl0l=0xe8; flad=1;break; //1.8ms
case(14): th0h=0xf8;th0l=0x94;tl0h=0xb9;tl0l=0x4c; flad=1;break; //1.9ms
case(15): th0h=0xf8;th0l=0x30;tl0h=0xb9;tl0l=0xb0; flad=1;break; //2.0ms
case(16): th0h=0xf7;th0l=0xcc;tl0h=0xba;tl0l=0x14; flad=1;break; //2.1ms
case(17): th0h=0xf7;th0l=0x68;tl0h=0xba;tl0l=0x78; flad=1;break; //2.2ms
case(18): th0h=0xf7;th0l=0x04;tl0h=0xba;tl0l=0xdc; flad=1;break;// 2.3ms
case(19): th0h=0xf6;th0l=0xa0;tl0h=0xbb;tl0l=0x40; flad=1;break; // 2.4ms
case(20): th0h=0xf6;th0l=0x3c;tl0h=0xbb;tl0l=0xa4; flad=1;break;// 2.5ms时舵机(从正面看)向左转到快到极限。
default:break;
}
}
}while(1);
if(!flau)
{
switch(key)
{
case(7): th1l=,th1h=,tl1l=,tl1h=;flau=1;break;
case(6): th1l=,th1h=,tl1l=,tl1h=;flau=1;break;
case(5): th1l=,th1h=,tl1l=,tl1h=;flau=1;break;
case(4): th1l=,th1h=,tl1l=,tl1h=;flau=1;break;
case(3): th1l=,th1h=,tl1l=,tl1h=;flau=1;break;
case(2): th1l=,th1h=,tl1l=,tl1h=;flau=1;break;
case(1): th1l=,th1h=,tl1l=,tl1h=;flau=1;break;
case(0): th1l=,th1h=,tl1l=,tl1h=;flau=1;break;
case(11): th1l=,th1h=,tl1l=,tl1h=;flau=1;break;
case(12): th1l=,th1h=,tl1l=,tl1h=;flau=1;break;
case(13): th1l=,th1h=,tl1l=,tl1h=;flau=1;break;
case(14): th1l=,th1h=,tl1l=,tl1h=;flau=1;break;
case(15): th1l=,th1h=,tl1l=,tl1h=;flau=1;break;
case(16): th1l=,th1h=,tl1l=,tl1h=;flau=1;break;
case(17): th1l=,th1h=,tl1l=,tl1h=;flau=1;break;
case(18): th1l=,th1h=,tl1l=,tl1h=;flau=1;break;
case(19): th1l=,th1h=,tl1l=,tl1h=;flau=1;break;
case(20): th1l=,th1h=,tl1l=,tl1h=;flau=1;break;
}
}
}
很简单,看懂以上程序也许会对你有所帮助。 |
|