📄 car.c
字号:
#include <reg52.h>
#define uchar unsigned char
#define ulong unsigned long
#define uint unsigned int
#include "irda.c"
uchar time_long;
ulong time_count;
sbit mo_en=P3^5;
//-------------------------------------------------------------------------------------------------
void delay(uint t) /*延时子程序*/
{while(t--);
}
/*----------------------------------------------------------------------*/
void int0_srv(void)interrupt 0 using 3
{
Regist_Value=time_long;
int0_flg=0;
time_long=0;
}
//-------------------------------------------------
void T0_interrupt (void) interrupt 1 using 1
{
TH0=0xff;
TL0=0xdc;
time_long++;
}
/*-------------------------------------------------------------------------*/
void mo_driver(uchar zkb,ulong time,uchar mo)
{ mo&=0x0f; P1=mo;
for(;time;time--)
{mo_en=1;
delay(50);
mo_en=0;
delay(zkb);
}
mo_en=0;
}
//--------------------------------------------------------------------------
void init(void)
{
TMOD=0x11;
TH0=0xff;
TL0=0xf6;
EA=1;
ET0=1;
IT0=1;
PT0=0;
EX0=1;
TR0=1;
PX0=1;
TH1=0x4b;
TL1=0xff;
ET1=1;
//TR1=1;
PT1=0;
}
/*-------------------------------------------------------------------------*/
//前进
void qianjing(uchar shudu,ulong time)
{
mo_driver(shudu,time,0x0a);
}
//------------------------------------------------------------
//后退
void houtui(uchar shudu,ulong time)
{
mo_driver(shudu,time,0x05);
}
//-----------------------------------------------------------
//左传
void t_left(uchar shudu,ulong time)
{
mo_driver(shudu,time,0x09);
}
//-----------------------------------------------------------
void t_right(uchar shudu,ulong time) //右转
{
mo_driver(shudu,time,0x06);
}
/*-------------------------------------------------------------------------*/
void main (void)
{
uchar mode=0;
uchar dta_irda=0;
init();
//---------------------------------------
for(;;)
{
dta_irda=irda();
if(dta_irda)
{
switch(dta_irda)
{
case 182:houtui(10,300) ;break;
case 188:qianjing(10,300);break;
case 190:t_left(0,150); break;
case 186:t_right(0,150); break;
//-------------------------------------
case 132:houtui(0,150);break;
case 164:qianjing(0,150);break;
//-------------------------------------
}
dta_irda=0;
}
//-----------------------------------
mode=0;
}//对应for(;;)
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -