资源描述:
《单片机心型流水灯程序》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、#include#defineuintunsignedint#defineucharunsignedcharucharcodetable0[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};//LED从低位往高位移ucharcodetable1[]={0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};//LED从高位往低位移ucharcodetable2[]={0xfe,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00};
2、//LED从1个亮到8个都点亮(从低位往高位)ucharcodetable3[]={0x7f,0x3f,0x1f,0x0f,0x07,0x03,0x01,0x00};//LED从1个亮到8个都点亮(从高位往低位)ucharcodetable4[]={0x00,0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff};//LED从8个全亮到一个都不亮(从低位往高位)ucharcodetable5[]={0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};//LED从8个
3、全亮到一个都不亮(从高位往低位)ucharcodetable6[]={0xfe,0xfc,0xfa,0xf6,0xee,0xde,0xbe,0x7e};//LED从低位往高位移(最低位始终为0)ucharcodetable7[]={0x7f,0x3f,0x5f,0x6f,0x77,0x7b,0x7d,0x7e};//LED从高位往低位移(最高位始终为0)uchari,j;//定义循环变量uinttt=70;//定义时间指数voiddelay(uinttime)//延时函数{uintx,y;for(x=time;x>0;x--)fo
4、r(y=110;y>0;y--);}voiddisp0()//状态0所有LED闪烁3次{for(i=0;i<3;i++){P0=0x00;P2=0x00;P3=0x00;P1=0x00;delay(300);P0=0xff;P2=0xff;P3=0xff;P1=0xff;delay(300);}}voiddisp1()//状态1LED顺时针转一圈{for(i=0;i<8;i++){P2=table1[i];delay(100);}P2=0xff;for(i=0;i<8;i++){P3=table1[i];delay(100);}P
5、3=0xff;for(i=0;i<8;i++){P1=table1[i];delay(100);}P1=0xff;for(i=0;i<8;i++){P0=table0[i];delay(100);}P0=0xff;}voiddisp2()//状态2LED逆时针转一圈{for(i=0;i<8;i++){P0=table1[i];delay(100);}P0=0xff;for(i=0;i<8;i++){P1=table0[i];delay(100);}P1=0xff;for(i=0;i<8;i++){P3=table0[i];dela
6、y(100);}P3=0xff;for(i=0;i<8;i++){P2=table0[i];delay(100);}P2=0xff;}voiddisp3()//状态34个LED同时顺时、逆时针移动1/4圈{for(i=0;i<8;i++){P0=table1[i];P1=table1[i];P2=table1[i];P3=table0[i];delay(100);}for(i=0;i<8;i++){P0=table0[i];P1=table0[i];P2=table0[i];P3=table1[i];delay(100);}P3=
7、0xff;P0=0xff;}voiddisp4()//状态42个LED同时顺时针移动半圈{for(i=0;i<8;i++){P2=table1[i];P1=table1[i];delay(100);}P2=0xff;P1=0xff;for(i=0;i<8;i++){P3=table1[i];P0=table0[i];delay(100);}P3=0xff;P0=0xff;}voiddisp5()//状态52个LED同时逆时针移动半圈{for(i=0;i<8;i++){P0=table1[i];P3=table0[i];delay(
8、100);}P0=0xff;P3=0xff;for(i=0;i<8;i++){P1=table0[i];P2=table0[i];delay(100);}P1=0xff;P2=0xff;}voiddisp6()//状态6LED自上而下逐渐点亮(一半