找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1972|回復: 3
打印 上一主題 下一主題
收起左側(cè)

AT89C2051單片機和74HC138控制64位LED燈 程序電路圖

[復制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:1133433 發(fā)表于 2024-11-5 10:34 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式
#include <reg2051.h>

void delay(unsigned int cnt)
{
  unsigned  int i;
        while(cnt--)
        {
                for(i = 0;i < 227;i++);
        }
}


void main()
{
                P1=0x01; //001
                P3=0x00;        
                delay(50);
                P3=0x01;
                delay(50);
                P3=0x02;        
                delay(50);
                P3=0x03;
                delay(50);
                P3=0x04;        
                delay(50);
                P3=0x05;
                delay(50);
                P3=0x06;        
                delay(50);
                P3=0x07;
                delay(50);

                P1=0x02; //10
                P3=0x00;        
                delay(50);
                P3=0x01;
                delay(50);
                P3=0x02;        
                delay(50);
                P3=0x03;
                delay(50);
                P3=0x04;        
                delay(50);
                P3=0x05;
                delay(50);
                P3=0x06;        
                delay(50);
                P3=0x07;
                delay(50);
               
                P1=0x04; //100
                P3=0x00;        
                delay(50);
                P3=0x01;
                delay(50);
                P3=0x02;        
                delay(50);
                P3=0x03;
                delay(50);
                P3=0x04;        
                delay(50);
                P3=0x05;
                delay(50);
                P3=0x06;        
                delay(50);
                P3=0x07;
                delay(50);

                P1=0x08; //1000
                P3=0x00;        
                delay(50);
                P3=0x01;
                delay(50);
                P3=0x02;        
                delay(50);
                P3=0x03;
                delay(50);
                P3=0x04;        
                delay(50);
                P3=0x05;
                delay(50);
                P3=0x06;        
                delay(50);
                P3=0x07;
                delay(50);
               
                P1=0x10; //1 0000
                P3=0x00;        
                delay(50);
                P3=0x01;
                delay(50);
                P3=0x02;        
                delay(50);
                P3=0x03;
                delay(50);
                P3=0x04;        
                delay(50);
                P3=0x05;
                delay(50);
                P3=0x06;        
                delay(50);
                P3=0x07;
                delay(50);

                P1=0x020; //10 0000
                P3=0x00;        
                delay(50);
                P3=0x01;
                delay(50);
                P3=0x02;        
                delay(50);
                P3=0x03;
                delay(50);
                P3=0x04;        
                delay(50);
                P3=0x05;
                delay(50);
                P3=0x06;        
                delay(50);
                P3=0x07;
                delay(50);
               
                P1=0x040; //100 0000
                P3=0x00;        
                delay(50);
                P3=0x01;
                delay(50);
                P3=0x02;        
                delay(50);
                P3=0x03;
                delay(50);
                P3=0x04;        
                delay(50);
                P3=0x05;
                delay(50);
                P3=0x06;        
                delay(50);
                P3=0x07;
                delay(50);
               
                P1=0x080; //1000 0000
                P3=0x00;        
                delay(50);
                P3=0x01;
                delay(50);
                P3=0x02;        
                delay(50);
                P3=0x03;
                delay(50);
                P3=0x04;        
                delay(50);
                P3=0x05;
                delay(50);
                P3=0x06;        
                delay(50);
                P3=0x07;
                delay(50);
}

AT89C2051和74HC138控制64位LED燈.png (76.38 KB, 下載次數(shù): 0)

AT89C2051和74HC138控制64位LED燈.png

評分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

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

使用道具 舉報

沙發(fā)
ID:468878 發(fā)表于 2024-11-18 10:17 | 只看該作者
看到樓主的代碼,讓我陷入深深的回憶當中——當年寫匯編代碼應該就是這樣的風格,你是不是還沒扭轉(zhuǎn)過來
回復

使用道具 舉報

板凳
ID:102963 發(fā)表于 2024-12-27 07:28 | 只看該作者
這程序?qū)懙奶L了,可以優(yōu)化下。搞個數(shù)組,然后for循環(huán)調(diào)用,很短的程序應該就能搞定。
回復

使用道具 舉報

地板
ID:1133433 發(fā)表于 2025-3-5 14:27 | 只看該作者
謝謝songxia8013提醒,現(xiàn)在修改如下:

#include <reg2051.h>

const unsigned char P1_arry[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};
const unsigned char P3_arry[8]={0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07};

void delay(unsigned int cnt)
{
  unsigned  int i;
        while(cnt--)
        {
                for(i = 0;i < 227;i++);
        }
}


void main()
{
         
         unsigned char i, j;

        while(1)
        {
                for(i=0;i<8;i++)
                {
                        P1 = P1_arry[ i];
                        for(j=0;j<8;j++)
                        {
                                P3 = P3_arry[j];
                                delay(200);
                        }                       
                }
        }       
}
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

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

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

快速回復 返回頂部 返回列表