我利用L6219DS驱动电机,程序如下,其中PH1,PH2控制电流方向。 #include "reg52.h" #define speed 5 sbit PH1 = P1^0; //定义管脚 sbit PH2 = P1^1; sbit I01 = P1^2; sbit I02 = P1^3; sbit I11 = P1^4; sbit I12 = P1^5; void delay(int time); /*************************************** 函数功能:产生单相四拍脉冲控制步进机 **************************************/ void Go() { //A PH1 = 0; I01 = 1; I11 = 1; PH2 = 0; I02 = 0; I12 = 0; delay(speed); //0 PH1 = 0; I01 = 0; I11 = 0; PH2 = 1; I02 = 1; I12 = 1; delay(speed); //B PH1 = 1; I01 = 1; I11 = 1; PH2 = 1; I02 = 0; I12 = 0; delay(speed); //0 PH1 = 1; I01 = 0; I11 = 0; PH2 = 0; I02 = 1; I12 = 1; delay(speed); } /*******************延时函数****************************/ void delay(int time) { int i,j; for(j=0; j <= time; j++) for(i =0 ; i <= 120; i++); } void main() { while(1) { Go(); } }
|