用單片機89C2051制作的延時控制器
KEY:SJMP MAIN1
SJMP KEY1 ;依次為:KEY值+2,4,6,8,因為SJMP占2個字節(jié)
SJMP KEY2 ;S1的KEYCODE=02H,S2: KEYCODE=04H
SJMP KEY3 ;S3: KEYCODE=06H, S4: KEYCODE=08H
SJMP KEY4
KEY1:CLR TR0;時計數(shù)器加1
MOV A,THBIN
CLR C
ADDC A,#01H
MOV THBIN,A
SUBB A,#24;24D
JC KEY11
MOV THBIN,#00H
KEY11: SJMP MAIN1
NOP
KEY2:CLR TR0;分計數(shù)器加1
MOV A,TMBIN
CLR C
ADDC A,#01H
MOV TMBIN,A
SUBB A,#60;60D
JC KEY21
MOV TMBIN,#00H
KEY21: SJMP MAIN1
NOP
KEY3:CLR TR0;秒計數(shù)器加1
MOV A,TSBIN
CLR C
ADDC A,#01H
MOV TSBIN,A
SUBB A,#60;60D
JC KEY31
MOV TSBIN,#00H
KEY31: SJMP MAIN1
NOP
KEY4:MOV TH0,#0DCH;退出校時狀態(tài)
MOV TL0,#00H
SETB TR0
SJMP MAIN1本文引用地址:http://butianyuan.cn/article/162125.htm
; ********** 顯示子程序 **************
ORG 0200H
DISPLY: MOV A,TSBIN;秒計數(shù)器調入A
MOV B,#0AH
DIV AB ;秒計數(shù)值÷10 (結果十位存于A,個位存于B)
SWAP A
ORL A,#07H;顯示秒的十位
MOV P1,A
MOV A,#DPS1
ANL A,OUT
MOV P3,A
ACALL DSPDEL;延時(顯示時)0.5ms
MOV C,P3.7;讀S4按鍵狀態(tài)
MOV A,#HIDE
ANL A,OUT
MOV P3,A
JC NP1
MOV KEYCODE,#08H;S4按下,鍵盤值=8
NP1:MOV P1,#0F7H;消隱
NOP
NOP
NOP
MOV A,B;顯示秒的個位
SWAP A
ORL A,#07H
MOV P1,A
MOV A,#DPS0
ANL A,OUT
MOV P3,A
ACALL DSPDEL
MOV A,#HIDE
ANL A,OUT
MOV P3,A
NOP
NOP
NOP
MOV A,TMBIN;
MOV B,#0AH
DIV AB;
SWAP A;顯示分的十位
ORL A,#07H
MOV P1,A
MOV A,#DPM1
ANL A,OUT
MOV P3,A
ACALL DSPDEL
MOV C,P3.7;檢測S2是否按下
MOV A,#HIDE
ANL A,OUT
MOV P3,A
JC NP2
MOV KEYCODE,#04H;S2按下,鍵盤值=4
NOP
NP2:MOV P1,#0F7H;消隱
NOP
NOP
MOV A,B
SWAP A;顯示分的個位
ORL A,#07H
MOV P1,A
;MOV C,KEYPRE
;MOV P1.3,C
SETB P1.3
MOV A,#DPM0
ANL A,OUT
MOV P3,A
ACALL DSPDEL
MOV C,P3.7;判斷S3是否按下
MOV A,#HIDE
ANL A,OUT
MOV P3,A
評論