0任务要求: LEDO ~ LED7经限流电阻分别接至P1口的P1.0~P1.7引脚.上,阳极共同接高电平。实现高低四个LED交替点亮的代码
时间: 2024-04-30 19:23:23 浏览: 91
```c
#include <reg52.h>
sbit LED0 = P1^0;
sbit LED1 = P1^1;
sbit LED2 = P1^2;
sbit LED3 = P1^3;
sbit LED4 = P1^4;
sbit LED5 = P1^5;
sbit LED6 = P1^6;
sbit LED7 = P1^7;
void main()
{
while(1)
{
LED0 = 1; //点亮LED0
LED2 = 1; //点亮LED2
LED1 = 0; //熄灭LED1
LED3 = 0; //熄灭LED3
LED4 = 0; //熄灭LED4
LED5 = 0; //熄灭LED5
LED6 = 0; //熄灭LED6
LED7 = 0; //熄灭LED7
delay(500); //延时500ms
LED0 = 0; //熄灭LED0
LED2 = 0; //熄灭LED2
LED1 = 1; //点亮LED1
LED3 = 1; //点亮LED3
LED4 = 1; //点亮LED4
LED5 = 1; //点亮LED5
LED6 = 1; //点亮LED6
LED7 = 1; //点亮LED7
delay(500); //延时500ms
}
}
//延时函数,单位ms
void delay(unsigned int ms)
{
unsigned int i, j;
for(i=0; i<ms; i++)
{
for(j=0; j<110; j++);
}
}
```
阅读全文