From 1cda67295cdacbfa07c149d6b726de768bafd71d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=A1=E5=9D=82=E3=82=B9=E3=83=90=E3=83=AB?= Date: Sun, 25 May 2025 01:08:58 +0800 Subject: [PATCH] fix: homework7 test3 animation bugs --- homework7/src/test3.c | 77 ++++++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 33 deletions(-) diff --git a/homework7/src/test3.c b/homework7/src/test3.c index 4acf33b..f9567d5 100644 --- a/homework7/src/test3.c +++ b/homework7/src/test3.c @@ -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; - } - delay_ms(1); // delay 1ms - P2 = 0xFF; // turn off the led matrix - } - i = 8; // @subsection reset i to 8 + EA = 1; + TMOD = 0x01; + TH0 = 0xFC; + TL0 = 0x67; + ET0 = 1; + TR0 = 1; + while (1); +} + +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; + } + + tmr++; + if (tmr >= 250) { + tmr = 0; + if (index == 0) { + index = 32; + } else { + index--; } - char_pos = 0; // @subsection reset char_pos to 0 } }