遥控器控制小车程序
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
while(sec==0);
sec=0;
if(HWIN==0)
time1=0;
}
}
}
/**********************/ //左转
{
for(r6=0;r6<4;r6++)
{
PLAY_OUT=TAB_Q[r6];
while(sec==0);
sec=0;
sec++;
if(sec==2)
{
sec=0;
min++;
}
}
/****************************/
void HWKEY(void)
{
for(r1=0;r1<8;r1++) //跳过4.5MS
{
#include"reg52.h"
#include"intrins.h"
#define unint unsigned int
#define unchar unsigned char
#define PLAY_OUT P1
sbit HWIN=P3^2;
unchar sec=0;
unchar min=0;
delay(1); //0.6MS
delay(1);
if(HWIN==1)
{
r4=r4<<1|0x01;
}
else r4=r4<<1;
}
for(r1=0;r1<8;r1++) //跳过4.5MS
{
while(HWIN==1);
delay(1); //0.6MS
while(HWIN==1); //等待低电平
delay(1); //0.6MS
ห้องสมุดไป่ตู้delay(1);
if(HWIN==1)
{
r2=r2<<1|0x01;
}
else r2=r2<<1;
}
for(r1=0;r1<8;r1++) //跳过4.5MS
unchar code TAB_Y[4]={0x9f,0x5f,0x6f,0xaf};//右转
unchar code TAB_Z[4]={0xaf,0x6f,0x5f,0x9f};//左转
/*************************/
void intiaton(void);
void int_time3(void);
unchar count=0;
bit gj=0; //光和遥控的切换
unchar r6,r7;
bit time0=1;
bit time1=1;
sbit PLAY_Q_Q=P3^0;
sbit PLAY_Z=P3^1;
sbit PLAY_Y=P3^4;
sbit PLAY_QH=P3^5;
void int_time0(void);
void fanzhuan_Y(void);
void fanzhuan_Z(void);
void zhenzhuan_Q(void);
void zhenzhuan_H(void);
void zhenzhuan_AQ(void);
void zhenzhuan_AH(void);
sec=0;
}
}
/*******************************/ //红外前进
void zhenzhuan_Q(void)
{
while(time0)
sec=0;
}
}
/*******************/ //按键后退
void delay238(void) //2.38ms
{
unint i,j;
for(j=125;j>0;j--)
for(i=0;i<1;i++);
}
/************************/
void intiaton(void) //初始化
void zhenzhuan_AH(void)
{
for(r6=0;r6<4;r6++)
{
PLAY_OUT=TAB_H[r6];
while(sec==0);
void zhenzhuan_AQ(void)
{
for(r6=0;r6<4;r6++)
{
PLAY_OUT=TAB_Q[r6];
while(sec==0);
void zhenzhuan_H(void)
{
while(time1)
{
for(r6=0;r6<4;r6++)
{
PLAY_OUT=TAB_H[r6];
if(!PLAY_Q_H)
{
count=3;
}
}
if((PLAY_Z==0)||(PLAY_Y==0))
{
delayms(1);
if(PLAY_Z==0)
{
delay(1);
if(HWIN==1)
{
r5=r5<<1|0x01;
}
else r5=r5<<1;
}
}
/*****************************/
void HWSHURU(void)
{
for(r0=0;r0<8;r0++)
{delayms(1); //0.884MS
{
while(HWIN==1);
delay(1); //0.6MS
delay(1);
if(HWIN==1)
{
r3=r3<<1|0x01;
}
else r3=r3<<1;
}
for(r1=0;r1<8;r1++) //跳过4.5MS
{
while(HWIN==1);
{
count++;
if(count==4)
{
count=0;
}
}
while(PLAY_QH==0);
}
switch(count)
{
case 0: PLAY_OUT=0xff;break;
fanzhuan_Z();count=1;
}
else
{
fanzhuan_Y();count=1;
}
}
if(PLAY_QH==0)
{
delayms(10);
if(PLAY_QH==0)
{
switch(r4)
{
case 0x00: PLAY_OUT=0XFF;break;
case 0xEA: time1=0;time0=1;zhenzhuan_Q();break;
case 0xA9: time1=1;time0=0;zhenzhuan_H();break;
case 1: zhenzhuan_AQ();break;
case 2: PLAY_OUT=0xff;break;
case 3: zhenzhuan_AH();break;
default :break;
}
}
/*******************************/ //按键前进
if(HWIN==1) r0=10;
}
if(r0==8)
{while(HWIN==0) ;
delay238(); //2.38ms
if(HWIN==1)
{
HWKEY();
}
}
}
/***************************/
void keytem(void)
{
HWIN=1;
TMOD=0x11;
TH1=0XFA;
TL1=0X56;
ET1=1;
TR1=1;
EA=1;
}
/*********************/
void int_time3() interrupt 3 using 3
{
TH1=0XFA;
TL1=0X56;
case 0xAA: PLAY_OUT=0XFF;break;
case 0xA6: fanzhuan_Y();break;
case 0xE6: fanzhuan_Z();break;
case 0xCA: gj=~gj;break;
default :break;
}
}
/*************************/ //光感与按键控制
void cankey()
{
if(gj)
{
if(!PLAY_Q_Q)
{
count=1;
}
if(!PLAY_T)
{
count=2;
}
void cankey(void);
void zhenzhuan_Q_H(void);
void zhenzhuan_H_H(void);
void play_HWAI(void);
/*************************/
delay(unint t) //0.6ms
{unint i;
for(i=55;i>t;i--) ;
}
/**************************/
delayms(unint k) //k=1延迟0.884毫秒
{unint i;
for(i=80;i>k;i--)
;
}
/*************************/
sbit PLAY_Q_H=P3^6;
sbit PLAY_T=P3^7;
unchar r0,r1,r2=0x00,r3=0x00,r4=0x00,r5=0x00;
unchar code TAB_Q[4]={0xf9,0xf5,0xf6,0xfa};//前进
unchar code TAB_H[4]={0xfa,0xf6,0xf5,0xf9};//后退
void fanzhuan_Z(void)
{
unchar i;
for(i=0;i<22;i++)
{
for(r7=0;r7<4;r7++)
{
PLAY_OUT=TAB_Z[r7];
if(HWIN==0)
time0=0;
}
}
}
/*******************/ //红外后退
sec=0;
if(HWIN==0)
time1=0;
}
}
}
/**********************/ //左转
{
for(r6=0;r6<4;r6++)
{
PLAY_OUT=TAB_Q[r6];
while(sec==0);
sec=0;
sec++;
if(sec==2)
{
sec=0;
min++;
}
}
/****************************/
void HWKEY(void)
{
for(r1=0;r1<8;r1++) //跳过4.5MS
{
#include"reg52.h"
#include"intrins.h"
#define unint unsigned int
#define unchar unsigned char
#define PLAY_OUT P1
sbit HWIN=P3^2;
unchar sec=0;
unchar min=0;
delay(1); //0.6MS
delay(1);
if(HWIN==1)
{
r4=r4<<1|0x01;
}
else r4=r4<<1;
}
for(r1=0;r1<8;r1++) //跳过4.5MS
{
while(HWIN==1);
delay(1); //0.6MS
while(HWIN==1); //等待低电平
delay(1); //0.6MS
ห้องสมุดไป่ตู้delay(1);
if(HWIN==1)
{
r2=r2<<1|0x01;
}
else r2=r2<<1;
}
for(r1=0;r1<8;r1++) //跳过4.5MS
unchar code TAB_Y[4]={0x9f,0x5f,0x6f,0xaf};//右转
unchar code TAB_Z[4]={0xaf,0x6f,0x5f,0x9f};//左转
/*************************/
void intiaton(void);
void int_time3(void);
unchar count=0;
bit gj=0; //光和遥控的切换
unchar r6,r7;
bit time0=1;
bit time1=1;
sbit PLAY_Q_Q=P3^0;
sbit PLAY_Z=P3^1;
sbit PLAY_Y=P3^4;
sbit PLAY_QH=P3^5;
void int_time0(void);
void fanzhuan_Y(void);
void fanzhuan_Z(void);
void zhenzhuan_Q(void);
void zhenzhuan_H(void);
void zhenzhuan_AQ(void);
void zhenzhuan_AH(void);
sec=0;
}
}
/*******************************/ //红外前进
void zhenzhuan_Q(void)
{
while(time0)
sec=0;
}
}
/*******************/ //按键后退
void delay238(void) //2.38ms
{
unint i,j;
for(j=125;j>0;j--)
for(i=0;i<1;i++);
}
/************************/
void intiaton(void) //初始化
void zhenzhuan_AH(void)
{
for(r6=0;r6<4;r6++)
{
PLAY_OUT=TAB_H[r6];
while(sec==0);
void zhenzhuan_AQ(void)
{
for(r6=0;r6<4;r6++)
{
PLAY_OUT=TAB_Q[r6];
while(sec==0);
void zhenzhuan_H(void)
{
while(time1)
{
for(r6=0;r6<4;r6++)
{
PLAY_OUT=TAB_H[r6];
if(!PLAY_Q_H)
{
count=3;
}
}
if((PLAY_Z==0)||(PLAY_Y==0))
{
delayms(1);
if(PLAY_Z==0)
{
delay(1);
if(HWIN==1)
{
r5=r5<<1|0x01;
}
else r5=r5<<1;
}
}
/*****************************/
void HWSHURU(void)
{
for(r0=0;r0<8;r0++)
{delayms(1); //0.884MS
{
while(HWIN==1);
delay(1); //0.6MS
delay(1);
if(HWIN==1)
{
r3=r3<<1|0x01;
}
else r3=r3<<1;
}
for(r1=0;r1<8;r1++) //跳过4.5MS
{
while(HWIN==1);
{
count++;
if(count==4)
{
count=0;
}
}
while(PLAY_QH==0);
}
switch(count)
{
case 0: PLAY_OUT=0xff;break;
fanzhuan_Z();count=1;
}
else
{
fanzhuan_Y();count=1;
}
}
if(PLAY_QH==0)
{
delayms(10);
if(PLAY_QH==0)
{
switch(r4)
{
case 0x00: PLAY_OUT=0XFF;break;
case 0xEA: time1=0;time0=1;zhenzhuan_Q();break;
case 0xA9: time1=1;time0=0;zhenzhuan_H();break;
case 1: zhenzhuan_AQ();break;
case 2: PLAY_OUT=0xff;break;
case 3: zhenzhuan_AH();break;
default :break;
}
}
/*******************************/ //按键前进
if(HWIN==1) r0=10;
}
if(r0==8)
{while(HWIN==0) ;
delay238(); //2.38ms
if(HWIN==1)
{
HWKEY();
}
}
}
/***************************/
void keytem(void)
{
HWIN=1;
TMOD=0x11;
TH1=0XFA;
TL1=0X56;
ET1=1;
TR1=1;
EA=1;
}
/*********************/
void int_time3() interrupt 3 using 3
{
TH1=0XFA;
TL1=0X56;
case 0xAA: PLAY_OUT=0XFF;break;
case 0xA6: fanzhuan_Y();break;
case 0xE6: fanzhuan_Z();break;
case 0xCA: gj=~gj;break;
default :break;
}
}
/*************************/ //光感与按键控制
void cankey()
{
if(gj)
{
if(!PLAY_Q_Q)
{
count=1;
}
if(!PLAY_T)
{
count=2;
}
void cankey(void);
void zhenzhuan_Q_H(void);
void zhenzhuan_H_H(void);
void play_HWAI(void);
/*************************/
delay(unint t) //0.6ms
{unint i;
for(i=55;i>t;i--) ;
}
/**************************/
delayms(unint k) //k=1延迟0.884毫秒
{unint i;
for(i=80;i>k;i--)
;
}
/*************************/
sbit PLAY_Q_H=P3^6;
sbit PLAY_T=P3^7;
unchar r0,r1,r2=0x00,r3=0x00,r4=0x00,r5=0x00;
unchar code TAB_Q[4]={0xf9,0xf5,0xf6,0xfa};//前进
unchar code TAB_H[4]={0xfa,0xf6,0xf5,0xf9};//后退
void fanzhuan_Z(void)
{
unchar i;
for(i=0;i<22;i++)
{
for(r7=0;r7<4;r7++)
{
PLAY_OUT=TAB_Z[r7];
if(HWIN==0)
time0=0;
}
}
}
/*******************/ //红外后退