|
智能红外循迹小车c程序:
//采用五线四相步进电机,P2及P3口通过ULN2003驱动步进电机,循迹模块的两个输出端分别接P1.0和P1.1
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
code uchar zheng1[]={0xe6,0xc7,0xd3,0x9b,0xb9,0x3d,0x7c,0x6e};
code uchar fan1[]={0x6e,0x7c,0x3d,0xb9,0x9b,0xd3,0xc7,0xe6};
code uchar zuo1[]={0xee,0xcc,0xdd,0x99,0xbb,0x33,0x77,0x66};
code uchar you1[]={0x66,0x77,0x33,0xbb,0x99,0xdd,0xcc,0xee};
uchar i,j,p,t,s;
uint n;
void play();
void delay()
{
s=t;
while(s--)
for(j=0;j<135;j++) ;
}
void delay1(uchar x)
{
while(x--)
for(j=0;j<125;j++) ;
}
void zheng()
{
t=4;
for(t=4;t>1;t--)
{
for(i=0;i<8;i++)
{
P3=zheng1[i];
P2=zheng1[i];
delay();
}
}
for(n=0;n<50;n++)
{
for(i=0;i<8;i++)
{
P3=zheng1[i];
P2=zheng1[i];
delay();
}
}
}
void zuo()
{
t=4;
for(t=4;t>1;t--)
{
for(i=0;i<8;i++)
{
P3=zuo1[i];
P2=zuo1[i];
delay();
}
}
for(n=0;n<50;n++)
{
for(i=0;i<8;i++)
{
P3=zuo1[i];
P2=zuo1[i];
delay();
}
}
}
void you()
{
t=4;
for(t=4;t>1;t--)
{
for(i=0;i<8;i++)
{
P3=you1[i];
P2=you1[i];
delay();
}
}
for(n=0;n<50;n++)
{
for(i=0;i<8;i++)
{
P3=you1[i];
P2=you1[i];
delay();
}
}
}
void main()
{
while(1)
{
P1=0xff;
p=P1;
if(p!=0xff)
{
delay1(20);
p=P1;
if(p!=0xff)
{
switch(p)
{
case 0xfe: you();break;
case 0xfd: zuo();break;
case 0xff: zuo();break;
case 0xfc: zheng();break;
}
}
}
}
}
|
评分
-
查看全部评分
|