Difference between revisions of "CSC270 Homework 8 Solution 2016"

From dftwiki3
Jump to: navigation, search
Line 39: Line 39:
 
</source>
 
</source>
 
<br />
 
<br />
   
+
==Software Loop==
 +
<br />
 +
Here we do not need to remember the state of the LEDs in a variable, since we always want one LED ON and the other 2 OFF.  So we don't need to remember their current state.  The coding is simple.  By the way, we have a function in the Monitor that waits one second if you call it.  Its address is C027.  Very useful!
 +
<source lang="asm">
 +
 
 +
LEDs    DB    0
 +
 
 +
start:  LDAA  #1    ; turn Green ON
 +
        STAA  8000 
 +
 
 +
        JSR  C027  ; wait 1 sec
 +
        JSR  C027  ; wait 2 sec
 +
        JSR  C027  ; wait 3 sec
 +
 
 +
        LDAA  #2    ; turn Yellow ON
 +
STAA  8000 
 +
 
 +
        JSR  C027  ; wait 1 sec
 +
 
 +
        LDAA  #4    ; turn Red ON
 +
STAA  8000 
 +
 
 +
        JSR  C027  ; wait 1 sec
 +
        JSR  C027  ; wait 1 sec
 +
        JSR  C027  ; wait 1 sec
 +
 +
JMP  start
 +
 
 +
</source>
 
</showafterdate>
 
</showafterdate>
  

Revision as of 10:26, 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


Software Loop


Here we do not need to remember the state of the LEDs in a variable, since we always want one LED ON and the other 2 OFF. So we don't need to remember their current state. The coding is simple. By the way, we have a function in the Monitor that waits one second if you call it. Its address is C027. Very useful!

LEDs    DB    0

start:  LDAA  #1    ; turn Green ON
        STAA  8000  

        JSR   C027  ; wait 1 sec
        JSR   C027  ; wait 2 sec
        JSR   C027  ; wait 3 sec

        LDAA  #2    ; turn Yellow ON
	STAA  8000  

        JSR   C027  ; wait 1 sec

        LDAA  #4    ; turn Red ON
	STAA  8000  

        JSR   C027  ; wait 1 sec
        JSR   C027  ; wait 1 sec
        JSR   C027  ; wait 1 sec
	
	JMP   start

</showafterdate>