拉幕式數(shù)碼顯示技術(shù)
1. 實(shí)驗(yàn)任務(wù)
用AT89S51單片機(jī)的P0.0/AD0-P0.7/AD7端口接數(shù)碼管的a-h端,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.電路原理圖
圖4.21.1
3.系統(tǒng)板上硬件連線
(1. 把“單片機(jī)系統(tǒng)”區(qū)域中的P0.0/AD0-P0.7/AD7用8芯排線連接到“動(dòng)態(tài)數(shù)碼顯示”區(qū)域中的a-h端口上;
(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ù)程序
DISPBUF EQU 30H
DISPCNT EQU 38H
DISPBIT EQU 39H
T1CNTA EQU 3AH
T1CNTB EQU 3BH
CNT EQU 3CH
ORG 00H
LJMP START
ORG 0BH
LJMP INT_T0
START: MOV DISPCNT,#8
MOV A,#10
MOV R1,#DISPBUF
LP: MOV @R1,A
INC R1
DJNZ DISPCNT,LP
MOV DISPBIT,#00H
MOV T1CNTA,#00H
MOV T1CNTB,#00H
MOV CNT,#00H
MOV TMOD,#01H
MOV TH0,#(65536-1000) / 256
MOV TL0,#(65536-1000) MOD 256
SETB TR0
SETB ET0
SETB EA
SJMP $
INT_T0:
MOV TH0,#(65536-1000) / 256
MOV TL0,#(65536-1000) MOD 256
MOV A,DISPBIT
ADD A,#DISPBUF
MOV R0,A
MOV A,@R0
MOV DPTR,#TABLE
MOVC A,@A+DPTR
MOV P0,A
MOV A,P1
ANL A,#0F8H
ADD A,DISPBIT
MOV P1,A
INC DISPBIT
MOV A,DISPBIT
CJNE A,#08H,NEXT
MOV DISPBIT,#00H
NEXT: INC T1CNTA
MOV A,T1CNTA
CJNE A,#50,LL1
MOV T1CNTA,#00H
INC T1CNTB
MOV A,T1CNTB
CJNE A,#8,LL1
MOV T1CNTB,#00H
INC CNT
MOV A,CNT
CJNE A,#9,LLX
MOV CNT,#00H
MOV A,CNT
LLX: CJNE A,#01H,NEX1
MOV 30H,#8
LL1: LJMP DONE
NEX1: CJNE A,#02H,NEX2
MOV 31H,#8
MOV 30H,#8
LJMP DONE
NEX2: CJNE A,#03H,NEX3
MOV 32H,#8
MOV 31H,#8
MOV 30H,#8
LJMP DONE
NEX3: CJNE A,#04H,NEX4
MOV 33H,#8
MOV 32H,#8
MOV 31H,#8
MOV 30H,#8
LJMP DONE
NEX4: CJNE A,#05H,NEX5
MOV 34H,#8
MOV 33H,#8
MOV 32H,#8
MOV 31H,#8
MOV 30H,#8
LJMP DONE
NEX5: CJNE A,#06H,NEX6
MOV 35H,#8
MOV 34H,#8
MOV 33H,#8
MOV 32H,#8
MOV 31H,#8
MOV 30H,#8
LJMP DONE
NEX6: CJNE A,#07H,NEX7
MOV 36H,#8
MOV 35H,#8
MOV 34H,#8
MOV 33H,#8
MOV 32H,#8
MOV 31H,#8
MOV 30H,#8
LJMP DONE
NEX7: CJNE A,#08H,NEX8
MOV 37H,#8
MOV 36H,#8
MOV 35H,#8
MOV 34H,#8
MOV 33H,#8
MOV 32H,#8
MOV 31H,#8
MOV 30H,#8
LJMP DONE
NEX8: CJNE A,#00H,DONE
MOV 37H,#10
MOV 36H,#10
MOV 35H,#10
MOV 34H,#10
MOV 33H,#10
MOV 32H,#10
MOV 31H,#10
MOV 30H,#10
LL: LJMP DONE
DONE: RETI
TABLE: DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH,00H
END
7.C語(yǔ)言源程序
#include AT89X51.H>
unsigned char code dispcode[]={0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,0x00};
unsigned char dispbitcode[]={0xf8,0xf9,0xfa,0xfb,
0xfc,0xfd,0xfe,0xff};
unsigned char dispbuf[8]={16,16,16,16,16,16,16,16};
unsigned char dispbitcnt;
unsigned int t02scnt;
unsigned char t5mscnt;
unsigned char u;
unsigned char i;
void main(void)
{
TMOD=0x02;
TH0=0x06;
TL0=0x06;
TR0=1;
ET0=1;
EA=1;
while(1);
}
void t0(void) interrupt 1 using 0
{
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;i8;i++)
{
dispbuf[i]=16;
}
for(i=0;iu;i++)
{
dispbuf[i]=8;
}
}
}
評(píng)論