0

I want to Write a program to read a value from the push buttons and display that value on the LEDs. The program should run continuously and as the push buttons are changed, the display changes. I tried many ways but it does not show any thing in Could any one help me to know where is the problem.

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
vogomatix
  • 4,856
  • 2
  • 23
  • 46
nas2016
  • 15
  • 5
  • @Ped7g : the problem when I pressed the button it does not show in LEDS I know how the to do it with the toggle switches. But in button not shows any thing even if I take NOT.B for value on button in order to present in LEDS but still not work. – nas2016 Jan 27 '17 at 01:40
  • @Ped7g: I edit it a new code to make it clear with comment, I appreciate any help – nas2016 Jan 27 '17 at 01:49
  • The new code works for me (although the value is "1 loop delayed", because you set D2 after you already wrote it to LEDS). I just run it by F9, and when I'm pushing the buttons, the LEDS do change. – Ped7g Jan 27 '17 at 01:58
  • @Ped7g: do you mean it works with you without any change in the code, I did not got what do you mean by D2 – nas2016 Jan 27 '17 at 02:03
  • Yes, it works for me without change. "D2": when you run the simulation, first time the `MOVE.B D2,LEDS` sets value at `$E00010` to zero, because `D2` contains zero from simulator init and you did not change it. Then you load `D2` with "not (button)" value, so in next iteration of loop this will be displayed (so it's sort of "delayed" .. if you would put the display right after NOT, you don't even need to copy D1 to D2). (the delay is only 7 instructions (between reading BUTTON and displaying it to LED), so human can't notice it) – Ped7g Jan 27 '17 at 02:06
  • @ Ped7g: oh it is strange that does not work with me, Thanks I appreciate your help – nas2016 Jan 27 '17 at 02:13

1 Answers1

0

A few things are missing from this.

  1. A button is normally a single bit, not a whole byte, so there should be some form of mask applied to the button input. Similarly setting an LED normally involves setting a single bit, not a byte, unless it is some form of multicolor LED. I am assuming you have 8 push buttons and 8 corresponding LEDs

  2. The code you have illustrated will run continuously because you load D0 with 2 after the LOOP label, and at the end of the loop you subtract 2 from D0 (which has the value 2) and then loop if that result is equal to zero i.e. always. If you really want a continuous loop, there is no point in using D0 at all.

    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
    
vogomatix
  • 4,856
  • 2
  • 23
  • 46