archive: homework4 homework1

This commit is contained in:
2025-04-14 13:14:52 +08:00
parent 83be5ac8da
commit cfaf068677
3 changed files with 35 additions and 7 deletions
+30
View File
@@ -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();
}