哈工大单片机原理与应用实验报告

四、实验过程

根据程序框图编写程序,调试无误后装载,运行后观察记录实验现象。

五、实验结果及分析

1、如何修改程序使定时器工作方式改变(实现12小时制)?

答:将原程序 “ CJNE A,#24,DONE ”改为“ CJNE A,#12,DONE ”,从而实现12小时制。

六、实验源程序

脉冲计数(定时/计数器实验) ORG 06E0H SE15: MOV SP,#53H MOV TMOD,#05H MOV TH0,#00H

MOV TL0,#00H SETB TR0 LO29: MOV R2,TH0

MOV R3,TL0 LCALL ZOY0 MOV R0,#79H MOV A,R6 LCALL PTDS MOV A,R5 LCALL PTDS MOV A,R4

LCALL PTDS LCALL SSEE SJMP LO29 ZOY0: CLR A MOV R4,A MOV R5,A

-16-

MOV R6,A MOV R7,#10H

LO30: CLR C MOV A,R3 RLC A MOV R3,A MOV A,R2 RLC A MOV R2,A MOV A,R6

ADDC A,R6 DA A MOV R6,A MOV A,R5 ADDC A,R5 DA A

MOV R5,A MOV A,R4 ADDC A,R4 DA A

MOV R4,A

DJNZ R7,LO30 RET

PTDS: MOV R1,A ACALL PTDS1 MOV A,R1 SWAP A

PTDS1: ANL A,#0FH MOV @R0,A INC R0 RET

SSEE: SETB RS1 MOV R5,#05H SSE2: MOV 30H,#20H MOV 31H,#7EH MOV R7,#06H SSE1: MOV R1,#0DDH MOV A,30H

MOVX @R1,A MOV R0,31H MOV A,@R0

MOV DPTR,#DDFF

MOVC A,@A+DPTR MOV R1,#0DCH

MOVX @R1,A MOV A,30H

-17-

RR A

MOV 30H,A DEC 31H

MOV A,#0FFH

MOVX @R1,A DJNZ R7,SSE1 DJNZ R5,SSE2 CLR RS1 RET

DDFF: DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H DB 88H,83H,0C6H,0A1H,86H,8EH,0FFH,0CH,89H,0DEH END

电脑时钟(定时器、中断综合实验) ORG 0000H SJMP CHK00 ORG 000BH

LJMP CLOCK;INT_T0 ORG 0030H CHK00: MOV SP,#60H LCALL LEDP

CHK0: LCALL LCK0 LCALL PTDS0 MOV TMOD,#01H

ORL IE,#10000010b MOV TL0,#0

MOV TH0,#4ch MOV 23H,#00H

SETB TR0 LOO5: LCALL DIS LCALL PTDS0 SJMP LOO5 PTDS0: MOV R0,#79H MOV A,22H ACALL PTDS MOV A,21H ACALL PTDS MOV A,20H ACALL PTDS RET

PTDS: MOV R1,A ACALL PTDS1 MOV A,R1 SWAP A

PTDS1: ANL A,#0FH MOV @R0,A

-18-

INC R0 RET

CLOCK: MOV TL0,#0B7H

MOV TH0,#3CH PUSH PSW PUSH ACC

SETB 0D3H INC 23H MOV A,23H

CJNE A,#20,DONE MOV 23H,#00H MOV A,22H

INC A DA A

MOV 22H,A CJNE A,#60H,DONE MOV 22H,#00H MOV A,21H INC A

DA A MOV 21H,A

CJNE A,#60H,DONE MOV 21H,#00H MOV A,20H INC A

DA A MOV 20H,A

CJNE A,#24H,DONE MOV 20H,#00H DONE: POP ACC POP PSW RETI

SSEE: SETB RS1 MOV R5,#05H SSE2: MOV 30H,#20H MOV 31H,#7EH MOV R7,#06H SSE1: MOV R1,#0DDH MOV A,30H

MOVX @R1,A MOV R0,31H MOV A,@R0

MOV DPTR,#DDFF

MOVC A,@A+DPTR MOV R1,#0DCH

MOVX @R1,A

-19-

联系客服:779662525#qq.com(#替换为@)