\documentclass[11pt]{article}
\usepackage{pdflscape}
\newif\ifpdf
\ifx\pdfoutput\undefined
    \pdffalse           % we are not running PDFLaTeX
\else
    \pdfoutput=1        % we are running PDFLaTeX
    \pdftrue
\fi
%----------------------------------------------------------------------
\ifpdf
    \usepackage[pdftex,
        letterpaper=true,
        colorlinks=true,
        urlcolor=rltblue,               % \href{...}{...}
        anchorcolor=rltbrightblue,
        filecolor=rltgreen,             % \href*{...}
        linkcolor=rltred,               % \ref{...} and \pageref{...}
        menucolor=webdarkblue,
        citecolor=webbrightgreen,
        pdftitle={EE 308 Spring 2009},
        pdfauthor={Bill Rison, New Mexico Tech},
        pagebackref,
        pdfpagemode=None,
        bookmarksopen=true]{hyperref}
    \pdfcompresslevel=9
    \usepackage[pdftex]{graphicx}
    \usepackage{thumbpdf}
\else
    \usepackage[dvips,
        letterpaper=true,
        colorlinks=true,
        urlcolor=rltblue,               % \href{...}{...}
        anchorcolor=rltbrightblue,
        filecolor=rltgreen,             % \href*{...}
        linkcolor=rltred,               % \ref{...} and \pageref{...}
        menucolor=webdarkblue,
        citecolor=webbrightgreen]{hyperref}
    \usepackage{graphicx}
\fi

\usepackage{color}
\definecolor{rltbrightred}{rgb}{1,0,0}
\definecolor{rltred}{rgb}{0.75,0,0}
\definecolor{rltdarkred}{rgb}{0.5,0,0}
%
\definecolor{rltbrightgreen}{rgb}{0,0.75,0}
\definecolor{rltgreen}{rgb}{0,0.5,0}
\definecolor{rltdarkgreen}{rgb}{0,0,0.25}
%
\definecolor{rltbrightblue}{rgb}{0,0,1}
\definecolor{rltblue}{rgb}{0,0,0.75}
\definecolor{rltdarkblue}{rgb}{0,0,0.5}

\definecolor{webred}{rgb}{0.5,.25,0}
\definecolor{webblue}{rgb}{0,0,0.75}
\definecolor{webgreen}{rgb}{0,0.5,0}


\usepackage{fancyheadings}
%\setlength{\parskip}{2ex}
%\setlength{\parindent}{2em}
\hoffset=-55pt
\voffset=-60pt
\textheight=9in
\textwidth=6.5in
\parindent=2em
\parskip=10pt
\pagestyle{fancy}
\lhead{\bfseries EE 308}
\chead{\bfseries }
\rhead{\bfseries Spring 2009}
\lfoot{\bfseries }
\cfoot{\thepage}
\rfoot{\bfseries }
\setlength{\headrulewidth}{0.5pt}

\begin{document}
\parindent=0pt
\parskip=10pt

\begin{center} 
{\bf EE 308 -- Homework 5} \\[.1in]
Due Feb. 23, 2009\\
\end{center}

For the homework problems which follow assume you have included the file {\tt
hcs12.h} in your C program. Thus, you can refer to {\tt PORTB} when you want
to access a byte at address {\tt 0x0001}. Where I ask for "some code" just
write that part of a C program which will do the task. Where I ask for "a
program" write a complete program, include the {\tt \#include "hcs12.h"}
line, the declaration of variables, the {\tt main()} function, etc.

\begin{enumerate}
\item Write some C code which will set bits 3 and 1 of the eight-bit register
at address {\tt 0x0075} while leaving the other bits unchanged.

\item Write some C code which will clear bits 13, 11, 6 and 0 of the sixteen-bit
register at address {\tt 0x0076} while leaving the other bits unchanged.

\item Write some C code which will set bit 0 of PORTB if the 16-bit value at
address {\tt 0x0099} is less than 72, and will clear bit 0 of PORTB if the
value is greater than or equal to 72.

\item Write some C code which will wait until Bit 7 of the eight-bit number at
address {\tt 0x00cc} becomes set.

\item Consider an array of 8-bit data located in memory with a starting
address of \verb+$1000+ and an ending address of \verb+$101F+.  Write a
C program which will swap the first element of the array with the last element;
the second element with the next-to-last element, etc.  

\item An MC9S12 has the following in some of its registers:

{\tt
\begin{center}
\begin{tabular}{|c|c|c|}\hline
TSCR1 & TSCR2 & TFLG2 \\ \hline
0x80 & 0x04 & 0x80 \\ \hline
\end{tabular}
\end{center}
}

\begin{enumerate}
\item Is the timer subsystem enabled?  How can you
tell this?
\item How long will it take (in ms) for the timer to overflow?  How can you
tell this?
\item Has the timer overflowed since the last time the TOF flip-flop was
reset?  How can you tell this?
\end{enumerate}

\item Write a C function to convert an eight-bit binary number to its
Gray code equivalent.  The procedure to do this is as follows:  Exclusive OR
the number with the same number shifted right by one bit.  The function should
have one argument (the eight-bit number), and should return the eight-bit Gray
code value.

\item Write a C function to generate the next pattern in the sequence for an
eight-bit Johnson counter.  The procedure to do this is as follows:  Shift the
present pattern to the right by one bit.  The most significant bit of the next
pattern is the inverse of the least significant bit of the present pattern.
The function should have one argument (the curent pattern, an eight-bit
number), and should return the eight-bit value of the next pattern.

\newpage

\item Write some C code to take the next entry out of a table, write it to {\tt
PORTB}, and update the index into the table.  Here is an example of what the
table might look like:

\begin{verbatim}
const char table[] = {0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80};
\end{verbatim}

Use a variable called \verb+table_index+ to hold the index of the pattern to
write to PORTB.  Your code should write the table entry corresponding to the
index to PORTB.  (For example, if \verb+table_index+ were 5, you would write
the fifth element of the table, 0x10, to PORTB.)  It should then update
\verb+table_index+ to point to the next element of the table.  Make sure that
\verb+table_index+ stays between 0 and \verb+sizeof(table)-1+.

\end{enumerate}

\end{document}
