fix: homework7 test3 animation bugs

This commit is contained in:
2025-05-25 01:08:58 +08:00
parent 420ae95641
commit 1cda67295c
+44 -33
View File
@@ -1,50 +1,61 @@
/* /*
* @name: test1.c * @name: test1.c
* @author: msksbr * @author: msksbr
* @date: 2025-05-24 * @date: 2025-05-25
* @description: a test for homework7's homework tests * @description: a test for homework7's homework tests
* @version: 1.0 * @version: 1.0f: fix animation bugs
* homework zh_CN: 点阵显示一个 I ❤ U 的向下移动动画 * homework zh_CN: 点阵显示一个 I ❤ U 的向下移动动画
* homework EN: display a animation of I ❤ U moving down on the led matrix * homework EN: display a animation of I ❤ U moving down on the led matrix
*/ */
#include "homework7.h" #include "homework7.h"
unsigned char code char_i[] = { unsigned char code display[] = {
0x00, 0x3C, 0x18, 0x18, // it is fucking reverse
0x18, 0x18, 0x18, 0x3C}; 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // space
unsigned char code char_heart[] = { 0x00, 0x66, 0x66, 0x66, 0x66, 0x66, 0x7E, 0x3C, // U
0x00, 0x66, 0xFF, 0xFF, 0x00, 0x66, 0xFF, 0xFF, 0xFF, 0x7E, 0x3C, 0x18, // ❤
0xFF, 0x7E, 0x3C, 0x18}; 0x00, 0x3C, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3C, // I
unsigned char code char_u[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // space
0x00, 0x66, 0x66, 0x66, };
0x66, 0x66, 0x7E, 0x3C};
void test3() void test3()
{ {
unsigned char i; // @var i: a counter for the loop EA = 1;
unsigned char char_pos; // @var char_pos: the position of the character to be displayed on the led matrix TMOD = 0x01;
while (1) { TH0 = 0xFC;
for (char_pos = 0; char_pos < 3; char_pos++) { // @loop: switch the char TL0 = 0x67;
for (i = 8; i > 0; i--) { // @loop: display shape on the led matrix ET0 = 1;
switch_138(i); // switch the 74HC138's address to i TR0 = 1;
switch (char_pos) { // switch the char to be displayed on the led matrix while (1);
case 0: }
P2 = ~char_i[i]; // display the char_i on the led matrix
break; void timer0ISF() interrupt 1
case 1: {
P2 = ~char_heart[i]; // display the char_heart on the led matrix static unsigned char i = 0;
break; static unsigned char tmr = 0;
case 2: static unsigned char index = 32;
P2 = ~char_u[i]; // display the char_u on the led matrix
break; TH0 = 0xFC;
} TL0 = 0x67;
delay_ms(1); // delay 1ms
P2 = 0xFF; // turn off the led matrix P2 = 0xFF;
}
i = 8; // @subsection reset i to 8 switch_138(i);
i++;
P2 = ~display[index + i];
if (i >= 8) {
i = 0;
}
tmr++;
if (tmr >= 250) {
tmr = 0;
if (index == 0) {
index = 32;
} else {
index--;
} }
char_pos = 0; // @subsection reset char_pos to 0
} }
} }