標(biāo)題: 用單片機(jī)+數(shù)碼管顯示兩位數(shù),但是個(gè)位數(shù)顯示不出來(lái) [打印本頁(yè)]

作者: 157297414    時(shí)間: 2019-1-4 23:02
標(biāo)題: 用單片機(jī)+數(shù)碼管顯示兩位數(shù),但是個(gè)位數(shù)顯示不出來(lái)
用數(shù)碼管顯示兩位數(shù),個(gè)位數(shù)顯示不出來(lái),能幫我看看錯(cuò)在哪里了

程序如下
#include<reg52.h>
#define uint unsigned  int
#define uchar  unsigned char
uchar temp,shi,ge;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71
};
sbit dula=P2^0;
sbit wela=P2^1;
void delay (uint z);

void main()
{   
    temp=25;
    while(1)
    {   
        shi=temp/10;
        ge=temp%10;

        dula=1;
        P0=table[shi];
        dula=0;

        wela=1;
        P0=0xfe;
        wela=0;
        delay(5);

        dula=1;
        P0=table[ge];
        dula=0;

        wela=1;
        P0=0xfd;
        wela=0;
        delay(5);               
    }

}

void delay(uint z)
{   
    uint i,j;
    for(i=z;i>0;i++)
        for(j=110;j>0;j++);
}



作者: wulin    時(shí)間: 2019-1-5 06:54
你的延時(shí)函數(shù)寫錯(cuò)了。死在for循環(huán)里出不來(lái)。另外段碼和位碼公用P0的動(dòng)態(tài)數(shù)碼管顯示要增加消隱語(yǔ)句,否則仿真出亂碼,實(shí)際電路有鬼影。給你改了,你試試。
#include<reg52.h>
#define uint unsigned  int
#define uchar  unsigned char
uchar temp,shi,ge;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71
};
sbit dula=P2^0;
sbit wela=P2^1;
void delay (uint z);

void main()
{   
        temp=25;
        while(1)
        {   
                shi=temp/10;
                ge=temp%10;
               
                dula=1;
                P0=0x00; //消隱
                dula=0;
               
                wela=1;
                P0=0xfe;
                wela=0;
               
                dula=1;
                P0=table[shi];
                dula=0;
                delay(5);
               
               
                dula=1;
                P0=0x00; //消隱
                dula=0;
               
                wela=1;
                P0=0xfd;
                wela=0;
               
                dula=1;
                P0=table[ge];
                dula=0;
                delay(5);
        }
}

void delay(uint z)
{   
    uint i,j;
    for(i=z;i>0;i--)
        for(j=110;j>0;j--);
}

作者: xuxiaochunabcd    時(shí)間: 2019-1-5 07:57
你的U2和U3的D0~D7是不是并一起接在單片機(jī)的P0口上。
作者: giygov    時(shí)間: 2019-1-5 10:06
小兄弟真是個(gè)新手,問(wèn)題不少,首先你while(1)循環(huán)最后加個(gè)break,循環(huán)就跳出了,那你還加while循環(huán)干什么,白白增加程序閱讀難度; 第二,所有程序都是順序執(zhí)行的,加上紅色部分count==0時(shí)應(yīng)該沒(méi)問(wèn)題,因?yàn)橐粋(gè)命令就回到循環(huán)了;為1時(shí)LED=0,然后等Dis2執(zhí)行一遍再循環(huán),應(yīng)該問(wèn)題也不大,雖然不是正常程序?qū)懛ǎ珣?yīng)該滿足你的要求;但為2時(shí)就無(wú)法滿足了,首先執(zhí)行dis1,輸出一個(gè)脈沖后,要去執(zhí)行dis2這時(shí)LED一直是高電平,也就是你dis2執(zhí)行多長(zhǎng)時(shí)間LED就多長(zhǎng)時(shí)間的高電平,然后返回來(lái)繼續(xù),這樣LED和EN兩個(gè)口是交替操作的,當(dāng)然不能滿足你的要求; 第三,你要在switch(count)的程序執(zhí)行完了才能回到上面的按鍵檢測(cè),當(dāng)然要等dis2執(zhí)行完才能檢測(cè)到按鍵。
作者: 157297414    時(shí)間: 2019-1-5 12:48
wulin 發(fā)表于 2019-1-5 06:54
你的延時(shí)函數(shù)寫錯(cuò)了。死在for循環(huán)里出不來(lái)。另外段碼和位碼公用P0的動(dòng)態(tài)數(shù)碼管顯示要增加消隱語(yǔ)句,否則仿 ...

非常感謝
作者: xqt1014    時(shí)間: 2019-1-5 23:21
你的延時(shí)函數(shù)寫錯(cuò)了。死在for循環(huán)里出不來(lái)。仔細(xì)看看




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1