完成:实验三 第三题
This commit is contained in:
@@ -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": {
|
||||||
|
|||||||
@@ -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();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user