前言
今天要介绍的这款项目,是一个基于STC89C52RC单片机设计的多功能爱心形状LED流水灯系统。这个项目不仅能够实现多种绚丽的灯光效果,还可以作为装饰品或电子设计教学的工具。
项目简介
本项目采用了STC89C52RC单片机作为控制核心,精心设计并制作了一个爱心形状的LED显示装置。通过编写程序,我们实现了多种多样的灯光效果,使其既美观又实用。这个装置不仅可以用于装饰,还能作为教学工具,帮助初学者更好地理解单片机编程和电路设计。
功能特点
以下是一些主要的功能特点:
- 全体LED同时闪烁:所有LED灯同时亮起和熄灭,营造出强烈的视觉冲击。
- 顺时针流水灯效果:LED灯从左上方向右下方依次亮起,如同流水一般流动。
- 逆时针流水灯效果:与顺时针效果相反,LED灯从右下方向左上方依次亮起。
- 两侧同时流水效果:两侧的LED灯同时向中间流动,形成独特的光影效果。
- 呼吸灯效果:LED灯的亮度逐渐变化,模拟呼吸时的明暗变化。
- 随机闪烁效果:LED灯随机亮起和熄灭,带来意想不到的惊喜。
除了上述效果,系统还支持多种其他效果,如交叉闪烁、心跳效果、波浪效果、跑马灯效果、渐变闪烁和螺旋效果。这些效果使得装置更加丰富多彩,能够满足不同的使用需求。
项目结构
GitHub仓库/Gitee仓库项目的文件结构如下:
1 2 3 4 5 6 7 8 9
| ├── Keil_Project/ # 程序源代码 │ ├── main.c # 主程序代码 │ └── Objects/ # 编译生成文件 ├── PCB_Project/ # PCB设计文件 │ ├── love-flow-lamp.PrjPcb # PCB项目文件 │ ├── love-flow-lamp.SchDoc # 原理图文件 │ ├── love-flow-lamp.PcbLib # PCB库文件 │ └── love-flow-lamp.PcbDoc # PCB图纸文件 └── 实物图片/ # 成品展示
|
开发环境
本项目使用了以下开发工具和环境:
- IDE: Keil uVision 5
- PCB设计工具: Altium Designer
- 编程语言: C语言
- 目标单片机: STC89C52RC
项目演示
以下是项目实物图片:

您可以在B站查看项目的详细演示视频:B站视频链接
项目源码
项目源码请参考GitHub仓库 Gitee仓库
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267
| #include <REGX52.H>
typedef unsigned char uchar; typedef unsigned int uint;
void Delay_ms(unsigned int xms);
void clock_wise(uint x); void anticlock_wise(uint x); void all_dance(void); void two_flanks(uint x); void breath_effect(void); void cross_flash(void); void random_flash(void); void heartbeat(void); void wave_effect(void); void marquee(void); void gradient_blink(void); void spiral(void); void rainbow_effect(void); void flash_center(void);
static uint i;
void main() { while(1) { Delay_ms(500); for (i = 60; i > 0; i -= 10) { clock_wise(i); } for (i = 60; i > 0; i -= 10) { anticlock_wise(i); } Delay_ms(60); clock_wise(50); Delay_ms(60); anticlock_wise(50); Delay_ms(60); two_flanks(50); Delay_ms(60); breath_effect(); Delay_ms(60); cross_flash(); Delay_ms(60); random_flash(); Delay_ms(60); heartbeat(); wave_effect(); Delay_ms(60); marquee(); Delay_ms(60); gradient_blink(); Delay_ms(60); spiral(); Delay_ms(60); rainbow_effect(); Delay_ms(60); flash_center(); Delay_ms(60); all_dance(); Delay_ms(100); } }
void Delay_ms(uint xms) { uchar i, j; while(xms) { i = 2; j = 239; do { while (--j); } while (--i); xms--; } }
void all_dance(void){ P0=0xFF;P1=0xFF;P2=0xFF;P3=0xFF; Delay_ms(600); P0=0x00;P1=0x00;P2=0x00;P3=0x00; Delay_ms(600); }
void clock_wise(uint x){ P1=0x7F;Delay_ms(x);P1=0xBF;Delay_ms(x);P1=0xDF;Delay_ms(x);P1=0xEF;Delay_ms(x); P1=0xF7;Delay_ms(x);P1=0xFB;Delay_ms(x);P1=0xFD;Delay_ms(x);P1=0xFE;Delay_ms(x); P1=0xFF;Delay_ms(x); P0=0xFE;Delay_ms(x);P0=0xFD;Delay_ms(x);P0=0xFB;Delay_ms(x);P0=0xF7;Delay_ms(x); P0=0xEF;Delay_ms(x);P0=0xDF;Delay_ms(x);P0=0xBF;Delay_ms(x);P0=0x7F;Delay_ms(x); P0=0xFF;Delay_ms(x); P2=0x7F;Delay_ms(x);P2=0xBF;Delay_ms(x);P2=0xDF;Delay_ms(x);P2=0xEF;Delay_ms(x); P2=0xF7;Delay_ms(x);P2=0xFB;Delay_ms(x);P2=0xFD;Delay_ms(x);P2=0xFE;Delay_ms(x); P2=0xFF;Delay_ms(x); P3=0x7f;Delay_ms(x);P3=0xBF;Delay_ms(x);P3=0xDF;Delay_ms(x);P3=0xEF;Delay_ms(x); P3=0xF7;Delay_ms(x);P3=0xFB;Delay_ms(x);P3=0xFD;Delay_ms(x);P3=0xFE;Delay_ms(x); P3=0xFF;Delay_ms(x); }
void anticlock_wise(uint x){ P3=0xFE;Delay_ms(x);P3=0xFD;Delay_ms(x);P3=0xFB;Delay_ms(x);P3=0xF7;Delay_ms(x); P3=0xEF;Delay_ms(x);P3=0xDF;Delay_ms(x);P3=0xBF;Delay_ms(x);P3=0x7F;Delay_ms(x); P3=0xFF;Delay_ms(x); P2=0xFE;Delay_ms(x);P2=0xFD;Delay_ms(x);P2=0xFB;Delay_ms(x);P2=0xF7;Delay_ms(x); P2=0xEF;Delay_ms(x);P2=0xDF;Delay_ms(x);P2=0xBF;Delay_ms(x);P2=0x7F;Delay_ms(x); P2=0xFF;Delay_ms(x); P0=0x7F;Delay_ms(x);P0=0xBF;Delay_ms(x);P0=0xDF;Delay_ms(x);P0=0xEF;Delay_ms(x); P0=0xF7;Delay_ms(x);P0=0xFB;Delay_ms(x);P0=0xFD;Delay_ms(x);P0=0xFE;Delay_ms(x); P0=0xFF;Delay_ms(x); P1=0xFE;Delay_ms(x);P1=0xFD;Delay_ms(x);P1=0xFB;Delay_ms(x);P1=0xF7;Delay_ms(x); P1=0xEF;Delay_ms(x);P1=0xDF;Delay_ms(x);P1=0xBF;Delay_ms(x);P1=0x7F;Delay_ms(x); P1=0xFF;Delay_ms(x); }
void two_flanks(uint x){ P1=0x7F;P3=0xFE;Delay_ms(x);P1=0xBF;P3=0xFD;Delay_ms(x);P1=0xDF;P3=0xFB;Delay_ms(x);P1=0xEF;P3=0xF7;Delay_ms(x); P1=0xF7;P3=0xEF;Delay_ms(x);P1=0xFB;P3=0xDF;Delay_ms(x);P1=0xFD;P3=0xBF;Delay_ms(x);P1=0xFE;P3=0x7F;Delay_ms(x); P1=0xFF;P3=0xFF;Delay_ms(x);
P0=0xFD;P2=0xFD;Delay_ms(x);P0=0xFE;P2=0xFE;Delay_ms(x);P0=0xFB;P2=0xFB;Delay_ms(x);P0=0xF7;P2=0xF7;Delay_ms(x); P0=0xEF;P2=0xEF;Delay_ms(x);P0=0xDF;P2=0xDF;Delay_ms(x);P0=0xBF;P2=0xBF;Delay_ms(x);P0=0x7F;P2=0x7F;Delay_ms(x); P0=0xFF;P2=0xFF;Delay_ms(x); }
void breath_effect(void) { uchar i; for(i=0; i<5; i++) { P0=0xFF<<i; P1=0xFF<<i; P2=0xFF<<i; P3=0xFF<<i; Delay_ms(80); } for(i=5; i>0; i--) { P0=0xFF<<i; P1=0xFF<<i; P2=0xFF<<i; P3=0xFF<<i; Delay_ms(80); } }
void random_flash(void) { uchar i; for(i=0; i<8; i++) { P0 = ~(0x01 << (i%8)); P1 = ~(0x01 << ((i+2)%8)); P2 = ~(0x01 << ((i+4)%8)); P3 = ~(0x01 << ((i+6)%8)); Delay_ms(80); } }
void cross_flash(void) { uchar i; for(i=0; i<4; i++) { P0=0xAA; P1=0xAA; P2=0x55; P3=0x55; Delay_ms(200); P0=0x55; P1=0x55; P2=0xAA; P3=0xAA; Delay_ms(200); } P0=0xFF; P1=0xFF; P2=0xFF; P3=0xFF; }
void heartbeat(void) { uchar i; for(i=0; i<3; i++) { P0=0x00; P1=0x00; P2=0x00; P3=0x00; Delay_ms(200); P0=0xFF; P1=0xFF; P2=0xFF; P3=0xFF; Delay_ms(200); } }
void wave_effect(void) { uchar i; for(i=0; i<4; i++){ P0 = ~(0x18 >> i); P1 = ~(0x18 >> i); P2 = ~(0x18 << i); P3 = ~(0x18 << i); Delay_ms(120); } P0=0xFF;P1=0xFF;P2=0xFF;P3=0xFF; }
void marquee(void) { uchar i; for(i=0; i<8; i++){ P0 = ~(0x80 >> i); P1 = ~(0x80 >> (i+2)%8); P2 = ~(0x80 >> (i+4)%8); P3 = ~(0x80 >> (i+6)%8); Delay_ms(150); } }
void gradient_blink(void) { uchar i; for(i=0; i<6; i++){ P0=0x00;P1=0xFF;P2=0x00;P3=0xFF; Delay_ms(100 + i*20); P0=0xFF;P1=0x00;P2=0xFF;P3=0x00; Delay_ms(100 + i*20); } }
void spiral(void) { uchar patterns[] = {0x7E,0xBD,0xDB,0xE7}; uchar i; for(i=0; i<4; i++){ P0 = patterns[i]; P1 = patterns[(i+1)%4]; P2 = patterns[(i+2)%4]; P3 = patterns[(i+3)%4]; Delay_ms(200); } P0=0xFF;P1=0xFF;P2=0xFF;P3=0xFF; }
void rainbow_effect(void) { uchar patterns[] = {0xFF, 0x0C, 0xF3, 0x7E, 0x9F, 0x3F}; uchar i; for(i=0; i<6; i++){ P0 = patterns[i]; P1 = patterns[(i+1)%6]; P2 = patterns[(i+2)%6]; P3 = patterns[(i+3)%6]; Delay_ms(150); } P0=0xFF;P1=0xFF;P2=0xFF;P3=0xFF; }
void flash_center(void) { uchar i; for(i=0; i<3; i++){ P0=0x80; P1=0x00; P2=0x00; P3=0x00; Delay_ms(200); P0=0x00; P1=0x80; P2=0x00; P3=0x00; Delay_ms(200); P0=0x00; P1=0x00; P2=0x80; P3=0x00; Delay_ms(200); P0=0x00; P1=0x00; P2=0x00; P3=0x80; Delay_ms(200); } P0=0xFF;P1=0xFF;P2=0xFF;P3=0xFF; }
|