20. 數(shù)字鐘﹝★﹞
(1.開機(jī)時,顯示12:00:00的時間開始計(jì)時;
(2.P0.0/AD0控制“秒”的調(diào)整,每按一次加1秒;
(3.P0.1/AD1控制“分”的調(diào)整,每按一次加1分;
(4.P0.2/AD2控制“時”的調(diào)整,每按一次加1個小時;
2.
(1.把“單片機(jī)系統(tǒng)”區(qū)域中的P1.0-P1.7端口用8芯排線連接到“動態(tài)數(shù)碼顯示”區(qū)域中的A-H端口上;
(2.把“單片機(jī)系統(tǒng):區(qū)域中的P3.0-P3.7端口用8芯排線連接到“動態(tài)數(shù)碼顯示”區(qū)域中的S1-S8端口上;
(3.把“單片機(jī)系統(tǒng)”區(qū)域中的P0.0/AD0、P0.1/AD1、P0.2/AD2端口分別用導(dǎo)線連接到“獨(dú)立式鍵盤”區(qū)域中的SP3、SP2、SP1端口上;
4.
(1.動態(tài)數(shù)碼顯示的方法
(2.獨(dú)立式按鍵識別過程
(3.“時”,“分”,“秒”數(shù)據(jù)送出顯示處理方法
5.
6.
SECONDEQU30H
MINITEEQU31H
HOUREQU32H
HOURKBITP0.0
MINITEKBITP0.1
SECONDKBITP0.2
DISPBUFEQU40H
DISPBITEQU48H
T2SCNTAEQU49H
T2SCNTBEQU4AH
TEMPEQU4BH
ORG00H
LJMPSTART
ORG0BH
LJMPINT_T0
START:MOVSECOND,#00H
MOVMINITE,#00H
MOVHOUR,#12
MOVDISPBIT,#00H
MOVT2SCNTA,#00H
MOVT2SCNTB,#00H
MOVTEMP,#0FEH
LCALLDISP
MOVTMOD,#01H
MOVTH0,#(65536-2000)/256
MOVTL0,#(65536-2000)MOD256
SETBTR0
SETBET0
SETBEA
WT:JBSECONDK,NK1
LCALLDELY10MS
JBSECONDK,NK1
INCSECOND
MOVA,SECOND
CJNEA,#60,NS60
MOVSECOND,#00H
NS60:LCALLDISP
JNBSECONDK,$
NK1:JBMINITEK,NK2
LCALLDELY10MS
JBMINITEK,NK2
INCMINITE
MOVA,MINITE
CJNEA,#60,NM60
MOVMINITE,#00H
NM60:LCALLDISP
JNBMINITEK,$
NK2:JBHOURK,NK3
LCALLDELY10MS
JBHOURK,NK3
INCHOUR
MOVA,HOUR
CJNEA,#24,NH24
MOVHOUR,#00H
NH24:LCALLDISP
JNBHOURK,$
NK3:LJMPWT
DELY10MS:
MOVR6,#10
D1:MOVR7,#248
DJNZR7,$
DJNZR6,D1
RET
DISP:
MOVA,#DISPBUF
ADDA,#8
DECA
MOVR1,A
MOVA,HOUR
MOVB,#10
DIVAB
MOV@R1,A
DECR1
MOVA,B
MOV@R1,A
DECR1
MOVA,#10
MOV@R1,A
DECR1
MOVA,MINITE
MOVB,#10
DIVAB
MOV@R1,A
DECR1
MOVA,B
MOV@R1,A
DECR1
MOVA,#10
MOV@R1,A
DECR1
MOVA,SECOND
MOVB,#10
DIVAB
MOV@R1,A
DECR1
MOVA,B
MOV@R1,A
DECR1
RET
INT_T0:
MOVTH0,#(65536-2000)/256
MOVTL0,#(65536-2000)MOD256
MOVA,#DISPBUF
ADDA,DISPBIT
MOVR0,A
MOVA,@R0
MOVDPTR,#TABLE
MOVCA,@A+DPTR
MOVP1,A
MOVA,DISPBIT
MOVDPTR,#TAB
MOVCA,@A+DPTR
MOVP3,A
INCDISPBIT
MOVA,DISPBIT
CJNEA,#08H,KNA
MOVDISPBIT,#00H
KNA:INCT2SCNTA
MOVA,T2SCNTA
CJNEA,#100,DONE
MOVT2SCNTA,#00H
INCT2SCNTB
MOVA,T2SCNTB
CJNEA,#05H,DONE
MOVT2SCNTB,#00H
INCSECOND
MOVA,SECOND
CJNEA,#60,NEXT
MOVSECOND,#00H
INCMINITE
MOVA,MINITE
CJNEA,#60,NEXT
MOVMINITE,#00H
INCHOUR
MOVA,HOUR
CJNEA,#24,NEXT
MOVHOUR,#00H
NEXT:LCALLDISP
DONE:RETI
TABLE:DB3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH,40H
TAB:DB0FEH,0FDH,0FBH,0F7H,0EFH,0DFH,0BFH,07FH
END
7.
#include
unsignedcharcodedispcode[]={0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71,0x00};
unsignedchardispbitcode[]={0xfe,0xfd,0xfb,0xf7,
0xef,0xdf,0xbf,0x7f};
unsignedchardispbuf[8]={0,0,16,0,0,16,0,0};
unsignedchardispbitcnt;
unsignedcharsecond;
unsignedcharminite;
unsignedcharhour;
unsignedinttcnt;
unsignedcharmstcnt;
unsignedchari,j;
voidmain(void)
{
TMOD=0x02;
TH0=0x06;
TL0=0x06;
TR0=1;
ET0=1;
EA=1;
while(1)
{
if(P0_0==0)
{
for(i=5;i>0;i--)
for(j=248;j>0;j--);
if(P0_0==0)
{
second++;
if(second==60)
{
second=0;
}
dispbuf[0]=second%10;
dispbuf[1]=second/10;
while(P0_0==0);
}
}
if(P0_1==0)
{
for(i=5;i>0;i--)
for(j=248;j>0;j--);
if(P0_1==0)
{
minite++;
if(minite==60)
{
minite=0;
}
dispbuf[3]=minite%10;
dispbuf[4]=minite/10;
while(P0_1==0);
}
}
if(P0_2==0)
{
for(i=5;i>0;i--)
for(j=248;j>0;j--);
if(P0_2==0)
{
hour++;
if(hour==24)
{
hour=0;
}
dispbuf[6]=hour%10;
dispbuf[7]=hour/10;
while(P0_2==0);
}
}
}
}
voidt0(void)interrupt1using0
{
mstcnt++;
if(mstcnt==8)
{
mstcnt=0;
P1=dispcode[dispbuf[dispbitcnt]];
P3=dispbitcode[dispbitcnt];
dispbitcnt++;
if(dispbitcnt==8)
{
dispbitcnt=0;
}
}
tcnt++;
if(tcnt==4000)
{
tcnt=0;
second++;
if(second==60)
{
second=0;
minite++;
if(minite==60)
{
minite=0;
hour++;
if(hour==24)
{
hour=0;
}
}
}
dispbuf[0]=second%10;
dispbuf[1]=second/10;
dispbuf[3]=minite%10;
dispbuf[4]=minite/10;
dispbuf[6]=hour%10;
dispbuf[7]=hour/10;
}
}
評論