archieve: homework7 test2

This commit is contained in:
2025-05-25 00:13:04 +08:00
parent 1b64a5df5b
commit 3b682e993c
4 changed files with 58 additions and 12 deletions
+16 -10
View File
@@ -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.
}
+36
View File
@@ -0,0 +1,36 @@
/*
* @name: test2.c
* @author: msksbr
* @date: 2025-05-24
* @description: a test for homework7's homework tests
* @version: 1.0
* homework zh_CN: 点阵显示心形图形
* homework EN: display a heart shape on the led matrix
*/
#include "homework7.h"
void test2()
{
unsigned char i; // @var i: a counter for the loop
unsigned char code heart[] = {
0x00, 0x66, 0xFF, 0xFF,
0xFF, 0x7E, 0x3C, 0x18};
// @subsection: display a heart shape on the led matrix
while (1) // @loop: display the heart shape on the led matrix
{
for (i = 8; i > 0; i--) // @loop: display the heart shape on the led matrix
{
switch_138(i); // switch the 74HC138's address to i
P2 = ~heart[i]; // display the heart shape on the led matrix
delay_ms(1);
P2 = 0xFF; // turn off the led matrix
}
i = 8;
}
}
void main()
{
test2();
}