当前位置:网站首页>基于51单片机的花样流水灯设计
基于51单片机的花样流水灯设计
2022-07-15 23:15:00 【(王子变青蛙)】
一、前言
花样流水灯就是让LED灯按照一定规律进行各种变化,流水灯在生活中也随处可见,例如在建筑物的棱角上装上流水灯,可以起到变换闪烁达到美不胜收的效果。此设计使用16个LED灯,有四种花样,循环往复显示,每隔15S左右的时间进行一次花样变换。也可手动切换花样。单片机系统装有按键复位电路可直接复位电路。
二、模块介绍及原理说明

单片机最小系统:
单片机最小系统完成系统运行的最基本电路,单片机最小系统可配合其他模块或自行搭建电路完成各种实验功能,单片机最小系统接口设计灵活,电路简洁,可完成基本的驱动任务。单片机最小系统包括晶振电路、复位电路。复位电路我使用按键复位,方便系统的重启。
三、硬件连接
本设计使用P0、P2控制LED灯由于LED灯所需电量少,所以不需要加驱动就可以完成显示。P3^0为按键控制端口,用于控制花样灯的切换。
仿真连接

实物连接

四、程序说明

主程序,用以调用不同的函数。
main()
{
Timer0Init(); //定时器0初始化
P2=0x00;//端口初始化
P0=0x00;
while(1)
{
key();
if(num==0)
{
P2=0x00;
P0=0x00;
}
else if(num==1)
num1();//花样一
else if(num==2)
num2(); //花样二
else if(num==3)
num3();
else if(num==4)
num4();
}
}
定时器函数,用来控制不同花样切换的时间,更加准确,此设计控制每种花样的显示时间为15S,可根据喜好自己调节。
void Timer0() interrupt 1
{
TH0=(65536-6000)/256; //给定时器赋初值,定时10ms
TL0=(65536-6000)%256;
ssec++;
if(ssec>=100) //毫秒 时钟
{
ssec=0;
sec++;
if(sec>=15) //秒
{
sec=0;
num++;
}
if(num==5)
num=1;
}
}
花样表格函数,将各种花样流水灯分开放入表格中,在主函数中进行调用。通过查表的方式显示各种花样,实用性更强,在花样较多时也方便进行管理。花样相对简单,可自己进行编写。
unsigned char code seg1[]={
0x7f,0xbf,0xdf,0xef,
0xf7,0xfb,0xfd,0xfe,
0xff,0xff,0x00,0x00,
0x55,0x55,0xaa,0xaa
}; //第一种
unsigned char code seg2[]={
0x01,0x03,0x07,0x0f,
0x1f,0x3f,0x7f,0xff,
0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff
};
unsigned char code seg3[]={
0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,
0x80,0xc0,0xe0,0xf0,
0xf8,0xfc,0xfe,0xff,
}; //第二种
unsigned char code seg4[]={
0x01,0x03,0x07,0x0f,
0x1f,0x3f,0x7f,0xff,
0xff,0x7f,0x3f,0x1f,
0x0f,0x07,0x03,0x01
};
unsigned char code seg5[]={
0x01,0x03,0x07,0x0f,
0x1f,0x3f,0x7f,0xff,
0xff,0x7f,0x3f,0x1f,
0x0f,0x07,0x03,0x01
}; //第三种
unsigned char code seg6[]={
0x00,0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x00,0x00,
0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,0x00,
0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x00,0x00,0x00,
0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x00,0x00,
0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x00,
0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,
0x81,0x82,0x84,0x88,0x90,0xa0,0xc0,
0xc1,0xc2,0xc4,0xc8,0xd0,0xe0,
0xe1,0xe2,0xe4,0xe8,0xf0,
0xf1,0xf2,0xf4,0xf8,
0xf9,0xfa,0xfc,
0xfd,0xfe,
0xff
};
unsigned char code seg7[]={
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x81,0x41,0x21,0x11,0x09,0x05,0x03,
0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x83,0x43,0x23,0x13,0x0b,0x07,
0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x87,0x47,0x27,0x17,0x0f,
0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x8f,0x4f,0x2f,0x1f,
0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x9f,0x5f,0x3f,
0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0xbf,0x7f,
0x7f,0x7f,0x7f,0x7f,0x7f,0x7f,0x7f,0x7f,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,0xff,
0xff,0xff,0xff,0xff,
0xff,0xff,0xff,
0xff,0xff,
0xff,
}; //第四种
按键函数,可以通过按键进行LED灯花样的切换,按键函数中需要加入消抖函数,以防止按键误触。
void key()
{
if(key1==0) //按键控制
{
delay(10);
if(key1==0)
{
num++;
if(num==5) num=0;
}
while(!key1); //检测按键是否松开
}
}
五、效果演示
仿真演示
花样流水灯仿真演示
实物演示
基于51单片机的花样流水灯实物演示
六、代码链接
欢迎留言评论分享自己的看法,如有错误欢迎指正。关注公众号:“小小创客者”回复“花样流水灯“获得源码及仿真。
边栏推荐
- Original error was: DLL load failed while importing _multiarray_umath: 找不到指定的模块
- 标准化研究院云迁移相关能力要求发布,万博智云参与能力要求和白皮书编写
- Reinforcement Learning 强化学习(一)
- PHP版本新特性摘選 - PHP8.0X
- Original error was: DLL load failed while importing _ multiarray_ Umath: the specified module cannot be found
- Sélection de nouvelles fonctionnalités pour la version PHP - PHP 8.0x
- PHP版本新特性摘选 - PHP7.1X
- 进程同步问题总结
- 编程语言学习和使用的观点
- Redis - redis list function explanation and industrial application
猜你喜欢

关于线程切换问题的一些思考总结

一文读懂软件测试的常见分类

STL next_ Analysis of the return value of permutation() function

Heartless sword Chinese translation of Michael's definition of algebra

STL next_permutation() 函数的返回值探析

IDEA - Could not autowire. No beans of ‘XXXMapper‘ type found.

npm ERR! cb() never called 处理办法

解决Google colab上安装GPU版本mxnet报错:libnvrtc.so.11.2: cannot open shared object file: No such file...

There is only one day left to prepare for the examination of Guangxi Second Construction Engineering Co., Ltd. the first three pages of the examination of second-class cost engineer came and raised sc

Keil mdk5, use of arm CC ---- >
随机推荐
编程语言学习和使用的观点
CentOS7.9安装MySQL8详细步骤
进程同步问题总结
stoi函数使用注意事项
There is only one day left to prepare for the examination of Guangxi Second Construction Engineering Co., Ltd. the first three pages of the examination of second-class cost engineer came and raised sc
2022-07-15:一开始有21个球,甲和乙轮流拿球,甲先、乙后, 每个人在自己的回合,一定要拿不超过3个球,不能不拿。 最终谁的总球数为偶数,谁赢。 请问谁
传输层 ------ UDP
Heartless sword Chinese translation of Michael's definition of algebra
从红魔7S系列看游戏手机的自驱进化
力扣练习——23 救生艇
Chrome 插件开发
留心那些潜在的系统设计问题
Richview table option options
Reinforcement Learning 强化学习(一)
【vulnhub】DC9
上下文对象实例
Lucas theorem
问题 V: hannnnah_j’s Biological Test
Repent of greed stonk
【Unity3D】UGUI之Slider