Homework 12
Due April 27, 2001


  1. How do you set up the HC12 to use the SPI in the following mode:

  2. Explain how the SPIF (SPI Flag) is set. Also, explain how to clear this flag.

  3. A 68HC12 is being used to communicate with two devices over the SPI. The devices are connected as shown below:

    \epsfig{file=exam3_q2a.eps,width=3in}

    Each byte you write to the LCD chip is displayed on an LCD display. The following shows how to write to the LCD chip over the SPI:

    \epsfig{file=exam3_q2b.eps,width=4in}

    The GP2D device is a distance sensor. When the HC12 reads from the GP2D chip, the GP2D sends it a byte which tells it how far it is from an object (such as a wall). The GP2D sends a 0x00 when it is almost touching the object. It sends a 0xFF when it is 2 feet (or more) from the object. The following shows how to read from the GP2D chip over the SPI:

    \epsfig{file=exam3_q2c.eps,width=4in}

    1. How do you set up the HC12 to communicate with the LCD and the GP2D? Explain what values you need to write to which registers. Be sure to set the correct clock phase and polarity. Also, set up Port P so that both the GP2D and the LCD are deselected.

    2. Write some C code to set up the HC12 to communicate with the LCD chip and the GP2D chip - i.e., write C code to implement (1).

    3. Write some C code to read the distance from the GP2D. Make sure the LCD chip is deselected while you are doing this.

    4. Write some C code to sent the sequence "Hello" to the LCD chip. Make sure the GP2D is deselected while you are doing this.



Bill Rison
2001-04-23