17. 99秒馬表設(shè)計(jì)
(1.開始時(shí),顯示“00”,第1次按下SP1后就開始計(jì)時(shí)。
(2.第2次按SP1后,計(jì)時(shí)停止。
(3.第3次按SP1后,計(jì)時(shí)歸零。
2.
(1.把“單片機(jī)系統(tǒng)”區(qū)域中的P0.0/AD0-P0.7/AD7端口用8芯排線連接到“四路靜態(tài)數(shù)碼顯示模塊”區(qū)域中的任一個(gè)a-h(huán)端口上;要求:P0.0/AD0對應(yīng)著a,P0.1/AD1對應(yīng)著b,……,P0.7/AD7對應(yīng)著h。
(2.把“單片機(jī)系統(tǒng)”區(qū)域中的P2.0/A8-P2.7/A15端口用8芯排線連接到“四路靜態(tài)數(shù)碼顯示模塊”區(qū)域中的任一個(gè)a-h(huán)端口上;要求:P2.0/A8對應(yīng)著a,P2.1/A9對應(yīng)著b,……,P2.7/A15對應(yīng)著h。
(3.把“單片機(jī)系統(tǒng)“區(qū)域中的P3.5/T1用導(dǎo)線連接到”獨(dú)立式鍵盤“區(qū)域中的SP1端口上;
4.
T0中斷服務(wù)程序框
TCNTAEQU30H
TCNTBEQU31H
SECEQU32H
KEYCNTEQU33H
SP1BITP3.5
ORG00H
LJMPSTART
ORG0BH
LJMPINT_T0
START:MOVKEYCNT,#00H
MOVSEC,#00H
MOVA,SEC
MOVB,#10
DIVAB
MOVDPTR,#TABLE
MOVCA,@A+DPTR
MOVP0,A
MOVA,B
MOVDPTR,#TABLE
MOVCA,@A+DPTR
MOVP2,A
MOVTMOD,#02H
SETBET0
SETBEA
WT:JBSP1,WT
LCALLDELY10MS
JBSP1,WT
INCKEYCNT
MOVA,KEYCNT
CJNEA,#01H,KN1
SETBTR0
MOVTH0,#06H
MOVTL0,#06H
MOVTCNTA,#00H
MOVTCNTB,#00H
LJMPDKN
KN1:CJNEA,#02H,KN2
CLRTR0
LJMPDKN
KN2:CJNEA,#03H,DKN
MOVSEC,#00H
MOVA,SEC
MOVB,#10
DIVAB
MOVDPTR,#TABLE
MOVCA,@A+DPTR
MOVP0,A
MOVA,B
MOVDPTR,#TABLE
MOVCA,@A+DPTR
MOVP2,A
MOVKEYCNT,#00H
DKN:JNBSP1,$
LJMPWT
DELY10MS:
MOVR6,#20
D1:MOVR7,#248
DJNZR7,$
DJNZR6,D1
RET
INT_T0:
INCTCNTA
MOVA,TCNTA
CJNEA,#100,NEXT
MOVTCNTA,#00H
INCTCNTB
MOVA,TCNTB
CJNEA,#4,NEXT
MOVTCNTB,#00H
INCSEC
MOVA,SEC
CJNEA,#100,DONE
MOVSEC,#00H
DONE:MOVA,SEC
MOVB,#10
DIVAB
MOVDPTR,#TABLE
MOVCA,@A+DPTR
MOVP0,A
MOVA,B
MOVDPTR,#TABLE
MOVCA,@A+DPTR
MOVP2,A
NEXT:RETI
TABLE:DB3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH
END
6.
#include
unsignedcharcodedispcode[]={0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,0x00};
unsignedcharsecond;
unsignedcharkeycnt;
unsignedinttcnt;
voidmain(void)
{
unsignedchari,j;
TMOD=0x02;
ET0=1;
EA=1;
second=0;
P0=dispcode[second/10];
P2=dispcode[second%10];
while(1)
{
if(P3_5==0)
{
for(i=20;i>0;i--)
for(j=248;j>0;j--);
if(P3_5==0)
{
keycnt++;
switch(keycnt)
{
case1:
TH0=0x06;
TL0=0x06;
TR0=1;
break;
case2:
TR0=0;
break;
case3:
keycnt=0;
second=0;
P0=dispcode[second/10];
P2=dispcode[second%10];
break;
}
while(P3_5==0);
}
}
}
}
voidt0(void)interrupt1using0
{
tcnt++;
if(tcnt==400)
{
tcnt=0;
second++;
if(second==100)
{
second=0;
}
P0=dispcode[second/10];
P2=dispcode[second%10];
}
}
評(píng)論