\documentclass[11pt,dvips]{article}
\usepackage{epsfig}
\usepackage{fancyheadings}
\setlength{\parskip}{2ex}
%\setlength{\parindent}{0em}
\hoffset=-55pt
\voffset=-60pt
\textheight=9in
\textwidth=6.5in
\parindent=0pt
\parskip=10pt
\pagestyle{fancy}
\lhead{\bfseries EE 308 Exam 2}
\chead{\bfseries }
\rhead{\bfseries Spring 1997}
\lfoot{\bfseries }
\cfoot{\thepage}
\rfoot{\bfseries }
\setlength{\headrulewidth}{0.5pt}
\begin{document}

\begin{center} 
{\bf EE 308 - Exam 2 } \\[.1in]
{\bf  March 7, 1997}
\end{center}


\begin{flushleft}
Name: \underline{\hspace{4in}}\\[0.2in] 
\end{flushleft}
You may use any of the Motorola data books.
No calculators allowed.  Show all work.  Partial credit will be given.  No
credit will be given if an answer appears with no supporting work.

\begin{enumerate}

\item Consider the timer subsystem of an HC11 with a 2 MHz E-clock.
\begin{enumerate}
\item Without adjusting the prescaler, what is the longest time interval the
HC11 can measure (without the timer wrapping around)?  
       \underline{\hspace{2in}}
\item If you change the prescaler, what is the longest time interval the
HC11 can measure (without the timer wrapping around)?  
       \underline{\hspace{2in}}
\item What value does the prescaler have to have to measure this length of
time?  What special consideration do you need to observe when adjusting the
prescaler?
       \underline{\hspace{1in}}
\vspace{1in}
\item Write some C code which will set the prescaler to the value needed in
the above part.
\vspace{1in}
\item Write some C code which will capture the time of a rising edge on
Port A Bit 0, and generate an interrupt when this happens.  This code should
not affect any of the other timer subsystem functions.
\vspace{1in}

\item What physical pin on the HC11 (on your EVBU) does Port A Bit 0
correspond to?
       \underline{\hspace{2in}}

\item Write some C code to clear the Output Capture 3 flag.  This code should
not clear any of the other timer flags.

\end{enumerate}

\newpage

\item  The following tables show the values of an HC11's registers and some of
its memory.

\begin{tt}

\begin{tabular}{|c|c|c|}\hline
Reg &  - & -  \\ \hline
    & \multicolumn{2}{c|} {S X H I N Z V C} \\
CCR & \multicolumn{2}{c|} {1 0 0 0 0 1 0 1} \\ \hline
A:B & \hspace{2ex} A3 \hspace{2ex} &  \hspace{2ex} 92  \hspace{2ex} \\ \hline
X & \multicolumn{2}{c|} {82F2} \\ \hline
Y & \multicolumn{2}{c|} {12F7} \\ \hline
SP& \multicolumn{2}{c|} {208D} \\ \hline
PC& \multicolumn{2}{c|} {31F4} \\ \hline
\end{tabular}

\begin{tabular}{||r||r|r|r|r|r|r|r|r|r|r|r|r|r|r|r|r||}\hline\hline
 & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & A & B & C & D & E & F \\ \hline
 \hline
2070 & 14 & 00 & B7 & 23 & B4 & 67 & 30 & 18 & 8F & FE & 22 & 02 & 5C & E7 &
       03 & 26 \\ \hline
2080 & 0F & CC & A6 & 04 & 1B & 9D & 3F & 12 & 20 & EC & 02 & BD & 00 & 1E &
       3C & 96 \\ \hline
2090 & 73 & 10 & 03 & 86 & 40 & B7 & 10 & 25 & 3B & 38 & 9A & 05 & F2 & 20 &
       A5 & ED \\ \hline
20A0 & 7A & 10 & 04 & 86 & 80 & B7 & 10 & 25 & 3B & 38 & 9A & 05 & F2 & 20 &
       A5 & ED \\ \hline\hline
FFD0 & 20 & 20 & 20 & 30 & 20 & 40 & 20 & 50 & 20 & 60 & 20 & 70 & 20 & 80 &
       20 & 90 \\ \hline
FFE0 & 21 & A0 & 21 & B0 & 30 & D0 & 32 & F0 & 21 & 00 & 21 & 10 & 21 & 20 &
       21 & 30 \\ \hline
FFF0 & 20 & A0 & 21 & 50 & 21 & 60 & 21 & 70 & 21 & 80 & 21 & 90 & 21 & A0 &
       30 & 00 \\ \hline
\end{tabular}

\begin{tabular}{|c|c|c|c|c|}\hline\hline
PACTL & TMSK1 & TMSK2 & TCTL1 & TCTL2 \\ \hline
02 & 41 & 83 & 4E & 1B\\  \hline\hline
\end{tabular}

\end{tt}

\begin{enumerate}
\item What is the address of the first instruction the HC11 will execute after
a reset? \underline{\hspace{1in}}
\item How often will the timer overflow?
       \underline{\hspace{2in}}
\item How often will the RTI flag be set?
       \underline{\hspace{2in}}
\item Which timer interrupts are enabled? \underline{\hspace{2in}}
\item What will happen to Port A Bit 6 when {\tt TCNT = TOC2}?
       \underline{\hspace{2in}}
\item What will happen to Port A Bit 5 when {\tt TCNT = TOC3}?
       \underline{\hspace{2in}}
\item What will happen to Port A Bit 4 when {\tt TCNT = TOC4}?
       \underline{\hspace{2in}}
\item Will {\tt TIC1} capture the time of a changing edge on Port A Bit 2?  
If so, what edge?   \underline{\hspace{2in}}
\item Will {\tt TIC2} capture the time of a changing edge on Port A Bit 1?  
If so, what edge?   \underline{\hspace{2in}}
\item Will {\tt TIC3} capture the time of a changing edge on Port A Bit 0?  
If so, what edge?   \underline{\hspace{2in}}
\item Write down the instructions in the RTI interrupt service routine.
\vspace{1in}

\newpage

\item Write down the instructions in the TOI interrupt service routine.
\vspace{1in}

\item Assume the Real Time Interrupt Flag 
is set when the memory and registers are as shown above..   Show what will be in the HC11's
memory and registers when the HC11 gets to the first instruction in the
interrupt service routine (before it actually executes that instruction).
You only have to fill in blanks where registers or memory was changed.

\begin{tt}

\begin{tabular}{|c|c|c||r||r|r|r|r|r|r|r|r|r|r|r|r|r|r|r|r||}\hline
Reg & - & - &  & 0 & 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & A & B & C & D & E & F  \\ \hline
    & \multicolumn{2}{c||}{S X H I N Z V C} & 2070 &    &    &    &    &    &    &    &    &    &    &    &    &    &    &
          &    \\ \hline
CCR & \multicolumn{2}{c||}{               } & 2080 &    &    &    &    &    &    &    &    &    &    &    &    &    &    &
          &    \\ \hline
A:B & \hspace{6ex} & \hspace{6ex}  &  2090 &    &    &    &    &    &    &    &    &    &    &    &    &    &    & &    \\ \hline
X & \multicolumn{2}{c||} {    }  &  20A0 &    &    &    &    &    &    &    &    &    &    &    &    &    &    & &    \\ \hline
Y & \multicolumn{2}{c||} {    }  &  FFD0 &    &    &    &    &    &    &    &    &    &    &    &    &    &    & &    \\ \hline
SP& \multicolumn{2}{c||} {    }  &  FFE0 &    &    &    &    &    &    &    &    &    &    &    &    &    &    & &    \\ \hline
PC& \multicolumn{2}{c||} {    }  &  FFF0 &    &    &    &    &    &    &    &    &    &    &    &    &    &    & &    \\ \hline
\end{tabular}

\end{tt}

\end{enumerate}

\newpage

\item A 68HC11 is used to count the number of people entering a room.
Every time some one enters the room, a pulse will be generated.  You are
asked to  connect this pulse to one of your input capture pins.  Write a
program which will generate an interrupt when someone enters the room,
and display the number of people in the room on LEDs connected to Port C.
When the program is started the room is empty.  (Don't worry about
decrementing Port C when someone leaves -- maybe this is a prison, and when
someone goes in, they can't get out again).

\begin{enumerate}
\item Which input capture pin are you going to use?  What pin on the HC11
should you connect the pulse to? 
       \underline{\hspace{2in}}
\item List at least six things you need to do in software to use interrupts on
the HC11.
\vspace{1in}
\item Here is the start of your program.  Finish writing the program.  Be sure
to include all the steps you listed above.
\begin{verbatim}
#include <hc11.h>

main()
{
   while (1)
   {
   }
}
\end{verbatim}
\end{enumerate}

\end{enumerate}

\end{document}
