archieve: homework6 test2
This commit is contained in:
@@ -18,7 +18,9 @@
|
|||||||
},
|
},
|
||||||
"targets": {
|
"targets": {
|
||||||
"Debug": {
|
"Debug": {
|
||||||
"excludeList": [],
|
"excludeList": [
|
||||||
|
"src/test1.c"
|
||||||
|
],
|
||||||
"toolchain": "Keil_C51",
|
"toolchain": "Keil_C51",
|
||||||
"compileConfig": {
|
"compileConfig": {
|
||||||
"options": "null"
|
"options": "null"
|
||||||
|
|||||||
Binary file not shown.
@@ -1,6 +1,8 @@
|
|||||||
// test1.c
|
// test1.c
|
||||||
// 定时器0中断实现流水灯,设定合适的初值实现1s定时,控制LED灯依次点亮,形成流水灯效果
|
// 定时器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"
|
#include "homework6.h"
|
||||||
|
|
||||||
|
|||||||
@@ -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();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user