\hypertarget{sharp_8c}{
\section{sharp.c File Reference}
\label{sharp_8c}\index{sharp.c@{sharp.c}}
}
{\tt \#include \char`\"{}t89c51cc02.h\char`\"{}}\par
{\tt \#include \char`\"{}datatypes.h\char`\"{}}\par
{\tt \#include \char`\"{}adc.h\char`\"{}}\par
{\tt \#include \char`\"{}sharp.h\char`\"{}}\par
\subsection*{Functions}
\begin{CompactItemize}
\item 
\hypertarget{sharp_8c_b4f83c75c335710dcc6b818af357be73}{
void \hyperlink{sharp_8c_b4f83c75c335710dcc6b818af357be73}{Sharp\_\-init} ()}
\label{sharp_8c_b4f83c75c335710dcc6b818af357be73}

\begin{CompactList}\small\item\em initializes GP2D120 subsystem \item\end{CompactList}\item 
void \hyperlink{sharp_8c_92f90bb0131a2025dfd6b80bd2720aa3}{Sharp\_\-Timer\-Init} ()
\begin{CompactList}\small\item\em initializes an ISR to signal that the Sharp GP2D120 is ready to be read. \item\end{CompactList}\item 
void \hyperlink{sharp_8c_76b1b3a701fecac895a48626f7078fab}{Sharp\_\-Timer\_\-interrupt} (void)
\begin{CompactList}\small\item\em Timer ISR for delaying the Sharp GP2D120. \item\end{CompactList}\item 
\hyperlink{datatypes_8h_89b917a7bdb582e19cbde98e817fa0b3}{WORD} \hyperlink{sharp_8c_2d083886f8c3d98135f42680a1615e13}{Sharp\_\-read} ()
\begin{CompactList}\small\item\em read Sharp GP2D120 sensor if it is active \item\end{CompactList}\end{CompactItemize}
\subsection*{Variables}
\begin{CompactItemize}
\item 
volatile bit \hyperlink{sharp_8c_191595114dcb045c796a27458c4411a2}{sharp\_\-ready}
\item 
volatile bit \hyperlink{sharp_8c_8e956acaea3581f6b7d4e15aa29ce03f}{wait\_\-bit}
\end{CompactItemize}


\subsection{Detailed Description}


Definition in file \hyperlink{sharp_8c-source}{sharp.c}.

\subsection{Function Documentation}
\hypertarget{sharp_8c_2d083886f8c3d98135f42680a1615e13}{
\index{sharp.c@{sharp.c}!Sharp_read@{Sharp\_\-read}}
\index{Sharp_read@{Sharp\_\-read}!sharp.c@{sharp.c}}
\subsubsection[Sharp\_\-read]{\setlength{\rightskip}{0pt plus 5cm}\hyperlink{datatypes_8h_89b917a7bdb582e19cbde98e817fa0b3}{WORD} Sharp\_\-read (void)}}
\label{sharp_8c_2d083886f8c3d98135f42680a1615e13}


read Sharp GP2D120 sensor if it is active 

\begin{Desc}
\item[Returns:]0xffff if Sharp is not active, Sharp reading else \end{Desc}


Definition at line 86 of file sharp.c.

References ADC(), SHARP\_\-PWRCTL, and sharp\_\-ready.

Referenced by main().\hypertarget{sharp_8c_76b1b3a701fecac895a48626f7078fab}{
\index{sharp.c@{sharp.c}!Sharp_Timer_interrupt@{Sharp\_\-Timer\_\-interrupt}}
\index{Sharp_Timer_interrupt@{Sharp\_\-Timer\_\-interrupt}!sharp.c@{sharp.c}}
\subsubsection[Sharp\_\-Timer\_\-interrupt]{\setlength{\rightskip}{0pt plus 5cm}void Sharp\_\-Timer\_\-interrupt (void)}}
\label{sharp_8c_76b1b3a701fecac895a48626f7078fab}


Timer ISR for delaying the Sharp GP2D120. 

This Timer ISR delays the Sharp GP2D120 and signals its readiness after 50ms via the \hyperlink{sharp_8c_191595114dcb045c796a27458c4411a2}{sharp\_\-ready} semaphore. The interrupt is triggered every 25ms. Therefor the routine uses a flag (\hyperlink{sharp_8c_8e956acaea3581f6b7d4e15aa29ce03f}{wait\_\-bit}) to signal its second run. The sensor readiness is signalled in the second run of the ISR. The ISR deactivates itself after its second execution.\par
 

Definition at line 64 of file sharp.c.

References sharp\_\-ready, SHARP\_\-TIMER\_\-RELOAD\_\-H, SHARP\_\-TIMER\_\-RELOAD\_\-L, and wait\_\-bit.\hypertarget{sharp_8c_92f90bb0131a2025dfd6b80bd2720aa3}{
\index{sharp.c@{sharp.c}!Sharp_TimerInit@{Sharp\_\-TimerInit}}
\index{Sharp_TimerInit@{Sharp\_\-TimerInit}!sharp.c@{sharp.c}}
\subsubsection[Sharp\_\-TimerInit]{\setlength{\rightskip}{0pt plus 5cm}void Sharp\_\-Timer\-Init (void)}}
\label{sharp_8c_92f90bb0131a2025dfd6b80bd2720aa3}


initializes an ISR to signal that the Sharp GP2D120 is ready to be read. 

Initializes an ISR to signal that the Sharp GP2D120 is ready to output a valid distance reading. Activates Timer 1 which counts for 25ms twice and sets a readiness signal upon 2nd ISR invocation. (\begin{Desc}
\item[See also:]\hyperlink{sharp_8c_191595114dcb045c796a27458c4411a2}{sharp\_\-ready}) \end{Desc}


Definition at line 39 of file sharp.c.

References sharp\_\-ready, SHARP\_\-TIMER\_\-RELOAD\_\-H, SHARP\_\-TIMER\_\-RELOAD\_\-L, and wait\_\-bit.

\subsection{Variable Documentation}
\hypertarget{sharp_8c_191595114dcb045c796a27458c4411a2}{
\index{sharp.c@{sharp.c}!sharp_ready@{sharp\_\-ready}}
\index{sharp_ready@{sharp\_\-ready}!sharp.c@{sharp.c}}
\subsubsection[sharp\_\-ready]{\setlength{\rightskip}{0pt plus 5cm}volatile bit \hyperlink{sharp_8c_191595114dcb045c796a27458c4411a2}{sharp\_\-ready}}}
\label{sharp_8c_191595114dcb045c796a27458c4411a2}


A semaphore that signals whether the GP2D120 is ready to be read 

Definition at line 19 of file sharp.c.

Referenced by Sharp\_\-read(), Sharp\_\-Timer\_\-interrupt(), and Sharp\_\-Timer\-Init().\hypertarget{sharp_8c_8e956acaea3581f6b7d4e15aa29ce03f}{
\index{sharp.c@{sharp.c}!wait_bit@{wait\_\-bit}}
\index{wait_bit@{wait\_\-bit}!sharp.c@{sharp.c}}
\subsubsection[wait\_\-bit]{\setlength{\rightskip}{0pt plus 5cm}volatile bit \hyperlink{sharp_8c_8e956acaea3581f6b7d4e15aa29ce03f}{wait\_\-bit}}}
\label{sharp_8c_8e956acaea3581f6b7d4e15aa29ce03f}


A semaphore that signals the second run of the Sharp delaying Timer interrupt if 0 

Definition at line 21 of file sharp.c.

Referenced by Sharp\_\-Timer\_\-interrupt(), and Sharp\_\-Timer\-Init().