|
建議將timer()函數(shù)改寫為參數(shù)傳遞機制:
6 y. J0 u5 `7 f A' @, h& C/ Mint timer0(int par)
+ Y, H1 G8 Z: A1 T; T{7 e. _2 g U/ o8 ?8 D {9 Q
switch(par)" r4 o p' g" J3 S, d! i+ B
{2 `) P4 I: v4 s9 Q- A
case 1:9 I% u: Z) t; B, \
...
v* c( W9 E$ J' o+ |..." p: s5 X( g& i; D8 @
case 12:
0 H7 ~ t e- H PWM0_5=0 ;3 {" m) _* m4 F" @6 P" ?) A
TH0=-(3300-PWM_Value1[5])/256;-1 i3 o4 v6 p' T1 `) i5 }1 {7 D
TL0=-(3300-PWM_Value1[5])%256;
! U2 x* l4 I4 g+ h$ k3 K9 b order1=0; //為什么要在這里清零?建議刪除該行,改為在主函數(shù)中調用timer0()后,判斷如果order1==13,則=1。* U/ @% O: Y! G* A, f
TR1=0; //為什么要在這里清零?建議刪除該行,改為在主函數(shù)中調用timer0()后,判斷如果order1==13,則清零。: Y/ E& I( \+ y4 j
break;;) `- S3 V; p5 H" b% u5 {7 S
}
7 h t7 ] t# P1 J+ Dreturn(par++); ( o |) }6 q) ?7 H: c+ o
}/ x9 _. y6 \! H P7 N2 X0 t/ J! K
% T/ q4 q8 f- c ]9 X在主函數(shù)中調用timer0()的語句:
4 a3 Y3 i0 w+ ]3 ?; a4 }order1=timer0(order1);
) l# h; s: m6 T* a5 c1 lif(order1==13) {order1=1; TR1=0;}
s$ ~# _8 s3 ^ |
|