辛辛苦苦编了一个10s循环计时的程序,原理图和程序如下:
ORG 0000H
AJMP MAIN
ORG 000BH
AJMP INTT0
ORG 0030H
MAIN:CLR P2.7
CLR P2.6
MOV DPTR,#TAB
CLR A
MOV R2,#0H
MOV R3,#0H
MOV TMOD,#01H
MOV TH0,#4CH
MOV TL0,#00H
SETB EA
SETB ET0
SETB TR0
HERE: CJNE R2,#14H,HERE
MOV R2,#0H
PUSH ACC
MOVC A,@A+DPTR
MOV P0,A
POP ACC
INC A
INC R3
CJNE R3,#0AH,HERE
MOV R3,#00H ;此处用DJNZ 更方便,只不过R3的初始值要设置为0AH,同时取消INC R3指令(此行上面第二行)
CLR A
AJMP HERE
ORG 80H
INTT0:MOV TH0,#4CH
MOV TL0,#00H
INC R2
RETI
TAB: DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H
END |