您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 交通运输 > 基于51单片机的C语言步进电机驱动程序
#includereg51.hsbitkey=P1^5;//°´¼üK1unsignedchara,flag;unsignedcharforword[4]={0xFC,0xF6,0xF3,0xF9};//Õýתunsignedcharback[4]={0xFC,0xF9,0xF3,0xF6};//·´×ªvoiddelay(unsignedintdly){unsignedchari;while(dly--){for(i=110;i0;i--);//1ºÁÃë}}voidfront_move(unsignedintstep)//Õýת{unsignedchari,j;for(j=0;jstep;j++){for(i=0;i4;i++){P0=forword[i];delay(50);}}}voidback_move(unsignedintstep)//·´×ª{unsignedcharj,i;for(j=step;j0;j--){for(i=0;i4;i++){P0=back[i];delay(145);}}}voidinit(void)//¶¨Ê±Æ÷³õʼ»¯{TMOD=0x11;TH1=0x3C;//²úÉú50msµÄÖжÏTL1=0xB0;EA=1;ET1=1;}voidTimer1ISR()interrupt3{TH1=0x3C;TL1=0xB0;TF1=0;a++;if(a==60)//ÖжÏ60´Î£¬¹²3Ãë{a=0;flag=1;//·¢ËÍÔÝÍ£ÐźÅ}}voidmain(){init();TR1=1;P0=0x00;//Êä³öÈ«¸ßkey=1;//°´¼üÖÃÊäÈë״̬while(1){if(key==0){delay(20);front_move(20);//Õýתdelay(20);if(flag==1)//Í£ÈýÃë{flag=0;TR1=0;P0=0x00;delay(2000);}delay(20);back_move(20);//·´×ªdelay(20);}}}
本文标题:基于51单片机的C语言步进电机驱动程序
链接地址:https://www.777doc.com/doc-4635365 .html