正反转可控的步进电机Proteus仿真.docx
正反转可控的步进电机Proteus仿真仿真图: 仿真程序: #include<reg52.h> #define uint unsigned int #define uchar unsigned char /-8拍- uchar code zz=0x01,0x03,0x02,0x06,0x04,0x0c,0x08,0x09; uchar code fz=0x09,0x08,0x0c,0x04,0x06,0x02,0x03,0x01; void delay(uint ms) void motor_zz(uint n) uint i,j; for(i=0;i<5*n;i+) uint t; while(ms-) for(t=0;t<120;t+); /正转 /反转 for(j=0;j<8;j+) if(P3=0xfb) break; P1=zzj; delay(20); void motor_fz(uint n) void main uint N=3; while(1) P3=0xff; if(P3=0xfe) while(P3=0xfe); uint i,j; for(i=0;i<5*n;i+) for(j=0;j<8;j+) if(P3=0xfb) break; P1=fzj; delay(20); P0=0xfe; motor_zz(N); if(P3=0xfb) break; else if(P3=0xfd) else P0=0xfb; P1=0x03; while(P3=0xfd); P0=0xfd; motor_fz(N); if(P3=0xfb) break;