EASy68K
http://www.easy68k.com/EASy68Kforum/

testing the bit
http://www.easy68k.com/EASy68Kforum/viewtopic.php?f=6&t=875
Page 1 of 1

Author:  soonph87 [ Tue Aug 17, 2010 6:00 pm ]
Post subject:  testing the bit

I want to write a code to test every bits of the LED. the specification is that if any LEDs are ON except LED0, then it will display Door Open, if LED7 - LED1 are OFF and only LED0 is ON, then it will display Pass. example, if LED1 and LED0 are ON, then it will display Door Open. my code is as followed:

CLR.B D0
MOVE.B SWITCH,D0
NOT.B D0
MOVE.B D0,LED ; let's say only LED1 and LED0 are ON
MOVE.L D0,A3

MOVE.B #7,D2
DOPEN BTST D2,(A3)
BNE DOPEN_MSG ; display the msg 'Door Open'
SUB.B #1,D2
CMPI #0,D2
BEQ PASS_MSG ; display the msg 'Pass'
BRA DOPEN

my problem is, when LED1 and LED0 are ON, the desired answer is the program will display Door Open, but in this case, it displayed Pass. May i know why???

Author:  clive [ Tue Aug 17, 2010 7:09 pm ]
Post subject: 

Your use of A3 and (A3) are not appropriate.

You load A3 with the bit vector sent to the LEDs, and then use it as an address from which to load a value in the bit test, rather than use the value itself.

Something like this would make more sense.

Code:
        CLR.B   D0
        MOVE.B  SWITCH,D0  ; Load Switch register
        NOT.B   D0  ; Invert
        MOVE.B  D0,LED  ; let's say only LED1 and LED0 are ON

        MOVE.B  #7,D2
DOPEN   BTST    D2,D0  ; Bit test data driving LED's
        BNE     DOPEN_MSG ; display the msg 'Door Open'
        SUB.B   #1,D2
        CMPI    #0,D2
        BEQ     PASS_MSG ; display the msg 'Pass'
        BRA     DOPEN

Author:  soonph87 [ Sat Aug 28, 2010 5:44 am ]
Post subject: 

thanks

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/