步進電機仿真.PNG (69.87 KB, 下載次數: 26)
下載附件
2019-6-7 16:12 上傳
步進電機參數.PNG (139.78 KB, 下載次數: 27)
下載附件
2019-6-7 16:12 上傳
單片機源程序如下:
- #include <reg52.h>
- unsigned char code FFW[]={0x01,0x03,0x02,0x06,0x04,0x0c,0x08,0x09};
- unsigned char code REV[]={0x09,0x08,0x0c,0x04,0x06,0x02,0x03,0x01};
- sbit K1 = P3^0;
- sbit K2 = P3^1;
- sbit K3 = P3^2;
- void DelayMS(unsigned char ms)
- {
- unsigned char i;
- while(ms--)
- {
- for(i=0;i<120;i++);
- }
- }
- void moter_FFW(unsigned char n)
- {
- unsigned char i,j;
- for(i=0;i<5*n;i++)
- {
- for(j=0;j<8;j++)
- {
- if(K3 == 0) break;
- P1 = FFW[j];
- DelayMS(25);
- }
- }
- }
- void moter_REV(unsigned char n)
- {
- unsigned char i,j;
- for(i=0;i<5*n;i++)
- {
- for(j=0;j<8;j++)
- {
- if(K3 == 0) break;
- P1 = REV[j];
- DelayMS(25);
- }
- }
- }
- void main()
- {
- unsigned char x = 3;
- while(1)
- {
- if(K1 == 0)
- {
- P0 = 0xfe;
- moter_FFW(x);
- if(K3 == 0)
- break;
- }
- else if(K2 == 0)
- {
- P0 = 0xfd;
- moter_REV(x);
- if(K3 == 0)
- break;
- }
- else
- {
- P0 = 0xfb;
- P1 = 0x03;
- }
- }
復制代碼
|