21. 拉幕式數(shù)碼顯示技術(shù)
用AT89S51單片機(jī)的P0.0/AD0-P0.7/AD7端口接數(shù)碼管的a-h(huán)端,8位數(shù)碼管的S1-S8通過74LS138譯碼器的Y0-Y7來控制選通每個(gè)數(shù)碼管的位選端。AT89S51單片機(jī)的P1.0-P1.2控制74LS138的A,B,C端子。在8位數(shù)碼管上從右向左循環(huán)顯示“12345678”。能夠比較平滑地看到拉幕的效果。
2.
(1.把“單片機(jī)系統(tǒng)”區(qū)域中的P0.0/AD0-P0.7/AD7用8芯排線連接到“動(dòng)態(tài)數(shù)碼顯示”區(qū)域中的a-h(huán)端口上;
(2.把“三八譯碼模塊”區(qū)域中的Y0-Y7用8芯排線連接到“動(dòng)態(tài)數(shù)碼顯示”區(qū)域中的S1-S8端口上;
(3.把“單片機(jī)系統(tǒng)”區(qū)域中的P1.0-P1.2端口用3根導(dǎo)線連接到“三八譯碼模塊”區(qū)域中的A、B、C“端口上;
4.程序設(shè)計(jì)方法
(1.動(dòng)態(tài)數(shù)碼顯示技術(shù);如何進(jìn)行動(dòng)態(tài)掃描,由于一次只能讓一個(gè)數(shù)碼管顯示,因此,要顯示8位的數(shù)據(jù),必須經(jīng)過讓數(shù)碼管一個(gè)一個(gè)輪流顯示才可以,同時(shí)每個(gè)數(shù)碼管顯示的時(shí)間大約在1ms到4ms之間,所以為了保證正確顯示,我必須每隔1ms,就得刷新一個(gè)數(shù)碼管。而這刷新時(shí)間我們采用單片機(jī)的定時(shí)/計(jì)數(shù)器T0來控制,每定時(shí)1ms對(duì)數(shù)碼管刷新一次,T0采用方式2。
(2.在進(jìn)行數(shù)碼顯示的時(shí)候,要對(duì)顯示單元開辟8個(gè)顯示緩沖區(qū),每個(gè)顯示緩沖區(qū)裝有顯示的不同數(shù)據(jù)即可。
5.程序框圖
主程序框圖
中斷服務(wù)程序
6.匯編源程序
DISPBUFEQU30H
DISPCNTEQU38H
DISPBITEQU39H
T1CNTAEQU3AH
T1CNTBEQU3BH
CNTEQU3CH
ORG00H
LJMPSTART
ORG0BH
LJMPINT_T0
START:MOVDISPCNT,#8
MOVA,#10
MOVR1,#DISPBUF
LP:MOV@R1,A
INCR1
DJNZDISPCNT,LP
MOVDISPBIT,#00H
MOVT1CNTA,#00H
MOVT1CNTB,#00H
MOVCNT,#00H
MOVTMOD,#01H
MOVTH0,#(65536-1000)/256
MOVTL0,#(65536-1000)MOD256
SETBTR0
SETBET0
SETBEA
SJMP$
INT_T0:
MOVTH0,#(65536-1000)/256
MOVTL0,#(65536-1000)MOD256
MOVA,DISPBIT
ADDA,#DISPBUF
MOVR0,A
MOVA,@R0
MOVDPTR,#TABLE
MOVCA,@A+DPTR
MOVP0,A
MOVA,P1
ANLA,#0F8H
ADDA,DISPBIT
MOVP1,A
INCDISPBIT
MOVA,DISPBIT
CJNEA,#08H,NEXT
MOVDISPBIT,#00H
NEXT:INCT1CNTA
MOVA,T1CNTA
CJNEA,#50,LL1
MOVT1CNTA,#00H
INCT1CNTB
MOVA,T1CNTB
CJNEA,#8,LL1
MOVT1CNTB,#00H
INCCNT
MOVA,CNT
CJNEA,#9,LLX
MOVCNT,#00H
MOVA,CNT
LLX:CJNEA,#01H,NEX1
MOV30H,#8
LL1:LJMPDONE
NEX1:CJNEA,#02H,NEX2
MOV31H,#8
MOV30H,#8
LJMPDONE
NEX2:CJNEA,#03H,NEX3
MOV32H,#8
MOV31H,#8
MOV30H,#8
LJMPDONE
NEX3:CJNEA,#04H,NEX4
MOV33H,#8
MOV32H,#8
MOV31H,#8
MOV30H,#8
LJMPDONE
NEX4:CJNEA,#05H,NEX5
MOV34H,#8
MOV33H,#8
MOV32H,#8
MOV31H,#8
MOV30H,#8
LJMPDONE
NEX5:CJNEA,#06H,NEX6
MOV35H,#8
MOV34H,#8
MOV33H,#8
MOV32H,#8
MOV31H,#8
MOV30H,#8
LJMPDONE
NEX6:CJNEA,#07H,NEX7
MOV36H,#8
MOV35H,#8
MOV34H,#8
MOV33H,#8
MOV32H,#8
MOV31H,#8
MOV30H,#8
LJMPDONE
NEX7:CJNEA,#08H,NEX8
MOV37H,#8
MOV36H,#8
MOV35H,#8
MOV34H,#8
MOV33H,#8
MOV32H,#8
MOV31H,#8
MOV30H,#8
LJMPDONE
NEX8:CJNEA,#00H,DONE
MOV37H,#10
MOV36H,#10
MOV35H,#10
MOV34H,#10
MOV33H,#10
MOV32H,#10
MOV31H,#10
MOV30H,#10
LL:LJMPDONE
DONE:RETI
TABLE:DB3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH,00H
END
7.C語言源程序
#include
unsignedcharcodedispcode[]={0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,0x00};
unsignedchardispbitcode[]={0xf8,0xf9,0xfa,0xfb,
0xfc,0xfd,0xfe,0xff};
unsignedchardispbuf[8]={16,16,16,16,16,16,16,16};
unsignedchardispbitcnt;
unsignedintt02scnt;
unsignedchart5mscnt;
unsignedcharu;
unsignedchari;
voidmain(void)
{
TMOD=0x02;
TH0=0x06;
TL0=0x06;
TR0=1;
ET0=1;
EA=1;
while(1);
}
voidt0(void)interrupt1using0
{
t5mscnt++;
if(t5mscnt==4)
{
t5mscnt=0;
P0=dispcode[dispbuf[dispbitcnt]];
P1=dispbitcode[dispbitcnt];
dispbitcnt++;
if(dispbitcnt==8)
{
dispbitcnt=0;
}
}
t02scnt++;
if(t02scnt==1600)
{
t02scnt=0;
u++;
if(u==9)
{
u=0;
}
for(i=0;i<8;i++)
{
dispbuf
}
for(i=0;i{
dispbuf
}
}
}
評(píng)論