1.
用AT89S51单片机的P0.0/AD0-P0.7/AD7端口接数码管的a-h端,8位数码管的S1-S8经过74LS138译码器的Y0-Y7来操控选通每个数码管的位选端。AT89S51单片机的P1.0-P1.2操控74LS138的A,B,C端子。在8位数码管上从右向左循环显现“12345678”。能够比较滑润地看到拉幕的作用。
2.
(1.把“单片机体系”区域中的P0.0/AD0-P0.7/AD7用8芯排线连接到“动态数码显现”区域中的a-h端口上;
(2.把“三八译码模块”区域中的Y0-Y7用8芯排线连接到“动态数码显现”区域中的S1-S8端口上;
(3.把“单片机体系”区域中的P1.0-P1.2端口用3根导线连接到“三八译码模块”区域中的A、B、C“端口上;
4.程序设计办法
(1.动态数码显现技能;怎么进行动态扫描,因为一次只能让一个数码管显现,因而,要显现8位的数据,有必要经过让数码管一个一个轮番显现才能够,一起每个数码管显现的时刻大约在1ms到4ms之间,所以为了确保正确显现,我有必要每隔1ms,就得改写一个数码管。而这改写时刻咱们选用单片机的守时/计数器T0来操控,每守时1ms对数码管改写一次,T0选用方法2。
(2.在进行数码显现的时分,要对显现单元拓荒8个显现缓冲区,每个显现缓冲区装有显现的不同数据即可。
5.程序框图
主程序框图
中止服务程序
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
}
}
}