新手一枚如題,在運行28byj-48步進電機的測試程序中,電機內部在動,外面的軸卻一點也不動,求大神解答!!
單片機程序如下:
- #include<reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- #define MotorData P0 //步進電機控制接口定義
- uchar phasecw[4] ={0x08,0x04,0x02,0x01};//正轉 電機導通相序 D-C-B-A
- uchar phaseccw[4]={0x01,0x02,0x04,0x08};//反轉 電機導通相序 A-B-C-D
- //ms延時函數
- void Delay_xms(uint x)
- {
- uint i,j;
- for(i=0;i<x;i++)
- for(j=0;j<112;j++);
- }
- //順時針轉動
- void MotorCW(void)
- {
- uchar i;
- for(i=0;i<4;i++)
- {
- MotorData=phasecw[i];
- Delay_xms(4);//轉速調節
- }
- }
- //逆時針轉動
- void MotorCCW(void)
- {
- uchar i;
- for(i=0;i<4;i++)
- {
- MotorData=phaseccw[i];
- Delay_xms(4);//轉速調節
- }
- }
- //停止轉動
- void MotorStop(void)
- {
- MotorData=0x00;
- }
- //主函數
- void main(void)
- {
- uint i;
- Delay_xms(50);//等待系統穩定
- while(1)
- {
- for(i=0;i<500;i++)
- {
- MotorCW(); //順時針轉動
- }
- MotorStop(); //停止轉動
- Delay_xms(500);
- for(i=0;i<500;i++)
- {
- MotorCCW(); //逆時針轉動
- }
- MotorStop(); //停止轉動
- Delay_xms(500);
- }
- }
復制代碼
請問問題出在哪里?
|