|
昨天看到有人卖混控,不忿,一天时间自制混控成功,共享!
源程序 1.0版本,写了一个小时,没有优化,轻微有点抖舵,有时间再修改!
#include<reg51.h>
unsigned char sig=0;
unsigned int elevator=1500;
unsigned int aileron=1500;
sbit int_0=P3^2;
sbit int_1=P3^3;
sbit CH0=P1^6;
sbit CH1=P1^7;
/********************************************/
void int_sever(unsigned int temp)
{
unsigned char sum;
TMOD=0x01;
temp=65535-temp;
sum=(unsigned char)(temp>>0x08);
TH0=sum;
sum=(unsigned char)(temp&0xff);
TL0=sum;
TR0=1;
while(!TF0){;}
TF0=0;
TR0=0;
TH0=0x00;TL0=0x00;
}
/********************************************/
V_DSP()
{
unsigned int E;
unsigned int A;
unsigned char E_sig;
unsigned char A_sig;
if(elevator>=1500) {E=elevator-1500;E_sig=1;}
else {E=1500-elevator;E_sig=0;}
if(aileron>=1500) {A=aileron-1500;A_sig=1;}
else {A=1500-aileron;A_sig=0;}
if(E_sig==1) {elevator=1500+E; aileron=1500+E;}
else {elevator=1500-E; aileron=1500-E;}
if(A_sig==1) {elevator+=A; aileron-=A;}
else {elevator-=A; aileron+=A;}
}
/********************************************/
unsigned int impluse_A()
{
unsigned int counter;
unsigned char sum;
sum=TH0;
counter=sum;
counter=(counter<<0x08)|TL0;
TH0=0x00;TL0=0x00;
return(counter);
}
/********************************************/
unsigned int impluse_B()
{
unsigned int name;
unsigned char sum;
sum=TH1;
name=sum;
name=(name<<0x08)|TL1;
TH1=0x00;TL1=0x00;
return(name);
}
/********************************************/
void main()
{
CH0=0;CH1=0;
while(1)
{
TMOD=0x99;
TH0=0x00;TL0=0x00;TH1=0x00;TL1=0x00;
while((int_0==1)||(int_1==1))
{
if(int_0==1)
{TR0=1;while(int_0==1){;}TR0=0; aileron=impluse_A(); sig++;}
else if(int_1==1)
{TR1=1;while(int_1==1){;}TR1=0; elevator=impluse_B(); sig++;}
else;
}
while(sig>=2)
{
V_DSP();
CH0=1;int_sever(aileron); CH0=0;
CH1=1;int_sever(elevator); CH1=0;
sig=0;
}
}
}
[ Last edited by suncxc on 2005-7-28 at 23:37 ] |
欢迎继续阅读楼主其他信息
|