单片机作业参考答案
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
2.19
ORG 0100H
START: MOV R0,#40H
MOV DPTR,#3000H
MOV R2,#21H
LOOP: MOV A,@R0
MOVX @DPTR,A
MOV @R0,#00H
INC R0
INC DPTR
DJNZ R2,LOOP
SJMP $
EDN
2.23
ORG 0100H
START: MOV R2,#100
MOV R3,#00H (零)
MOV R4,#00H (正)
MOV R5,#00H (负)
MOV DPTR,#2000H LOOP: MOVX A,@DPTR
CJNE A,#00H,NET1
INC R3
SJMP NET3
NET1: JC NET2
INC R4
SJMP NET3
NET2: INC R5
NET3: INC DPTR
DJNZ R2,LOOP
SJMP $
END
2.24
ORG 0100H START: MOV DPTR,#2000H
MOV R2,#9FH LOOP: MOVX A,@DPTR
XRL A,#41H
JZ FIND
INC DPTR
DJNZ R2,LOOP
SJMP LOOP1 FIND: MOV 30H,DPL
MOV 31H,DPH
MOV A,30H
MOV DPTR,#20A0H
MOVX @DPTR,A
MOV A,31H
MOV DPTR,#20A1H
MOVX @DPTR,A LOOP1: SJMP $
END
ORG 0100H START: MOV DPTR,#2000H
MOV R7,#9FH
LP0: MOVX A,@DPTR
CJNE A,#41H,LP1
MOV R2,DPL
MOV R3,DPH
MOV DPTR,#20A0H
MOV A,R2
MOVX @DPTR,A
INC DPTR
MOV A,R3
MOVX @DPTR,A
SJMP LP2
LP1: INC DPTR
DJNZ R7,LP0
LP2: RET
END
2.27
ORG 0100H START: MOV 30H,#24H
MOV 31H,#00H
MOV 32H,#25H
MOV 33H,#00H
MOV R2,#51H LOOP: MOV DPH,30H
MOV DPL,31H
MOVX A,@DPTR
MOV DPH,32H
MOV DPL,33H
MOVX @DPTR,A
INC 31H
INC 33H
DJNZ R2,LOOP
SJMP $
END
ORG 0100H MAIN: MOV R7,#51H
MOV DPTR,#2400H LOOP: MOVX A,@DPTR
MOV DPH,#25H
MOV @DPTR,A
MOV DPH,#24H
INC DPTR
DJNZ R7,LOOP
SJMP $
END
3.37 利用MCS-51单片机定时器从P1.0输出周期为2ms的方波,设单片机晶振频率为6MHZ,试编程实现。
f=6MHZ 机器周期=12/6MHZ=2μs
1ms/2μs=500 2^16-500=65536-500=65036=FE0CH
ORG 0000H
AJMP START
ORG 000BH
AJMP TIME0
ORG 0030H
START: MOV SP,#60H
MOV TMOD,#01H
MOV TH0,#0FEH
MOV TL0,#0CH
SETB EA
SETB ET0
SETB TR0
LOOP: AJMP LOOP
TIME0: PUSH ACC
PUSH PSW
CPL P1.0
MOV TH0,#0FEH
MOV TL0,#0CH
SETB TR0
POP PSW
POP ACC
RETI
END
3.38 已知8051单片机系统时钟频率为6MHZ,请利用定时器T0和P1.2输出占空比为1:8的矩形脉冲,其波形如下图所示,试编程实现。
ORG 0000H
AJMP START
ORG 0030H
START: MOV SP,#60H
MOV TMOD,#02H
MOV TH0,#0E7H
MOV TL0.#0E7H
CLR P1.2
SETB TR0
HIGH0: SETB P1.2
HIGH1: JBC TF0,LOW0
AJMP HIGH1
LOW0: MOV R7,#7
CLR P1.2
LOW1: JBC TF0,LOW2
AJMP LOW1
LOW2: DJNZ R7,LOW1
AJMP HIGH0
END