單片機源程序如下:
- #include<reg51.h>
- #include<intrins.h>
- sbit SRCLK=P3^6;
- sbit RCLK=P3^5;
- sbit SER=P3^4;
- //--定義要使用的IO口--//
- #define COMMONPORTS P0
- //--列選通控制--//
- unsigned char code TAB[8] = {0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe};
- //--點陣字碼--//
- unsigned char code CHARCODE[18][8]=
- {
- {0x00,0x00,0x3e,0x41,0x41,0x41,0x3e,0x00}, //0
- {0x00,0x00,0x00,0x00,0x21,0x7f,0x01,0x00}, //1
- {0x00,0x00,0x27,0x45,0x45,0x45,0x39,0x00}, //2
- {0x00,0x00,0x22,0x49,0x49,0x49,0x36,0x00}, //3
- {0x00,0x00,0x0c,0x14,0x24,0x7f,0x04,0x00}, //4
- {0x00,0x00,0x72,0x51,0x51,0x51,0x4e,0x00}, //5
- {0x00,0x00,0x3e,0x49,0x49,0x49,0x26,0x00}, //6
- {0x00,0x00,0x40,0x40,0x40,0x4f,0x70,0x00}, //7
- {0x00,0x00,0x36,0x49,0x49,0x49,0x36,0x00}, //8
- {0x00,0x00,0x32,0x49,0x49,0x49,0x3e,0x00}, //9
- {0x00,0x00,0x7F,0x48,0x48,0x30,0x00,0x00}, //P
- {0x00,0x00,0x7F,0x48,0x4C,0x73,0x00,0x00}, //R
- {0x00,0x00,0x7F,0x49,0x49,0x49,0x00,0x00}, //E
- {0x00,0x00,0x3E,0x41,0x41,0x62,0x00,0x00}, //C
- {0x00,0x00,0x7F,0x08,0x08,0x7F,0x00,0x00}, //H
- {0x00,0x00,0x00,0xFF,0xFF,0x00,0x00,0x00}, //I
- {0x00,0x7F,0x10,0x08,0x04,0x7F,0x00,0x00}, //N
- {0x7C,0x48,0x48,0xFF,0x48,0x48,0x7C,0x00} //中
- };
- void delay(unsigned int time)
- {
- unsigned int i,j;
- for(i=0;i<time;i++)
- for(j=0;j<121;j++);
- }
- /*******************************************************************************
- * 函數名 : Hc595SendByte(unsigned char dat)
- * 函數功能 : 想74H595發送一個字節的數據
- * 輸入 : 無
- * 輸出 : 無
- *******************************************************************************/
- void Hc595SendByte(unsigned char dat)
- {
- unsigned char a;
- SRCLK=0;
- RCLK=0;
- for(a=0;a<8;a++)
- {
- SER=dat>>7;
- dat<<=1;
- SRCLK=1;
- _nop_();
- _nop_();
- SRCLK=0;
- }
- RCLK=1;
- _nop_();
- _nop_();
- RCLK=0;
- }
- /*******************************************************************************
- * 函數名 : main
- * 函數功能 : 主函數
- * 輸入 : 無
- * 輸出 : 無
- *******************************************************************************/
- void main()
- {
- unsigned char tab, j;
- unsigned int i;
- while(1)
- {
- for(i= 0; i<50; i++ ) //兩個字之間的掃描間隔時間
- {
- for(tab=0;tab<8;tab++)
- {
- Hc595SendByte(0x00); //消隱
- COMMONPORTS = TAB[tab]; //輸出字碼
- Hc595SendByte(CHARCODE[j][tab]);
- delay(2);
- }
-
- }
- j++;
- if(j == 18)
- {
- j = 0;
- }
- }
- }
復制代碼
所有資料51hei提供下載:
LED點陣顯示數字.zip
(8.08 KB, 下載次數: 9)
2018-4-1 12:28 上傳
點擊文件名下載附件
led點陣顯示數字
|