|
用單片機(jī)最便宜,也最簡(jiǎn)單不過(guò)。寫(xiě)個(gè)小程序輕松搞定!7 @( w7 t: W$ B7 `) Z/ i. r |% E. V! k
注KM-----電機(jī)控制. k4 g% N8 z+ j0 R1 ~
SB-----按鍵(自己隨便定義IO口)
/ ~* L% v3 U. r" I( Z, K #include<reg51.h>
5 ?( P2 |( a9 v0 e/ o: P sbit KM=P0^0;, l) b+ w7 U/ {/ c8 N
sbit SB=P1^4; , m) A- J7 [* p3 ^) y; `
void mDelay(unsigned int Delay)
. s4 P6 E8 G: _" j- v { unsigned int i;
9 u0 t- M; C, d- O for(;Delay>0;Delay--)
1 O! {( o8 H7 S) N { for(i=0;i<124;i++)
5 |- o$ ^$ @3 X w( s {;}2 B" ^2 Q+ ~0 N$ ^7 y* V9 K
}
& r: I: P' t/ ~3 F' O( h4 ? } : q6 F; t9 h) j& ^
void main()
. m, r2 W9 s- R5 v4 ^ {
, D; }5 y2 x' D- s5 s8 U while(1)( W& t/ _2 G5 p* Z
{" Y- E: O+ {& ]6 U. r* d/ k+ Y! W
if(SB==0)
" B. u' K% A4 K9 S, @% M { ! w, \0 |9 F) f$ f9 S( V
mDelay(100);
+ a" Q* K3 Z7 n9 L1 }/ @3 H KM=!KM;
/ J; t, S% ]& @9 b8 S0 v8 p6 o while(SB==0); //等待鍵釋放
" |( [ f6 W- u# A5 x+ M# c mDelay(100);
* c' ^( P2 ^# O j& Z5 q' d }
1 B0 M( Y" B$ A9 ~/ V4 K
+ ?5 g, c3 Y# M! R } 5 m# A7 l4 @) ]4 C
}8 D5 `- G2 M. I" T& J+ i" V
至于PLC就更簡(jiǎn)單了,LD X0 ALT Y0 |
|