0

我想编写一个程序来从按钮中读取一个值并在 LED 上显示该值。程序应该连续运行,并且随着按钮的改变,显示也会改变。我尝试了很多方法,但它没有显示任何东西可以帮助我知道问题出在哪里。

LEDS       EQU     $E00010                 ;LEDS adress
BUTTON     EQU     $E00014                 ;BUTTON address
           ORG     $400                    ;start of program area

START
Loop        MOVE.B  #2,D0                             
            MOVE.B  BUTTON,D1               ;move the value of button to D1   
            MOVE.B  D2,LEDS 
            NOT.B   D1                      ;take NOT to flip the value in order to present it in LEDS                                    
           MOVE.B  D1,D2                    ;move the value to LEDS                        
           SUB.B    #2,D0                   ; if D0 =0 then loop again
            BEQ     Loop                     



          SIMHALT       
            END     START
4

1 回答 1

0

这其中缺少一些东西。

  1. 按钮通常是单个位,而不是整个字节,因此应该对按钮输入应用某种形式的掩码。同样,设置 LED 通常涉及设置单个位,而不是字节,除非它是某种形式的多色 LED。我假设您有 8 个按钮和 8 个相应的 LED

  2. 您说明的代码将连续运行,因为您在 LOOP 标签后加载 D0 2,并在循环结束时从 D0 中减去 2(其值为 2),然后如果该结果等于 0 则循环,即始终. 如果你真的想要一个连续的循环,那么使用 D0 根本没有意义。

    LEDS    EQU     $E00010        ;LEDS address
    BUTTON  EQU     $E00014        ;BUTTON address
    
            ORG     $400           ;start of program area               
    START
    
    LOOP                        
            MOVE.B  BUTTON,D1      ; Read buttons
            NOT.B   D1             ; LEDs are inverse of button    
            MOVE.B  D1,LEDS        ; write to LEDs
            BRA.S   LOOP           ; do continously
    
            SIMHALT                 ; doesn't get here but still
            END     START
    
于 2018-09-11T15:23:46.197 回答