archive: homework4
This commit is contained in:
@@ -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();
|
||||
}
|
||||
Reference in New Issue
Block a user