|
在網上買兩套uln2003驅動板和步進電機,程序用下面的去測試,怎么都無法驅動這兩套電機,用的最小系統STC89C52。程序在仿真軟件上試過能驅動電機,下載到板上就是不行,請教一下,這是什么問題。驅動線和電源線連接都沒錯。
*******************************************************
接線方式:
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};//正轉 電機導通相序 D-C-B-A
- uchar phaseccw[4]={0x01,0x02,0x04,0x08};//反轉 電機導通相序 A-B-C-D
- uchar speed;
- //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(speed);//轉速調節
- }
- }
- //停止轉動
- void MotorStop(void)
- {
- MotorData=0x00;
- }
- //主函數
- void main(void)
- {
- uint i;
- Delay_xms(50);//等待系統穩定
- speed=40;
- while(1)
- {
- for(i=0;i<10;i++)
- {
- MotorCW(); //順時針轉動
- }
- speed--; //減速
- if(speed<4)
- {
- speed=40; //重新開始減速運動
- MotorStop();
- Delay_xms(500);
- }
- }
- }
復制代碼 |
-
1.jpg
(113.42 KB, 下載次數: 80)
下載附件
2019-11-20 11:28 上傳
|