找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索
查看: 3910|回復(fù): 0
收起左側(cè)

藍(lán)橋杯51單片機(jī)—點(diǎn)亮靜態(tài)數(shù)碼管程序

[復(fù)制鏈接]
ID:889082 發(fā)表于 2021-3-8 15:51 | 顯示全部樓層 |閱讀模式
點(diǎn)亮靜態(tài)數(shù)碼管
1.png
1.74HC138譯碼器
2.png 如圖:  Y4:1 0 0                     Y5: 1 0 1                     Y6: 1 1 0                     Y7: 1 1 1                     當(dāng)輸入為100時(shí),Y4打開,依次類推。
2.數(shù)碼管
要點(diǎn)亮一個(gè)數(shù)碼管,要知道一個(gè)位碼和段碼;(位類似一個(gè)旅店的位置,段類似一個(gè)這個(gè)房間的鑰匙)位碼:想點(diǎn)亮數(shù)碼管的位置端碼:想點(diǎn)亮的內(nèi)容要想點(diǎn)亮一個(gè)數(shù)碼管,要先確定位碼(確定位置),然后在確定斷碼(確定要點(diǎn)亮的內(nèi)容)
段碼
共陽(yáng)數(shù)碼管段碼unsigned char code SEG_CODE[] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
位碼
當(dāng)二進(jìn)制的1在什么位置時(shí),什么位置的數(shù)碼管亮。
代碼#include <REGX52.H>
#include <intrins.H>
unsigned char code sum[18] =
    {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,
     0x80,0x90,0x88,0x80,0xc6,0xc0,0x86,0x8e,
     0xbf,0x7f};                                                            //段選碼
void HC138(unsigned char n);
unsigned char i = 0x01;
int j;
void DisplayShow(unsigned char post , unsigned char show);
void showed();
void main(){
    showed();
}
void HC138(unsigned char n){
    switch(n){
        case 6:
            P2 = (P2 & 0x1f) | 0xc0;
        break;
        case 7:
            P2 = (P2 & 0x1f) | 0xe0;
        break;}
    }

    void DisplayShow(unsigned char post , unsigned char show){
        HC138(6);
        P0 = (0x01 << post);                //位操作
        HC138(7);
        P0 = show;
    }
    void showed(){
    DisplayShow(0,sum[2]);              //第一個(gè)位置顯示“2”
    Delay1000ms();
    }


回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表