|
#include <reg52.h>
#include <pwm.h>
sbit k1=P3^0;
sbit k2=P3^3;
uchar i,mor,k,p=1,a;
void key()
{
while(k1==0)
{
delayms(20);
if(k1==1)
{
delayms(200);
c++;
a=0;
if(c>=2)
c=0;
}
}
}
void main()
{
init_lcd ();
for(i=0;i<8;i++)
cn_display(1,i,i," 榆林学院 ");
for(i=0;i<8;i++)
cn_display(2,i,i," 智能履带小车 ");
led1=0;
led2=0;
delayms(200);
led1=1;
led2=1;
led1=0;
led2=0;
delayms(200);
led1=1;
led2=1;
delayms(2000);
TMOD=0X11;
Timer1_Init(); //定时器1初始化
INT0_Init();
Data_Init();
TH0=(65536-20)/256;
TL0=(65536-20)%256;
EA=1;
ET0=1;
EX1=1;
clrram();
for(i=0;i<8;i++)
cn_display(0,i,i," 智能履带小车 ");
for(i=0;i<8;i++)
cn_display(1,i,i," 智能模式 ");
stop();
while(1)
{
key();
if(c==0&&p==1)
{
stop();
speak();
led1=0;
led2=0;
delayms(100);
led1=1;
led2=1;
delayms(100);
led1=0;
led2=0;
delayms(100);
led1=1;
led2=1;
delayms(100);
led1=0;
led2=0;
delayms(100);
led1=1;
led2=1;
p=0;
k=1;
TR0=0;
}
if(c==1&&k==1)
{
speak();
delayms(300);
speak();
delayms(300);
speak();
delayms(2000);
k=0;
p=1;
a=0;
TR0=1;
}
if(mor==0)
{
for(i=0;i<8;i++)
cn_display(2,i,i," 红外避障 ");
for(i=0;i<8;i++)
cn_display(3,i,i," ");
modern1();
}
if(mor==1)
{
if(a==0)
{
for(i=0;i<8;i++)
cn_display(2,i,i," 黑线寻迹 ");
a=1;
}
modern4();
}
if(mor==2)
{
for(i=0;i<8;i++)
cn_display(2,i,i," 超声波避障!!! ");
for(i=0;i<3;i++)
cn_display(3,i,i,"距离: ");
cn_display(3,7,0,"cm");
modern3();
}
}
}
void init1() interrupt 2
{
EX1=0;
delayms(100);
if(k2==1)
{
mor++;
if(mor>=3)
mor=0;
a=0;
}
EX1=1;
}
|
|