\hypertarget{sharp_8h}{
\section{sharp.h File Reference}
\label{sharp_8h}\index{sharp.h@{sharp.h}}
}
{\tt \#include \char`\"{}datatypes.h\char`\"{}}\par
{\tt \#include \char`\"{}t89c51cc02.h\char`\"{}}\par
\subsection*{Defines}
\begin{CompactItemize}
\item 
\#define \hyperlink{sharp_8h_91ae6624561f0f3ab67f74ca73f01dac}{SHARP\_\-PWRCTL}~P3\_\-2
\item 
\#define \hyperlink{sharp_8h_af9d624d746735332760d696823aabd1}{SHARP\_\-PWRCTL\_\-MASK}~0x04
\item 
\#define \hyperlink{sharp_8h_181a10c4536739f68af0f39641005e24}{SHARP\_\-ONLY}~0x03
\item 
\#define \hyperlink{sharp_8h_3582f952f36678f0e6a187d42a5aae71}{SHARP\_\-TIMER\_\-RELOAD\_\-H}~0x7d
\item 
\#define \hyperlink{sharp_8h_45d3b415b430e5dc79dbe697a7cf9679}{SHARP\_\-TIMER\_\-RELOAD\_\-L}~0xcb
\item 
\#define \hyperlink{sharp_8h_914bbfd290fb3cd512e7b42942ee38cb}{Sharp\_\-Power\-On}()~P3=(P3 \& SHARP\_\-ONLY)$|$SHARP\_\-PWRCTL\_\-MASK; Sharp\_\-Timer\-Init();
\item 
\#define \hyperlink{sharp_8h_d464b1bd22d8ed80116307e7dc7f42bc}{Sharp\_\-Power\-Off}()~SHARP\_\-PWRCTL=0; TR1=0; ET1=0;
\end{CompactItemize}
\subsection*{Functions}
\begin{CompactItemize}
\item 
\hypertarget{sharp_8h_6bdcc874aeacf405596ffeea06137929}{
void \hyperlink{sharp_8h_6bdcc874aeacf405596ffeea06137929}{Sharp\_\-init} (void)}
\label{sharp_8h_6bdcc874aeacf405596ffeea06137929}

\begin{CompactList}\small\item\em initializes GP2D120 subsystem \item\end{CompactList}\item 
void \hyperlink{sharp_8h_b47643d0110ae8903c4755d9909797fd}{Sharp\_\-Timer\-Init} (void)
\begin{CompactList}\small\item\em initializes an ISR to signal that the Sharp GP2D120 is ready to be read. \item\end{CompactList}\item 
\hyperlink{datatypes_8h_89b917a7bdb582e19cbde98e817fa0b3}{WORD} \hyperlink{sharp_8h_ee151c9d57b86953b6a9300d3d53d811}{Sharp\_\-read} (void)
\begin{CompactList}\small\item\em read Sharp GP2D120 sensor if it is active \item\end{CompactList}\item 
void \hyperlink{sharp_8h_bb90fdc715c31718e10849b9f929049c}{Sharp\_\-Timer\_\-interrupt} (void) interrupt 3 using 2
\begin{CompactList}\small\item\em Timer ISR for delaying the Sharp GP2D120. \item\end{CompactList}\end{CompactItemize}


\subsection{Detailed Description}


Definition in file \hyperlink{sharp_8h-source}{sharp.h}.

\subsection{Define Documentation}
\hypertarget{sharp_8h_181a10c4536739f68af0f39641005e24}{
\index{sharp.h@{sharp.h}!SHARP_ONLY@{SHARP\_\-ONLY}}
\index{SHARP_ONLY@{SHARP\_\-ONLY}!sharp.h@{sharp.h}}
\subsubsection[SHARP\_\-ONLY]{\setlength{\rightskip}{0pt plus 5cm}\#define SHARP\_\-ONLY~0x03}}
\label{sharp_8h_181a10c4536739f68af0f39641005e24}


bit mask to clear all enable bits for optic sensors 

Definition at line 11 of file sharp.h.\hypertarget{sharp_8h_d464b1bd22d8ed80116307e7dc7f42bc}{
\index{sharp.h@{sharp.h}!Sharp_PowerOff@{Sharp\_\-PowerOff}}
\index{Sharp_PowerOff@{Sharp\_\-PowerOff}!sharp.h@{sharp.h}}
\subsubsection[Sharp\_\-PowerOff]{\setlength{\rightskip}{0pt plus 5cm}\#define Sharp\_\-Power\-Off()~SHARP\_\-PWRCTL=0; TR1=0; ET1=0;}}
\label{sharp_8h_d464b1bd22d8ed80116307e7dc7f42bc}


deactivates the Sharp GP2D120 and its Timer 

Definition at line 21 of file sharp.h.

Referenced by main(), and Sharp\_\-init().\hypertarget{sharp_8h_914bbfd290fb3cd512e7b42942ee38cb}{
\index{sharp.h@{sharp.h}!Sharp_PowerOn@{Sharp\_\-PowerOn}}
\index{Sharp_PowerOn@{Sharp\_\-PowerOn}!sharp.h@{sharp.h}}
\subsubsection[Sharp\_\-PowerOn]{\setlength{\rightskip}{0pt plus 5cm}\#define Sharp\_\-Power\-On()~P3=(P3 \& SHARP\_\-ONLY)$|$SHARP\_\-PWRCTL\_\-MASK; Sharp\_\-Timer\-Init();}}
\label{sharp_8h_914bbfd290fb3cd512e7b42942ee38cb}


deactivates all optic sensors except for the Sharp GP2D120 and starts the Sharp Timer ISR (see \hyperlink{sharp_8h_bb90fdc715c31718e10849b9f929049c}{Sharp\_\-Timer\_\-interrupt} ) 

Definition at line 19 of file sharp.h.

Referenced by main().\hypertarget{sharp_8h_91ae6624561f0f3ab67f74ca73f01dac}{
\index{sharp.h@{sharp.h}!SHARP_PWRCTL@{SHARP\_\-PWRCTL}}
\index{SHARP_PWRCTL@{SHARP\_\-PWRCTL}!sharp.h@{sharp.h}}
\subsubsection[SHARP\_\-PWRCTL]{\setlength{\rightskip}{0pt plus 5cm}\#define SHARP\_\-PWRCTL~P3\_\-2}}
\label{sharp_8h_91ae6624561f0f3ab67f74ca73f01dac}


Port pin that activates the powersupply for the Sharp GP2D120 

Definition at line 6 of file sharp.h.

Referenced by Photosensor\_\-read(), and Sharp\_\-read().\hypertarget{sharp_8h_af9d624d746735332760d696823aabd1}{
\index{sharp.h@{sharp.h}!SHARP_PWRCTL_MASK@{SHARP\_\-PWRCTL\_\-MASK}}
\index{SHARP_PWRCTL_MASK@{SHARP\_\-PWRCTL\_\-MASK}!sharp.h@{sharp.h}}
\subsubsection[SHARP\_\-PWRCTL\_\-MASK]{\setlength{\rightskip}{0pt plus 5cm}\#define SHARP\_\-PWRCTL\_\-MASK~0x04}}
\label{sharp_8h_af9d624d746735332760d696823aabd1}


bit mask for accessing the Shapr powercontrol flag 

Definition at line 8 of file sharp.h.\hypertarget{sharp_8h_3582f952f36678f0e6a187d42a5aae71}{
\index{sharp.h@{sharp.h}!SHARP_TIMER_RELOAD_H@{SHARP\_\-TIMER\_\-RELOAD\_\-H}}
\index{SHARP_TIMER_RELOAD_H@{SHARP\_\-TIMER\_\-RELOAD\_\-H}!sharp.h@{sharp.h}}
\subsubsection[SHARP\_\-TIMER\_\-RELOAD\_\-H]{\setlength{\rightskip}{0pt plus 5cm}\#define SHARP\_\-TIMER\_\-RELOAD\_\-H~0x7d}}
\label{sharp_8h_3582f952f36678f0e6a187d42a5aae71}


reload values to get approx. 25ms timing @ 16MHz: 0x10000 - 0x8235 = 0x7dcb - HIByte 

Definition at line 14 of file sharp.h.

Referenced by Sharp\_\-Timer\_\-interrupt(), and Sharp\_\-Timer\-Init().\hypertarget{sharp_8h_45d3b415b430e5dc79dbe697a7cf9679}{
\index{sharp.h@{sharp.h}!SHARP_TIMER_RELOAD_L@{SHARP\_\-TIMER\_\-RELOAD\_\-L}}
\index{SHARP_TIMER_RELOAD_L@{SHARP\_\-TIMER\_\-RELOAD\_\-L}!sharp.h@{sharp.h}}
\subsubsection[SHARP\_\-TIMER\_\-RELOAD\_\-L]{\setlength{\rightskip}{0pt plus 5cm}\#define SHARP\_\-TIMER\_\-RELOAD\_\-L~0xcb}}
\label{sharp_8h_45d3b415b430e5dc79dbe697a7cf9679}


reload values to get approx. 25ms timing @ 16MHz: 0x10000 - 0x8235 = 0x7dcb - LOByte 

Definition at line 16 of file sharp.h.

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

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


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_8h_bb90fdc715c31718e10849b9f929049c}{
\index{sharp.h@{sharp.h}!Sharp_Timer_interrupt@{Sharp\_\-Timer\_\-interrupt}}
\index{Sharp_Timer_interrupt@{Sharp\_\-Timer\_\-interrupt}!sharp.h@{sharp.h}}
\subsubsection[Sharp\_\-Timer\_\-interrupt]{\setlength{\rightskip}{0pt plus 5cm}void Sharp\_\-Timer\_\-interrupt (void)}}
\label{sharp_8h_bb90fdc715c31718e10849b9f929049c}


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_8h_b47643d0110ae8903c4755d9909797fd}{
\index{sharp.h@{sharp.h}!Sharp_TimerInit@{Sharp\_\-TimerInit}}
\index{Sharp_TimerInit@{Sharp\_\-TimerInit}!sharp.h@{sharp.h}}
\subsubsection[Sharp\_\-TimerInit]{\setlength{\rightskip}{0pt plus 5cm}void Sharp\_\-Timer\-Init (void)}}
\label{sharp_8h_b47643d0110ae8903c4755d9909797fd}


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.