您好,欢迎访问三七文档
当前位置:首页 > 建筑/环境 > 工程监理 > 心形LED流水灯制作方法
LED心形流水灯加程序1.原件清单:一个万能板,一个底座,一个STC89C52芯片,32个LED灯,32个贴片电阻,两个30uf电容,一个晶振。2.原理图:注:电源处的复位可以不用;就是上面红框里的内容3.正面图背面图:亮灯图:4.程序代码:#includereg52.h#includeintrins.h#defineuintunsignedint#defineucharunsignedcharucharcodetable[]={0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00};//逐个点亮0~7ucharcodetable1[]={0x7f,0x3f,0x1f,0x0f,0x07,0x03,0x01,0x00};//逐个点亮7~0ucharcodetable2[]={0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff};//逐个灭0~7ucharcodetable3[]={0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};//逐个灭7~0/***********************************************************/voiddelay(uintt);//延时voidzg(uintt,uchara);//两边逐个亮voidqs(uintt,uchara);//全部闪烁voidzgxh(uintt,uchara);//逆时针逐个点亮//voidzgxh1(uintt,uchara);//顺时针逐个点亮voiddjs(uintt,uchara);//对角闪voidlbzgm(uintt,uchara);//两边逐个灭//voidsszgm(uintt,uchara);//顺时针逐个灭voidnszgm(uintt,uchara);//逆时针逐个灭voidsztl(uintt,uchara);//顺时逐个同步亮voidnztl(uintt,uchara);//逆时逐个同步亮voidsztm(uintt,uchara);//顺时逐个同步灭voidnztm(uintt,uchara);//逆时逐个同步灭voidhwzjl(uintt,uchara);//横往中间亮voidhwzjm(uintt,uchara);//横往中间灭//voidswzjl(uintt,uchara);//竖往中间亮//voidswzjm(uintt,uchara);//竖往中间灭voidnzdl(uintt,uchara);//逆时逐段亮voidnzdgl(uintt,uchara);//逆时逐段一个点亮voidjgs(uintt,uchara);//间隔闪/**********************************************************/voidzg(uintt,uchara)//两边逐个亮{uchari,j;for(j=0;ja;j++){P0=P1=P2=P3=0xff;P0=0x7f;delay(t);for(i=0;i7;i++){P0=table1[i+1];P2=table1[i];delay(t);}P2=0x00;P1=0xfe;delay(t);for(i=0;i7;i++){P1=table[i+1];P3=table1[i];delay(t);}P3=0x00;delay(t);}}voidqs(uintt,uchara)//全部闪烁{ucharj;for(j=0;ja;j++){P0=P1=P2=P3=0xff;delay(t);P0=P1=P2=P3=0x00;delay(t);}}voidzgxh(uintt,uchara)//逆时针逐个点亮{uchari,j;for(j=0;ja;j++){P0=P1=P2=P3=0xff;for(i=0;i8;i++){P0=table1[i];delay(t);}for(i=0;i8;i++){P1=table[i];delay(t);}for(i=0;i8;i++){P3=table[i];delay(t);}for(i=0;i8;i++){P2=table[i];delay(t);}}}voidnszgm(uintt,uchara)//逆时针逐个灭{uchari,j;for(j=0;ja;j++){P0=P1=P2=P3=0x00;for(i=0;i8;i++){P0=table3[i];delay(t);}for(i=0;i8;i++){P1=table2[i];delay(t);}for(i=0;i8;i++){P3=table2[i];delay(t);}for(i=0;i8;i++){P2=table2[i];delay(t);}}}/*voidzgxh1(uintt,uchara)//顺时针逐个点亮{uchari,j;for(j=0;ja;j++){P0=P1=P2=P3=0xff;for(i=0;i8;i++){P2=table1[i];delay(t);}for(i=0;i8;i++){P3=table1[i];delay(t);}for(i=0;i8;i++){P1=table1[i];delay(t);}for(i=0;i8;i++){P0=table[i];delay(t);}}}*//*voidsszgm(uintt,uchara)//顺时针逐个灭{uchari,j;for(j=0;ja;j++){P0=P1=P2=P3=0x00;for(i=0;i8;i++){P2=table3[i];delay(t);}for(i=0;i8;i++){P3=table3[i];delay(t);}for(i=0;i8;i++){P1=table3[i];delay(t);}for(i=0;i8;i++){P0=table2[i];delay(t);}}}*/voiddjs(uintt,uchara)//对角闪{ucharj;for(j=0;ja;j++){P0=P1=P2=P3=0xff;P0=P3=0x00;delay(t);P0=P1=P2=P3=0xff;P1=P2=0x00;delay(t);}}voidlbzgm(uintt,uchara)//两边逐个灭{uchari,j;for(j=0;ja;j++){P0=P2=0x00;P3=0x01;delay(t);for(i=7;i1;i--){P1=table[i-1];P3=table1[i-2];delay(t);}P1=0xfe;P3=0xff;delay(t);P1=0xff;P2=0x01;delay(t);for(i=7;i1;i--){P0=table1[i-1];P2=table1[i-2];delay(t);}P0=0x7f;P2=0xff;delay(t);P0=0xff;delay(t);}}voidsztl(uintt,uchara)//顺时逐个同步亮{uchari,j;for(j=0;ja;j++){P0=P1=P2=P3=0xff;for(i=0;i8;i++){P0=table[i];P1=P2=P3=table1[i];delay(t);}}}voidnztl(uintt,uchara)//逆时逐个同步亮{uchari,j;for(j=0;ja;j++){P0=P1=P2=P3=0xff;for(i=0;i8;i++){P0=table1[i];P1=P2=P3=table[i];delay(t);}}}voidsztm(uintt,uchara)//顺时逐个同步灭{uchari,j;for(j=0;ja;j++){P0=P1=P2=P3=0x00;for(i=0;i8;i++){P0=table2[i];P1=P2=P3=table3[i];delay(t);}}}voidnztm(uintt,uchara)//逆时逐个同步灭{uchari,j;for(j=0;ja;j++){P0=P1=P2=P3=0xff;for(i=0;i8;i++){P0=table3[i];P1=P2=P3=table2[i];delay(t);}}}voidhwzjl(uintt,uchara)//横往中间亮{uchari,j;for(j=0;ja;j++){P0=P1=P2=P3=0xff;for(i=0;i8;i++){P0=P2=P1=table1[i];P3=table[i];delay(t);}}}voidhwzjm(uintt,uchara)//横往中间灭{uchari,j;for(j=0;ja;j++){P0=P1=P2=P3=0x00;for(i=0;i8;i++){P0=P2=P1=table3[i];P3=table2[i];delay(t);}}}/*voidswzjl(uintt,uchara)//竖往中间亮{uchari,j;for(j=0;ja;j++){P0=P1=P2=P3=0xff;for(i=0;i8;i++){P0=P2=P1=table[i];P3=table1[i];delay(t);}}}voidswzjm(uintt,uchara)//竖往中间灭{uchari,j;for(j=0;ja;j++){P0=P1=P2=P3=0x00;for(i=0;i8;i++){P0=P2=P1=table2[i];P3=table3[i];delay(t);}}}*/voidnzdl(uintt,uchara)//逆时逐段亮{uchari,j;for(j=0;ja;j++){P0=P1=P2=P3=0xff;for(i=0;i8;i++){P0=table1[i];delay(t);}P0=0xff;for(i=0;i8;i++){P1=table[i];delay(t);}P1=0xff;for(i=0;i8;i++){P3=table[i];delay(t);}P3=0xff;for(i=0;i8;i++){P2=table[i];delay(t);}P2=0xff;}}voidnzdgl(uintt,uchara)//逆时逐段一个点亮{uchari,j,k,l;for(j=0;ja;j++){k=table1[0];P0=k;l=table[0];P1=P2=P3=l;delay(t);for(i=0;i8;i++){k=_crol_(k,-1);P0=k;l=_crol_(l,1);P1=P2=P3=l;delay(t);}}}voidjgs(uintt,uchara)//间隔闪{ucharj;for(j=0;ja;j++){P0=0x55;P1=P2=P3=0xaa;delay(t);P0=0xaa;P1=P2=P3=0x55;delay(t);}}voidmain(){uchari;while(1){zg(100,1);//两边逐个亮lbzgm(100,1);//两边逐个灭jgs(300,10);djs(100,20);//对角闪////////////////////////////////////////////P1=P2=P3=0xff;for(i=0;i3;i++){P0=0x00;delay(800);P0=0xff;delay(800);}P0=0x00;for(i=0;i3;i++){P1=0x00;delay(800);P1=0xff;delay(800);}P1=0x00;for(i=0;i3;i++){P3=0x00;delay(800);P3=0xff;delay(800);}P3=0x00;for(i=0;i3;i++){P2=0x00;delay(800);P2=0xff;delay(800);}qs(500,3);/////////////
本文标题:心形LED流水灯制作方法
链接地址:https://www.777doc.com/doc-4688245 .html