51单片机led流水灯程序+PROTEUS
时间: 2023-08-06 18:08:29 浏览: 128
以下是51单片机LED流水灯程序和PROTEUS仿真电路图:
```c
#include <reg52.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
sbit led1 = P1^0;
sbit led2 = P1^1;
sbit led3 = P1^2;
sbit led4 = P1^3;
sbit led5 = P1^4;
sbit led6 = P1^5;
sbit led7 = P1^6;
sbit led8 = P1^7;
void delay(uint ms)
{
uint i, j;
for(i = ms; i > 0; i--)
{
for(j = 110; j > 0; j--);
}
}
void main()
{
while(1)
{
led1 = 0;
delay(500);
led1 = 1;
led2 = 0;
delay(500);
led2 = 1;
led3 = 0;
delay(500);
led3 = 1;
led4 = 0;
delay(500);
led4 = 1;
led5 = 0;
delay(500);
led5 = 1;
led6 = 0;
delay(500);
led6 = 1;
led7 = 0;
delay(500);
led7 = 1;
led8 = 0;
delay(500);
led8 = 1;
}
}
```
PROTEUS仿真电路图如下:
![image](https://img-blog.csdn.net/20180427174611270?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvaGFuZ3hpMjAxNjMwNzMxNjU0/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/q/80)
注意:P1口需要接上8个LED灯,否则仿真不会有输出效果。
阅读全文