熱門: 51單片機(jī) | 24小時(shí)必答區(qū) | 單片機(jī)教程 | 單片機(jī)DIY制作 | STM32 | Cortex M3 | 模數(shù)電子 | 電子DIY制作 | 音響/功放 | 拆機(jī)樂園 | Arduino | 嵌入式OS | 程序設(shè)計(jì)
![]() |
發(fā)布時(shí)間: 2021-4-30 14:02
正文摘要:我用仿真尋跡時(shí),出現(xiàn)一個(gè)正轉(zhuǎn),一個(gè)反轉(zhuǎn), 但仿真藍(lán)牙時(shí),就沒有出現(xiàn)這種情況。 |
用普通的直流電機(jī)調(diào)換線頭就行了 |
wc86110 發(fā)表于 2021-4-30 17:53 我已經(jīng)發(fā)了代碼和原理圖,您抽時(shí)間看一下,萬分感謝 如果還是不明白,您可以留個(gè)郵箱,我把仿真程序和程序可以發(fā)給你, |
#include<reg52.h> #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() //電機(jī)起動(dòng) { 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() //左進(jìn) { P1=0x30; delay_1ms(200); P1=0x00; delay_1ms(20); } void motor_right() //右進(jìn) { P1=0x05; delay_1ms(200); P1=0x00; delay_1ms(20); } void motor_big_right() //粗右進(jìn) { P1=0x55; delay_1ms(200); P1=0x00; delay_1ms(20); } void motor_big_left() //粗左轉(zhuǎn) { P1=0x33; delay_1ms(200); P1=0x00; delay_1ms(20); } void motor_stop() //電機(jī)停止 { P1=0x00; } void motor_back() //電機(jī)后退 { 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; //得到紅外反向信號(hào) 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; } } */[/code] |
問題是沒圖程序不好找問題 |
Powered by 單片機(jī)教程網(wǎng)