通电以后步进电机一直在转,我分析的应该转5个周期就停下了啊
单片机源程序如下:
- #include<reg51.h>
- #define uint unsigned int
- #define uchar unsigned char
- #define GPIO_DJ P1
- unsigned char code eight_pos[8]={0x06,0x07,0x03,0x0b,0x09,0x0d,0x0c,0x0e};//八拍驱动方式正转表 AD-D-DC-C-CB-B-BA-A
- unsigned char code eight_rev[8]={0x0e,0x0c,0x0d,0x09,0x0b,0x03,0x07,0x06};//八拍驱动方式反转表 A-AB-B-BC-C-CD-D-DA
- unsigned char code eight_pos[8]={0x06,0x07,0x03,0x0b,0x09,0x0d,0x0c,0x0e};//八拍驱动方式正转表 AD-D-DC-C-CB-B-BA-A
- unsigned char code eight_rev[8]={0x0e,0x0c,0x0d,0x09,0x0b,0x03,0x07,0x06};//八拍驱动方式反转表 A-AB-B-BC-C-CD-D-DA
- void Delay1ms(unsigned int c);//定义延时程序
- unsigned int a,b,i,j,k,z; //采集的亮度值及当前的步进电机角度
- unsigned char pp; //读取二十次ad值for循环
- unsigned int c=0,d=0;
- void Delay(unsigned int i)//延时
- {
- while(--i);
- }
- void delay1ms(z)
- {
- unsigned int x,y;
- for(x=z;x>0;x--)
- for(y=110;y>0;y--);
- }
- void m_eight_pos()
- {
- j=0;
- for(i=0;i<8;i++)//在八拍工作方式下,一个脉冲转子转动角度为5.625度,八拍共45度
- {
- P1=eight_pos[j];
- delay1ms(2);
- j++;
- }
-
- }
- /*******************八拍驱动反转(N*45/16)度***********************/
- void m_eight_rev()
- {
- j=0;
- for(i=0;i<8;i++)//在八拍工作方式下,一个脉冲转子转动角度为5.625度,八拍共45度
- {
- P1=eight_rev[j];
- delay1ms(2);
- j++;
- }
- }
- void main(void)
- {
- b=0;
- while(1)
- {
- a=100;
- if(a>=b)
- {
- for(i=((a-b)/20);i>0;i--)
- {
- b+=20;
- m_eight_rev();
- }
- }
- else
- {
- for(i=((b-a)/20);i>0;i--)
- {
- b-=20;
- m_eight_pos();
- }
- }
- }
- }
复制代码
|