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

QQ登錄

只需一步,快速開(kāi)始

搜索
查看: 3472|回復(fù): 2
打印 上一主題 下一主題
收起左側(cè)

新手求教---數(shù)碼管動(dòng)態(tài)顯示閃爍問(wèn)題

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:88716 發(fā)表于 2015-8-22 11:37 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit we=P2^7;
sbit du=P2^6;
sbit S2=P3^0;
sbit S3=P3^1;
sbit S4=P3^2;
sbit S5=P3^3;
uchar count;
uint timer_count;
uchar code leddata[]={

                0x3F,  //"0"
                0x06,  //"1"
                0x5B,  //"2"
                0x4F,  //"3"
                0x66,  //"4"
                0x6D,  //"5"
                0x7D,  //"6"
                0x07,  //"7"
                0x7F,  //"8"
                0x6F,  //"9"
                0x77,  //"A"
                0x7C,  //"B"
                0x39,  //"C"
                0x5E,  //"D"
                0x79,  //"E"
                0x71,  //"F"
                0x76,  //"H"
                0x38,  //"L"
                0x37,  //"n"
                0x3E,  //"u"
                0x73,  //"P"
                0x5C,  //"o"
                0x40,  //"-"
                0x00,  //熄滅
                0x00  //自定義

                         };
void delay(uint z)
{
        uint x,y;
        for(x = z; x > 0; x--)
                for(y = 114; y > 0 ; y--);
}
void timer_init()
{
        TMOD=0x01;
        TH0=0x4b;
        TL0=0xfd;
        TR0=1;
}
void display(uint i)
{
        char ge,shi,bai,qian;
        qian=i/1000;
        bai=i%1000/100;
        shi=i%1000%100/10;
        ge=i%1000%100%10;

        du=1;
        P0=leddata[qian];
        du=0;
        P0=0xff;
        we=1;
        P0=0xfe;
        we=0;
        delay(1);
        du=1;
        P0=leddata[bai];
        du=0;
        P0=0xff;
        we=1;
        P0=0xfd;
        we=0;
        delay(1);

        du=1;
        P0=leddata[shi];
        du=0;
        P0=0xff;
        we=1;
        P0=0xfb;
        we=0;
        delay(1);

        du=1;
        P0=leddata[ge];
        du=0;
        P0=0xff;
        we=1;
        P0=0xf7;
        we=0;
        delay(1);       
}
void main()
{
        timer_init();
        while(1)
        {
                if(TF0==1)
                {
                        TF0=0;
                        TH0=0x4b;
                        TL0=0xfd;
                        count++;       
                }
                if(count==2)
                {
                        count=0;
                        timer_count++;
                        if(timer_count>=9999)
                        timer_count=0;
                        display(timer_count);
                }
        }
}
這是從0開(kāi)始到9999,每次增加1程序,為什么前三位出現(xiàn)閃爍現(xiàn)象,怎么改延遲時(shí)間都沒(méi)用,求幫忙看看

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩

相關(guān)帖子

回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:79908 發(fā)表于 2015-8-22 19:29 | 只看該作者
本帖最后由 電子愛(ài)好者life 于 2015-8-23 13:08 編輯

void main()
{        
        timer_init();
        while(1)
        {
                display(timer_count);        
        }
}

void timer0() interrupt 1
{
        TH0 = 0x4b;
        TL0 = 0xfd;
        count++;
        if(count==2)
        {                               count = 0;
                timer_count++;
                if(timer_count>=10000)
                {
                        timer_count = 0;
                }
        }
}


你試一試,主函數(shù)里就一個(gè)顯示函數(shù)!

回復(fù)

使用道具 舉報(bào)

板凳
ID:88716 發(fā)表于 2015-8-26 17:39 | 只看該作者
最后我通過(guò)將display(timer_count);拿出IF語(yǔ)句外就解決了呢
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

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

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

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