Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Assembly 如何在汇编程序中更改函数的按钮_Assembly_Stopwatch_Picoblaze - Fatal编程技术网

Assembly 如何在汇编程序中更改函数的按钮

Assembly 如何在汇编程序中更改函数的按钮,assembly,stopwatch,picoblaze,Assembly,Stopwatch,Picoblaze,我在汇编程序中的代码有问题。我有这些秒表。按下按钮1,它将开始计数;再次按下按钮,它将暂停计数;按下按钮2,它将复位;翻转开关1,它将开始减小当前的值。但我现在需要它来使用3号按钮,而不是1号开关。我已经有一段时间没有编程了。有人能帮我吗?谢谢 VHDL "ROM_blank.vhd", "ProgMem.vhd", "ProgMem" BUTTON DSIN $00 SWITCH DSIN $01 LED DSOUT

我在汇编程序中的代码有问题。我有这些秒表。按下按钮1,它将开始计数;再次按下按钮,它将暂停计数;按下按钮2,它将复位;翻转开关1,它将开始减小当前的值。但我现在需要它来使用3号按钮,而不是1号开关。我已经有一段时间没有编程了。有人能帮我吗?谢谢

VHDL    "ROM_blank.vhd", "ProgMem.vhd", "ProgMem"
BUTTON      DSIN        $00
SWITCH      DSIN        $01
LED         DSOUT       $02
SEG0        DSOUT       $03
SEG1        DSOUT       $04
SEG2        DSOUT       $05
SEG3        DSOUT       $06

wait0 equ s0
wait1 equ s1
wait2 equ s2
cnt0 equ s3
cnt1 equ s4
cnt2 equ s5
cnt3 equ s6
state equ s7
segsel equ s8
temp equ sf
updown equ s9

state_r0 equ 0
state_r1 equ 1
state_s0 equ 2
state_s1 equ 3

decoded_dp equ 254
decoded_0 equ 3
decoded_1 equ 159
decoded_2 equ 37
decoded_3 equ 13
decoded_4 equ 153
decoded_5 equ 73
decoded_6 equ 65
decoded_7 equ 27
decoded_8 equ 1
decoded_9 equ 25
decoded_A equ 5
decoded_B equ 193
decoded_C equ 229
decoded_D equ 133
decoded_E equ 97
decoded_F equ 113


init:
     load cnt0, 0
     load cnt1, 0
     load cnt2, 0
     load cnt3, 0
     load state, state_s0
start:

; read buttons
    in temp, BUTTON
; reset check
    and temp, 2
    jump z, startstop_check
    load cnt0, 0
    load cnt1, 0
    load cnt2, 0
    load cnt3, 0

startstop_check:
    in temp, BUTTON
    and temp, 1

; state machine
    comp state, state_r0
    jump z,run0
    comp state, state_r1
    jump z,run1
    comp state, state_s0
    jump z, stop0
    comp state, state_s1
    jump z, stop1
    load state, state_s0

stop0:
    comp temp, 1
    jump nz, fsm_end
    load state, state_r0
    jump fsm_end
run0:
    comp temp, 0
    jump nz, fsm_end
    load state, state_r1
    jump fsm_end
run1:
    comp temp, 1
    jump nz, fsm_end
    load state, state_s1
    jump fsm_end
stop1:
    comp temp, 0
    jump nz, fsm_end
    load state, state_s0

fsm_end:

;wait 0.01s     
    call waitfcn

    comp state, state_s0
    jump z, decode
    comp state, state_s1
    jump z, decode

    in updown, SWITCH
    comp updown, 1
    jump z, odecitej

    add cnt0, 1
    comp cnt0, 10
    jump nz, decode
    load cnt0, 0
    add cnt1, 1
    comp cnt1, 10
    jump nz, decode
    load cnt1, 0
    add cnt2, 1
    comp cnt2, 10
    jump nz, decode
    load cnt2, 0
    add cnt3, 1
    comp cnt3, 10
    jump nz, decode
    load cnt3, 0
    call decode

odecitej:
    sub cnt0, 1
    comp cnt0, 255
    jump nz, decode
    load cnt0, 9
    sub cnt1, 1
    comp cnt1, 255
    jump nz, decode
    load cnt1, 9
    sub cnt2, 1
    comp cnt2, 255
    jump nz, decode
    load cnt2, 9
    sub cnt3, 1
    comp cnt3, 255
    jump nz, decode
    load cnt3, 9

decode:
;decode for output
    load temp, cnt0
    call decodefcn
    out temp, SEG0

    load temp, cnt1
    call decodefcn
    out temp, SEG1

    load temp, cnt2
    call decodefcn
;add decimal point
    and temp, 254
    out temp, SEG2

    load temp, cnt3
    call decodefcn
    out temp, SEG3

    jump start

decodefcn:
    comp temp, 0
    jump nz, dec1
    load temp, decoded_0
    ret
dec1:
    comp temp, 1
    jump nz, dec2
    load temp, decoded_1
    ret
dec2:
    comp temp, 2
    jump nz, dec3
    load temp, decoded_2
    ret
dec3:
    comp temp, 3
    jump nz, dec4
    load temp, decoded_3
    ret
dec4:
    comp temp, 4
    jump nz, dec5
    load temp, decoded_4
    ret
dec5:
    comp temp, 5
    jump nz, dec6
    load temp, decoded_5
    ret
dec6:
    comp temp, 6
    jump nz, dec7
    load temp, decoded_6
    ret
dec7:
    comp temp, 7
    jump nz, dec8
    load temp, decoded_7
    ret
dec8:
    comp temp, 8
    jump nz, dec9
    load temp, decoded_8
    ret
dec9:
    load temp, decoded_9
    ret

waitfcn:
    load wait2, 25
wt0:
    load wait1, 25
wt1 :   
    load wait0, 200
wt2 :
    sub wait0, 1
    jump nz, wt2
    sub wait1, 1
    jump nz, wt1
    sub wait2, 1
    jump nz, wt0
    ret
END

就像我说的,你可以通过用第二个按钮替换开关来改变它

您可以通过以下方式将重置按钮移动到按钮3:

; reset check
    and temp, 4
添加两个新的开关状态和“状态变量”:

以及:

然后,放下这个:

in updown, SWITCH

也许这有帮助?

重点是:还有两个州,但这也有帮助。您只需要在startstop_检查中处理启动/停止和向上/向下状态。是的,谢谢,我尝试了与上一个主题不同的方法(如您所见),但我仍然无法正确处理。自从我写这本书以来,这本书真是太多了,老实说,我迷路了。我不知道怎么做,所以我想如果有人知道,也许他可以尝试完成代码。这是可行的,但在一个开关上,这比在一个按钮上容易。我也有一个在按钮上工作的版本,但是使用2个状态,而不是4个,所以只有当我在空白的窗口中找到按钮状态时,按钮才会工作。如果你按下一个按钮,只要按下一个足够长的按钮就可以检测到它。乍一看,由于主从机制,它应该可以工作。很难说,因为我不知道这段代码是怎么运行的:显示器和按钮是如何工作的。啊,你指的是两态版本。。。不管怎样,Picobaze看起来很有趣。
startstop_check:
    in temp, BUTTON
    and temp, 3 ; mask extra bits off

    comp temp, 2 ; check if button 2 only
    jump nz,button1_check ; no
    comp temp, 3 ; check if buttons 1 and 2
    jump nz,button1_check ; no
    ; button 2 was pressed - "simulate" switch
    comp switch_state switch_state0 ; still being pressed
    jump nz button1_check ; yes - don't toggle
    load switch_state switch_state0 ; no, mark new press
    xor updown 1 ; toggle switch

button1_check:
    comp switch_state switch_state0 ; "switch"-button been pressed
    jump nz button1_check ; don't toggle
    load switch_state switch_state1 ; mark "switch"-button released

    and temp, 1
    ...
in updown, SWITCH