基于单片机智能遥控小车的设计说明

内容发布更新时间 : 2024/11/15 2:02:08星期一 下面是文章的全部内容请认真阅读。

do{ _nop_(); }while(--k); {

unsigned char i; while(x--) }while(--j); }while(--i); }

void delay_nus(unsigned int i) { i=i/10; while(--i); }

void delay_nms(unsigned int n) { n=n+1; while(--n)

delay_nus(900); }

void delayms(unsigned char x) {

for (i = 0; i<13; i++) {} } }

void Delay() {

unsigned int DelayTime=30000; while(DelayTime--); return; } void

ControlCar(unsigned

char

ConType)

tingzhi();

switch(ConType) {

case 1: //前进

{

LeftLed = 0 ; qianjin();

tingzhi(); } }

break;

break; }

case 2: //后退 } {

LeftLed = 1 ;

houtui(); break; }

case 3: //左转 { zuozhuan(); break;

}

case 4: //右转 { youzhuan(); break;

}

case 8: //停止 {

void

ControlCar_yaokong(unsigned

char ConType)

{

tingzhi();

switch(ConType) {

case 1: //前进 {

tingzhi();

Delay1ms(150);

LeftLed = 0 ;

qianjin();

break;

}

case 2: //后退

{

tingzhi();

Delay1ms(150); LeftLed = 1 ;

houtui(); break; }

case 3: //左转 {

tingzhi();

Delay1ms(150);

zuozhuan(); break;

}

case 4: //右转 {

tingzhi();

Delay1ms(150);

youzhuan();

break;

}

case 8: //停止 {

tingzhi();

break;

}

} }

void main()

{

bit RunFlag=0;

LedFlash=3000; EX1=1; IT1=1; EA=1; ControlCar(8); while(1) {

if(P3_2 == 0)

{

delay_nms(10);

if(P3_2 == 0) {

temp++;

while(!P3_2);

EX1 = 1;break; } }

void IR_IN() interrupt 2 using 0 }

} }

if(temp > 3) {

temp = 1; }

switch(temp) {

case 1:

ShowPort=

LedShowData[1];Robot_Traction(); EX1 = 0;break;

case 2:

ShowPort=

LedShowData[2];Robot_Avoidance(); EX1 = 0;break;

case 3:

ShowPort = LedShowData[3];

{

unsigned char j,k,N=0;

EX1 = 0; delayms(15); if (IRIN==1) {

EX1 =1;

return; }

while (!IRIN) {

delayms(1); }

for (j=0;j<4;j++)

{ }

for (k=0;k<8;k++) {

IRCOM[j]=IRCOM[j] >> 1;

while (IRIN) if (N>=8) {

delayms(1); }

while (!IRIN) {

delayms(1); }

while (IRIN) {

delayms(1); N++; if (N>=30)

{

EX1=1;

return; } {

IRCOM[j] = IRCOM[j] | 0x80; }

N=0; } }

if (IRCOM[2]!=~IRCOM[3]) {

EX1=1; return; }

for(j=0;j<10;j++) {

if(IRCOM[2]==RecvData[j]) {

ControlCar_yaokong(j);

联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4 ceshi