Files
51-microcontroller-homework/homework4/src/test5.c
T
2025-04-14 18:20:23 +08:00

38 lines
665 B
C

// test5.c
// 数码管静态显示秒表的倒计时;
#include "homework4.h"
unsigned char cnt = 0; // 定时器溢出计数
unsigned char second = 0; // 秒计数
void test5()
{
set_38_2SEG();
TMOD = 0x01;
TH0 = 0x3C;
TL0 = 0xB0;
TR0 = 1;
// 初始化时立即显示9
second = 9;
show_number(second);
while (1) {
if (TF0 == 1) {
TF0 = 0;
TH0 = 0x3C;
TL0 = 0xB0;
if (++cnt >= 20) {
cnt = 0;
second = (second > 0) ? --second : 9;
show_number(second);
}
}
}
}
void main()
{
test5();
}