EE 308
Homework #4
Due Feb. 7, 1996

  1. The following subroutine produces a 10 ms delay on the 68HC11:
      d_10ms:   pshx
                ldx    #(20000/6)  ;1 us = 2 cycles => 10 ms = 20,000 cycles
                                   ;loop takes 6 cycles, so run loop 20000/6 times
      d_10ms_1: dex
                bne    d_10ms_1
                pulx
                rts
    

    Write a subroutine called "delay" which will call this routine a number of times equal to what's in the A accumulator. For example, to create a 1 second delay, do the following:

              ldaa    #100
              jsr     delay
    

  2. Write a program which increments Port B forever. Between each increment, use your "delay" routine to pause for 100 ms.

  3. Repeat Problem 2, but decrement Port B instead.

  4. Write a program which flashes between the binary patterns 0b01010101 and 0b10101010. Call your delay subroutine to delay for 100 ms between flashes.

  5. Write a program which implements a Thunderbird-style turn signal that alternates between left and right:

  6. Write a program which reads Port C, and uses bits 5 and 7 to control the function displayed on the LEDs. The following table shows what function to implement for different patterns of Port C:

    PC 7 PC 5 Port B Function
    0 0 Up Counter
    0 1 Down Counter
    1 0 Flasher
    1 1 Turn Signal

  7. Write a subroutine which takes the absolute value of the signed 16-bit number in the D accumulator and puts the result in the D accumulator.