設計目標:1.使用一個七段數碼管,在數碼管上順序顯示0~F,顯示間隔1s。
2.使用8個七段數碼管,穩定顯示自己學號后8位。(已實現循環顯示完整學號)
本案例用到單片機定時器,數碼管等知識。
需要軟件:keil c51 (本機環境 Keil uVision5)
proteus (本機環境 proteus 8.11)
仿真電路圖如下:
pro.png (49.15 KB, 下載次數: 71)
下載附件
2021-2-13 15:02 上傳
需要原件: AT89C51
74LS245 (P0口驅動不了,加245驅動數碼管)
74LS138 (3 8 譯碼器 驅動多段位置信息)
7SEG-MPX8-CC-BLUE
7SEG-MPX1-CC
共陰數碼管段碼和共陽數碼管段碼加起來為FF,如顯示不正常另行計算。因本人區分不來就不誤導人了,程序中led和led8為數碼管斷碼。
驅動程序如下:
- #include <reg51.h>
- #include<stdio.h>
- #define uchar unsigned char
- #define uint unsigned int
- uchar leddata[] = "124F09124847-2020.7";//學號自行修改
- //0x00 滅燈 0x80 點 0x40 橫杠
- uchar led[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f, 0x77,0x7c,0x39, 0x5e,0x79,0x71,0x80,0x40};
- /*0-9 A-F*/
- uchar led8[] = {0xC0,0xf9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90, 0x88,0x83,0xC6,0xA1,0x86,0x8E};
- /*位信息*/
- //uchar wei[] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
- /*138譯碼器位信息*/
- uchar wei[] = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07};
- uint Rank = 0 , charNUm = 0, tem = 0;
- void delay(int t){
- while(t!=0)
- {
- uchar i;
- for(i=124;i>0;i--); //??124*8+10=1002us
- t--;
- }
- }
- //-----------------字符查表----------------------
- void charToNum(uchar strs){
- switch (strs)
- {
- case '0':
- P0 = led[0];
- break;
- case '1':
- P0 = led[1];
- break;
- case '2':
- P0 = led[2];
- break;
- case '3':
- P0 = led[3];
- break;
- case '4':
- P0 = led[4];
- break;
- case '5':
- P0 = led[5];
- break;
- case '6':
- P0 = led[6];
- break;
- case '7':
- P0 = led[7];
- break;
- case '8':
- P0 = led[8];
- break;
- case '9':
- P0 = led[9];
- break;
- case 'A':
- P0 = led[10];
- break;
- case 'B':
- P0 = led[11];
- break;
- case 'C':
- P0 = led[12];
- break;
- case 'D':
- P0 = led[13];
- break;
- case 'E':
- P0 = led[14];
- break;
- case 'F':
- P0 = led[15];
- break;
- case '.':
- P0 = led[16];
- break;
- case '-':
- P0 = led[17];
- break;
- default:
- P0 = 0xff;
- break;
- }
- }
- //-----------------初始化----------------------
- void init(){
- TMOD = 0x01;
- TH0 = (65536-1000)/256;
- TL0 = (65536-1000)%256;
- TR0 = 1;
- ET0 = 1;
- EA = 1;
- P0 = 0x00;
- P3 = 0x00;
- }
- //-----------------單個數碼管顯示----------------------0-F
- void OneledRun(){
- uint s = 0;
- for(;s<16;s++){
- P3 = led[s];
- delay(3000);
- }
- }
- //-----------------TT0----------------------1MS
- void TT0(void) interrupt 1
- {
- P0 = 0x00; //消影
- TH0 = (65536-1000)/256;
- TL0 = (65536-1000)%256;
- P2 = wei[Rank];
- //P0 = led[Rank];
- charToNum(leddata[Rank+charNUm]);
- Rank++;
- tem++;
- if(Rank == 8) { Rank = 0; }
- if(tem == 1000)
- {
- charNUm++;
- if(charNUm == (sizeof(leddata) - 8)) {
- charNUm = 0;
- }
- tem = 0;
- }
- }
- //-----------------主函數----------------------
- void main(){
- init();
- delay(1000);
- while (1)
- {
- OneledRun();
- }
- }
復制代碼 全部資料51hei下載地址:
led8.zip
(83.73 KB, 下載次數: 26)
2021-2-13 15:03 上傳
點擊文件名下載附件
工程文件 下載積分: 黑幣 -5
|