仿真原理图如下(proteus仿真工程文件可到本帖附件中下载)
单片机源程序如下:
- #include<reg52.h>
- #include<intrins.h>
- typedef unsigned char u8;
- typedef unsigned int u16;
- sbit R3 = P1^2; //
- sbit R2 = P1^1; //
- sbit R1 = P1^0; //
- sbit DS = P1^4; //
- sbit SHCP = P1^5; //
- sbit STCP = P1^6; //
- code u8 g[16][8]={
- {0x00,0x38,0x44,0x44,0x44,0x44,0x38,0x00},//0
- {0x00,0x08,0x18,0x08,0x08,0x08,0x1C,0x00},//1
- {0x00,0x3C,0x04,0x04,0x3C,0x20,0x20,0x3C},//2
- {0x00,0x3C,0x04,0x04,0x3C,0x04,0x04,0x3C},//3
- {0x04,0x0C,0x14,0x24,0x44,0xFF,0x04,0x04},//4
- {0x00,0x1E,0x10,0x10,0x1E,0x02,0x02,0x1E},//5
- {0x00,0x3C,0x20,0x20,0x3E,0x22,0x22,0x3E},//6
- {0x00,0x1E,0x02,0x04,0x08,0x08,0x08,0x08},//7
- {0x1C,0x22,0x22,0x22,0x1C,0x22,0x22,0x1C},//8
- {0x3C,0x24,0x24,0x3C,0x04,0x04,0x3C,0x00},//9
- {0x00,0x10,0x28,0x44,0x7C,0x44,0x44,0x00},//A
- {0x00,0x38,0x24,0x24,0x38,0x24,0x24,0x38},//B
- {0x1C,0x22,0x20,0x20,0x20,0x22,0x1C,0x00},//C
- {0x00,0x38,0x24,0x24,0x24,0x24,0x38,0x00},//D
- {0x00,0x3C,0x20,0x20,0x3C,0x20,0x20,0x3C},//E
- {0x00,0x3C,0x20,0x3C,0x20,0x20,0x20,0x00} //F
- };
- void wrong(u16 i) //调试用
- {
- if(i)
- P0=0xff;
- }
- void delay1ms(void) //100ms延时
- {
- unsigned char a,b;
- for(b=199;b>0;b--)
- for(a=1;a>0;a--);
- }
- void row(u8 r) //选择点亮第几行
- {
- switch(r)
- {
- case 1:{R3=1;R2=1;R1=1;};break;
- case 2:{R3=1;R2=1;R1=0;};break;
- case 3:{R3=1;R2=0;R1=1;};break;
- case 4:{R3=1;R2=0;R1=0;};break;
- case 5:{R3=0;R2=1;R1=1;};break;
- case 6:{R3=0;R2=1;R1=0;};break;
- case 7:{R3=0;R2=0;R1=1;};break;
- case 8:{R3=0;R2=0;R1=0;};break;
-
- default :wrong(1);break;
- }
- }
- void send(u8 d) //选择该行显示的内容
- {
- u8 i;
-
- SHCP = 0;
- STCP = 0;
-
- for(i=0;i<8;i++)
- {
- DS = d>>7;
- d<<=1;
- SHCP = 1;
- _nop_();
- _nop_();
- SHCP = 0;
- }
- STCP = 1;
- _nop_();
- _nop_();
- STCP = 0;
- }
- void main()
- {
- u8 i;
- unsigned int k,m;
- while(1)
- {
- for(k=0;k<16;k++)
- {
- for(m=0;m<100;m++)
- {
-
- for(i=0;i<8;i++)
- {
- send(g[k][i]);
- row(i+1); //i+1表示第几行
- delay1ms(); //延时
- send(0); //消隐,和延时一起使?
- }
- }
- }
- }
- }
复制代码
所有资料51hei提供下载:
8x8led点阵 显示0-f等字符.zip
(73.15 KB, 下载次数: 39)
|