diff --git a/Project Backups/circuit1 [Autosaved].pdsprj b/Project Backups/circuit1 [Autosaved].pdsprj new file mode 100644 index 0000000..3a58c6b Binary files /dev/null and b/Project Backups/circuit1 [Autosaved].pdsprj differ diff --git a/circuit1.pdsprj b/circuit1.pdsprj new file mode 100644 index 0000000..59bb1eb Binary files /dev/null and b/circuit1.pdsprj differ diff --git a/homework5/.eide/eide.json b/homework5/.eide/eide.json index c52fb13..8e7c5be 100644 --- a/homework5/.eide/eide.json +++ b/homework5/.eide/eide.json @@ -18,7 +18,9 @@ }, "targets": { "Debug": { - "excludeList": [], + "excludeList": [ + "src/test.c" + ], "toolchain": "Keil_C51", "compileConfig": { "options": "null" diff --git a/homework5/homework5.code-workspace b/homework5/homework5.code-workspace index 8c192af..7177d54 100644 --- a/homework5/homework5.code-workspace +++ b/homework5/homework5.code-workspace @@ -1,44 +1,45 @@ { - "folders": [ - { - "path": "." - } - ], - "settings": { - "files.autoGuessEncoding": true, - "C_Cpp.default.configurationProvider": "cl.eide", - "C_Cpp.errorSquiggles": "disabled", - "files.associations": { - ".eideignore": "ignore", - "*.a51": "a51", - "*.h": "c", - "*.c": "c", - "*.hxx": "cpp", - "*.hpp": "cpp", - "*.c++": "cpp", - "*.cpp": "cpp", - "*.cxx": "cpp", - "*.cc": "cpp" - }, - "[yaml]": { - "editor.insertSpaces": true, - "editor.tabSize": 4, - "editor.autoIndent": "advanced" - } - }, - "extensions": { - "recommendations": [ - "cl.eide", - "keroc.hex-fmt", - "xiaoyongdong.srecord", - "hars.cppsnippets", - "zixuanwang.linkerscript", - "redhat.vscode-yaml", - "IBM.output-colorizer", - "cschlosser.doxdocgen", - "ms-vscode.vscode-serial-monitor", - "alefragnani.project-manager", - "cl.stm8-debug" - ] + "folders": [ + { + "path": "." } -} \ No newline at end of file + ], + "settings": { + "files.autoGuessEncoding": true, + "C_Cpp.default.configurationProvider": "cl.eide", + "C_Cpp.errorSquiggles": "disabled", + "files.associations": { + ".eideignore": "ignore", + "*.a51": "a51", + "*.h": "c", + "*.c": "c", + "*.hxx": "cpp", + "*.hpp": "cpp", + "*.c++": "cpp", + "*.cpp": "cpp", + "*.cxx": "cpp", + "*.cc": "cpp", + "REG52.H": "cpp" + }, + "[yaml]": { + "editor.insertSpaces": true, + "editor.tabSize": 4, + "editor.autoIndent": "advanced" + } + }, + "extensions": { + "recommendations": [ + "cl.eide", + "keroc.hex-fmt", + "xiaoyongdong.srecord", + "hars.cppsnippets", + "zixuanwang.linkerscript", + "redhat.vscode-yaml", + "IBM.output-colorizer", + "cschlosser.doxdocgen", + "ms-vscode.vscode-serial-monitor", + "alefragnani.project-manager", + "cl.stm8-debug" + ] + } +} diff --git a/homework5/src/homework5.h b/homework5/src/homework5.h index 3d9cd41..0051786 100644 --- a/homework5/src/homework5.h +++ b/homework5/src/homework5.h @@ -1,10 +1,15 @@ // homework5.h /* * this header defines: + * variables: * 1. pin numbers to control the LED and the Seg. - * 2. the function to control the LED and the Seg. - * 3. the function to display the number on the Seg. - * 4. the function to set the 38 transistors. + * 2. sdf for timer + * functions: + * 1. control the LED and the Seg. + * 2. to display the number on the Seg. + * 3. to set the 38 transistors. + * 4. to display the number on the Seg. + * 5. timer. */ #include @@ -37,4 +42,26 @@ void set38Transistors(unsigned char number) // set the 38 transistors. ADDR2 = (number & 0x04) >> 2; ADDR1 = (number & 0x02) >> 1; ADDR0 = (number & 0x01); +} +// timer +int timer(unsigned int ms) +{ + 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. + return 0; } \ No newline at end of file diff --git a/homework5/src/test1.c b/homework5/src/test1.c new file mode 100644 index 0000000..c5c0a07 --- /dev/null +++ b/homework5/src/test1.c @@ -0,0 +1,63 @@ +// test1.c +// 数码管动态显示自己学号后6位 +// display the last 6 digits of your student ID on the Seg. + +#include "homework5.h" + +unsigned char code LedChar[] = { + 0xC0, + 0xF9, + 0XA4, + 0XB0, + 0X99, + 0X92, + 0X82, + 0XF8, + 0X80, + 0X90, + 0X88, + 0X83, + 0XC6, + 0XA1, + 0X86, + 0X8E, +}; +unsigned char LedBuff[6] = { + 0xFF, 0XFF, 0XFF, 0XFF, 0XFF, 0XFF}; +unsigned char i = 0; + +void test1() +{ + // display the number on the Seg. + LedBuff[5] = LedChar[1]; + LedBuff[4] = LedChar[3]; + LedBuff[3] = LedChar[0]; + LedBuff[2] = LedChar[0]; + LedBuff[1] = LedChar[7]; + LedBuff[0] = LedChar[1]; + while (1) { + /* + * seg id on 38 transistors: + * Y0: LEDS0 the latest digit. + * Y1: LEDS1 the second digit. + * Y2: LEDS2 the third digit. + * Y3: LEDS3 the forth digit. + * Y4: LEDS4 the fifth digit. + * Y5: LEDS5 the highest digit. + * Y6: 2LED to the LED lights. + */ + set38Transistors(i); + P2 = LedBuff[i]; + i++; + timer(1); + // reset the i to 0 when it reaches 6. + if (i >= 6) { + i = 0; + } + } +} + +void main() +{ + test1(); +} \ No newline at end of file