我试图找出如何显示从赫斯基11板上的拨动开关读取的两个十六进制数字。我们的实验室只要求我们显示1个数字,但我很好奇如何显示2个数字。我只想在按下Pa0按钮时读取开关,就像我在第一个实验室中那样。下面的代码显示了当我按下pa0按钮时的两个值,但是当我释放按钮时,最右边的lcd(显示较低的半字节)关闭。我该如何解决?我尝试过几次不同的延迟,但它没有用。感谢。
;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