【文件属性】:
文件名称:寻迹小车51单片机程序
文件大小:1012B
文件格式:NONE
更新时间:2013-04-22 18:01:50
C语言寻迹小车51单片机程序
51单片机寻迹小车程序
//////***红外
#include
#include
unsigned int thigh_zuo;
unsigned int thigh_you;
unsigned int thigh_zuo1;
unsigned int thigh_you1;
unsigned int count=0;
sbit en0=P1^2;
sbit en1=P1^3;
sbit fan0=P1^4;
sbit fan1=P1^5;
timer_set()
{
TMOD=0x99;
TH0=TH1=TL0=TL1=0;
TR0=TR1=TR2=1;
EX0=EX1=ET2=EA=1;
IT0=IT1=1;
RCAP2H=TH2=255;
RCAP2L=TL2=0;
}
void ex0_int() interrupt 0
{
thigh_zuo=TH0*256+TL0;
if(thigh_zuo>500)
{
en0=1;
fan0=0;
}
else fan0=1;
TH0=TL0=0;
}
void ex1_int() interrupt 2
{
thigh_you=TH1*256+TL1;
if(thigh_you>500)
{
en1=1;
fan1=0;
}
else fan1=1;
TH1=TL1=0;
}
void time2_int() interrupt 5
{
count++;
if(count>520)
{
en0=0;
en1=0;
count=0;
thigh_zuo1=thigh_zuo;
thigh_you1=thigh_you;
}
if(count>thigh_zuo1)
{
en0=1;
}
if(count>thigh_you1)
{
en1=1;
}
}
main()
{
timer_set();
while(1)
{
_nop_();
}
}