编写一个基于STC89c52的流水灯程序
时间: 2023-05-23 08:03:52 浏览: 112
非常感谢您的问题!下面是基于STC89c52的流水灯程序的代码:
```c
#include<reg52.h>
#include<intrins.h>
typedef unsigned char uchar;
typedef unsigned int uint;
sbit L1 = P1^0;
sbit L2 = P1^1;
sbit L3 = P1^2;
sbit L4 = P1^3;
sbit L5 = P1^4;
sbit L6 = P1^5;
sbit L7 = P1^6;
sbit L8 = P1^7;
void Delay_1ms(uint);
void main()
{
while(1){
L1 = 1;L2 = 0;L3 = 0;L4 = 0;L5 = 0;L6 = 0;L7 = 0;L8 = 0;
Delay_1ms(500);
L1 = 0;L2 = 1;L3 = 0;L4 = 0;L5 = 0;L6 = 0;L7 = 0;L8 = 0;
Delay_1ms(500);
L1 = 0;L2 = 0;L3 = 1;L4 = 0;L5 = 0;L6 = 0;L7 = 0;L8 = 0;
Delay_1ms(500);
L1 = 0;L2 = 0;L3 = 0;L4 = 1;L5 = 0;L6 = 0;L7 = 0;L8 = 0;
Delay_1ms(500);
L1 = 0;L2 = 0;L3 = 0;L4 = 0;L5 = 1;L6 = 0;L7 = 0;L8 = 0;
Delay_1ms(500);
L1 = 0;L2 = 0;L3 = 0;L4 = 0;L5 = 0;L6 = 1;L7 = 0;L8 = 0;
Delay_1ms(500);
L1 = 0;L2 = 0;L3 = 0;L4 = 0;L5 = 0;L6 = 0;L7 = 1;L8 = 0;
Delay_1ms(500);
L1 = 0;L2 = 0;L3 = 0;L4 = 0;L5 = 0;L6 = 0;L7 = 0;L8 = 1;
Delay_1ms(500);
}
}
void Delay_1ms(uint n)
{
uchar i, j;
while(n--)
{
_nop_();
i = 1;
j = 86;
do
{
while (--j);
} while (--i);
}
}
```
希望我的回答能对您有所帮助,有问题可以随时问我哦!
阅读全文