diff --git a/homework7/.eide/eide.json b/homework7/.eide/eide.json index 40c5dc6..a8f6f42 100644 --- a/homework7/.eide/eide.json +++ b/homework7/.eide/eide.json @@ -18,7 +18,9 @@ }, "targets": { "Debug": { - "excludeList": [], + "excludeList": [ + "src/test1.c" + ], "toolchain": "Keil_C51", "compileConfig": { "options": "null" diff --git a/homework7/homework7.code-workspace b/homework7/homework7.code-workspace index 8c192af..855e186 100644 --- a/homework7/homework7.code-workspace +++ b/homework7/homework7.code-workspace @@ -9,6 +9,7 @@ "C_Cpp.default.configurationProvider": "cl.eide", "C_Cpp.errorSquiggles": "disabled", "files.associations": { + "*.dbclient-js": "javascript", ".eideignore": "ignore", "*.a51": "a51", "*.h": "c", @@ -18,7 +19,8 @@ "*.c++": "cpp", "*.cpp": "cpp", "*.cxx": "cpp", - "*.cc": "cpp" + "*.cc": "cpp", + "REG52.H": "cpp" }, "[yaml]": { "editor.insertSpaces": true, diff --git a/homework7/src/homework7.h b/homework7/src/homework7.h index f4a2ebe..b5a75ba 100644 --- a/homework7/src/homework7.h +++ b/homework7/src/homework7.h @@ -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. } \ No newline at end of file diff --git a/homework7/src/test2.c b/homework7/src/test2.c new file mode 100644 index 0000000..db713c6 --- /dev/null +++ b/homework7/src/test2.c @@ -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(); +} \ No newline at end of file