archive: homework4

This commit is contained in:
2025-04-14 18:20:23 +08:00
parent 8d9c147092
commit e1acc51117
2 changed files with 40 additions and 1 deletions
+2 -1
View File
@@ -21,7 +21,8 @@
"excludeList": [ "excludeList": [
"src/test1.c", "src/test1.c",
"src/test2.c", "src/test2.c",
"src/test3.c" "src/test3.c",
"src/test4.c"
], ],
"toolchain": "Keil_C51", "toolchain": "Keil_C51",
"compileConfig": { "compileConfig": {
+38
View File
@@ -0,0 +1,38 @@
// 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();
}