|
學(xué)習(xí)了步進(jìn)電機(jī)的簡(jiǎn)單編程和仿真,分享給大家 功能:實(shí)現(xiàn)步進(jìn)電機(jī)轉(zhuǎn)動(dòng)(每次90°)
51hei.png (89.63 KB, 下載次數(shù): 32)
下載附件
2020-6-21 22:17 上傳
- #include <reg51.h>
- #define uint unsigned int
- unsigned char code f_rotation[4]={0xCF,0x9F,0x3F,0x6F }; //雙4拍正轉(zhuǎn)相序字
- unsigned char code b_rotation[4]={0x6F,0x3F,0x9F,0xCF }; //雙4拍反轉(zhuǎn)相序字
- void delay_ms(uint x) //以毫秒為單位的步間延時(shí)函數(shù)
- {
- uint i,j;
- for (i=x; i>0; i--)
- for (j=700; j>0;j--);
- }
- void main()
- { unsigned char i;
- while(1)
- {
- for(i=0;i<4;i++)
- {
- P2=f_rotation[ i]; //查表并輸出相序字,可自行換成反轉(zhuǎn)表格[ i]
- delay_ms(200); //改變延時(shí)可調(diào)整步進(jìn)電機(jī)的轉(zhuǎn)速
- }
- }
- }
復(fù)制代碼 |
|