要求步进电机转过90度后,把电机轴锁住。结果既停不下来,又锁不住。程序错在哪里?求大家帮一帮。
- #include <reg51.h> //要求步进电机转过90度后,把电机轴锁住。
- unsigned char code up_data[8]={ 0xf9,0xf1,0xf3,0xf2,0xf6,0xf4,0xfc,0xf8};
- /********以下是延时函数,延时时间为speed×1ms********/
- void Delay(unsigned int speed)
- {
- unsigned int i,j;
- for(i=speed;i>0;i--)
- for(j=110;j>0;j--);
- }
- /********以下是主函数********/
- void main()
- {
- unsigned char i;
- unsigned int cnt=0;
- for (i=0; i<8; i++) //1个脉冲转5.625度,(16个脉冲转了90度)
- {
- P1 = up_data[i];
- Delay(5);
- cnt++;
- if (cnt==16)
- {
- P1 = up_data[i]; //达到16个脉冲后,把电机轴锁住20秒钟。
- Delay(20000);
- }
- }
- }
复制代码
|