archieve: homework7 test2
This commit is contained in:
+16
-10
@@ -57,15 +57,21 @@ void switch_138(unsigned char n)
|
||||
// 2. void delay_ms(unsigned char ms): a timer by ms base on timer0 mode 1
|
||||
void delay_ms(unsigned char ms)
|
||||
{
|
||||
unsigned char i;
|
||||
TMOD &= 0xF0;
|
||||
TMOD |= 0x01;
|
||||
for (i = 0; i < ms; i++) {
|
||||
TH0 = 0xFC;
|
||||
TL0 = 0x18;
|
||||
TR0 = 1;
|
||||
while (!TF0);
|
||||
TR0 = 0;
|
||||
TF0 = 0;
|
||||
TMOD &= 0xF0; // set the timer mode to 16-bit timer mode.
|
||||
TMOD |= 0x01; // set the timer mode to 16-bit timer mode.
|
||||
|
||||
// 1ms timer definition:
|
||||
TH0 = 0XFC;
|
||||
TL0 = 0X18;
|
||||
|
||||
// start the timer:
|
||||
TR0 = 1;
|
||||
|
||||
while (ms--) {
|
||||
while (!TF0) {} // wait for the timer to overflow.
|
||||
TF0 = 0; // clear the timer flag.
|
||||
TH0 = 0XFC; // reload the timer value.
|
||||
TL0 = 0X18; // reload the timer value.
|
||||
}
|
||||
TR0 = 0; // stop the timer.
|
||||
}
|
||||
Reference in New Issue
Block a user