hw19SLN

# hw19SLN - ECE 212 HW Set 19 SOLUTIONS p 1 of 10...

This preview shows pages 1–4. Sign up to view the full content.

ECE 212 HW Set 19 SOLUTIONS p 1 of 10 //home/vdimitrov/9117/53b8521898f646d1f885b4166fe826fd51d9a63e.doc ECE 212 Homework Set 19 – SOLUTIONS 1. (a) For the green and red LEDs interfaced to Port B in lecture, write the subroutine GonRoff specified. (b) Complete the Destroys line of the documentation. ;Name: GonRoff ;Preconditions: None. ;Postcondition: None. ;Destroys: ;Description: Turn the four green LEDs on, the four ; red LEDs off. ; (The green LEDs are connected to bits ; 3, 2, 1, 0 of Port B; the red LEDS are ; connected to bits 7, 6, 5, 4.) GonRoff: NOTE: To turn an LED on, you must sent the value 1 to the corresponding bit. A Solution: ;Name: GonRoff ;Preconditions: None. ;Postcondition: None. ;Destroys: A, flags. ;Description: Turn the four green LEDs on, the four ; red LEDs off. GonRoff: movb #0b00001111,PortB ;Activate all LEDs at the same time. rts Another Solution: ;Name: GonRoff ;Preconditions: None. ;Postcondition: None. ;Destroys: Flags. ;Description: Turn the four green LEDs on, the four ; red LEDs off. GonRoff: bclr PortB,0b11110000 ;First turn off the red, bset PortB,0b00001111 ; Then turn on the green. rts

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
ECE 212 HW Set 19 SOLUTIONS p 2 of 10 2. (a) For the eight switches interfaced to Port E in lecture, write the subroutine SW631OnOffOff specified. Use one 'compare' instruction in your routine, but do not use either brclr or brset . (b) Complete the Destroys line of the documentation. ;Name: SW631OnOffOff ;Preconditions: None. ;Postcondition: None. ;Destroys: ;Description: if (SW6 is On ; AND ; SW3 is Off ; AND ; SW1 is Off) A = 1; ; else A = 0; SW631OnOffOff: NOTE: An 'on' switch produces a 0 at the port. Therefore the 'if' condition is that Port E has the value x0xx1x1x, where 'x' denotes a don't-care. One Solution: ;Name: SW631OnOffOff ;Preconditions: None. ;Postcondition: None. ;Destroys: (A), B, flags. ;Description: if (SW6 is On ; AND ; SW3 is Off ; AND ; SW1 is Off) A = 1; ; else A = 0; SW631OnOffOff: ldaa #1 ;Anticipate success. ldab PortE ;Get the switch status, andb #0b01001010 ; isolate bits 6,3,1. cmpb #0b0 0 00 1 0 1 0 ;Looking for 0 1 1 beq OnOffOff ;Got it. deca ;Nope -- make A = 0. OnOffOff: rts
ECE 212 HW Set 19 SOLUTIONS p 3 of 10 3. Write the subroutine NumberOfSWsOn specified below. The subroutine refers to the eight switches interfaced to Port E in lecture. ;Name:

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 10

hw19SLN - ECE 212 HW Set 19 SOLUTIONS p 1 of 10...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online