|
51單片機(jī)控制步進(jìn)電機(jī)正轉(zhuǎn)5圈,反轉(zhuǎn)5圈。
單片機(jī)源程序如下:
- //步進(jìn)電機(jī)正反轉(zhuǎn)
- //電機(jī)使用端口P1.0,P1.1,P1.2,P1.3
- //單雙八拍工作方式:A-AB-B-BC-C-CD-D-DA
- //
- #include <reg51.h>
- #include <intrins.h>
- //**********************正向旋轉(zhuǎn)相序表*****************************
- unsigned char code FFW[8]={0x08,0x0c,0x04,0x06,0x02,0x03,0x01,0x09};
- //**********************反向旋轉(zhuǎn)相序表*****************************
- unsigned char code REV[8]={0x09,0x01,0x03,0x02,0x06,0x04,0x0c,0x08};
- //***********************延時(shí)子程序********************************
- void delay(unsigned int t)
- {
- unsigned int k;
- while(t--)
- {
- for(k=0; k<125; k++)
- {}
- }
- }
-
- //**********************步進(jìn)電機(jī)正轉(zhuǎn)******************************
- void motor_ffw(unsigned int n)
- {
- unsigned char i;
- unsigned int j;
- for (j=0; j<8*64*n; j++)
- {
- for (i=0; i<8; i++)
- {
- P1 = FFW[i];
- delay(1);
- }
- }
- }
- //*********************步進(jìn)電機(jī)反轉(zhuǎn)********************************
- void motor_rev(unsigned int n)
- {
- unsigned char i;
- unsigned int j;
- for (j=0; j<8*64*n; j++)
- {
- for (i=0; i<8; i++)
- {
- P1 = REV[i];
- delay(1);
- }
- }
- }
-
- //*************************主程序*********************************
- main()
- {
- while(1)
- {
- motor_ffw(5); //正轉(zhuǎn)5圈
- delay(1000);
- motor_rev(5); //反轉(zhuǎn)5圈
- delay(1000);
- }
- }
復(fù)制代碼
所有資料51hei提供下載:
28BYJ48.zip
(693 Bytes, 下載次數(shù): 44)
2017-12-25 23:12 上傳
點(diǎn)擊文件名下載附件
|
評分
-
查看全部評分
|