|
51单片机做的步进电机的控制系统
源程序:
- #include <reg51.h>
- #include <absacc.h>
- sbit p10=P1^0;
- sbit p11=P1^1;
- sbit p12=P1^2;
- #define UP 20
- #define DOWN 30
- #define STOP 40
- void delay()//延时程序
- {
- unsigned i,j,k;
- for(i=0;i<0x02;i++)
- for(j=0;j<0x02;j++)
- for(k=0;k<0xff;k++);
- }
- main()
- {
- unsigned char temp;
- while(1)
- {
- if(p10==0)
- {
- temp=UP;//控制正转
- P2=0X00;
- delay();
- }
- if(p11==0)
- {
- temp=DOWN;//控制反转
- P2=0X00;
- delay();
- }
- if(p12==0)
- {
- temp=STOP;//控制停止
- }
- switch(temp)
- {
- case DOWN : P2=0X01;//控制反转 //0011
- delay();
- delay();
- P2=0X02;//0110
- delay();
- delay();
- P2=0X04;//1100
- delay();
- delay();
- P2=0X08;//1001
- delay();
- delay();
- break;
- case UP : P2=0X08;//控制正转
- delay();
- delay();
- P2=0X04;
- delay();
- delay();
- P2=0X02;
- delay();
- delay();
- P2=0X01;
- delay();
- delay();
- break;
- case STOP ://控制停止
- P2=0X00;
- delay();
- delay();
- break;
- }
- }
- }
复制代码
|
评分
-
查看全部评分
|