部分程序
單片機源程序如下:
- #include <reg51.h>
- //* 單雙八拍工作方式:A-AB-B-BC-C-CD-D-DA *
- unsigned char code shun[8] = {0x08,0x0c,0x04,0x06,0x02,0x03,0x01,0x09};
- unsigned char code ni[8] = {0x09,0x01,0x03,0x02,0x06,0x04,0x0c,0x08};
- void delay(char x)//延時程序
- {
- char i;
- while(x--)
- {
- for(i=0; i<120; i++);
- }
- }
- void motor_1(float a)//a即想要轉的圈數
- {
- unsigned char b;
- unsigned int c;
- for (c=0; c<8*64*a; c++)
- {
- for (b=0; b<8; b++)
- {
- P1 = shun[b];
- delay(1);
- }
- }
- }
- void motor_2(float a)//a即想要轉的圈數
- {
- unsigned char b;
- unsigned int c;
- for (c=0; c<8*64*a; c++)
- {
- for (b=0; b<8; b++)
- {
- P1 = ni[b];
- delay(1);
- }
- }
- }
- void main()//主程序
- {
- while(1)
- {
- motor_1(0.5); //轉2圈(可以改動)
- delay(1000);
- P1 = 0; //防止電機發熱
- motor_2(0.5); //轉2圈(可以改動)
- delay(1000);
- P1 = 0; //防止電機發熱
- }
- }
復制代碼
所有資料51hei提供下載:
步進電機.zip
(24.35 KB, 下載次數: 55)
2019-6-20 21:41 上傳
點擊文件名下載附件
|