单片机 STC 89C52RC
功能
向一个方向流水三次,然后全亮,几秒钟后继续流水
代码
#include "reg52.h"
typedef unsigned char u8;
typedef unsigned int u16;
sbit LED1 = P2^0;
sbit LED2 = P2^1;
sbit LED3 = P2^2;
sbit LED4 = P2^3;
sbit LED5 = P2^4;
sbit LED6 = P2^5;
sbit LED7 = P2^6;
sbit LED8 = P2^7;
void delay_10us(u16 ten_us)//ten_us = 1时,大约延时10us
{
while(ten_us--);
}
void main()
{ u8 i;
while(1)
{
for(i=0;i<3;i++)
{
LED1 = 0; //点亮
delay_10us(5000);
LED1 = 1; //熄灭
delay_10us(5000);
LED2 = 0; //点亮
delay_10us(5000);
LED2 = 1; //熄灭
delay_10us(5000);
LED3 = 0; //点亮
delay_10us(5000);
LED3 = 1; //熄灭
delay_10us(5000);
LED4 = 0; //点亮
delay_10us(5000);
LED4 = 1; //熄灭
delay_10us(5000);
LED5 = 0; //点亮
delay_10us(5000);
LED5 = 1; //熄灭
delay_10us(5000);
LED6 = 0; //点亮
delay_10us(5000);
LED6 = 1; //熄灭
delay_10us(5000);
LED7 = 0; //点亮
delay_10us(5000);
LED7 = 1; //熄灭
delay_10us(5000);
LED8 = 0; //点亮
delay_10us(5000);
LED8 = 1; //熄灭
delay_10us(5000);
}
LED1 = 0;
LED2 = 0;
LED3 = 0;
LED4 = 0;
LED5 = 0;
LED6 = 0;
LED7 = 0;
LED8 = 0;
delay_10us(50000000);
delay_10us(50000000);
delay_10us(50000000);
delay_10us(50000000);
delay_10us(50000000);
delay_10us(50000000);
delay_10us(50000000);
delay_10us(50000000);
delay_10us(50000000);//延迟熄灭时间
}
}
实验结果
功能基本实现,但是led灯不是同时熄灭,需要进一步改进,延时时间可以改动的
版权声明:本文为CSDN博主「♬ 巴不得,卫护你*」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_48773375/article/details/122558006
单片机 STC 89C52RC
功能
向一个方向流水三次,然后全亮,几秒钟后继续流水
代码
#include "reg52.h"
typedef unsigned char u8;
typedef unsigned int u16;
sbit LED1 = P2^0;
sbit LED2 = P2^1;
sbit LED3 = P2^2;
sbit LED4 = P2^3;
sbit LED5 = P2^4;
sbit LED6 = P2^5;
sbit LED7 = P2^6;
sbit LED8 = P2^7;
void delay_10us(u16 ten_us)//ten_us = 1时,大约延时10us
{
while(ten_us--);
}
void main()
{ u8 i;
while(1)
{
for(i=0;i<3;i++)
{
LED1 = 0; //点亮
delay_10us(5000);
LED1 = 1; //熄灭
delay_10us(5000);
LED2 = 0; //点亮
delay_10us(5000);
LED2 = 1; //熄灭
delay_10us(5000);
LED3 = 0; //点亮
delay_10us(5000);
LED3 = 1; //熄灭
delay_10us(5000);
LED4 = 0; //点亮
delay_10us(5000);
LED4 = 1; //熄灭
delay_10us(5000);
LED5 = 0; //点亮
delay_10us(5000);
LED5 = 1; //熄灭
delay_10us(5000);
LED6 = 0; //点亮
delay_10us(5000);
LED6 = 1; //熄灭
delay_10us(5000);
LED7 = 0; //点亮
delay_10us(5000);
LED7 = 1; //熄灭
delay_10us(5000);
LED8 = 0; //点亮
delay_10us(5000);
LED8 = 1; //熄灭
delay_10us(5000);
}
LED1 = 0;
LED2 = 0;
LED3 = 0;
LED4 = 0;
LED5 = 0;
LED6 = 0;
LED7 = 0;
LED8 = 0;
delay_10us(50000000);
delay_10us(50000000);
delay_10us(50000000);
delay_10us(50000000);
delay_10us(50000000);
delay_10us(50000000);
delay_10us(50000000);
delay_10us(50000000);
delay_10us(50000000);//延迟熄灭时间
}
}
实验结果
功能基本实现,但是led灯不是同时熄灭,需要进一步改进,延时时间可以改动的
版权声明:本文为CSDN博主「♬ 巴不得,卫护你*」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_48773375/article/details/122558006
暂无评论