0

I am trying to figure out how to display two hex numbers read from the dipswitches on a husky 11 board. Our Lab only required us to display 1 number, but I am curious on how to display 2 numbers. I only want the switches to be read when I push the Pa0 button, as it does in my first lab. The code below shows both values when I push the pa0 button but the right most lcd (that displays the lower nibble) turns off as soon as I release the button. How do I fix this? I have tried doing a couple different delays but it doesn't work. Thanks.

                          ;Simple program written to display in Hex the values of the upper 4 and lower for dipswitches on the built LCD's.
                  ;Only load values when button PA0 is pressed.

    REGBAS  EQU $1000   ;register block pointer, also represents address for PORT A
    PORTB   EQU     $1004   ;port B starting at $1004
    PORTD   EQU     $08     ;port D starting at $1008
    DDRD    EQU     $09     ;port direction for portd
    PORTC   EQU     $1003   ;dip switch

    ; the BCD codes for hexadecimal numbers 0 through F
    SEG     FCB     $3f, $06, $5b, $4f, $66, $6d, $7d, $07
FCB $7f, $67, $77, $39, $7c, $5e, $79, $71
    DIP     RMB     1       ;reserve space to store the 8-bit value read from the switch

ORG     $D000       ;user code stored starting at address $D000
LDX     #REGBAS         ;load IX with the address of PORT A
BSET    DDRD,X $0F      ;configure the data direction register of port D to use the lower 4-bits as output data
BSET    PORTD,X $3B     ;set bits 2-5 of port D (recall that they control the 4 seven segment displays)

    WAIT    LDAA    REGBAS          ;wait for PA0 to be press (if not pressed the DIP switch value will not be read)
ANDA    #$01
CMPA    #$00
BNE     WAIT
READ    LDAB    PORTC           ;Once PA0 is pressed read the DIP switch value
LDX     #DIP
STAB    0,X             ;store a copy of the read 8-bit value at the reserved memory location (DIP)
ANDB    #$0F            ;now that you have a copy of the read value in memory, modify the contents of ACC B
            ;so that lower nibble represents the 4-bit value read from lower switches (1-4)
    LDY     #SEG            ;prepare to read the BCD code of this lower 4-bit value from the switch
ABY
LDAA    0,Y
 ;Enable the rightmost seven segment display to display the value of the lower 4-bit of the switch
LDX     #REGBAS
BCLR    PORTD,X 4
BSET    PORTD,X 8
BSET    PORTD,X $10
BSET    PORTD,X $20
LDX     #PORTB          ;send the corresponding hexadecimal value of the nibble to port B for displaying
STAA    0,X
ldy    #$ff
delay   dey                     ;Delay to hold the LCD on
bne     delay
LDX     #DIP
STAB    0,X             ;store a copy of the read 8-bit value at the reserved memory location (DIP)
ANDB    #$F0            ;now that you have a copy of the read value in memory, modify the contents of ACC B
            ;so that lower nibble represents the 4-bit value read from lower switches (1-4)
    LDY     #SEG            ;prepare to read the BCD code of this lower 4-bit value from the switch
ABY
LDAA    0,Y
    LDX     #DIP
LDAB    0,X
LDY     #SEG            ;prepare to read the corresponding BCD code of this nibble from your BCD code table
ABY
LDAA    0,Y
LDX     #REGBAS
BSET    PORTD,X 4       ;setup the corresponding bits of PORT D that control the second from right seven segment display
BCLR    PORTD,X 8
BSET    PORTD,X $10
BSET    PORTD,X $20
LDX     #PORTB          ;prepare to send the BCD code for the upper nibble to PORT B (the seven segment display)
STAA    0,X
ldy     #$ff
bne     WAIT

BRA     READ

    END
EEFez
  • 1
  • You need to refactor your code to make it clearer. There is unnecessary use of Y register when the X register is available (and produces shorter/faster instructions.) One immediately logical error is at the end `LDY #$FF` followed by `BNE WAIT` is always true and possibly this is your problem. But, I haven't taken a more thorough look at your code. – tonypdmtr Jun 15 '17 at 20:46
  • You do not need to access you `DIP` variable via register X or Y. You can load from it or store to it directly. For example, instead of `LDX #DIP` `LDAA ,X` you can do `LDAA DIP` – tonypdmtr Jun 15 '17 at 21:00

0 Answers0