##原理图


##//源码
#include <reg52.h>
#include <intrins.h> //包含移位函数
#define uint unsigned int //宏定义
#define uchar unsigned char
sbit S1=P3^7; //定义S1变量
void delay(uint);
uchar temp;
void main()
{
temp=0xfe; //初始化
P2=temp;
while(1)
{
if(S1==0) //判断是否按下
{
delay(10);
if(S1==0) //再次判断是否按下
{
temp=_crol_(temp,1);//右移
delay(100); //延时
P2=temp; //重新赋值
while(!S1); //消抖
delay(5);
while(!S1);
}
}
}
}
void delay(uint z) //延时程序
{
uint x,y;
for(x=200;x>0;x--)
{
for(y=z;y>0;y--);
}
}
本文介绍了一个简单的51单片机程序,通过按键控制8个LED灯依次循环闪烁的效果。程序中使用了_crol_函数实现数据位的循环左移,并通过延时函数确保了LED灯闪烁的稳定性和视觉效果。此外,还包含了消除按键抖动的处理逻辑。
1472

被折叠的 条评论
为什么被折叠?



