diff --git a/homework6/.eide/eide.json b/homework6/.eide/eide.json index 7ba4042..8d94045 100644 --- a/homework6/.eide/eide.json +++ b/homework6/.eide/eide.json @@ -18,7 +18,9 @@ }, "targets": { "Debug": { - "excludeList": [], + "excludeList": [ + "src/test1.c" + ], "toolchain": "Keil_C51", "compileConfig": { "options": "null" diff --git a/homework6/homework6.pdsprj b/homework6/homework6.pdsprj index a35b880..0003266 100644 Binary files a/homework6/homework6.pdsprj and b/homework6/homework6.pdsprj differ diff --git a/homework6/src/test1.c b/homework6/src/test1.c index a4fd7e5..1a92f76 100644 --- a/homework6/src/test1.c +++ b/homework6/src/test1.c @@ -1,6 +1,8 @@ // test1.c // 定时器0中断实现流水灯,设定合适的初值实现1s定时,控制LED灯依次点亮,形成流水灯效果 -// Timer 0 interrupt to implement the LED light, set the appropriate initial value to implement 1s timing, control the LED light to turn on one by one, forming the light effect. +// Timer 0 interrupt to implement the LED light, +// set the appropriate initial value to implement 1s timing, +// control the LED light to turn on one by one, forming the light effect. #include "homework6.h" diff --git a/homework6/src/test2.c b/homework6/src/test2.c new file mode 100644 index 0000000..72e3fde --- /dev/null +++ b/homework6/src/test2.c @@ -0,0 +1,39 @@ +// test2.c +// 定时器1中断控制两个LED交替闪烁。设置定时器1的初值,使其每隔25ms产生一次中断。 +// 在中断服务程序中,每次中断对两个LED的状态进行切换,一个LED亮时另一个LED灭, +// 从而实现交替闪烁 +// Timer 1 interrupt to control two LED lights to alternate. +// Set the initial value of the timer 1 to make it produce an interrupt every 25ms. +// In the interrupt service program, +// switch the state of the two LED lights every time an interrupt occurs, +// one LED light on at a time, and the other LED light off, +// thus implementing alternating flashing. + +#include "homework6.h" + +void test2() +{ + // Set the 38 transistors to the address. + set38(TO_LED); + // init the timer 1. + TMOD = 0x9E; // set the timer 1 to mode 1. + TH1 = 0x58; // set the timer 1 to 25ms. + TL1 = 0x66; // set the timer 1 to 25ms. + TR1 = 1; // start the timer 1. + ET1 = 1; // enable the timer 1 interrupt. + EA = 1; // enable the interrupt. + P2 = 0xFC; // init mode: the first LED light. + while (1) {} +} + +void Timer1_ISR() interrupt 3 +{ + TH1 = 0x9E; // reset the timer 1. + TH1 = 0x58; // reset the timer 1. + P2 ^= 0x03; // switch the state of the two LED lights. +} + +void main() +{ + test2(); +} \ No newline at end of file