weixin_43777875
weixin_43777875
采纳率33.3%
2020-10-01 13:59 阅读 102

怎么在MOV R0,#19 和CPL P2.3之间插入一个延迟两秒的指令?

5

ORG 0H
MOV R0,#20
MOV R1,#0 //Set time value = 0, seconds
MOV R2,#0 //minutes
MOV R3,#0 //hours
ACALL SETDIS //initialise the display
MOV TMOD,#0x01
REPEAT: MOV TH0,#0x3C
MOV TL0,#0xB0
SETB TR0
WAIT: JNB TF0,WAIT
CLR TR0
CLR TF0
DJNZ R0,REPEAT
MOV TH0,#0x3C
MOV TL0,#0xB0
SETB TR0
MOV R0,#19
CPL P2.3 //output every second
ACALL INCT //Increment time
ACALL DIST //Display time
AJMP WAIT

SETDIS: MOV A,#30H //Display initialisation routine
ACALL COMNWRT

ACALL DELAY1

MOV A,#0CH

ACALL COMNWRT

ACALL DELAY1

MOV A,#01

ACALL COMNWRT

ACALL DELAY2

MOV A,#06H

ACALL COMNWRT

ACALL DELAY1

RET

INCT: MOV A,R1 //Update time count routine

    //your code here
    ADD A,#01H
    DA A
    MOV R1,A
    CJNE A,#60H,INCE
    MOV R1,#0
    MOV A,R2
    ADD A,#1
    DA A
    MOV R2,A
    CJNE A,#60H,INCE
    MOV R2,#0
    MOV A,R3
    ADD A,#01H
    DA A
    MOV R3,A
    CJNE A,#24H,INCE
    MOV R3,#0

INCE: RET

DIST: MOV A,#01 //Update display routine
ACALL COMNWRT //Reset display
ACALL DELAY2

MOV A,R3 //MSD first

    //your code here
    SWAP A
    ACALL FUNC1
    MOV A,R3
    ACALL FUNC1
    MOV A,#3AH
    ACALL DATAWRT
    ACALL DELAY1
    MOV A,R2
    SWAP A
    ACALL FUNC1
    MOV A,R2
    ACALL FUNC1
    MOV A,#3AH
    ACALL DATAWRT
    ACALL DELAY1
    MOV A,R1
    SWAP A
    ACALL FUNC1
    MOV A,R1
    ACALL FUNC1



    RET

FUNC1:

ANL A,#0FH
ORL A,#30H
ACALL DATAWRT
ACALL DELAY1
RET

COMNWRT:

MOV P0,A

CLR P2.0

CLR P2.1

SETB P2.2

ACALL DELAY1

CLR P2.2

RET
DATAWRT:

MOV P0,A

SETB P2.0

CLR P2.1

SETB P2.2

ACALL DELAY1

CLR P2.2

RET

DELAY1: MOV R5,#30 //Short delay
LP1: DJNZ R5,LP1

RET

DELAY2: MOV R5,#50 //long delay
HERE2: MOV R4,#50

HERE: DJNZ R4,HERE

DJNZ R5,HERE2
RET

    END
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    caozhy 从今以后生命中的每一秒都属于我爱的人 2020-10-01 14:36
    DELAY:  MOV  R6, #13
    DELAY1: MOV  R5, #250
    DELAY2: NOP
     DJNZ  R5, DELAY2
     DJNZ  R6, DELAY1
    RET
    

    上面的代码在12MHz的处理器上延迟1秒,如果你要2秒,就改下数字,2倍,如果你的cpu频率更高,也要相应修改增加循环次数。

    点赞 评论 复制链接分享

相关推荐