archieve: homework7 test5

This commit is contained in:
2025-05-25 02:08:11 +08:00
parent a3cf2cbc8e
commit 23ea54ea6a
2 changed files with 67 additions and 1 deletions
+65
View File
@@ -0,0 +1,65 @@
/*
* @name: test5.c
* @author: msksbr
* @date: 2025-05-25
* @description: a test for homework7's homework tests
* @version: 1.0
* homework zh_CN: 基于点阵的 9 到 0 的倒计时秒表显示
* homework EN: display a countdown timer on the led matrix from 9 to 0
*/
#include "homework7.h"
unsigned char code number_char[10][8] = {
{0x70, 0xd8, 0xd8, 0xd8, 0xd8, 0xd8, 0x70, 0x00}, // 0
{0x30, 0xf0, 0x30, 0x30, 0x30, 0x30, 0xf8, 0x00}, // 1
{0xf0, 0xd8, 0x18, 0x38, 0x70, 0xe0, 0xf8, 0x00}, // 2
{0xf0, 0xd8, 0x18, 0x78, 0x18, 0xd8, 0xf0, 0x00}, // 3
{0x30, 0x30, 0x70, 0xf0, 0xf8, 0x30, 0x30, 0x00}, // 4
{0xf8, 0xc0, 0xf0, 0x18, 0x18, 0xd8, 0xf0, 0x00}, // 5
{0x78, 0xe0, 0xf0, 0xd8, 0xd8, 0xf8, 0x70, 0x00}, // 6
{0xf8, 0x18, 0x38, 0x30, 0x70, 0x60, 0x60, 0x00}, // 7
{0x70, 0xd8, 0xf8, 0xf8, 0xd8, 0xd8, 0x70, 0x00}, // 8
{0x70, 0xd8, 0xd8, 0xd8, 0x78, 0x38, 0xf0, 0x00} // 9
};
void test5()
{
TMOD = 0x10;
TH1 = 0xFC;
TL1 = 0x18;
TR1 = 1;
ET1 = 1;
EA = 1;
while (1);
}
void timer1_ISR() interrupt 3
{
static unsigned char i = 0;
static unsigned int count = 0;
static unsigned char current_num = 9;
TH1 = 0xFC;
TL1 = 0x18;
P2 = 0xFF;
switch_138(i);
P2 = ~number_char[current_num][i];
if (++i >= 8) i = 0;
if (++count >= 1000) {
count = 0;
if (current_num > 0) {
current_num--;
} else {
current_num = 9;
}
}
}
void main()
{
test5();
}