EE 308 -- LAB 7
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.
SCRIPT E:\EE308\E.SCR
.
Set a breakpoint at the first line of your Input Capture 2 interrupt
service routine. Set Port A so the Input Capture 2 is high. Start the
program running. Stop the program, and change the Port A value so that
Input Capture 2 is low. Note the values of TCNT and TIC2.
Continue your program. It should stop when your interrupt service routine
is called. What are the values of TCNT and TIC2 now? Why?
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 unsigned integer to the serial port */ { char i; unsigned char t,c[6]; for (i=3;i>=0;i--) /* Four nibbles, starting with rightmost */ { t = (n&0x0f); /* Isolate right-most four bits */ if (t < 10) /* Convert to ASCII */ c[i] = t | 0x30; else c[i] = t + 55; n = n >> 4; /* Pick up next four bits to the left */ } c[4] = 0x0d; /* Add a CR LF to the end */ c[5] = 0x0a; for (i=0;i<6;i++) /* Send the 6 bytes out the serial port */ { while (!(SCSR&0x80)) ; /* Wait until transmitter ready */ SCDR = c[i]; /* Send bit to RS-232 transmitter */ } }
Also, add the following two lines of code to the initialization portion of your main program. It initializes the HC11's RS-232 port to 9600 baud.
SCCR2 = 0x08; /* Enable RS-232 transmitter */ BAUD = 0x30; /* Set RS-232 baud rate to 9600 */