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

QQ登錄

只需一步,快速開始

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

51單片機(jī)控制兩個(gè)數(shù)碼管動(dòng)態(tài)顯示00,11,22,33,44,55,66,77,88,99循環(huán)

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
#include<reg52.h>
sbit ENLED=P1^4;
sbit ADDR3=P1^3;
sbit ADDR2=P1^2;
sbit ADDR1=P1^1;
sbit ADDR0=P1^0;
unsigned char code LedChar[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E};
void delay_ms(unsigned char cnt)
{
        unsigned char i;
        unsigned char j;
        while(cnt--)
        {
                for(i=0;i<=110;i++);
                for(j=0;j<=110;j++);
}
}
void main()
{
        ENLED=0;
        ADDR3=1;
        while(1)
        {
                unsigned char i;
                ADDR2=0;
                ADDR1=0;
                ADDR0=0;
         {P0=LedChar[i];
                 i++;
                delay_ms(1000);
                 if(i==10)
                 {
                         i=0;
                 }
         }
        { unsigned char j;
                ADDR2=0;
                ADDR1=0;
                ADDR0=1;
         {P0=LedChar[j];
                 j++;
                delay_ms(1000);
                 if(j==10)
                 {
                         j=0;
                 }
         }
}
}
}


但是它確實(shí)兩個(gè)數(shù)碼管之間跳動(dòng)顯示,求解答,修改

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏1 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

沙發(fā)
ID:161164 發(fā)表于 2024-10-5 21:29 | 只看該作者

回復(fù)

使用道具 舉報(bào)

板凳
ID:624769 發(fā)表于 2024-10-5 21:45 | 只看該作者
顯示用定時(shí)器,走數(shù)用主循環(huán)
回復(fù)

使用道具 舉報(bào)

地板
ID:579397 發(fā)表于 2024-10-6 01:27 | 只看該作者
#include<reg52.h>

sbit ADDR0=P1^0;
sbit ADDR1=P1^1;
sbit ADDR2=P1^2;
sbit ADDR3=P1^3;
sbit ENLED=P1^4;
unsigned char code LedChar[17]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E,0xff};

void delay_ms(unsigned char cnt)
        {
                unsigned char i;
                unsigned char j;
                while(cnt--)
                        {
                                for(i=0;i<=110;i++);
                                for(j=0;j<=110;j++);
                        }
        }
       
void main()
        {
                unsigned char i,j;
                ENLED=0;
                while(1)
                        {
                                for(i=0;i<10;i++)                //循環(huán)掃描,修改i可設(shè)置時(shí)長(zhǎng)
                                        {
                                                ADDR0=0;ADDR1=0;ADDR2=0;ADDR3=0;P0=LedChar[17];                //消隱
                                                ADDR0=0;ADDR1=0;ADDR2=0;ADDR3=1;P0=LedChar[j];                //顯示數(shù)字
                                                delay_ms(20);                //動(dòng)態(tài)掃描顯示延時(shí),不能修改
                                                ADDR0=0;ADDR1=0;ADDR2=0;ADDR3=0;P0=LedChar[17];                //消隱
                                                ADDR0=0;ADDR1=0;ADDR2=1;ADDR3=0;P0=LedChar[j];                //顯示數(shù)字                                               
                                                delay_ms(20);                //動(dòng)態(tài)掃描顯示延時(shí),不能修改
                                        }
                                        if(j++==10)        j=0;                //數(shù)字指針累加
                        }
        }
回復(fù)

使用道具 舉報(bào)

5#
ID:1109793 發(fā)表于 2024-10-6 17:57 | 只看該作者
也沒看到電路,ADDR是數(shù)碼管位還是譯碼器的輸入?
看起來兩個(gè)在閃是你延時(shí)太長(zhǎng)了。
代碼有點(diǎn)看不懂,多兩個(gè)大括弧,不知道干啥用的。還有什么時(shí)候KEIL可以在函數(shù)任意位置定義變量了?我都不知道呢。
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

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

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

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