|
在網(wǎng)上買兩套uln2003驅(qū)動板和步進電機,程序用下面的去測試,怎么都無法驅(qū)動這兩套電機,用的最小系統(tǒng)STC89C52。程序在仿真軟件上試過能驅(qū)動電機,下載到板上就是不行,請教一下,這是什么問題。驅(qū)動線和電源線連接都沒錯。
*******************************************************
接線方式:
IN1 ---- P00
IN2 ---- P01
IN3 ---- P02
IN4 ---- P03
+ ---- +5V
- ---- GND
*********************/
- #include<reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- #define MotorData P1 //步進電機控制接口定義
- uchar phasecw[4] ={0x08,0x04,0x02,0x01};//正轉(zhuǎn) 電機導(dǎo)通相序 D-C-B-A
- uchar phaseccw[4]={0x01,0x02,0x04,0x08};//反轉(zhuǎn) 電機導(dǎo)通相序 A-B-C-D
- uchar speed;
- //ms延時函數(shù)
- void Delay_xms(uint x)
- {
- uint i,j;
- for(i=0;i<x;i++)
- for(j=0;j<112;j++);
- }
- //順時針轉(zhuǎn)動
- void MotorCW(void)
- {
- uchar i;
- for(i=0;i<4;i++)
- {
- MotorData=phasecw[i];
- Delay_xms(speed);//轉(zhuǎn)速調(diào)節(jié)
- }
- }
- //停止轉(zhuǎn)動
- void MotorStop(void)
- {
- MotorData=0x00;
- }
- //主函數(shù)
- void main(void)
- {
- uint i;
- Delay_xms(50);//等待系統(tǒng)穩(wěn)定
- speed=40;
- while(1)
- {
- for(i=0;i<10;i++)
- {
- MotorCW(); //順時針轉(zhuǎn)動
- }
- speed--; //減速
- if(speed<4)
- {
- speed=40; //重新開始減速運動
- MotorStop();
- Delay_xms(500);
- }
- }
- }
復(fù)制代碼 |
-
1.jpg
(113.42 KB, 下載次數(shù): 80)
下載附件
2019-11-20 11:28 上傳
|