单片机定时器汇编程序
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
ORG 0000H
AJMP MAIN
ORG 002BH
LJMP CTC2
ORG 0050H
MAIN: MOV SP,#7FH
MOV TH0,#0DCH
MOV TL0,#00H
MOV RCAP2H,#0DCH
MOV RCAP2L,#00H
MOV T2CON,#00H
SETB ET2
SETB EA
MOV 35H,#0H
MOV 34H,#0H
MOV 33H,#0H
MOV 32H,#0H
MOV 31H,#0H
MOV 30H,#0H
LOOP0: LCALL DISPLAY
JB P3.4,LOOP0 ;判启动
LCALL DISPLAY
JB P3.4,LOOP0
SETB TR2
LOOP1: LCALL DISPLAY
JB P3.5,LOOP1 ;判暂停
LCALL DISPLAY
JB P3.5,LOOP1
CLR TR2
X1: LCALL DISPLAY
JB P3.6,X1 ;判复位0秒
LCALL DISPLAY
JB P3.6,X1
LJMP MAIN
CTC2: PUSH PSW ;百分之一秒(10ms)到
PUSH ACC
ADDONE: INC 30H
MOV A,30H
CJNE A,#10,ADDONE1
MOV 30H,#0H
INC 31H
MOV A,31H
CJNE A,#10,ADDONE1
MOV 31H,#0H
INC 32H
MOV A,32H
CJNE A,#10,ADDONE1
MOV 32H,#0H
INC 33H
MOV A,33H
CJNE A,#6,ADDONE1
MOV 33H,#0H
INC 34H
MOV A,34H
CJNE A,#10,ADDONE1
MOV 34H,#0H
INC 35H
MOV A,35H
CJNE A,#06H,ADDONE1
MOV 35H,#0H
ADDONE1:CLR TF2
POP ACC
POP PSW
RETI
DISPLAY:MOV R0,#30H
MOV DPTR,#TAB
MOV 36H,#0DFH
LOOP: MOV A,@R0
MOVC A,@A+DPTR
MOV P0,A
SETB P2.6
NOP
CLR P2.6
MOV A,36H
MOV P0,A
SETB P2.7
LCALL DELAY
MOV P0,#0FFH
CLR P2.7
RR A
MOV 36H,A
INC R0
MOV A,@R0
MOVC A,@A+DPTR
MOV P0,A
SETB P2.6
NOP
CLR P2.6
MOV A,36H
MOV P0,A
SETB P2.7
LCALL DELAY
MOV P0,#0FFH
CLR P2.7
RR A
MOV 36H,A
INC R0
MOV A,@R0
MOVC A,@A+DPTR
ORL A,#80H
MOV P0,A
SETB P2.6
NOP
CLR P2.6
MOV A,36H
MOV P0,A
SETB P2.7
LCALL DELAY
MOV P0,#0FFH
CLR P2.7
RR A
MOV 36H,A
INC R0
MOV A,@R0
MOVC A,@A+DPTR
MOV P0,A
SETB P2.6
NOP
CLR P2.6
MOV A,36H
MOV P0,A
SETB P2.7
LCALL DELAY
MOV P0,#0FFH
CLR P2.7
RR A
MOV 36H,A
INC R0
MOV A,@R0
MOVC A,@A+DPTR
ORL A,#80H
MOV P0,A
SETB P2.6
NOP
CLR P2.6
MOV A,36H
MOV P0,A
SETB P2.7
LC
ALL DELAY
MOV P0,#0FFH
CLR P2.7
RR A
MOV 36H,A
INC R0
MOV A,@R0
MOVC A,@A+DPTR
MOV P0,A
SETB P2.6
NOP
CLR P2.6
MOV A,36H
MOV P0,A
SETB P2.7
LCALL DELAY
MOV P0,#0FFH
CLR P2.7
RET
DELAY: MOV R6,#2
DEL1: MOV R5,#250
DJNZ R5 ,$
DJNZ R6,DEL1
RET
TAB: DB 3FH,06H,5BH,4FH,66H,6DH,7DH,07H,7FH,6FH,77H,7CH,39H,5EH,79H,71H,00H
END