欢迎来到天天文库
浏览记录
ID:30749620
大小:51.00 KB
页数:12页
时间:2019-01-03
《42步进电机驱动程序》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、42步进电机驱动程序#include#defineuintunsignedint#clefineucharunsignedchar#definems*77//f=12M#defineLEDLen4#defineDjstar()Pridj=0;}ShacheShacheLEDBuf#defineDj_stop(){IE=0x00;Pri_clj=1;Pl=0XFF;=〃0〃.Delay(800ms):Delay(800ms);Delay(400ms);=1;}#defineChilunN
2、um8/*thegearnumber8*/#definesetdisplaynum(){LEDBuf[0]=TMP/1000;[1]二TMP/100%10;LEDBuf[2]二TMP/10%;LEDBuf[3]二TMP%10}UcharLEDBuf[LEDLen]二{0,0,0,0}Voidreadnum():/*readthesowingcodetosetroundnum*Voiddisplay();Voiddelay(uintdelay_time){uintI;For(1=0;I3、me;I++);}Voidrun();Voidfx_run();Uintround_num二0;/*recordthenumberofgearsthathavebeenturned,interrupted1timesplus1*/Uintset_round_num二0;/*sowingplattersetsthewindingnumber*/Uintset_pwm_width=0;/*sowingplattersetsthestepmotortothespeed*/Bitone_round_flg二0;4、Sbitled_1000二P0八7;//useforthedisplaySbitled_100=P06;//useforthedisplaySbitled_10=P05://useforthedisplaySbitled_l=P04;//useforthedisplaySbitkey_start二P3八0;Sbitkey_puse二P3八0;Sbitkey_clear=P31;/**/P3八2pickupgearsensorinterruptSbitbujin_zx_stop二P3八3;/*taketh5、estepintothemotor,thesensorisinplace,0stop*/Sbitbujin_fx_stop=P34;/*takethestepintothemotor,thereversepositionsensor,0down*/Sbitshache二P3八5;/*thebrakecontrolrelays0potentialeffective*/Sbitpri_dj=P36;/*themainmotorcontrolrelays0potentialeffective*/Voidmai6、n(){TCON=0xOl;Thedisplay();While(1){IE二〃0x00〃;Roundnum二0;Thedisplay();If(bujin_fxstop)fxrun();While(key_start);Delay(8ms);If(!Key_start){Read_num();//set_round_num二8;While(!Key_start);Therun();Fx_run();Voidrun(){PoundsigndefineDelay_time180/*turnaround507、cycles,4stepspercycle,50*4二200,200*1.8二360*/UcharI;Pl二0XFF;Set_pwm_width二15+set_pwm_width/10;While(1)While(!)Dj_star();For(I二〃0〃;)Pl二0xf9;延迟(延迟时间);//bujinzxstop=P33;Pl=0xfc://bujinfxstop=P34;延迟(延迟时间);//keypuse=P30;Pl=0xf6;//keyclear=P31;延迟(延迟时间);//shache8、=P35;Pl=0xf3;//pridj=P36;如果(i==setpwmwidth)Pl=Oxff;i=0;—圆fig二0;while(!one_roundflg&key_puse);}如果(!keypuse)延迟(4ms);如果(!keypuse)中断;}Pl二0xff;如果(pridj)中断;如果(!key_puse){延迟女士(8);如果(!key_puse){Dj_stop();而(!key_puse);//下一个试验的关键而(I
3、me;I++);}Voidrun();Voidfx_run();Uintround_num二0;/*recordthenumberofgearsthathavebeenturned,interrupted1timesplus1*/Uintset_round_num二0;/*sowingplattersetsthewindingnumber*/Uintset_pwm_width=0;/*sowingplattersetsthestepmotortothespeed*/Bitone_round_flg二0;
4、Sbitled_1000二P0八7;//useforthedisplaySbitled_100=P06;//useforthedisplaySbitled_10=P05://useforthedisplaySbitled_l=P04;//useforthedisplaySbitkey_start二P3八0;Sbitkey_puse二P3八0;Sbitkey_clear=P31;/**/P3八2pickupgearsensorinterruptSbitbujin_zx_stop二P3八3;/*taketh
5、estepintothemotor,thesensorisinplace,0stop*/Sbitbujin_fx_stop=P34;/*takethestepintothemotor,thereversepositionsensor,0down*/Sbitshache二P3八5;/*thebrakecontrolrelays0potentialeffective*/Sbitpri_dj=P36;/*themainmotorcontrolrelays0potentialeffective*/Voidmai
6、n(){TCON=0xOl;Thedisplay();While(1){IE二〃0x00〃;Roundnum二0;Thedisplay();If(bujin_fxstop)fxrun();While(key_start);Delay(8ms);If(!Key_start){Read_num();//set_round_num二8;While(!Key_start);Therun();Fx_run();Voidrun(){PoundsigndefineDelay_time180/*turnaround50
7、cycles,4stepspercycle,50*4二200,200*1.8二360*/UcharI;Pl二0XFF;Set_pwm_width二15+set_pwm_width/10;While(1)While(!)Dj_star();For(I二〃0〃;)Pl二0xf9;延迟(延迟时间);//bujinzxstop=P33;Pl=0xfc://bujinfxstop=P34;延迟(延迟时间);//keypuse=P30;Pl=0xf6;//keyclear=P31;延迟(延迟时间);//shache
8、=P35;Pl=0xf3;//pridj=P36;如果(i==setpwmwidth)Pl=Oxff;i=0;—圆fig二0;while(!one_roundflg&key_puse);}如果(!keypuse)延迟(4ms);如果(!keypuse)中断;}Pl二0xff;如果(pridj)中断;如果(!key_puse){延迟女士(8);如果(!key_puse){Dj_stop();而(!key_puse);//下一个试验的关键而(I
此文档下载收益归作者所有