最近在研究单片机驱动16x16点阵,分享一个程序~
关于大家想要显示的图形,可以自行更改uchar code tab1[] ={..}的内容
单片机源程序:
- #include <REG51.H>
- //--重定义函数变量--//
- #define uchar unsigned char
- #define uint unsigned int
- #define ulong unsigned long
- #define GPIO_KEY P1
- //--定义SPI要使用的 IO--//
- sbit MOSIO = P3^4;
- sbit R_CLK = P3^5;
- sbit S_CLK = P3^6;
- //---全局变量声明--//
- ulong column; //点阵列
- ulong row; //点阵行
- ulong dt;
- void Delay10ms(unsigned int c);
- unsigned char Key_Scan();
- //--点阵显示数组--//
- unsigned char code tab0[] =
- {0x00, 0x01, 0x00, 0x02, 0x00, 0x04, 0x00, 0x08,
- 0x00, 0x10, 0x00, 0x20, 0x00, 0x40, 0x00, 0x80,
- 0x01, 0x00, 0x02, 0x00, 0x04, 0x00, 0x08, 0x00,
- 0x10, 0x00, 0x20, 0x00, 0x40, 0x00, 0x80, 0x00};
- uchar code tab1[] ={255,255,1,128,1,128,1,128,1,128,1,128,1,128,1,128,1,128,1,128,1,128,1,128,1,128,1,128,1,128,255,255};
- uchar code tab2[] ={255,255,1,128,253,191,5,160,5,160,5,160,5,160,5,160,5,160,5,160,5,160,5,160,5,160,253,191,1,128,255,255} ;
- uchar code tab3[] = {255,255,1,128,253,191,5,160,245,175,21,168,21,168,21,168,21,168,21,168,21,168,245,175,5,160,253,191,1,128,255,255};
- uchar code tab4[] ={255,255,1,128,253,191,5,160,245,175,21,168,213,171,85,170,85,170,213,171,21,168,245,175,5,160,253,191,1,128,255,255};
- uchar code tab5[] ={0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,1,128,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
- uchar code tab6[] = {0,0,0,0,0,0,0,0,0,0,224,7,32,4,160,5,160,5,32,4,224,7,0,0,0,0,0,0,0,0,0,0};
- uchar code tab7[] = {0,0,0,0,0,0,248,31,8,16,232,23,40,20,168,21,168,21,40,20,232,23,8,16,248,31,0,0,0,0,0,0};
- uchar code tab8[] = {0,0,254,127,2,64,250,95,10,80,234,87,42,84,170,85,170,85,42,84,234,87,10,80,250,95,2,64,254,127,0,0};
- //--全局函数声明--//
- void HC595SendData( uchar BT3, uchar BT2,uchar BT1,uchar BT0);
-
- void main(void)
- {
- int k, i, ms;
- i = 40; //显示时间
- while(1)
- {
- //--显示10--//
- for(ms = i; ms > 0; ms--)
- {
- for(k = 0; k < 16; k++)
- {
- HC595SendData(~tab1[2*k +1],~tab1[2*k],tab0[2*k],tab0[2*k + 1]);
- }
- }
- HC595SendData(0xff,0xff,0,0);
-
- //--显示09--//
- for(ms = i; ms > 0; ms--)
- {
- for(k = 0; k < 16; k++)
- {
- HC595SendData(~tab2[2*k +1],~tab2[2*k],tab0[2*k],tab0[2*k + 1]);
- }
- }
- HC595SendData(0xff,0xff,0,0);
-
- //--显示08--//
- for(ms = i; ms > 0; ms--)
- {
- for(k = 0; k < 16; k++)
- {
- HC595SendData(~tab3[2*k +1],~tab3[2*k],tab0[2*k],tab0[2*k + 1]);
- }
- }
- HC595SendData(0xff,0xff,0,0);
-
- //--显示07--//
- for(ms = i; ms > 0; ms--)
- {
- for(k = 0; k < 16; k++)
- {
- HC595SendData(~tab4[2*k +1],~tab4[2*k],tab0[2*k],tab0[2*k + 1]);
- }
- }
- HC595SendData(0xff,0xff,0,0);
-
- //--显示06--//
- for(ms = i; ms > 0; ms--)
- {
- for(k = 0; k < 16; k++)
- {
- HC595SendData(~tab5[2*k +1],~tab5[2*k],tab0[2*k],tab0[2*k + 1]);
- }
- }
- HC595SendData(0xff,0xff,0,0);
-
- //--显示05--//
- for(ms = i; ms > 0; ms--)
- {
- for(k = 0; k < 16; k++) //欢
- {
- HC595SendData(~tab6[2*k +1],~tab6[2*k],tab0[2*k],tab0[2*k + 1]);
- }
- }
- HC595SendData(0xff,0xff,0,0);
-
- //--显示04--//
- for(ms = i; ms > 0; ms--)
- {
- for(k = 0; k < 16; k++)
- {
- HC595SendData(~tab7[2*k +1],~tab7[2*k],tab0[2*k],tab0[2*k + 1]);
- }
- }
- HC595SendData(0xff,0xff,0,0);
-
- //--显示03--//
- for(ms = i; ms > 0; ms--)
- {
- for(k = 0; k < 16; k++)
- {
- HC595SendData(~tab8[2*k +1],~tab8[2*k],tab0[2*k],tab0[2*k + 1]);
- }
- }
- HC595SendData(0xff,0xff,0,0);
- }
- }
- void HC595SendData( uchar BT3, uchar BT2,uchar BT1,uchar BT0)
- {
- uchar i;
-
- //--发送第一个字节--//
- for(i=0;i<8;i++)
- {
- MOSIO = BT3 >> 7 ; //从高位到低位
- BT3 <<= 1;
- S_CLK = 0;
- S_CLK = 1;
- }
- //--发送第一个字节--//
- for(i=0;i<8;i++)
- {
- MOSIO = BT2 >>7; //从高位到低位
- BT2 <<= 1;
- S_CLK = 0;
- S_CLK = 1;
- }
- //--发送第一个字节--//
- for(i=0;i<8;i++)
- {
- MOSIO = BT1 >> 7; //从高位到低位
- BT1 <<= 1;
- S_CLK = 0;
- S_CLK = 1;
- }
- //--发送第一个字节--//
- for(i=0;i<8;i++)
- {
- MOSIO = BT0 >> 7; //从高位到低位
- BT0 <<= 1;
- S_CLK = 0;
- S_CLK = 1;
- }
-
- //--输出--//
- R_CLK = 0; //set dataline low
- R_CLK = 1; //片选
- R_CLK = 0; //set dataline low
- }
- unsigned char Key_Scan()
- {
- unsigned char keyValue = 0 , i; //????
- //--????1--//
- if (GPIO_KEY != 0xFF) //????K1????
- {
- Delay10ms(1); //????
- if (GPIO_KEY != 0xFF) //??????????
- {
- keyValue = GPIO_KEY;
- i = 0;
- while ((i<50) && (GPIO_KEY != 0xFF)) //????????
- {
- Delay10ms(1);
- i++;
- }
- }
- }
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码
下载:
dianzhen.zip
(1.44 KB, 下载次数: 37)
|