跟我一樣的。我給你代碼運行一下。/*******************************************************
ULN2003驅(qū)動5V減速步進電機程序
Target:STC89C52RC-40C
Crystal:12MHz
Author:戰(zhàn)神單片機工作室
Platform:51&avr單片機最小系統(tǒng)板+ULN2003步進電機驅(qū)動套件
*******************************************************
接線方式:
IN1 ---- P00
IN2 ---- P01
IN3 ---- P02
IN4 ---- P03
+ ---- +5V
- ---- GND
*********************/
- #include<reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- #define MotorData P0 //步進電機控制接口定義
- uchar phasecw[4] ={0x08,0x04,0x02,0x01};//正轉(zhuǎn) 電機導通相序 D-C-B-A
- uchar phaseccw[4]={0x01,0x02,0x04,0x08};//反轉(zhuǎn) 電機導通相序 A-B-C-D
- //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(4);//轉(zhuǎn)速調(diào)節(jié)
- }
- }
- //逆時針轉(zhuǎn)動
- void MotorCCW(void)
- {
- uchar i;
- for(i=0;i<4;i++)
- {
- MotorData=phaseccw[i];
- Delay_xms(4);//轉(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)定
- while(1)
- {
- for(i=0;i<500;i++)
- {
- MotorCW(); //順時針轉(zhuǎn)動
- }
- MotorStop(); //停止轉(zhuǎn)動
- Delay_xms(500);
- for(i=0;i<500;i++)
- {
- MotorCCW(); //逆時針轉(zhuǎn)動
- }
- MotorStop(); //停止轉(zhuǎn)動
- Delay_xms(500);
- }
- }
復制代碼
|