fix: homework7 test3 animation bugs

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