求助啊,用uln2003驱动,但是电机抖动,转的非常慢,抖动的也很厉害,大佬们看一下,是程序
- #include "reg52.h"
- void delay(unsigned int t);
- //Motor
- sbit F1 = P3 ^ 0;
- sbit F2 = P3 ^ 1;
- sbit F3 = P3 ^ 2;
- sbit F4 = P3 ^ 3;
- unsigned char code FFW[8] = {0xf1, 0xf3, 0xf2, 0xf6, 0xf4, 0xfc, 0xf8, 0xf9}; //反转
- unsigned char code FFZ[8] = {0xf9, 0xf8, 0xfc, 0xf4, 0xf6, 0xf2, 0xf3, 0xf1}; //正转
- unsigned int K;
- /**********************************************************************
- * *
- * 步进电机驱动 *
- * *
- ***********************************************************************/
- void motor_ffw()
- {
- unsigned char i;
- unsigned int j;
- for (j = 0; j < 12; j++) //转1*n圈
- {
- for (i = 0; i < 8; i++) //一个周期转30度
- {
- if(K == 1) P1 = FFW[i] & 0x1f; //取数据
- if(K == 2) P1 = FFZ[i] & 0x1f;
- delay(100); //调节转速
- }
- }
- }
- /******************************************************
- *
- * 延时程序
- *
- ********************************************************/
- void delay(unsigned int t)
- {
- unsigned int k;
- while(t--)
- {
- for(k = 0; k < 80; k++)
- { }
- }
- }
- main()
- {
- while(1)
- {
- K = 1;
- motor_ffw();
- K = 2;
- motor_ffw();
- }
- }
复制代码
|