C51单片机8*8点阵循环显示0123456789.
制作出来的实物图如下:
单片机源程序如下:
- #include <reg52.h>
- #include <intrins.h>
- typedef unsigned char u8;
- typedef unsigned int u16;
- #define MATRIX_PORT P0
- sbit SCK = P3^6;
- sbit RCK = P3^5;
- sbit SER = P3^4;
- u8 gLineCode[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
- u8 g0[] = {0x0,0x0,0x7F,0x41,0x41,0x7F,0x0,0x0};
- u8 g1[] = {0x0,0x0,0x0,0x22,0x7E,0x2,0x0,0x0};
- u8 g2[] = {0x0,0x0,0x4F,0x49,0x49,0x79,0x0,0x0};
- u8 g3[] = {0x0,0x0,0x49,0x49,0x49,0x7F,0x0,0x0};
- u8 g4[] = {0x0,0x0,0x78,0x8,0x8,0x7F,0x0,0x0};
- u8 g5[] = {0x0,0x0,0x79,0x49,0x49,0x4F,0x0,0x0};
- u8 g6[] = {0x0,0x0,0x7F,0x49,0x49,0x4F,0x0,0x0};
- u8 g7[] = {0x0,0x0,0x40,0x40,0x40,0x7F,0x0,0x0};
- u8 g8[] = {0x0,0x0,0x7F,0x49,0x49,0x7F,0x0,0x0};
- u8 g9[] = {0x0,0x0,0x79,0x49,0x49,0x7F,0x0,0x0};
- u8 g10[] = {0x0,0x7F,0x0,0x7F,0x41,0x41,0x7F,0x0};
- void Hc595SendByte(u8 dat);
- void MatrixDisplay(u8 *zimo);
- void delay1s();
- void main(void)
- {
- int i;
- while(1)
- {
- for(i=0;i<999;i++)
- {
- MatrixDisplay(g0);
-
-
- }
-
- for(i=0;i<999;i++)
- {
- MatrixDisplay(g1);
-
- }
-
- for(i=0;i<999;i++)
- {
- MatrixDisplay(g2);
-
- }
-
- for(i=0;i<999;i++)
- {
- MatrixDisplay(g3);
-
- }
-
- for(i=0;i<999;i++)
- {
- MatrixDisplay(g4);
-
- }
-
- for(i=0;i<999;i++)
- {
- MatrixDisplay(g5);
-
- }
-
- for(i=0;i<999;i++)
- {
- MatrixDisplay(g6);
-
- }
-
- for(i=0;i<999;i++)
- {
- MatrixDisplay(g7);
-
- }
-
- for(i=0;i<999;i++)
- {
- MatrixDisplay(g8);
-
- }
-
- for(i=0;i<999;i++)
- {
- MatrixDisplay(g9);
-
- }
-
- for(i=0;i<999;i++)
- {
- MatrixDisplay(g10);
-
- }
-
- }
- }
- void MatrixDisplay(u8 *zimo)
- {
- u8 i = 0;
-
-
- for(i=0;i<8;i++)
- {
- MATRIX_PORT = gLineCode[i];
- Hc595SendByte(zimo[i]);
- Hc595SendByte(0x00);
- }
-
- }
- void Hc595SendByte(u8 dat)
- {
- u8 i = 0, j = 0;
- SCK = 0;
- RCK = 0;
- for (i=0; i<8; i++)
- {
- SER = dat & (0x01);
- dat >>= 1;
- SCK = 1;
-
- SCK = 0;
- }
- RCK = 1;
- }
- void delay1s(void)
- {
- unsigned char a,b,c;
- for(c=167;c>0;c--)
- for(b=171;b>0;b--)
- for(a=16;a>0;a--);
- _nop_();
- }
复制代码
所有资料51hei提供下载:
点阵循环显示.zip
(847 Bytes, 下载次数: 35)
|