Difference between revisions of "CSC270 Homework 8 Solution 2016"

From dftwiki3
Jump to: navigation, search
(Created page with "--~~~~ ---- <showafterdate after="20160101 00:00" before="20160601 00:00"> =Problem 1= <br /> The hardware design is the same as the one we used in class, with 3 LEDs. Other...")
 
Line 16: Line 16:
 
   
 
   
 
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 />
 +
<source lang="asm">
 
         LDAA      #2                  ;get ready to turn LED 2 ON
 
         LDAA      #2                  ;get ready to turn LED 2 ON
 
         ORAA      LEDs              ;OR with that the current settings of the LEDs, as reflected in variables
 
         ORAA      LEDs              ;OR with that the current settings of the LEDs, as reflected in variables
 
         STAA      LEDs              ;update variable
 
         STAA      LEDs              ;update variable
 
         STAA      8000            ;store new configuration in real LEDs
 
         STAA      8000            ;store new configuration in real LEDs
+
</source>
 +
<br />
 
This way all 3 LEDs are initialized, the 2nd one with a 1, the other 2 with the values they had before.
 
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:
 
If we want to turn OFF an LED, say the third one, we can do this:
+
<br />
 +
<source lang="asm">
 
         LDAA      #255-4          ;get ready to turn LED 3 OFF
 
         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
 
         ANDA      LEDs              ;AND with that the current settings of the LEDs, as reflected in variables
 
         STAA      LEDs              ;update variable
 
         STAA      LEDs              ;update variable
 
         STAA      8000            ;store new configuration in real LEDs
 
         STAA      8000            ;store new configuration in real LEDs
+
</source>
+
<br />
 
      
 
      
 
</showafterdate>
 
</showafterdate>

Revision as of 09:17, 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>