日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

循迹小车c语言程序51单片机,51单片机循迹小车Proteus仿真程序

發(fā)布時間:2023/12/31 编程问答 26 豆豆
生活随笔 收集整理的這篇文章主要介紹了 循迹小车c语言程序51单片机,51单片机循迹小车Proteus仿真程序 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

#include

#define uchar unsigned char

#define uint unsigned int

uchar temp,signal,tt1,t0,t1,t2,t3,t4,t5,t6;

void delay_1ms(uint d)

{

uint i;

while(d--)

for(i=0;i<75;i++);

}

void motor_run()? ? ? ? ? ? ? ?? ? //電機起動

{

P1=0x35;

delay_1ms(200);

P1=0x53;

delay_1ms(10);

/*? ? ? ? ENA=1;

OUT1=0;

OUT2=1;

delay_1ms(800);

OUT2=0;

delay_1ms(200);

ENB=1;

OUT4=0;

OUT3=1;

delay_1ms(800);

OUT3=0;

delay_1ms(200);

*/

}

void motor_left()? ? ? ? ? ? ? ? ? ? ? ???//左進

{

P1=0x30;

delay_1ms(200);

P1=0x00;

delay_1ms(20);

}

void motor_right()? ? ? ? ? ? ? ?? ? //右進

{

P1=0x05;

delay_1ms(200);

P1=0x00;

delay_1ms(20);

}

void motor_big_right()? ? ? ? ? ? ? ? ? ? ? ???//粗右進

{

P1=0x55;

delay_1ms(200);

P1=0x00;

delay_1ms(20);

}

void motor_big_left()

{

P1=0x33;

delay_1ms(200);

P1=0x00;

delay_1ms(20);

}

void motor_stop()? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //電機停止

{

P1=0x00;

}

void motor_back()

{

P1=0x53;

}

void main()

{

t0=0;

t1=0;

t2=0;

t3=0;

t4=0;

t5=0;

t6=0;

tt1=0;

EA=1;

ET1=1;

TR1=1;

TMOD=0x01;

TH1=-(1000/256);

TL1=-(1000%256);

while(1)

{

temp=P2;

signal=temp&0xff;? ? ? ? ? ? ? ?? ? //得到紅外反向信號

switch(signal)

{

case 0xff:? ? ? ?? ? //無偏差

motor_run();

t0++;

if(t0==10)

{

t0=0;

motor_left();

motor_right();

}

t1=t2=t3=t4=t5=t6=0;

break;

case 0xfd:? ? ? ?? ? //1輪右偏

motor_big_left();

t1++;

if(t1==4)

{

t1=0;

motor_left();

}

t0=t2=t3=t4=t5=t6=0;

break;

case 0xef:? ? ? ?? ???//4輪左偏

motor_big_right();

t2++;

if(t2==4)

{

t2=0;

motor_right();

}

t0=t1=t3=t4=t5=t6=0;

break;

case 0xfb:? ???//2輪右偏出軌

case 0xf9:? ? ? ?? ? //1、2輪右偏

motor_big_left();

t3++;

if(t3==4)

{

t3=0;

motor_left();

}

t0=t1=t2=t4=t5=t6=0;

//? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? delay_1ms(10);

break;

case 0xdf:? ? ? ?? ? //5左偏出軌

case 0xcf:? ?? ?//4、5輪左偏

motor_big_right();

t4++;

if(t4==4)

{

t4=0;

motor_right();

}

t0=t1=t2=t3=t5=t6=0;

//? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? delay_1ms(10);

break;

case 0xfe:? ? ? ?? ? //0最右偏出軌

case 0xfa:

motor_big_left();

t5++;

if(t5==1)

{

t5=0;

motor_left();

motor_left();

}

t0=t1=t2=t3=t4=t6=0;

//? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? delay_1ms(10);

break;

case 0xbf:? ???//6最左偏出軌

case 0x9f:

motor_big_right();

t6++;

if(t6==1)

{

t6=0;

motor_right();

motor_right();

}

t0=t1=t2=t3=t4=t5=0;

//? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? delay_1ms(10);

break;

case 0xeb:? ? ? ???//前兩傳感器壓在黑線上

case 0xdb:? ? ? ???//后兩傳感器壓在黑線上

case 0xbe:? ? ? ???//中間兩傳感器壓在黑線上

case 0xac:? ? ? ???? ? ? ? //前四傳感器壓在黑線上

case 0x9a:? ? ? ? ? ? ? ? //后四傳感器壓在黑線上

motor_back();

delay_1ms(200);

motor_stop();

//? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? delay_1ms(1000);

default:

//? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? motor_back();

//? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? delay_1ms(50);

//? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? motor_left();

//? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? motor_right();

break;

}

}

}

/*void time1() interrupt 3

{

TH1=-(1000/256);

TL1=-(1000%256);

tt1++;

if(tt1==300)

{

motor_back();

//? ? ? ? delay_1ms(1);

tt1=0;

}

} */

總結

以上是生活随笔為你收集整理的循迹小车c语言程序51单片机,51单片机循迹小车Proteus仿真程序的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。