51單片機(jī)做的16X16點(diǎn)陣仿真的2個(gè)例子,一個(gè)是顯示 漢字 一個(gè)是倒計(jì)時(shí),,詳見壓縮包里面的2個(gè)程序.用74hc595來(lái)驅(qū)動(dòng)16*16點(diǎn)陣.
全部資料下載:
16點(diǎn)陣顯示.rar
(162.43 KB, 下載次數(shù): 67)
下面是16X16點(diǎn)陣上面實(shí)現(xiàn)倒計(jì)時(shí)的單片機(jī)程序:
- /*****************************************************************************************
- * *
- * LED點(diǎn)陣實(shí)驗(yàn) (顯示數(shù)字) *
- 行:高電平有效,,低16位 列:低電平有效,高16位
- ******************************************************************************************/
- #include <REG51.H>
- #include <intrins.h>
- #define NOP() _nop_() // 定義空指令 ,這個(gè)函數(shù)在庫(kù) <intrins.h> 中
- //SPI IO
- sbit MOSIO = P3^4;
- sbit R_CLK = P3^5;
- sbit S_CLK = P3^6;
- //變量聲明
- unsigned long column; //點(diǎn)陣列
- unsigned long row; //點(diǎn)陣行
- unsigned long dt;
- //點(diǎn)陣顯示數(shù)組
- 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};
- unsigned char code tab1[] = {0,0,0,0,0,0,8,24,14,36,8,66,8,66,8,66,8,66,8,66,8,66,8,36,62,24,0,0,0,0,0,0};
- unsigned char code tab2[] = {0,0,0,0,0,0,24,24,36,36,66,66,66,66,66,66,66,100,66,88,66,64,66,64,36,36,24,28,0,0,0,0} ;
- unsigned char code tab3[] = {0,0,0,0,0,0,24,60,36,66,66,66,66,66,66,36,66,24,66,36,66,66,66,66,36,66,24,60,0,0,0,0};
- unsigned char code tab4[] = {0,0,0,0,0,0,24,126,36,34,66,34,66,16,66,16,66,8,66,8,66,8,66,8,36,8,24,8,0,0,0,0};
- unsigned char code tab5[] = {0,0,0,0,0,0,24,56,36,36,66,2,66,2,66,26,66,38,66,66,66,66,66,66,36,36,24,24,0,0,0,0};
- unsigned char code tab6[] = {0,0,0,0,0,0,24,126,36,2,66,2,66,2,66,26,66,38,66,64,66,64,66,66,36,34,24,28,0,0,0,0};
- unsigned char code tab7[] = {0,0,0,0,0,0,24,32,36,48,66,40,66,36,66,36,66,34,66,34,66,126,66,32,36,32,24,120,0,0,0,0};
- unsigned char code tab8[] = {0,0,0,0,0,0,24,60,36,66,66,66,66,32,66,24,66,32,66,64,66,64,66,66,36,34,24,28,0,0,0,0};
- unsigned char code tab9[] = {0,0,0,0,0,0,24,60,36,66,66,66,66,66,66,32,66,32,66,16,66,8,66,4,36,66,24,126,0,0,0,0};
- unsigned char code tab10[] = {0,0,0,0,0,0,24,8,36,14,66,8,66,8,66,8,66,8,66,8,66,8,66,8,36,8,24,62,0,0,0,0};
- unsigned char code tab11[] = {0,0,0,0,0,0,24,24,36,36,66,66,66,66,66,66,66,66,66,66,66,66,66,66,36,36,24,24,0,0,0,0};
- unsigned char code tab12[] = {0,0,0,0,0,0,60,28,34,34,34,65,1,65,1,65,1,65,113,65,33,65,34,65,34,34,28,28,0,0,0,0};
- //函數(shù)聲明
- void HC595SendData( unsigned char BT3, unsigned char BT2,unsigned char BT1,unsigned char BT0);
-
- /*************主函數(shù)*****************************/
- void main(void)
- {
- int k,i,ms;
- i = 16; //顯示時(shí)間
- while(1)
- {
- 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); //清屏
- 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); //清屏
- 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); //清屏
- 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); //清屏
- 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); //清屏
- 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); //清屏
- 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); //清屏
- 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); //清屏
- for(ms = i; ms > 0; ms--)
- {
- for(k = 0; k < 16; k++) //用
- {
- HC595SendData(~tab9[2*k +1],~tab9[2*k],tab0[2*k],tab0[2*k + 1]);
- }
- }
- HC595SendData(0xff,0xff,0,0); //清屏
- for(ms = i; ms > 0; ms--)
- {
- for(k = 0; k < 16; k++) //普
- {
- HC595SendData(~tab10[2*k +1],~tab10[2*k],tab0[2*k],tab0[2*k + 1]);
- }
- }
- HC595SendData(0xff,0xff,0,0); //清屏
- for(ms = i; ms > 0; ms--)
- {
- for(k = 0; k < 16; k++) //中
- {
- HC595SendData(~tab11[2*k +1],~tab11[2*k],tab0[2*k],tab0[2*k + 1]);
- }
- }
- HC595SendData(0xff,0xff,0,0); //清屏
-
- while(1)
- {
- for(ms = i; ms > 0; ms--)
- {
- for(k = 0; k < 16; k++) //中
- {
- HC595SendData(~tab12[2*k +1],~tab12[2*k],tab0[2*k],tab0[2*k + 1]);
- }
- }
- for(ms = i; ms > 0; ms--)
- {
- for(k = 0; k < 16; k++) //中
- {
- HC595SendData(0xff,0xff,0,0);
- }
- }
- } //清屏
- }
- }
- /*********************************************************************************************************
- ** 函數(shù)名稱: HC595SendData
- ** 功能描述: 向SPI總線發(fā)送數(shù)據(jù)
- *********************************************************************************************************/
- void HC595SendData( unsigned char BT3, unsigned char BT2,unsigned char BT1,unsigned char BT0)
- {
- unsigned char i;
- for(i = 0; i < 32; i++)
- {
- if(i > 23 )
- {
- if((BT0 << (i - 24)) & 0x80)
- {
- MOSIO = 1;
- }
- else
- {
- MOSIO = 0;
- }
- }
-
- else if(i > 15 & i < 24 )
- {
- if((BT1 << (i - 16)) & 0x80) //set dataline high 0X80000000 最高位與SendVal左移的最高位 進(jìn)行邏輯運(yùn)算
- {
- MOSIO = 1; // 如果為真 MOSIO = 1
- }
- else
- {
- MOSIO = 0;
- }
- }
- else if(i < 16 & i > 7 )
- {
- if((BT2 << (i - 8)) & 0x80)
- {
- MOSIO = 1;
- }
- else
- {
- MOSIO = 0;
- }
- }
-
- else
- {
- if((BT3 << i) & 0x80) //set dataline high 0X80000000 最高位與SendVal左移的最高位 進(jìn)行邏輯運(yùn)算
- {
- MOSIO = 1; // 如果為真 MOSIO = 1
- }
- else
- {
- MOSIO = 0;
- }
- }
- S_CLK = 0;
- // NOP(); //產(chǎn)生方形波
- S_CLK = 1;
- }
-
- R_CLK = 0; //set dataline low
- // NOP(); //產(chǎn)生方形波
- R_CLK = 1; //片選
- }
復(fù)制代碼
下面是顯示漢字的程序:
- /*****************************************************************************************
- * *
- * LED點(diǎn)陣實(shí)驗(yàn) (顯示數(shù)字) *
- 行:高電平有效,,低16位 列:低電平有效,高16位
- ******************************************************************************************/
- #include <REG51.H>
- #include <intrins.h>
- #define NOP() _nop_() // 定義空指令 ,,這個(gè)函數(shù)在庫(kù) <intrins.h> 中
- //SPI IO
- sbit MOSIO = P3^4;
- sbit R_CLK = P3^5;
- sbit S_CLK = P3^6;
- //變量聲明
- unsigned long column; //點(diǎn)陣列
- unsigned long row; //點(diǎn)陣行
- unsigned long dt;
- //點(diǎn)陣顯示數(shù)組
- 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};
- unsigned char code tab1[] = {96,2,28,10,16,18,16,2,254,63,16,2,16,18,112,18,24,10,22,10,16,36,16,42,16,49,156,32,0,0,0,0};
- unsigned char code tab2[] = {0,30,252,9,72,8,144,4,254,63,66,32,252,31,32,0,240,15,80,4,136,2,4,1,194,6,56,56,0,0,0,0};
- unsigned char code tab3[] = {144,0,144,0,208,63,72,32,40,16,12,2,10,2,136,10,136,18,72,18,72,34,40,34,8,2,136,3,0,0,0,0};
- unsigned char code tab4[] = {0,0,0,0,60,240,102,156,67,130,0,0,0,0,0,0,0,0,0,0,48,24,96,8,192,7,0,0,0,0,0,0};
- //函數(shù)聲明
- void HC595SendData( unsigned char BT3, unsigned char BT2,unsigned char BT1,unsigned char BT0);
-
- /*************主函數(shù)*****************************/
- void main(void)
- {
- int k,i,ms;
- i = 16; //顯示時(shí)間
- while(1)
- {
- 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); //清屏
- 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); //清屏
- 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); //清屏
-
- for(ms = 30; 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);
- }
- }
- /*********************************************************************************************************
- ** 函數(shù)名稱: HC595SendData
- ** 功能描述: 向SPI總線發(fā)送數(shù)據(jù)
- *********************************************************************************************************/
- void HC595SendData( unsigned char BT3, unsigned char BT2,unsigned char BT1,unsigned char BT0)
- {
- unsigned char i;
- for(i = 0; i < 32; i++)
- {
- if(i > 23 )
- {
- if((BT0 << (i - 24)) & 0x80)
- {
- MOSIO = 1;
- }
- else
- {
- MOSIO = 0;
- }
- }
-
- else if(i > 15 & i < 24 )
- {
- if((BT1 << (i - 16)) & 0x80) //set dataline high 0X80000000 最高位與SendVal左移的最高位 進(jìn)行邏輯運(yùn)算
- {
- MOSIO = 1; // 如果為真 MOSIO = 1
- }
- else
- {
- MOSIO = 0;
- }
- }
- else if(i < 16 & i > 7 )
- {
- if((BT2 << (i - 8)) & 0x80)
- {
- MOSIO = 1;
- }
- else
- {
- MOSIO = 0;
- }
- }
-
- else
- {
- if((BT3 << i) & 0x80) //set dataline high 0X80000000 最高位與SendVal左移的最高位 進(jìn)行邏輯運(yùn)算
- {
- MOSIO = 1; // 如果為真 MOSIO = 1
- }
- else
- {
- MOSIO = 0;
- }
- }
- S_CLK = 0;
- // NOP(); //產(chǎn)生方形波
- S_CLK = 1;
- }
-
- R_CLK = 0; //set dataline low
- // NOP(); //產(chǎn)生方形波
- R_CLK = 1; //片選
- }
復(fù)制代碼
|