完成:实验三 第三题

This commit is contained in:
2025-03-25 13:22:49 +08:00
parent a60eec5800
commit 48fae403e5
2 changed files with 35 additions and 1 deletions
+2 -1
View File
@@ -19,7 +19,8 @@
"targets": { "targets": {
"Debug": { "Debug": {
"excludeList": [ "excludeList": [
"src/test1.c" "src/test1.c",
"src/test2.c"
], ],
"toolchain": "Keil_C51", "toolchain": "Keil_C51",
"compileConfig": { "compileConfig": {
+33
View File
@@ -0,0 +1,33 @@
// test3.c
// 左右流水灯
#include "homework3.h"
unsigned char cnt = 0;
void test3()
{
ENLED = 0;
ADDR3 = 1;
ADDR2 = 1;
ADDR1 = 1;
ADDR0 = 0;
while (true) {
if(cnt < 8) {
P2 = ~(0x01 << cnt); // 左向流水
} else {
P2 = ~(0x80 >> (cnt-8)); // 右向流水
}
Delay(20000);
cnt++;
if (cnt >= 16) { // 0-7左移,8-15右移
cnt = 0;
}
}
}
void main()
{
test3();
}