程序中含有红外循迹 避障 和测速 测速程序无法正常执行 求指教
#include
#define uint unsigned int
#define uchar unsigned char
***it zuo1=P1^0;
***it zuo2=P1^1;
***it you1=P1^2;
***it you2=P1^3;
***it left=P1^4;
***it mid=P1^5;
***it right=P1^6;
***it zhui=P1^7;
***it dula=P2^6;
***it wela=P2^7;
***it lcden=P3^0;
***it lcdrs=P3^1;
uint num,s1,s2;//s1 s2为对应的int型各位数字
uint num1,shu;
uchar shi,ge;//对应的uchar的各位数字
uchar i;
uchar code table[]="THE SPEED IS:";
uchar code table1[]="123456789";
//unsigned char code Disp_Tab[] = { 0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0xbf,0xc7,0x8c,0xc1, 0xff, 0xf7 };
void delay(uint z)
{
uint i,j;
for(i=z;i>0;i--)
for(j=110;j>0;j--);
}
void down()
{
zuo1=1;
zuo2=1;
you1=1;
you2=1;
}
void qian() //前进
{
zuo1=0;
zuo2=1;
you1=0;
you2=1;
delay(10-3);
down();
delay(3);
}
void hou() //后退
{
zuo1=1;
zuo2=0;
you1=1;
you2=0;
delay(10-5);
down();
delay(5);
}
void you()
{
zuo1=0;
zuo2=1;
you1=1;
you2=0;
delay(10-5);
down();
delay(5);
}
void zuo()
{
zuo1=1;
zuo2=0;
you1=0;
you2=1;
delay(10-5);
down();
delay(5);
}
void bizhang()
{
uint i1,j1;
for(i1=5;i1>0;i1--)
for(j1=110;j1>0;j1--)
{
zuo();
}
for(i1=30;i1>0;i1--)
for(j1=110;j1>0;j1--)
{
qian();
}
for(i1=8;i1>0;i1--)
for(j1=110;j1>0;j1--)
{
you();
}
for(i1=40;i1>0;i1--)
for(j1=110;j1>0;j1--)
{
qian();
}
zhui=1;
}
void writecom(uchar com)
{
lcdrs=0;
P0=com;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void writedata(uchar date)
{
lcdrs=1;
P0=date;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void init()
{
dula=0;
wela=0;
lcden=0;
writecom(0x38);
writecom(0x0c);
writecom(0x06);
writecom(0x01);
}
void main()
{
TMOD=0x15;// 计数器计数模式1
// IT0=0; //低电平触发
EA=1;
IT0=1;
ET0=1; //下降沿触发
EX0=1;
// TMOD=0x01;
TH1=(65535-50000)/256;
TL1=(65535-50000)%256;
//EA=1;
ET1=1;
TR1=1;
//num=11;
init();
writecom(0x80);
// while(1)
// {
for(i=0;i<13;i++)
{
writedata(table[i]);
delay(10);
}
delay(100);
//writecom(0x80+0x40);
/* for(i=0;i<10;i++)
{
writedata(table1[i]);
delay(10);
}*/
while(1)
{
qian();
while(zhui==0)
{
bizhang();
zhui=1;
}
while(right==1&&left==0&&mid==0)
{
you();
}
while(left==1&&right==0&&mid==0)
{
zuo();
}
while(mid==0&&right==1&&left==1)
{
down();
}
while(left==0&&mid==0&&right==0) //遇到黑线变0
{
qian();
}
//}
// while(1);
}
}
void time0() interrupt 0 //外部中断脉冲计数
{
EX0=0;
num++;
EX0=1;
}
void time1() interrupt 3 //定时器1中断函数 定时到时间为1s
{
//TR1=0;
TH1=(65535-50000)/256;
TL1=(65535-50000)%256;
num1++;
if(num1==20)
{
//s1=num/24*3.14*65;
s1=TL0/10;
s2=TL0%10;
ge=s1;
shi=s2;
//int i=55;
//shi=i/10;
// ge=i%10;
writecom(0x80+0x40);
writedata(table1[shi]);
delay(10);
// writecom(0x80+0x40+0x01);
writedata(table[ge]);
delay(10);
}
}
|