CE121L - Microprocessor System Design
Laboratory 5
Weeks of February 17, 1997

This laboratory will focus in I/O programming with interrupts. The interrupt programming will also be part of the homework assignment. Labs checked off after the start of lab on Friday, February 28, will receive a minimum 3-point (of 10 possible) late penalty.

Prelab

  1. Design and diagram the hookup between the terminal and your HC11 system.
  2. Write a program for polling I/O that echos characters from the PC keyboard to the PC screen. This will be very similar to your program from laboratory 3. Always check the status registers before reading or writing the DUART data registers.
  3. Read the HC11 section on interrupt processing. Reread the sections. You may wish to mask out all interrupts from everything except the UART.
  4. Write a program for interrupt-driven I/O. What follows is a description of the code -- you will need to thoroughly understand why everything is set up the way it is before you will be able to write the code. Both reading and writing will use circular queues (why circular?), so writing basic queue routines in assembler could be a good starting point (no, don't use a linked list). Reading and writing are both broken into two parts: the interrupt service routine, which is called when an interrupt occurs and then transfers data to or from the UART, and a request routine, which is called by your main program to retrieve or send data. You can think of the interrupt service routines as being part of an operating system kernel, while the request routines are the user's means of accessing the I/O device.

    Thus, there are four routines: a read interrupt service routine, a write interrupt service routine, a read request routine, and a write request routine. Additionally, you will write a main program that writes a preprogrammed string to the terminal (using the write request routine) and then executes an infinite loop of calls to the read and write request routines to test keyboard echo. Ideally, implement two versions of the write request routine: one for single characters, and the other for null-terminated strings.

    The write queue will need two pointers: the front and the back. When a character is added to the queue, it is added to the front (which is then incremented). When a character is transferred across the serial line, it is removed from the back after the transfer is complete, as indicated by an interrupt. In the write request routine (called by the main program), if the queue is full, enter a busy loop until it is not, and write a character to the front of the queue. If the write queue now has more than one character (the one you just added plus at least one more), a write is in progress, and the new character will be appended to the previous write request. If the write queue now has exactly one character (the one you just added), initiate a new transfer by copying the data to the UART. In the write interrupt service routine, update the write queue to remove the character just transmitted and, if present, transmit the next character.

    The read queue acts much the same way as the write queue: characters are added to the front of the queue by the read interrupt service routine and read from the back by the read request routine. If the read queue is empty, the read request routine should enter a loop until a character is available.

    Be sure to mask out interrupts while changing the queue pointers. If the read queue becomes full, discard additional characters. The queues must be circular, and should be small enough to verify their function (20 or fewer characters).

  5. Consider the transmitter CTS signal. Use one of the HC11's parallel input pins as a CTS line -- check the CTS line before writing to the UART. If it is not asserted, do not write to the UART. Wire it (for example, to a DIP switch) so that one can by hand change its assertion. What should happen if the character echo program is running and then CTS is disabled? Why? Write your answer in your lab notebook before coming to lab.

Laboratory

  1. Complete your RS-232C hookup.
  2. Test the polling program using CTS. Use the scope to examine the transmission.
  3. Test the interrupt program using CTS. Use the scope to examine the transmission.
  4. How fast a baud rate can you use to communicate to the PC?


Richard Hughey
Wed Feb 12 12:45:07 PST 1997