要求:用單片機的P0口外接74LS245作為控制8×8 LED點陣屏的行驅(qū)動,列選通由P1端口控制,程序運行時,8×8 LED點陣屏依次循環(huán)顯示數(shù)字0~9。刷新時間由定時器T1的定時中斷來完成。
二、設(shè)計方案:
方案1:74LS245驅(qū)動芯片加上單片機8255和8X8點陣進行設(shè)計。
優(yōu)點:電路相對穩(wěn)定,易實現(xiàn)實驗方案
缺點:連接的線多,切要對74LS245進行了解,寫程序麻煩
方案2:只用單片機8255和8X8點陣來設(shè)計,本次用這個
優(yōu)點;簡單,連線少,程序簡單
缺點:電路沒有方案1的穩(wěn)定
三、理論設(shè)計
軟件流圖
開始
↓
定時器1初始化
↓
主循環(huán)←←←←↑
↓ 無↑ ↑
定時中斷函數(shù)→→有無中斷→→ → ↑ ↑
↓有 ↑
↓ ↑
調(diào)用顯示子函數(shù) ↑
↓→→→→→→↑
原理圖;
時鐘電路和復位電路;
顯示電路;
主要程序段
顯示部分;
signed char code tab[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};//給單片機端口賦值為低電平時燈亮
signed char code digittab[10][8]={{0x00,0x00,0x3e,0x41,0x41,0x41,0x3e,0x00}, //0
{0x00,0x00,0x00,0x00,0x21,0x7f,0x01,0x00}, //1
{0x00,0x00,0x27,0x45,0x45,0x45,0x39,0x00}, //2
{0x00,0x00,0x22,0x49,0x49,0x49,0x36,0x00}, //3
{0x00,0x00,0x0c,0x14,0x24,0x7f,0x04,0x00}, //4
{0x00,0x00,0x72,0x51,0x51,0x51,0x4e,0x00}, //5
{0x00,0x00,0x3e,0x49,0x49,0x49,0x26,0x00}, //6
{0x00,0x00,0x40,0x40,0x40,0x4f,0x70,0x00}, //7
{0x00,0x00,0x36,0x49,0x49,0x49,0x36,0x00}, //8
{0x00,0x00,0x32,0x49,0x49,0x49,0x3e,0x00} //9
};
定時部分:
TMOD=0x10; //設(shè)置定時器1為工作方式1
TH1=(65536-3000)/256;
TL1=(65536-3000)%256;//定時600000us
TR1=1; //啟動定時器1
ET1=1; //開啟定時器1 中斷
|