Altium Designer画的51单片机贴片心形灯原理图和PCB图如下:(51hei附件中可下载工程文件)
单色心形灯CAD亚克力外壳设计图
单片机源程序如下:
- /*******************************************************************/
- /* 作品:单色心形流水灯
- /* 主控采用STC89c52RC单片机 晶振12M
- /*******************************************************************/
-
- #include<reg52.h>
- #define uchar unsigned char
- #define uint unsigned int
- uchar code table0[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};//LED从低位往高位移
- uchar code table1[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};//LED从高位往低位移
- uchar code table2[]={0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00};//LED从1个亮到8个都点亮(从低位往高位)
- uchar code table3[]={0x7f,0x3f,0x1f,0x0f,0x07,0x03,0x01,0x00};//LED从1个亮到8个都点亮(从高位往低位)
- uchar code table4[]={0x00,0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff};//LED从8个全亮到一个都不亮(从低位往高位)
- uchar code table5[]={0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};//LED从8个全亮到一个都不亮(从高位往低位)
- uchar code table6[]={0xfe,0xfc,0xfa,0xf6,0xee,0xde,0xbe,0x7e};//LED从低位往高位移(最低位始终为0)
- uchar code table7[]={0x7f,0x3f,0x5f,0x6f,0x77,0x7b,0x7d,0x7e};//LED从高位往低位移(最高位始终为0)
- uchar code Tab1[]={0xFE,0xFD,0xFB,0xF7,0xEF,0xDF,0xBF,0x7F,0xFF};//暗中左移 向下
- uchar code Tab2[]={0x7F,0xBF,0xDF,0xEF,0xF7,0xFB,0xFD,0xFE,0xFF};//暗中右移 向上
- uchar code Tab3[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80,0x00};//亮中左移 向下
- uchar code Tab4[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01,0x00};//亮中右移 向上
- uchar code Tab11[]={0xFE,0xFC,0xF8,0xF0,0xE0,0xC0,0x80,0x00,0xff};//暗中左移 向下
- uchar code Tab22[]={0x7F,0x3F,0x1F,0x0F,0x07,0x03,0x01,0x00,0xff};
- uchar code Tab33[]={0x80,0xC0,0xE0,0xF0,0xF8,0xFC,0xFE,0xFF};
- uchar code Tab44[]={0x01,0x03,0x07,0x0F,0x1F,0x3F,0x7F,0xFF};
- uchar code Tab55[]={0x08,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff,0xff};
- uchar code Tab5[]={0x00,0x80,0xC0,0xE0,0xF0,0xF8,0xFC,0xFE,0xff};
- uchar code Tab6[]={0x00,0x01,0x03,0x07,0x0F,0x1F,0x3F,0x7F,0xff};
- uchar code Tab7[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
- uchar code Tab8[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
- uchar i,j,flag=200; //定义循环变量
- uint tt=70,temp,cycle=350,xunhuan; //定义时间指数
- void shansuo();
- void xl();
- void delay()
- {
- uchar m,n;
- for(m=0;m<flag;m++)
- for(n=0;n<250;n++);
-
- }
- void delay1(uint z) //延时函数
- {
- uint x,y;
- for(x=z;x>0;x--)
- for(y=110;y>0;y--);
- }
- void delay2(uint x) //延时函数,要足够快,否则灯会闪烁,而不是慢慢变化。
- {
- uint i;
- for(i=x;i>0;i--);
-
- }
- void liushuideng1()
- {
- for(xunhuan=0;xunhuan<2;xunhuan++)
- {
- for(temp=0;temp<cycle;temp++) //由暗到亮(灯的亮度是亮和灭保持时间的平均值)
- {
- P0=P1=P2=P3=0x00;
- delay2(temp); //延时逐渐加大,led=0(亮)保持的时间越来越长,亮度随之变大。
- P0=P1=P2=P3=0xff;
- delay2(cycle-temp); //延时减短,led=1(灭)保持的时间越来越短,结合上一句,整体亮度变大
- }
-
- for(temp=cycle;temp>0;temp--)//由亮到暗
- {
- P0=P1=P2=P3=0x00;
- delay2(temp); //延时逐渐减短,led=0(亮)保持的时间越来越短,亮度随之变小。
- P0=P1=P2=P3=0xff;
- delay2(cycle-temp); //延时增长,led=1(灭)保持的时间越来越长,结合上一句,整体亮度变小
- }
- }
- }
- void liushuideng2()
- {
- P0=P1=P2=P3=0x00;
- delay1(600);
- for(xunhuan=0;xunhuan<2;xunhuan++)
- {
- for(temp=0;temp<cycle;temp++) //由暗到亮(灯的亮度是亮和灭保持时间的平均值)
- {
- P0=P1=P2=P3=0x55;
- delay2(temp); //延时逐渐加大,led=0(亮)保持的时间越来越长,亮度随之变大。
- P0=P1=P2=P3=0xaa;
- delay2(cycle-temp); //延时减短,led=1(灭)保持的时间越来越短,结合上一句,整体亮度变大
- }
- delay1(600);
- for(temp=cycle;temp>0;temp--)//由亮到暗
- {
- P0=P1=P2=P3=0xaa;
- delay2(temp); //延时逐渐减短,led=0(亮)保持的时间越来越短,亮度随之变小。
- P0=P1=P2=P3=0x55;
- delay2(cycle-temp); //延时增长,led=1(灭)保持的时间越来越长,结合上一句,整体亮度变小
- }
-
- delay1(600);
- }
-
- }
- void liushuideng3()
- {
- delay1(1000);
- for(xunhuan=0;xunhuan<2;xunhuan++)
- {
- for(temp=0;temp<cycle;temp++) //由暗到亮(灯的亮度是亮和灭保持时间的平均值)
- {
- P0=P1=P2=P3=0x0f;
- delay2(temp); //延时逐渐加大,led=0(亮)保持的时间越来越长,亮度随之变大。
- P0=P1=P2=P3=0xf0;
- delay2(cycle-temp); //延时减短,led=1(灭)保持的时间越来越短,结合上一句,整体亮度变大
- }
- delay1(600);
- for(temp=cycle;temp>0;temp--)//由亮到暗
- {
- P0=P1=P2=P3=0xf0;
- delay2(temp); //延时逐渐减短,led=0(亮)保持的时间越来越短,亮度随之变小。
- P0=P1=P2=P3=0x0f;
- delay2(cycle-temp); //延时增长,led=1(灭)保持的时间越来越长,结合上一句,整体亮度变小
- }
- delay1(600);
-
- }
-
- }
- void liushuideng4()
- {
- for(xunhuan=0;xunhuan<1;xunhuan++)
- {
- for(temp=0;temp<cycle;temp++) //由暗到亮(灯的亮度是亮和灭保持时间的平均值)
- {
- P0=P2=0x00;
- delay2(temp); //延时逐渐加大,led=0(亮)保持的时间越来越长,亮度随之变大。
- P0=P2=0xff;
- delay2(cycle-temp); //延时减短,led=1(灭)保持的时间越来越短,结合上一句,整体亮度变大
- }
-
- for(temp=cycle;temp>0;temp--)//由亮到暗
- {
- P0=P2=0x00;
- delay2(temp); //延时逐渐减短,led=0(亮)保持的时间越来越短,亮度随之变小。
- P0=P2=0xff;
- delay2(cycle-temp); //延时增长,led=1(灭)保持的时间越来越长,结合上一句,整体亮度变小
- }
- for(temp=0;temp<cycle;temp++) //由暗到亮(灯的亮度是亮和灭保持时间的平均值)
- {
- P1=P3=0x00;
- delay2(temp); //延时逐渐加大,led=0(亮)保持的时间越来越长,亮度随之变大。
- P1=P3=0xff;
- delay2(cycle-temp); //延时减短,led=1(灭)保持的时间越来越短,结合上一句,整体亮度变大
- }
-
- for(temp=cycle;temp>0;temp--)//由亮到暗
- {
- P1=P3=0x00;
- delay2(temp); //延时逐渐减短,led=0(亮)保持的时间越来越短,亮度随之变小。
- P1=P3=0xff;
- delay2(cycle-temp); //延时增长,led=1(灭)保持的时间越来越长,结合上一句,整体亮度变小
- }
- }
- }
- void liushuideng5()
- {
- for(xunhuan=0;xunhuan<1;xunhuan++)
- {
- for(temp=0;temp<cycle;temp++) //由暗到亮(灯的亮度是亮和灭保持时间的平均值)
- {
- P1=P0=0x00;
- delay2(temp); //延时逐渐加大,led=0(亮)保持的时间越来越长,亮度随之变大。
- P1=P0=0xff;
- delay2(cycle-temp); //延时减短,led=1(灭)保持的时间越来越短,结合上一句,整体亮度变大
- }
-
- for(temp=cycle;temp>0;temp--)//由亮到暗
- {
- P1=P0=0x00;
- delay2(temp); //延时逐渐减短,led=0(亮)保持的时间越来越短,亮度随之变小。
- P1=P0=0xff;
- delay2(cycle-temp); //延时增长,led=1(灭)保持的时间越来越长,结合上一句,整体亮度变小
- }
- for(temp=0;temp<cycle;temp++) //由暗到亮(灯的亮度是亮和灭保持时间的平均值)
- {
- P3=P2=0x00;
- delay2(temp); //延时逐渐加大,led=0(亮)保持的时间越来越长,亮度随之变大。
- P3=P2=0xff;
- delay2(cycle-temp); //延时减短,led=1(灭)保持的时间越来越短,结合上一句,整体亮度变大
- }
-
- for(temp=cycle;temp>0;temp--)//由亮到暗
- {
- P3=P2=0x00;
- delay2(temp); //延时逐渐减短,led=0(亮)保持的时间越来越短,亮度随之变小。
- P3=P2=0xff;
- delay2(cycle-temp); //延时增长,led=1(灭)保持的时间越来越长,结合上一句,整体亮度变小
- }
- }
- }
- void liushuideng6()
- {
- for(xunhuan=0;xunhuan<1;xunhuan++)
- {
- for(temp=0;temp<cycle;temp++) //由暗到亮(灯的亮度是亮和灭保持时间的平均值)
- {
- P0=P3=0x00;
- delay2(temp); //延时逐渐加大,led=0(亮)保持的时间越来越长,亮度随之变大。
- P0=P3=0xff;
- delay2(cycle-temp); //延时减短,led=1(灭)保持的时间越来越短,结合上一句,整体亮度变大
- }
-
- for(temp=cycle;temp>0;temp--)//由亮到暗
- {
- P0=P3=0x00;
- delay2(temp); //延时逐渐减短,led=0(亮)保持的时间越来越短,亮度随之变小。
- P0=P3=0xff;
- delay2(cycle-temp); //延时增长,led=1(灭)保持的时间越来越长,结合上一句,整体亮度变小
- }
- for(temp=0;temp<cycle;temp++) //由暗到亮(灯的亮度是亮和灭保持时间的平均值)
- {
- P1=P2=0x00;
- delay2(temp); //延时逐渐加大,led=0(亮)保持的时间越来越长,亮度随之变大。
- P1=P2=0xff;
- delay2(cycle-temp); //延时减短,led=1(灭)保持的时间越来越短,结合上一句,整体亮度变大
- }
-
- for(temp=cycle;temp>0;temp--)//由亮到暗
- {
- P1=P2=0x00;
- delay2(temp); //延时逐渐减短,led=0(亮)保持的时间越来越短,亮度随之变小。
- P1=P2=0xff;
- delay2(cycle-temp); //延时增长,led=1(灭)保持的时间越来越长,结合上一句,整体亮度变小
- }
- }
- }
- void disp0() //状态0 所有LED闪烁3次
- {
- for(i=0;i<3;i++)
- {
- P0=0x00; P2=0x00; P3=0x00; P1=0x00;
- delay1(300);
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei附件下载:
单色心形流水灯工程项目.zip
(949.92 KB, 下载次数: 59)
|