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
A few things are missing from this.
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
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 ie 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.