📄 步进电机控制程序(c语言51单片机).mht
字号:
}<BR>}</P>
<P>void run () =
{<BR> =20
#define Delay_time =20
180<BR> /* =
=D7=AA=D2=BB=C8=A6 50 =B4=CE=D1=AD=BB=B7=A3=AC=C3=BF=D1=AD=BB=B7=20
4 =B2=BD =A3=AC50 * 4 =3D 200 =A3=AC 200 * =
1=A1=A38 =3D 360=20
*/<BR> uchar i=20
;<BR> P1 =3D=20
0xff;<BR> =
set_pwm_width =3D=20
15 + set_pwm_width /=20
10;<BR> while ( 1 =
) {</P>
=
<P> &nbs=
p;=20
while( !shache | !key_start=20
=
);<BR> &=
nbsp;=20
=
Dj_star();<BR>  =
; =20
for ( i=3D"0" ; bujin_zx_stop & =
!pri_dj;i++=20
=
){<BR> &=
nbsp; =20
P1 =3D =20
=
0xf9;<BR> &nbs=
p; =20
delay ( Delay_time =20
=
); =20
// bujin_zx_stop =3D=20
=
P3^3;<BR> &nbs=
p; =20
P1 =3D =20
=
0xfc; &n=
bsp; =20
// bujin_fx_stop =3D=20
=
P3^4;<BR> &nbs=
p; =20
delay (=20
=
Delay_time); =
// =
key_puse =3D=20
=
P3^0;<BR> &nbs=
p; =20
P1 =3D =20
=
0xf6; &n=
bsp; =20
// key_clear =
=3D=20
=
P3^1;<BR> &nbs=
p; =20
delay ( Delay_time =20
=
); =20
//=20
=
shache =20
=3D=20
=
P3^5;<BR> &nbs=
p; =20
P1 =3D =20
=
0xf3; &n=
bsp; =20
//=20
=
pri_dj =20
=3D=20
=
P3^6;<BR> &nbs=
p; =20
delay ( Delay_time=20
=
);<BR> &=
nbsp; =20
if( i =3D=3D set_pwm_width ) { P1 =3D =
0xff; i =3D 0;=20
one_round_flg =3D 0; while ( =
!one_round_flg &=20
key_puse=20
=
);}<BR> =
=20
if(!key_puse) { delay(4ms); =20
if(!key_puse) break; =20
=
}<BR> &n=
bsp;=20
}</P>
=
<P> &nbs=
p;=20
P1 =3D=20
=
0xff;<BR> &nbs=
p; =20
if ( pri_dj ) break;</P>
=
<P> &nbs=
p;=20
if ( !key_puse )=20
=
{<BR> &n=
bsp; =20
delay ( 8ms=20
=
);<BR> &=
nbsp; =20
if ( !key_puse )=20
=
{<BR> &n=
bsp; =20
=
Dj_stop();<BR>  =
; =20
while ( !key_puse=20
=
);<BR> &=
nbsp; =20
// next pree=20
=
key<BR> =
=20
while( !shache );</P>
=
<P> &nbs=
p; =20
=
while(1){<BR> =
&=
nbsp; =20
while ( key_puse =
& =20
key_clear=20
=
);<BR> &=
nbsp; &n=
bsp;=20
delay ( 8ms=20
=
);<BR> &=
nbsp; &n=
bsp;=20
if ( !key_clear ) { round_num =
=3D 0;=20
display();=20
=
}<BR> &n=
bsp; &nb=
sp;=20
if ( !key_puse ) =20
=
break;<BR> &nb=
sp; =20
=
}<BR> &n=
bsp; =20
while( !key_puse=20
=
);<BR> &=
nbsp; =20
=
delay(8ms);<BR> &nbs=
p; =20
while( !key_puse=20
=
);<BR> &=
nbsp; =20
=
}<BR> &n=
bsp;=20
}<BR> =
}<BR>}<BR>void=20
ext_int0(void) interrupt 0 =20
{ /* =D6=F7=B5=E7=BB=FA =
=B3=DD=C2=D6 =D6=D0=B6=CF=20
*/<BR> uint=20
tmp;<BR> EA =3D=20
0;<BR> if( !pri_dj =
=
){<BR> &=
nbsp;=20
round_num=20
=
++;<BR> =
=20
if (round_num % Chilun_Num =3D=3D 0=20
=
){<BR> &=
nbsp; =20
one_round_flg =3D=20
=
1;<BR> &=
nbsp; =20
tmp =3D round_num / Chilun_Num =
=
;<BR> &n=
bsp; =20
=
set_display_num();<BR> &nb=
sp; =20
P0 =3D=20
=
0xf0;<BR> &nbs=
p; =20
P0 =3D P0 | LEDBuf[0]=20
=
;<BR> &n=
bsp; =20
led_1000 =3D=20
=
0;<BR> &=
nbsp; =20
P0 |=3D 0xf0;</P>
=
<P> &nbs=
p; =20
P0 =3D=20
=
0xf0;<BR> &nbs=
p; =20
P0 =3D P0 | LEDBuf[1]=20
=
;<BR> &n=
bsp; =20
led_100 =3D=20
=
0;<BR> &=
nbsp; =20
P0 |=3D 0xf0;</P>
=
<P> &nbs=
p; =20
P0 =3D=20
=
0xf0;<BR> &nbs=
p; =20
P0 =3D P0 | LEDBuf[2]=20
=
;<BR> &n=
bsp; =20
led_10 =3D=20
=
0;<BR> &=
nbsp; =20
P0 |=3D 0xf0;</P>
=
<P> &nbs=
p; =20
P0 =3D=20
=
0xf0;<BR> &nbs=
p; =20
P0 =3D P0 | LEDBuf[3]=20
=
;<BR> &n=
bsp; =20
led_1 =3D=20
=
0;<BR> &=
nbsp; =20
P0 |=3D 0xf0;</P>
=
<P> &nbs=
p; =20
P0 =3D=20
=
0xf0;<BR> &nbs=
p; =20
=
}<BR> &n=
bsp;=20
if ( round_num >=3D =
set_round_num )=20
=
Dj_stop();<BR> =20
}<BR> EA =3D =
0x81;<BR>}</P>
<P>void=20
=
display(){<BR> uchar=20
i;<BR> uint =
tmp =3D=20
0;<BR> tmp =
=3D=20
round_num / Chilun_Num=20
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -