EE 308 -- LAB 6
More on the HC11 Timer Subsystem
Connect one of your debounced switches to Input Capture 2 (Port A, Bit 1),
as shown below:
Figure 1: Circuit to measure speed of button pushing.
The right part of Figure 1 is what the signal to IC2 will look
like if you push the pushbutton twice.
- Write a program to use the HC11 to measure the time between the two
falling edges of the signal in Figure 1. Set the prescaler so
you can measure time differences up to 500 ms. Your program should use
interrupts to catch the time of the falling edges.
- Attach the following
write_to_serial function to your program.
When you call this function with the time you calculated in Part 1, it
will print the time on the terminal. Call the function in your program
to display the time.
int write_to_serial(unsigned short n)
/* Routine to write an integer to the serial port */
unsigned char t,c;
t = (n&0x0f);
if (t < 10)
c[i] = t + 48;
c[i] = t + 55;
n = n >> 4;
c = 0x0d;
c = 0x0a;
while (!(SCSR&0x80)) ;
SCDR = c[i];
- Test your program on your EVBU. See how fast you can push the switch
- Add a TOC2 interrupt routine to generate a 1000 Hz square wave on
the OC2 pin. Show that it works by displaying the output of the OC2 pin
on the logic analyzer. While the 1 kHz signal is being generated, you should
be able to measure your push-button time.
Combine your 1000 Hz wave program with the Lab 5 program for incrementing
Port B using the RTI. You should simultaneously display the Port B output
on LEDs and the OC2 pin output on the logic analyzer. You should still be
able to measure you push-button time.
Fri Feb 23 1996
© 1996, New Mexico Tech