diff --git a/Project Backups/circuit1 [Autosaved].pdsprj b/Project Backups/circuit1 [Autosaved].pdsprj deleted file mode 100644 index 3a58c6b..0000000 Binary files a/Project Backups/circuit1 [Autosaved].pdsprj and /dev/null differ diff --git a/circuit1.pdsprj b/circuit1.pdsprj deleted file mode 100644 index 59bb1eb..0000000 Binary files a/circuit1.pdsprj and /dev/null differ diff --git a/homework5/.eide/eide.json b/homework5/.eide/eide.json index 8e7c5be..a837da6 100644 --- a/homework5/.eide/eide.json +++ b/homework5/.eide/eide.json @@ -19,7 +19,8 @@ "targets": { "Debug": { "excludeList": [ - "src/test.c" + "src/test.c", + "src/test1.c" ], "toolchain": "Keil_C51", "compileConfig": { diff --git a/homework5/src/homework5.h b/homework5/src/homework5.h index 0051786..5e3dee5 100644 --- a/homework5/src/homework5.h +++ b/homework5/src/homework5.h @@ -3,7 +3,7 @@ * this header defines: * variables: * 1. pin numbers to control the LED and the Seg. - * 2. sdf for timer + * 2. seg chars to display the number on the Seg. * functions: * 1. control the LED and the Seg. * 2. to display the number on the Seg. @@ -30,6 +30,25 @@ sbit ADDR1 = P1 ^ 1; // to B(A1) sbit ADDR2 = P1 ^ 2; // to C(A2) sbit ADDR3 = P1 ^ 3; // to E1 sbit ENLED = P1 ^ 4; // to E2 & E3 +// seg chars: +unsigned char code LedChar[] = { + 0xC0, + 0xF9, + 0XA4, + 0XB0, + 0X99, + 0X92, + 0X82, + 0XF8, + 0X80, + 0X90, + 0X88, + 0X83, + 0XC6, + 0XA1, + 0X86, + 0X8E, +}; // functions: // 38 transistors controller: diff --git a/homework5/src/test1.c b/homework5/src/test1.c index c5c0a07..2a2f797 100644 --- a/homework5/src/test1.c +++ b/homework5/src/test1.c @@ -3,25 +3,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; diff --git a/homework5/src/test2.c b/homework5/src/test2.c new file mode 100644 index 0000000..10c81bd --- /dev/null +++ b/homework5/src/test2.c @@ -0,0 +1,84 @@ +// test2.c +// 不使用中断,让数码管动态显示秒表 +// display the stopwatch on the Seg. without using interrupt. +/* + * seg display format: + * 00.00.00 + * HH.MM.SS + * HH: hour, MM: minute, SS: second + * dot . is dp + */ + +/* + * how it work? + * 1. sleep 1s + * 2. count the seconds, minutes, hours. + * 3. reset the seconds, minutes when it reaches 60. + * 4. reset all when everything overflow. + * 5. log the number in the buffer. + * 6. display the number on the Seg. + */ +#include "homework5.h" +unsigned char LedBuff[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; // buffer to store the seg chars. + +void test2() +{ + unsigned char second = 0; // to count the seconds. + unsigned char minute = 0; // to count the minutes. + unsigned char hour = 0; // to count the hours. + unsigned char i = 0; // to count the times. + unsigned long time_counter = 0; + + while (1) { + for (i = 0; i < 6; i++) { + // display number + set38Transistors(i); + P2 = LedBuff[i]; + // display dot + if (i == 2 || i == 4) { + // 2nd dot between the minutes and seconds. + // 4th dot between the hours and minutes. + BUS8DP = 0; // display the dot. + } else { + BUS8DP = 1; // hide the dot on other places. + } + + timer(1); // delay 1ms. + time_counter++; + + // update time when 1000ms passed. + if (time_counter >= 1000) { + time_counter = 0; // reset the counter. + second++; // count the seconds. + // solve unit overflow. + // second overflow + if (second >= 60) { + second = 0; // reset the second. + minute++; // count the minutes. + } + // minute overflow. + if (minute >= 60) { + minute = 0; // reset the minute. + hour++; // count the hours. + } + // everything overflow. + if (hour >= 99 && second >= 59 && minute >= 59) { + hour = 0; // reset the hour. + second = 0; // reset the second. + minute = 0; // reset the minute. + } + } + // log the number in the buffer. + LedBuff[5] = LedChar[hour / 10]; // log the hour tens. + LedBuff[4] = LedChar[hour % 10]; // log the hour units. + LedBuff[3] = LedChar[minute / 10]; // log the minute tens. + LedBuff[2] = LedChar[minute % 10]; // log the minute units. + LedBuff[1] = LedChar[second / 10]; // log the second tens. + LedBuff[0] = LedChar[second % 10]; // log the second units. + } + } +} +void main() +{ + test2(); +} \ No newline at end of file