本帖最后由 THISISME 于 2019-1-7 21:45 编辑
这是一个时钟的程序,是别人编的,本人学生党,再练习读程序加自己编写中,但是不是很能读懂,尤其是主程序和中断服务程序那部分,想把这个程序当做一个典型例子学习,希望有大佬可以给它从主程序开始写个注释(越详细越好),非常感谢
程序如下:
ORG 0000H
LJMP MAIN
ORG 0003H
LJMP INT0INT0
ORG 0013H
LJMP INT1INT1
ORG 000BH
LJMP IT0P
ORG 0040H
BEEP EQU P3.4 ;speaker
/**************主程序*******************/
MAIN:MOV P0,#0FFH
MOV P1,#0FFH
MOV P2,#0FFH
MOV 30H,#14H
MOV 40H,#00H
MOV 41H,#00H
MOV 42H,#00H
MOV TCON,#05H
MOV TMOD,#01H
MOV IE,#87H
MOV IP,#01H
MOV TH0,#3CH
MOV TL0,#0B0H
LOOP: LCALL DISPLAYSECOND
LCALL DISPLAYMINUTE
LCALL DISPLAYHOUR
SECOND0:JNB P2.0,SECOND£
MINUTE0:JNB P2.1,MINUTE
HOUR0: JNB P2.2,HOUR
CLEAR0: JNB P2.3,CLEAR
LAST: LJMP LOOP
/**************秒调整*******************/
SECOND: LCALL DELAY100MS
JNB P2.0,HAVES
LCALL DELAY10MS;·À¶¶
LJMP RETURNS
HAVES: MOV A,#01H
ADD A,42H
DA A
MOV 42H,A
CJNE A,#60H,RETURNS
MOV 42H,#00H
RETURNS:LCALL DISPLAYSECOND
LJMP MINUTE0
/**************分调整*******************/
MINUTE: LCALL DELAY100MS
JNB P2.1,HAVEM
LCALL DELAY10MS
LJMP RETURNM
HAVEM: MOV A,#01H
ADD A,41H
DA A
MOV 41H,A
CJNE A,#60H,RETURNM
MOV 41H,#00H
RETURNM:LCALL DISPLAYMINUTE
LJMP HOUR0
/**************时调整*******************/
HOUR: LCALL DELAY100MS
JNB P2.2,HAVEH
LCALL DELAY10MS
LJMP RETURNH
HAVEH: MOV A,#01H
ADD A,40H
DA A
MOV 40H,A
CJNE A,#24H,RETURNH
MOV 40H,#00H
RETURNH:LCALL DISPLAYHOUR
LJMP CLEAR0
/**************清零*******************/
CLEAR: LCALL DELAY100MS
JNB P2.3,HAVEC
LJMP RETURNC
HAVEC: CLR TR0
MOV 40H,#00H
MOV 41H,#00H
MOV 42H,#00H
CLR BEEP;speaker ring
LCALL DL1S
SETB BEEP
RETURNC:LJMP LAST
/**************秒显示*******************/
DISPLAYSECOND:
SECONDGE: SETB P1.0
MOV A,42H
ANL A,#0FH
LCALL SEG
LCALL DELAY1MS
CLR P1.0
SECONDSHI:SETB P1.1
MOV A,42H
SWAP A
ANL A,#0FH
LCALL SEG
LCALL DELAY1MS
CLR P1.1
RET
/**************·分显示*******************/
DISPLAYMINUTE:
MINUTEGE: SETB P1.2
MOV A,41H
ANL A,#0FH
LCALL SEG
LCALL DELAY1MS
CLR P1.2
MINUTESHI:SETB P1.3
MOV A,41H
SWAP A
ANL A,#0FH
LCALL SEG
LCALL DELAY1MS
CLR P1.3
RET
/**************时显示*******************/
DISPLAYHOUR:
HOURGE: SETB P1.4
MOV A,40H
ANL A,#0FH
LCALL SEG
LCALL DELAY1MS
CLR P1.4
HOURSHI: SETB P1.5
MOV A,40H
SWAP A
ANL A,#0FH
LCALL SEG
LCALL DELAY1MS
CLR P1.5
RET
/**************启动int0终端服务*******************/
INT0INT0:CLR EA
LCALL DELAY10MS
JNB INT0,HAVEKEY1
SETB EA
RETI
HAVEKEY1:PUSH PSW
PUSH Acc
SETB EA
SETB TR0
CLR EA
POP Acc
POP PSW
SETB EA
RETI
/************暂停int1终端服务*******************/
INT1INT1:CLR EA
LCALL DELAY10MS
JNB INT1,HAVEKEY2
SETB EA
RETI
HAVEKEY2:PUSH PSW
PUSH Acc
SETB EA
CLR TR0
CLR EA
POP Acc
POP PSW
SETB EA
RETI
/*****************定时器0中断服务*****************/
IT0P:PUSH PSW
PUSH Acc
CLR TR0
MOV TH0,#3CH
MOV TL0,#0B0H
DJNZ 30H,RETURN
MOV 30H,#14H
MOV A,#01H
ADD A,42H
DA A
MOV 42H,A
CJNE A,#60H,RETURN
MOV 42H,#00H
MOV A,#01H
ADD A,41H
DA A
MOV 41H,A
CJNE A,#60H,RETURN
MOV 41H,#00H
MOV A,#01H
ADD A,40H
DA A
MOV 40H,A
CJNE A,#24H,RETURN
MOV 40H,#00H
RETURN:
SETB TR0
POP Acc
POP PSW
RETI
/*************查表***************/
SEG:MOV DPTR,#TAB
MOVC A,@A+DPTR
CPL A
MOV P0,A
RET
TAB:
DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH
/*************1mS*****************/
DELAY1MS:MOV R7,#04H
D1: MOV R6,#7DH
DJNZ R6,$
DJNZ R7,D1
RET
/*************10ms****************/
DELAY10MS:MOV R7,#28H
D2: MOV R6,#7DH
DJNZ R6,$
DJNZ R7,D2
RET
/*************100mS****************/
DELAY100MS:MOV R7,#02H
DEL1:MOV R6,#0C8H
DEL2:MOV R5,#7DH
DEL3:DJNZ R5,DEL3
DJNZ R6,DEL2
DJNZ R7,DEL1
RET
/***********蜂鸣器延时************/
DL1S: MOV R4, #10
DL3: LCALL DELAY10MS
DJNZ R4, DL3
RET
END
|