51单片机做的8*8数字转换及循环实物图:
仿真原理图如下(proteus仿真工程文件可到本帖附件中下载):
单片机源程序如下:
- #include<reg52.h>
- void delay();
- unsigned char code digittab[88]={ //行选通
- 0x00,0x00,0x00,0x00,//缓冲下,0从右端出来啦!!!
- 0x00,0x00,0x7c,0x82,0x82,0x82,0x7c,0x00,//0
- 0x00,0x00,0x00,0x00,0x84,0xfe,0x80,0x00,/*1*/
- 0x00,0x00,0xe4,0xa2,0xa2,0xa2,0x9c,0x00,/*2*/
- 0x00,0x00,0x44,0x92,0x92,0x92,0x6c,0x00,/*3*/
- 0x00,0x00,0x30,0x28,0x24,0xfe,0x20,0x00,/*4*/
- 0x00,0x00,0x4e,0x8a,0x8a,0x8a,0x72,0x00,/*5*/
- 0x00,0x00,0x7c,0x92,0x92,0x92,0x64,0x00,/*6*/
- 0x00,0x00,0x02,0x02,0x02,0xf2,0x0e,0x00,/*7*/
- 0x00,0x00,0x6c,0x92,0x92,0x92,0x6c,0x00,/*8*/
- 0x00,0x00,0x4c,0x92,0x92,0x92,0x7c,0x00,/*9*/
- 0x00,0x00,0x00,0x00//让9继续滚动完
- };
- unsigned char code tab[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f,}; //列选通
- unsigned char code lie[]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
- unsigned char code ssy[]={0xff,0xfc,0xf8,0xf0,0xe0,0xc0,0x80,0x00};
- unsigned char code zjl[]={0x7e,0x3c,0x18,0x00,0x18,0x3c,0x7e};
- unsigned char code ssz[]={0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};
- void delay(int z) //延时函数
- {
- int x,y;
- for(x=z;x>0;x--)
- for(y=156;y>0;y--); }
- void ss(void)
- {
- unsigned char i;
- P0=0xff;
- for(i=0;i<8;i++)
- {
- P2=ssy[i];
- delay(100);
- P2=0xff;
- delay(100);
- }
- for(i=0;i<8;i++)
- {
- P2=ssz[i];
- delay(100);
- P2=0XFF;
- delay(100);
- }
- }
-
- void zh(void)
- {
- unsigned char i;
- P0=0xff;
- for(i=0;i<7;i++)
- {P2=zjl[i];
- delay(100);}
- }
- void lsy(void)
- {
- unsigned char j,i,k;
- for(k=8;k>0;k--)
- {
- P0=lie[i];
- i++;
- if(i%2==0)
- {
- for(j=8;j>0;j--)
- {
- P2=tab[j-1];
- delay(100);
- }
- }
- else
- {
- for(j=0;j<8;j++)
- {
- P2=tab[j];
- delay(100);
- }
- }
- if(i==8)
- {i=0;}
- }
- }
- void lsl(void)
- {
- unsigned char j,i,k;
- for(k=8;k>0;k--)
- {
- P2=tab[7-i];
- i++;
- if(i%2==0)
- {
- for(j=8;j>0;j--)
- {
- P0=lie[j-1];
- delay(100);}
- }
- else
- {
- for(j=0;j<8;j++)
- {
- P0=lie[j];
- delay(100);
- }
- }
- if(i==8)
- {i=0;}
- }
- }
- void xh(void)
- {
- int j,i;
- for(i=0;i<8;i++)
- {
- P0=lie[i];
- for(j=0;j<8;j++)
- {
- P2=tab[7-j];
- delay(200);
- }
- }
- }
- void main()
- {
- unsigned char i=1,x=0,j=0,tcount=0;
- unsigned int ledroll[8];
- for(j=0;j<8;j++)
- ledroll[j]=digittab[j];
- zh();
- ss();
- lsl();
- P0=0X00;
- lsy();
- while(1)
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
所有资料51hei提供下载:
led趣味作品 - 副本.rar
(16.05 MB, 下载次数: 20)
|