- #include <reg52.h>
- unsigned char code F_Rotation[4]={0x02,0x04,0x08,0x10};//正轉表格
- unsigned char code B_Rotation[4]={0x10,0x08,0x040,0x02};//反轉表格
- void Delay(unsigned int i)//延時
- {
- while(--i);
- }
- main()
- {
- unsigned char i;
- while(1)
- {
- for(i=0;i<4;i++) //4相
- {
- P1=F_Rotation[i]; //輸出對應的相 可以自行換成反轉表格
- Delay(500); //改變這個參數可以調整電機轉速
- }
- }
- }
復制代碼 |