本帖最后由 57185490 于 2023-1-15 12:38 編輯
52單片機(jī)+a8944驅(qū)動(dòng)控制2相4線步進(jìn)電機(jī) 按鍵控制正反轉(zhuǎn) A8944 “ENABLE 啟動(dòng)”空懸 ,接電后(由于低電平屬于啟動(dòng))所以按鍵無操作,電機(jī)也有電流持續(xù)升溫,時(shí)間長就燒電機(jī)(已經(jīng)燒了一個(gè),但正反轉(zhuǎn)運(yùn)行正常)!所以必須接單片機(jī)拉高電平,只有按鍵操作拉低電平再轉(zhuǎn)動(dòng),松開按鍵停止啟動(dòng)(無電流,避免電機(jī)持續(xù)發(fā)熱) 現(xiàn)在“ENABLE”接的單片機(jī)P1^1, 問題出現(xiàn)啦~~~1:正轉(zhuǎn)按鍵按下(P2_0)高電平3.9v拉低到0v,運(yùn)行!但松開按鍵電平還是低電平 2:反轉(zhuǎn)按鍵按下(P2_1)高電平只能拉低到1.7v,無法運(yùn)行!松開按鍵,電平恢復(fù)到3.9v ENABLE=1和ENABLE=0 放到這個(gè)程序的任何位置都這樣~~哪里出問題了? while 不用“y” (就是取消“y”這個(gè)操作,只用ENABLE=1和ENABLE=0 來啟動(dòng)和停止,也是這種情況) 這個(gè)是程序: #include <reg51.h> #define uchar unsigned char unsigned int y ; /**********************????****************/ void Delay(unsigned int xms) //@12.000MHz Delay(1)=1ms { unsigned char i, j; while(xms--) { i = 2; j = 239; do {while (--j);} while(--i); } } void delay1(unsigned int b)//可忽略,閑著無聊加個(gè)延時(shí)~~~ { uchar g; for(;b>0;b--) { g=250; while(--g); g=249; while(--g); } } /***********************************************/ sbit DIR=P2^0; // sbit STEP=P2^1; // sbit P2_0=P2^2; // sbit P2_1=P2^5; sbit ENABLE=P1^1; void step(void) { STEP=0; //脈沖 Delay(1); // Delay(1)=1ms STEP=1; Delay(1); } void UP_dj(void) //正轉(zhuǎn) { DIR=0; //正轉(zhuǎn) step(); if(P2_0==1)// 按鍵松開,電機(jī)停止 delay1(10);// 延時(shí),防按鍵誤操作 if(P2_0==1) { y=0;//while循環(huán)程序停止 } } void DN_dj(void) //反轉(zhuǎn) { DIR=1; //反轉(zhuǎn) step(); if(P2_0==1) // 按鍵松開,電機(jī)停止 delay1(10); // 延時(shí) ,防按鍵誤操作 if(P2_0==1) { y=0; } } void main() //??? { ENABLE=1; y=1; while(y) { if(P2_0==0) //?????????? delay1(10); if(P2_0==0) { ENABLE=0; UP_dj(); //正轉(zhuǎn) } if(P2_1==0) //?????????? delay1(10); if(P2_1==0) { ENABLE=0; DN_dj(); //反轉(zhuǎn) } } }
|