int i=0;
Void T_0yan ()
{TMOD=0 x01;
TL0=(65536-50000)%256;
TH0=(65536-50000)/256;
EA=1;
ET0=1;
}
Void T0zhongduan () interrupt 1
{TL0=(65536-50000) % 256;
TH0=(65536-50000)/256;
i++;
}
Void lianggreenred20 ()//delay 20 s
{
T_0yan (); TR0=1;
While (i<=400) {P1=0 XDD; } TR0=0; I=0;
}
Void shan3 ()//delay 3 s
{T_0yan (); TR0=1;
While (i<=60)
{P1=0 XDD; P1_1=~ P1_1; } TR0=0; I=0;
}
Void redgreen2 ()//delay 2 s
{T_0yan (); TR0=1;
While (i<=40)
{P1=0 xde; } TR0=0; I=0;
}
Void main ()
{
While (1)
{
Lianggreenred20 ();
Shan3 ();
Redgreen2 ();
}
}
CodePudding user response:
Roughly to see, can, but not good:1. T_0yan (); Just call time,
2. TL0=(65536-50000) % 256;
TH0=(65536-50000)/256;
Written two macro definition, macro name take time units, such as # defind TH0_500ms (65536-50000)/256,
3. It is better to let the timer has been run, inside to write a few more variables, to achieve timing for 3 seconds and timing for 20 seconds, automatic switching function you want,
CodePudding user response:
Register used the library development, and now I feel a little look not to understandCodePudding user response:
To separate write function function, delay the time delay function just do and don't do single chip microcomputer control pin change,CodePudding user response:
In the main program executes, lianggreenred20 with redgreen2 () () the time of fundamental right, but a subroutine shan3 () time difference, I don't know what reason?