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
+1 -3
View File
@@ -18,9 +18,7 @@
},
"targets": {
"Debug": {
"excludeList": [
"src/test1.c"
],
"excludeList": [],
"toolchain": "Keil_C51",
"compileConfig": {
"options": "null"
+4 -4
View File
@@ -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;
}
+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();
}