99秒馬表設(shè)計(jì)
(1. 開(kāi)始時(shí),顯示“00”,第1次按下SP1后就開(kāi)始計(jì)時(shí)。
(2. 第2次按SP1后,計(jì)時(shí)停止。
(3. 第3次按SP1后,計(jì)時(shí)歸零。
2. 電路原理圖
圖4.17.1
3. 系統(tǒng)板上硬件連線
(1. 把“單片機(jī)系統(tǒng)”區(qū)域中的P0.0/AD0-P0.7/AD7端口用8芯排線連接到“四路靜態(tài)數(shù)碼顯示模塊”區(qū)域中的任一個(gè)a-h端口上;要求:P0.0/AD0對(duì)應(yīng)著a,P0.1/AD1對(duì)應(yīng)著b,……,P0.7/AD7對(duì)應(yīng)著h。
(2. 把“單片機(jī)系統(tǒng)”區(qū)域中的P2.0/A8-P2.7/A15端口用8芯排線連接到“四路靜態(tài)數(shù)碼顯示模塊”區(qū)域中的任一個(gè)a-h端口上;要求:P2.0/A8對(duì)應(yīng)著a,P2.1/A9對(duì)應(yīng)著b,……,P2.7/A15對(duì)應(yīng)著h。
(3. 把“單片機(jī)系統(tǒng)“區(qū)域中的P3.5/T1用導(dǎo)線連接到”獨(dú)立式鍵盤(pán)“區(qū)域中的SP1端口上;
4. 程序框
T0中斷服務(wù)程序框
圖4.17.2
5. 匯編源程序
TCNTA EQU 30H
TCNTB EQU 31H
SEC EQU 32H
KEYCNT EQU 33H
SP1 BIT P3.5
ORG 00H
LJMP START
ORG 0BH
LJMP INT_T0
START: MOV KEYCNT,#00H
MOV SEC,#00H
MOV A,SEC
MOV B,#10
DIV AB
MOV DPTR,#TABLE
MOVC A,@A+DPTR
MOV P0,A
MOV A,B
MOV DPTR,#TABLE
MOVC A,@A+DPTR
MOV P2,A
MOV TMOD,#02H
SETB ET0
SETB EA
WT: JB SP1,WT
LCALL DELY10MS
JB SP1,WT
INC KEYCNT
MOV A,KEYCNT
CJNE A,#01H,KN1
SETB TR0
MOV TH0,#06H
MOV TL0,#06H
MOV TCNTA,#00H
MOV TCNTB,#00H
LJMP DKN
KN1: CJNE A,#02H,KN2
CLR TR0
LJMP DKN
KN2: CJNE A,#03H,DKN
MOV SEC,#00H
MOV A,SEC
MOV B,#10
DIV AB
MOV DPTR,#TABLE
MOVC A,@A+DPTR
MOV P0,A
MOV A,B
MOV DPTR,#TABLE
MOVC A,@A+DPTR
MOV P2,A
MOV KEYCNT,#00H
DKN: JNB SP1,$
LJMP WT
DELY10MS:
MOV R6,#20
D1: MOV R7,#248
DJNZ R7,$
DJNZ R6,D1
RET
INT_T0:
INC TCNTA
MOV A,TCNTA
CJNE A,#100,NEXT
MOV TCNTA,#00H
INC TCNTB
MOV A,TCNTB
CJNE A,#4,NEXT
MOV TCNTB,#00H
INC SEC
MOV A,SEC
CJNE A,#100,DONE
MOV SEC,#00H
DONE: MOV A,SEC
MOV B,#10
DIV AB
MOV DPTR,#TABLE
MOVC A,@A+DPTR
MOV P0,A
MOV A,B
MOV DPTR,#TABLE
MOVC A,@A+DPTR
MOV P2,A
NEXT: RETI
TABLE: DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH
END
6. 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 second;
unsigned char keycnt;
unsigned int tcnt;
void main(void)
{
unsigned char i,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)
{
case 1:
TH0=0x06;
TL0=0x06;
TR0=1;
break;
case 2:
TR0=0;
break;
case 3:
keycnt=0;
second=0;
P0=dispcode[second/10];
P2=dispcode[second%10];
break;
}
while(P3_5==0);
}
}
}
}
void t0(void) interrupt 1 using 0
{
tcnt++;
if(tcnt==400)
{
tcnt=0;
second++;
if(second==100)
{
second=0;
}
P0=dispcode[second/10];
P2=dispcode[second%10];
}
}
評(píng)論