|
用單片機(jī)最便宜,,也最簡(jiǎn)單不過(guò),。寫(xiě)個(gè)小程序輕松搞定!; }" N8 g1 }7 Y6 _# |/ J8 `
注KM-----電機(jī)控制: \: k0 y( W0 m W2 X2 A
SB-----按鍵(自己隨便定義IO口)
$ q( h) f( v/ n x; _ #include<reg51.h> + j# L6 K! ]- g; x8 Y0 u% Q
sbit KM=P0^0;
- c. b+ ?$ @3 u: t# _ i sbit SB=P1^4; q7 B% D4 O( B4 p8 n2 T/ |& C
void mDelay(unsigned int Delay)
+ h7 X+ K2 R; Q { unsigned int i;- U" C* R, R q
for(;Delay>0;Delay--)
6 F/ U1 h0 G7 B1 I) o) P' P { for(i=0;i<124;i++)
& h5 f) ]% h: l. ]! ~/ O {;}2 ]9 W5 d$ ` c
} 8 N. n: T( R/ @* S
}
8 k5 {' z. p( D3 P6 k void main()
0 |3 n" E* e n# ]" l {1 B% S' [! s6 f( o, X
while(1)' p) d6 G: B' V. j T6 X/ n
{5 I1 A7 p/ P, Y# e
if(SB==0)% g" ~8 @7 w; S1 T
{
% |& |# t7 d' H: k mDelay(100);- z( n5 q* ]: T' B. B3 G
KM=!KM;
p: R0 C: `* v0 \9 v; J- r while(SB==0); //等待鍵釋放; ?$ k8 b& x! y. P+ j+ D; c
mDelay(100);8 o- r E- z; ?, g2 G
}
O* v& C) h6 l, B
( k0 I3 W ~! c } 8 u5 y) u) M- U; w
}% ^# w- Z9 j% m! {9 _
至于PLC就更簡(jiǎn)單了,LD X0 ALT Y0 |
|