仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)
51hei.png (17.83 KB, 下載次數: 55)
下載附件
2020-12-9 22:52 上傳
單片機源程序如下:
- #include "reg51.h"
- #define uchar unsigned char
- #define uint unsigned int
- #define out P2
- sbit pos=P0^0;
- sbit neg=P0^1;
- void delayms(uint);
- uchar code turn[]={0x07,0x06,0x0e,0x0c,0x0d,0x09,0x0b,0x03};
- uchar code turn1[]={0x02,0x06,0x04,0x0c,0x08,0x09,0x01,0x03};
- void main(void)
- {
- uchar i;
- out=0x03;
- while(1)
- {
- if(!pos)
- {
- //i = i < 8 ? i+1 : 0;
- if(i<8)
- i=i+1;
- else
- i=0;
- out=turn[i];
- delayms(1000);
- }
- else if(!neg)
- {
- i = i > 0 ? i-1 : 7;
- out=turn[i];
- delayms(1000);
- }
- }
- }
- void delayms(uint j)
- {
- uchar i;
- for(;j>0;j--)
- {
- i=250;
- while(--i);
- i=249;
- while(--i);
- }
- }
復制代碼
所有資料51hei提供下載:
JINBU.zip
(52.94 KB, 下載次數: 53)
2020-12-9 18:19 上傳
點擊文件名下載附件
步進電機仿真 下載積分: 黑幣 -5
|