diff --git a/homework4/.eide/eide.json b/homework4/.eide/eide.json index 5e01018..8c6e288 100644 --- a/homework4/.eide/eide.json +++ b/homework4/.eide/eide.json @@ -18,9 +18,7 @@ }, "targets": { "Debug": { - "excludeList": [ - "src/test1.c" - ], + "excludeList": [], "toolchain": "Keil_C51", "compileConfig": { "options": "null" diff --git a/homework4/src/homework4.h b/homework4/src/homework4.h index 691c3b1..5b0803b 100644 --- a/homework4/src/homework4.h +++ b/homework4/src/homework4.h @@ -29,18 +29,18 @@ sbit BUS8DP = P2 ^ 7; void set_38_2LED() { // e.g. set Y3 to 1, others to 0: - ADDR0 = 0; + ADDR0 = 1; ADDR1 = 1; - ADDR2 = 1; + ADDR2 = 0; ADDR3 = 1; ENLED = 0; } void set_38_2SEG() { // e.g. set Y4 to 1, others to 0: - ADDR0 = 1; + ADDR0 = 0; ADDR1 = 0; - ADDR2 = 0; + ADDR2 = 1; ADDR3 = 1; ENLED = 0; } \ No newline at end of file diff --git a/homework4/src/test1.c b/homework4/src/test1.c new file mode 100644 index 0000000..990264a --- /dev/null +++ b/homework4/src/test1.c @@ -0,0 +1,30 @@ +// test1.c +// 通过定时器实现以0.5Hz的频率闪烁一个小灯 +#include "homework4.h" + +unsigned char cnt = 0; // log timer T0 overflow counts + +void test1() +{ + set_38_2LED(); + TMOD = 0x01; // timer T0 mode 1, 16-bit timer + TH0 = 0XB8; + TL0 = 0X00; + TR0 = 1; // timer T0 run + while (1) { + if (TF0 == 1) { // timer T0 overflow + TF0 = 0; // clear timer T0 overflow flag + TH0 = 0xB8; // reload timer T0 value + TL0 = 0x00; + cnt++; // log timer T0 overflow counts + if (cnt >= 50) { + cnt = 0; // clear log timer T0 overflow counts + BUS1A = ~BUS1A; // toggle LED + } + } + } +} +void main() +{ + test1(); +} \ No newline at end of file