您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 综合/其它 > 51单片机经典程序分析
#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);for(i=0;i6;i++){zgxh(50,1);nszgm(50,1);}djs(100,20);//对角闪for(i=0;i3;i++){zg(100,1);//两边逐个亮lbzgm(100,1);//两边逐个灭}qs(200,10);djs(100,50);for(i=0;i5;i++){sztl(200,1);//顺时逐个同步亮nztm(200,1);nztl(200,1);
本文标题:51单片机经典程序分析
链接地址:https://www.777doc.com/doc-5325659 .html