單片機(jī)數(shù)字電子時(shí)鐘系統(tǒng)
單片機(jī)系統(tǒng)的開發(fā)。其實(shí),這個(gè)時(shí)鐘系統(tǒng)花了我一個(gè)禮拜的時(shí)間。從剛開始的顯示模塊,到鍵盤模塊,我都一步一步
實(shí)現(xiàn)。當(dāng)然,這其中,也遇到了很多困難,麻煩!剛開始,數(shù)碼管部分一點(diǎn)不顯示,鍵盤也沒用,很煩人,很惱火。
但是,我還是把程序調(diào)試出來了,并且在硬件上運(yùn)行達(dá)到效果。本以為這幾部分實(shí)現(xiàn)了后,聯(lián)合在一塊,偶的時(shí)鐘系統(tǒng)就OK 了。然而,我錯(cuò)了,一個(gè)模塊運(yùn)行成功并不意味著模塊組成的系統(tǒng)就能按照預(yù)想的一樣達(dá)到目的,實(shí)現(xiàn)功能!當(dāng)我將幾個(gè)模塊結(jié)合在一塊時(shí)候,問題有接踵而至!哎呀!煩人??!我只能重新設(shè)計(jì)方案,重新檢查,重新寫程序,源代碼寫了
一遍又一遍,程序調(diào)了又調(diào),程序一遍又一遍地下載到單片機(jī)中運(yùn)行,觀察現(xiàn)象,分析出錯(cuò)原因,找出解決辦法!最終,
在我的不斷努力下,我的單片機(jī)數(shù)字電子時(shí)鐘系統(tǒng)成功的實(shí)現(xiàn)了所有的功能,達(dá)到了預(yù)期的效果!!先把我寫了好多遍,
調(diào)試了好多遍的源代碼上傳,來和大家一起分享一下!!
ORG 0000H
SJMP START
ORG 0003H
LJMP INTT0
ORG 000BH
LJMP TIME0
ORG 001BH
LJMP TIME1
ORG 0045H
START:MOV SP,#60H
SETB EA
SETB ET0
SETB ET1
MOV TMOD,#11H
MOV TL0,#0B0H
MOV TH0,#3CH
MOV TL1,#80H
MOV TH1,#0C1H
SETB EX0
CLR IT0
SETB PX0
MOV R0,#20
MOV 40H,#0
MOV 41H,#0
MOV 42H,#0
MOV 30H,#0
MOV 31H,#0
MOV 32H,#0
MOV 33H,#0
MOV 34H,#0
MOV 35H,#0
MOV P2,#0FFH
SETB TR0
SETB TR1
SJMP $
INTT0:CLR TR0
CLR TR1
PUSH ACC
PUSH PSW
LCALL DISP
MOV P1,#0FFH
KEY1:JNB P1.0,ST
LCALL DISP
JNB P1.1,MT
LCALL DISP
JNB P1.2,HT
LCALL DISP
JNB P1.3,COMN
LCALL DISP
SJMP KEY1
COMN:LCALL CONT
ST:LCALL DELAY2
JB P1.0,KEY1
JNB P1.0,$
INC 40H
MOV A,40H
MOV B,#10
DIV AB
MOV 31H,A
MOV A,B
MOV 30H,A
LCALL DISP
MOV A,40H
CJNE A,#60,KEY1
MOV 30H,#0
MOV 31H,#0
MOV 40H,#0
LJMP KEY1
MT:LCALL DELAY2
JB P1.1,KEY1
JNB P1.1,$
INC 41H
MOV A,41H
MOV B,#10
DIV AB
MOV 33H,A
MOV A,B
MOV 32H,A
LCALL DISP
MOV A,41H
CJNE A,#60,KEY1
MOV 32H,#0
MOV 33H,#0
MOV 41H,#0
LJMP KEY1
HT:LCALL DELAY2
JB P1.2,KEY1
JNB P1.2,$
INC 42H
MOV A,42H
MOV B,#10
DIV AB
MOV 35H,A
MOV A,B
MOV 34H,A
LCALL DISP
MOV A,42H
CJNE A,#24,KEYPRESS
MOV 34H,#0
MOV 35H,#0
MOV 42H,#0
LJMP KEY1
KEYPRESS:LCALL KEY1
CONT:LCALL DELAY2
JB P1.3,KEYPRESS
JNB P1.3,$
SETB TR0
SETB TR1
POP PSW
POP ACC
RETI
TIME0:PUSH ACC
PUSH PSW
MOV TL0,#0B0H
MOV TH0,#3CH
DJNZ R0,BACK
MOV R0,#20
INC 40H
MOV A,40H
MOV B,#10
DIV AB
MOV 31H,A
MOV A,B
MOV 30H,A
MOV A,40H
CJNE A,#60,BACK
MOV 30H,#0
MOV 31H,#0
MOV 40H,#0
INC 41H
MOV A,41H
MOV B,#10
DIV AB
MOV 33H,A
MOV A,B
MOV 32H,A
MOV A,41H
CJNE A,#60,BACK
MOV 32H,#0
MOV 33H,#0
MOV 41H,#0
INC 42H
MOV A,42H
MOV B,#10
DIV AB
MOV 35H,A
MOV A,B
MOV 34H,A
MOV A,42H
CJNE A,#24,BACK
MOV 42H,#0
MOV 34H,#0
MOV 35H,#0
MOV 30H,#0
MOV 31H,#0
MOV 32H,#0
MOV 33H,#0
BACK:POP PSW
POP ACC
RETI
TIME1:PUSH ACC
PUSH PSW
MOV TL1,#80H
MOV TH1,#0C1H
LCALL DISP
POP PSW
POP ACC
RETI
DISP:MOV DPTR,#TAB1
MOV A,30H
MOVC A,@A+DPTR
MOV P0,A
SETB P2.0
CLR P2.5
LCALL DELAY1
SETB P2.5
MOV A,31H
MOVC A,@A+DPTR
MOV P0,A
SETB P2.0
CLR P2.4
LCALL DELAY1
MOV DPTR,#TAB2
MOV A,32H
MOVC A,@A+DPTR
SETB P2.4
MOV P0,A
SETB P2.0
CLR P2.3
LCALL DELAY1
MOV DPTR,#TAB1
MOV A,33H
MOVC A,@A+DPTR
SETB P2.3
MOV P0,A
SETB P2.0
CLR P2.2
LCALL DELAY1
MOV DPTR,#TAB2
MOV A,34H
MOVC A,@A+DPTR
SETB P2.2
MOV P0,A
SETB P2.0
CLR P2.1
LCALL DELAY1
MOV DPTR,#TAB1
MOV A,35H
MOVC A,@A+DPTR
SETB P2.1
MOV P0,A
CLR P2.0
LCALL DELAY1
RET
DELAY1:MOV R7,#02H
DL:MOV R6,#0FFH
DL1:DJNZ R6,DL1
DJNZ R7,DL
RET
DELAY2:MOV R7,#10H
TS1:MOV R6,#0FFH
TS2:DJNZ R6,TS2
DJNZ R7,TS1
RET
TAB1:DB 0C0H,0F9H,0A4H,0B0H,99H
DB 92H,82H,0F8H,80H,90H
TAB2:DB 40H,79H,24H,30H,19H
DB 12H,02H,78H,00H,10H
END
評(píng)論