I have written the following assembly code (for an 8052 soft processor) to show a number on my Altera DE-2's 8 7-segment displays:
mov HEX0, #0x98 ; show 9
mov HEX1, #0xC0 ; show 0
mov HEX2, #0xF9 ; show 1
mov HEX3, #0xF8 ; show 7
mov HEX4, #0x92 ; show 5
mov HEX5, #0x92 ; show 5
mov HEX6, #0x92 ; show 5
mov HEX7, #0xA4 ; show 2
HEXns are defined as follows:
HEX0 DATA 091H ; Zero turns the segment on
HEX1 DATA 092H ;
HEX2 DATA 093H ;
HEX3 DATA 094H ;
HEX4 DATA 08EH ;
HEX5 DATA 08FH ;
HEX6 DATA 096H ;
HEX7 DATA 097H ;
The above code works just fine on its own, but when I try to rotate the number using the following code, all of the 7-segment displays output as though the HEXn registers were set to 0x00.
M0:
wait(2)
mov A, HEX0 ; store HEX0 in the accumulator
mov HEX0, HEX1
mov HEX1, HEX2
mov HEX2, HEX3
mov HEX3, HEX4
mov HEX4, HEX5
mov HEX5, HEX6
mov HEX6, HEX7
mov HEX7, A
ljmp M0
END
Here wait(2)
is a macro that uses up about two seconds worth of clock cycles. Could someone tell me (or even speculate) as to why HEXn are being written to 0?
This is an answer from my professor Jesus Calvino-Fraga:
HEX0 to HEX7 are write only registers. They can not be read back. The traditional way of overcoming this limitation is by using variables (or registers if enough are available). First let define eight byte variables. Something like this will do:
dseg at 30H
shex0: ds 1
shex1: ds 1
shex2: ds 1
shex3: ds 1
shex4: ds 1
shex5: ds 1
shex6: ds 1
shex7: ds 1
cseg
Then initialize the variables with numbers:
mov shex0, #0x98 ; show 9
.
.
.
mov shex7, #0xA4 ; show 2
Finally the loop, where the variables are sent to the displays and rotated:
M0:
; Send to displays
mov hex0, shex0
.
.
mov hex7, shex7
;Rotate
mov A, shex0; store HEX0 in the accumulator
mov shex0, shex1
.
.
.
mov shex6, shex7
mov shex7, A
sjmp M0