Difference between revisions of "CSC270 Homework 8 Solution 2016"
Line 12: | Line 12: | ||
But you can figure out what is stored in the flip-flops by storing the same information in a byte variable, in memory. Let's call this variable LEDs. | But you can figure out what is stored in the flip-flops by storing the same information in a byte variable, in memory. Let's call this variable LEDs. | ||
− | + | <br /> | |
+ | <source lang="asm"> | ||
+ | |||
LEDs DB 0 | LEDs DB 0 | ||
− | + | ||
+ | </source> | ||
+ | <br /> | ||
Whenever you want to store a 1 in one of the LEDs, say the second one, you can do this: | Whenever you want to store a 1 in one of the LEDs, say the second one, you can do this: | ||
<br /> | <br /> |
Revision as of 09:18, 11 April 2016
--D. Thiebaut (talk) 10:16, 11 April 2016 (EDT)
<showafterdate after="20160101 00:00" before="20160601 00:00">
Problem 1
The hardware design is the same as the one we used in class, with 3 LEDs. Other designs could work, of course, but this one is fine.
With this design, storing a 1 at 8000 activates the first LED. Storing a 2 activates the 2nd one. Storing a 4 activates the 3rd one. Storing a 7 activates all 3. Storing a 0 turns them all OFF.
The trick here is that what you have is an output port. Once a flip-flop is set to some bit, either 0 or 1, there is no way for the processor to read that bit back to figure out if the attached LED is ON or OFF. So LDAA 8000, ORA 8000, ANDA 8000 won't work! They won't because they will all read from Address 8000, but there is nothing there to be read. What the 6811 will get is the input of the D flipflops. You cannot get the bits inside a flip-flop by looking at its input; only by looking at its Q output. So, these proposed solutions did not work.
But you can figure out what is stored in the flip-flops by storing the same information in a byte variable, in memory. Let's call this variable LEDs.
LEDs DB 0
Whenever you want to store a 1 in one of the LEDs, say the second one, you can do this:
LDAA #2 ;get ready to turn LED 2 ON
ORAA LEDs ;OR with that the current settings of the LEDs, as reflected in variables
STAA LEDs ;update variable
STAA 8000 ;store new configuration in real LEDs
This way all 3 LEDs are initialized, the 2nd one with a 1, the other 2 with the values they had before.
If we want to turn OFF an LED, say the third one, we can do this:
LDAA #255-4 ;get ready to turn LED 3 OFF
ANDA LEDs ;AND with that the current settings of the LEDs, as reflected in variables
STAA LEDs ;update variable
STAA 8000 ;store new configuration in real LEDs
</showafterdate>