完成:实验三 第一题

This commit is contained in:
2025-03-25 13:11:20 +08:00
parent f9016dcc62
commit b4a3a188fe
3 changed files with 100 additions and 42 deletions
+2 -1
View File
@@ -18,7 +18,8 @@
"*.c++": "cpp",
"*.cpp": "cpp",
"*.cxx": "cpp",
"*.cc": "cpp"
"*.cc": "cpp",
"REG52.H": "cpp"
},
"[yaml]": {
"editor.insertSpaces": true,
+29
View File
@@ -0,0 +1,29 @@
// homework3.h
// 这个文件是用来存放本实验中用到的宏定义和函数的
#include <REG52.H>
#define true 1
#define false 0
unsigned int i = 0;
sbit D1 = P2 ^ 7;
sbit D2 = P2 ^ 6;
sbit D3 = P2 ^ 5;
sbit D4 = P2 ^ 4;
sbit D5 = P2 ^ 3;
sbit D6 = P2 ^ 2;
sbit D7 = P2 ^ 1;
sbit D8 = P2 ^ 0;
sbit ADDR0=P1^0;
sbit ADDR1=P1^1;
sbit ADDR2=P1^2;
sbit ADDR3=P1^3;
sbit ENLED=P1^4;
void Delay(unsigned int t)
{
while (t--);
}
+28
View File
@@ -0,0 +1,28 @@
// test1.c
// 左向流水灯
#include "homework3.h"
unsigned char cnt = 0;
void test1()
{
ENLED = 0;
ADDR3 = 1;
ADDR2 = 1;
ADDR1 = 1;
ADDR0 = 0;
while (true) {
P2 = ~(0x80 >> cnt);
Delay(20000);
cnt++;
if (cnt >= 8) {
cnt = 0;
}
}
}
void main()
{
test1();
}