reset: homework4 code

This commit is contained in:
2025-04-14 12:15:02 +08:00
parent 58c39aa710
commit 7fadeb5d2a
6 changed files with 10 additions and 65 deletions
-33
View File
@@ -1,33 +0,0 @@
// test1.c
// 通过定时器实现以0.5Hz的频率闪烁一个小灯
#include "homework4.h"
unsigned char cnt = 0; // log timer T0 overflow counts
void main()
{
ENLED = 0;
D_ADDR3 = 1;
D_ADDR2 = 1;
D_ADDR1 = 1;
D_ADDR0 = 0;
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
D1 = ~D1; // toggle LED
}
}
}
}