標(biāo)題:
為什么我這個燒進(jìn)單片機(jī)車子只是正轉(zhuǎn)
[打印本頁]
作者:
蟲蟲大作戰(zhàn)
時間:
2016-11-26 15:28
標(biāo)題:
為什么我這個燒進(jìn)單片機(jī)車子只是正轉(zhuǎn)
頭文件
******************************************************************/
#include<AT89X52.H>
/******************************************************************
** 接線定義
******************************************************************/
#define Left_moto_go {P1_0=1,P1_2=1;P1_3=0;} //左電機(jī)正轉(zhuǎn)
#define Left_moto_back {P1_0=1,P1_2=0;P1_3=1;} //左電機(jī)反轉(zhuǎn)
#define Left_moto_Stop {P1_0=0;} //左電機(jī)停轉(zhuǎn)
#define Right_moto_go {P1_1=1,P1_4=1;P1_5=0;} //右電機(jī)正轉(zhuǎn)
#define Right_moto_back {P1_1=1,P1_4=0;P1_5=1;} //右電機(jī)反轉(zhuǎn)
#define Right_moto_Stop {P1_1=0;} //右電機(jī)停轉(zhuǎn)
/******************************************************************
** 延時函數(shù)
******************************************************************/
void delay(unsigned int k)
{
unsigned int x,y;
for(x=0;x<k;x++)
for(y=0;y<2000;y++);
}
/******************************************************************
** 小車前進(jìn)
******************************************************************/
void front_run(void)
{
Left_moto_go;
Right_moto_go;
}
/******************************************************************
** 小車倒退
******************************************************************/
void back_run(void)
{
Left_moto_back;
Right_moto_back;
}
/******************************************************************
** 小車左轉(zhuǎn)
******************************************************************/
void left_run(void)
{
Left_moto_Stop;
Right_moto_go;
}
/******************************************************************
** 小車右轉(zhuǎn)
******************************************************************/
void right_run(void)
{
Right_moto_Stop;
Left_moto_go;
}
/******************************************************************
** 小車停走
******************************************************************/
void stop(void)
{
Left_moto_Stop
Right_moto_Stop;
}
/******************************************************************
** 主函數(shù)
******************************************************************/
void main(void)
{
delay(100);
while(1)
{
front_run();
delay(200);
back_run();
delay(200);
left_run();
delay(200);
right_run();
delay(200);
stop();
delay(400);
}
}
/******************************************************************
** 結(jié)束
作者:
lgjdqm
時間:
2016-11-27 16:38
應(yīng)該考慮延時的問題
作者:
我不配11
時間:
2016-11-27 17:25
宏定義部分有問題
作者:
minilong95
時間:
2016-11-27 17:27
試試加大延遲
作者:
daifei1234
時間:
2016-11-27 21:48
因為它不會反轉(zhuǎn)呀
作者:
咆哮的阿杰
時間:
2016-11-27 22:11
你這個電機(jī)是不需要驅(qū)動電路的嗎????為什么直接對I/O口賦值就能對電機(jī)進(jìn)行操作?
作者:
a0931727149
時間:
2016-11-28 17:37
咆哮的阿杰 發(fā)表于 2016-11-27 22:11
你這個電機(jī)是不需要驅(qū)動電路的嗎????為什么直接對I/O口賦值就能對電機(jī)進(jìn)行操作?
在正到反轉(zhuǎn)間下個停車ㄧ點(diǎn)時間。試試看
在宏定義中en先除能。等到命令下完在致能。
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1