標(biāo)題: 新手求教---數(shù)碼管動(dòng)態(tài)顯示閃爍問(wèn)題 [打印本頁(yè)]

作者: hzb123    時(shí)間: 2015-8-22 11:37
標(biāo)題: 新手求教---數(shù)碼管動(dòng)態(tài)顯示閃爍問(wèn)題
#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開始到9999,每次增加1程序,為什么前三位出現(xiàn)閃爍現(xiàn)象,怎么改延遲時(shí)間都沒(méi)用,求幫忙看看


作者: 電子愛好者life    時(shí)間: 2015-8-22 19:29
本帖最后由 電子愛好者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ù)!


作者: hzb123    時(shí)間: 2015-8-26 17:39
最后我通過(guò)將display(timer_count);拿出IF語(yǔ)句外就解決了呢




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