\documentclass[10pt,hyperref={implicit=true}]{beamer} \mode { %\usetheme{Warsaw} \usetheme[hideothersubsections]{Goettingen} % or ... \setbeamercovered{transparent} % or whatever (possibly just delete it) \subject{C Programming for Engineers} \setbeamertemplate{footline}% {% \par\vspace*{-\baselineskip}\par% \raisebox{0.5ex}{\usebeamercolor[fg]{structure}% \ slide \insertframenumber/\inserttotalframenumber}% }% } \mode
{ \renewcommand{\floatpagefraction}{0.75} % default is .5, to increase % density. \renewcommand*{\bottomfraction}{0.6} % default is 0.3 \renewcommand*{\topfraction}{0.85} % default is 0.7 \renewcommand*{\textfraction}{0.1} % default is 0.2 \pagestyle{fancy} \fancyhf{} \newlength{\markWidth} \setlength{\markWidth}{0.5\textwidth} \newlength{\topicnumwidth} \settowidth{\topicnumwidth}{1.114.3} \addtolength{\markWidth}{-0.6\topicnumwidth} %\addtolength{\headheight}{1.92ex} \renewcommand{\sectionmark}[1]{\markright{\thesection. #1}} \lhead{\parbox[t]{\markWidth}{\raggedright\nouppercase{\rightmark}}} \rhead{\thepage} \AtBeginDocument{\thispagestyle{empty}} } \usepackage[english]{babel} \usepackage{alltt,booktabs,array,cols,multicol,meta} \usepackage[utf8]{inputenc} % or whatever \usepackage{lgrindsetup} \usepackage{times} \usepackage[T1]{fontenc} \usepackage{xcolour-names} % Or whatever. Note that the encoding and the font should match. If T1 % does not look nice, try deleting the line with the fontenc. \title{Parallel Port on a PC} % <======== FILL IN THE TITLE \subtitle{C Programming for Engineers} \author[Nick Urbanik]{Nick Urbanik \texttt{\footnotesize{}nicku\at{}nicku.org}\\ {\tiny This document Licensed under GPL---see slide~\pageref{sld:license}}% } \date{2005 October} % Copyright (C) 2005 Nick Urbanik % You can redistribute modified or unmodified copies of this document % provided that this copyright notice and this permission notice are % preserved on all copies under the terms of the GNU General Public % License as published by the Free Software Foundation--either version 2 % of the License or (at your option) any later version. \AtBeginSubsection[] { \begin{frame} \frametitle{Outline} \small \begin{multicols}{2} \tableofcontents[currentsection,currentsubsection] \end{multicols} \end{frame} } % If you wish to uncover everything in a step-wise fashion, uncomment % the following command: %\beamerdefaultoverlayspecification{<+->} \newcounter{program} %\newcommand*{\program}[1]{\refstepcounter{program}\label{#1}\arabic{program}} % \newcommand*{\program}[1]{% % \refstepcounter{program}\hypertarget{#1}{Program \texttt{#1}}% % } %\newcommand*{\program}[1]{\refstepcounter{program}\label{#1}\arabic{program}} \newcommand*{\program}[1]{% \hypertarget{#1}{Program \texttt{#1}}% } \newcommand*{\linkto}[1]{\hyperlink{#1}{\texttt{#1}}} \providecommand*{\bs}{\texttt{\char '134}} % Backslash, no break \newcommand{\obc}[1]{\ensuremath{\overline{\mbox{\textsc{\lowercase{#1}}}}}}% \newcommand{\ob}[1]{\ensuremath{\overline{\mbox{#1}}}}% \begin{document} \maketitle \mode
{\thispagestyle{empty}} \begin{frame} \frametitle{Outline} \mode {% \small \begin{multicols}{2} \tableofcontents \end{multicols} % You might wish to add the option [pausesections] }% \mode
{% \tableofcontents }% \end{frame} \section{I/O Ports on a PC} %\subsection{} \begin{frame} \frametitle{I/O Ports on a PC} \begin{itemize} \item There are $2^{16} = 65536$ I/O addesses \item each of these is called an \alert{I/O port} \item They are accessed with the \red{\texttt{in}} and \red{\texttt{out}} Intel assembly language instructions \item The I/O ports are separate from ordinary memory addresses \begin{itemize} \item We say, ``\blue{I/O ports have a separate \alert{address space} from memory addresses}''. \end{itemize} \item I/O ports usually connect to \alert{registers} on integrated circuits on the motherboard or on cards plugged into the motherboard \end{itemize} \end{frame} \begin{frame} \frametitle{Hardware of I/O ports} \begin{itemize} \item We cannot connect hardware directly to the data bus on the CPU \item CPU may not source or sink enough current \item but the main reason is that the data bus is changing all the time \begin{itemize} \item Carries instructions and other data, continuously passing back and forth \end{itemize} \item For output: need a latch (set of flip-flops% %, e.g., 347% ) to catch the data when the output instruction is executed, and hold the data steady \item For input: a tristate buffer (e.g., 571) that connects input pin to data bus at the time the input instruction is executed \end{itemize} \end{frame} \begin{frame} \frametitle{Hardware of Output Port} \begin{center} \includegraphics{output-port-embedded} \end{center} \begin{itemize} \item the latch ``catches'' the data and holds it when the output instruction is executed to the correct address \item The \ob{XIOW} control line from the CPU's control bus is activated by the output instruction \item This keeps the I/O addresses separate from memory addresses even when they have the same address number \end{itemize} \end{frame} \begin{frame} \frametitle{Hardware of Input Port} \begin{center} \includegraphics{input-port-embedded} \end{center} \begin{itemize} \item The tristate buffer connects the input pin to the data bus \blue{only} when the input instruction is executed with the appropriate address \item The \ob{XIOR} control line from the CPU's control bus is activated by the input instruction \end{itemize} \end{frame} % \begin{frame} % \frametitle{} % \begin{itemize} % \item % \end{itemize} % \end{frame} \section{Parallel Port in a PC} \subsection{Introduction} \begin{frame} \frametitle{Five modes of Operation} \begin{itemize} \item Newer parallel ports are standardised under IEEE standard 1284 \begin{itemize} \item released in 1994 \end{itemize} \item The standard defines \alert{five modes of operation}: \begin{description} \item[Compatibility mode] --- sometimes called ``Centronics Mode'' \begin{itemize} \item can send data out only \item upper limit: 50\,kBps to 150\,kBps, depending on hardware \end{itemize} \item[nibble mode] Can input 4 bits at a time \item[byte mode] can input a byte at a time using parallel port's bi-directional feature \item[EPP mode] (Enhanced Parallel Port) --- Uses additional hardware to perform \alert{handshaking} \item[ECP Mode] (Extended Capabilities Port) Uses DMA and FIFO buffers to move data without using I/O instructions \end{description} \end{itemize} \end{frame} \begin{frame} \frametitle{Handshaking with a printer in Compatibility Mode}% To output a byte from the parallel port to the printer in \alert{compatibity mode}: \begin{enumerate} \item Write the byte to the Data Port \item Check if the BUSY line is active \begin{itemize} \item If the printer is busy, the port will not accept any data, so any data sent to the data port will be lost \end{itemize} \item Take the \ob{STROBE} line low \begin{itemize} \item Tells printer that valid data is waiting on the data pins 2--9 \end{itemize} \item Put \ob{STROBE} high again after about 5 microseconds. \end{enumerate} \end{frame} \subsection{The Three Printer Port Base Addresses} \begin{frame} \frametitle{The Three Printer Port Base Addresses} \noindent% %@- \begin{tabularx}{\linewidth}{@{}lY@{}} %@+ \toprule% \textbf{Address} & \textbf{Notes} \\ \midrule% 0x3bc -- 0x3bf & Used for parallel ports that were incorporated into video cards, and now an option for an additional port. Does not support ECP \\ 0x378 -- 0x37f & Usual address for LPT1 (first parallel port)\\ 0x278 -- 0x27f & Usual address for LPT2 (second parallel port) \\ \bottomrule \end{tabularx} \end{frame} % \begin{frame} % \frametitle{BIOS addresses for printer addresses} % \begin{itemize} % \item The BIOS stores the address of each printer port's base % address as follows: % \par\medskip\par % %@- % \begin{tabularx}{\linewidth}{@{}lY@{}} % %@+ % \toprule% % \textbf{Start Address} & \textbf{Contents} \\ % \midrule% % 0000:0408 & first Parallel port base address\\ % 0000:040C & second Parallel port base address\\ % 0000:040E & third Parallel port base address\\ % \bottomrule % \end{tabularx} % \end{itemize} % \end{frame} \section{The Three Registers} \begin{frame} \frametitle{There are three I/O Ports} \begin{itemize} \item Data port \begin{itemize} \item At printer port base address \item all eight bits normally output \item Can input data if port has bi-directional hardware \end{itemize} \item Status port \begin{itemize} \item at base address + 1 \item read only \end{itemize} \item Control Port \begin{itemize} \item at base address + 2 \item read and write, though was originally intented as a write only port. \end{itemize} \end{itemize} \end{frame} \subsection{The Data Port} \begin{frame} \frametitle{The Data Port} \begin{itemize} \item At: base address of printer port \item Write only, unless the port hardware is bi-directional \end{itemize} %@- \begin{tabular}[t]{@{}cll@{}}%1 %@+ \toprule% \textbf{pin number} & \textbf{Bit number} & \textbf{signal name}\\ \midrule% 2 & bit 0 & D${}_{0}$\\ 3 & bit 1 & D${}_{1}$\\ 4 & bit 2 & D${}_{2}$\\ 5 & bit 3 & D${}_{3}$\\ 6 & bit 4 & D${}_{4}$\\ 7 & bit 5 & D${}_{5}$\\ 8 & bit 6 & D${}_{6}$\\ 9 & bit 7 & D${}_{7}$\\ \bottomrule \end{tabular} \end{frame} \subsection{The Status Port} \begin{frame}[fragile] \frametitle{The Status Port} \begin{itemize} \item At: Base address + 1 \item Read only \end{itemize} %@- \begin{tabular}[t]{@{}cll@{}}%2 %@+ \toprule% \textbf{pin number} & \textbf{Bit number} & \textbf{signal name}\\ \midrule% & bit 0 & reserved\\ & bit 1 & reserved\\ & bit 2 & \ob{IRQ}\\ 15 & bit 3 & \ob{ERROR}\\ 13 & bit 4 & SLCT\\ 12 & bit 5 & PE (Paper End)\\ 10 & bit 6 & \ob{ACK}\\ 11 & bit 7 & BUSY\\ \bottomrule \end{tabular} \end{frame} \subsection{The Control Port} \begin{frame}[fragile] \frametitle{The Control Port} \begin{itemize} \item At: base address + 2 \item Read and Write \end{itemize} %@- \begin{tabular}[t]{@{}cll@{}}%3 %@+ \toprule% \textbf{pin number} & \textbf{Bit number} & \textbf{signal name}\\ \midrule% 1 & bit 0 & \ob{STROBE}\\ 14 & bit 1 & \ob{AUTOFEED} (Auto Linefeed)\\ 16 & bit 2 & INIT PRN\\ 17 & bit 3 & \ob{SELECT}\\ & bit 4 & Enable IRQ via Ack\\ & bit 5 & Enable Bi-Directional Port\\ & bit 6 & Unused\\ & bit 7 & Unused\\ \bottomrule \end{tabular} \end{frame} \section{Using the Printer Port for General I/O} \label{sec:Printer Port for I/O} \begin{frame} \frametitle{Using the Printer Port for I/O} \begin{itemize} \item Here, we use the printer port in compatibility mode \item In this mode, the three ports are not available as general purpose \alert{8-bit} input/output ports \begin{itemize} \item They are set up to talk to a printer \item But you can still use these ports for many purposes \end{itemize} \end{itemize} \end{frame} \begin{frame}[fragile] \frametitle{Signals and pin numbers for general purpose I/O} \mode{\footnotesize} \renewcommand{\extrarowheight}{0pt}% \noindent% %@- \begin{tabularx}{\linewidth}{@{}rlYY@{}} %@+ \toprule% \emph{Port}\hfill{}\mbox{} & \emph{Signal Name} & \emph{DB25 pin number} & \emph{Comments} \\ \midrule% Data\hfill{}\mbox{} & D${}_{0}$ & 2 & All outputs latched \\ base\hfill{}\mbox{} & D${}_{1}$ & 3 \\ & D${}_{2}$ & 4 &\\ & D${}_{3}$ & 5 &\\ & D${}_{4}$ & 6 &\\ & D${}_{5}$ & 7 &\\ & D${}_{6}$ & 8 &\\ & D${}_{7}$ & 9 &\\ \midrule% Status \hfill{} bit 3 & ERROR & 15 & input \\ base + 1\hfill{}bit 4 & SLCT & 13 & input \\ bit 5 & PE & 12 & input \\ bit 6 & ACK & 10 & input \\ bit 7 & BUSY & 11 & inverted input \\ \midrule% Control \hfill{} bit 0 & STROBE & 1 & inverted output \\ base + 2 \hfill{} bit 1 & AUTOFEED & 14 & inverted output \\ bit 2 & INIT PRN & 16 & output \\ bit 3 & SELECT & 17 & inverted output \\ \midrule & GND & 18--25 & \\ \bottomrule \end{tabularx} \end{frame} \section{The pins on the 25-pin connector} \label{sec:pinnout} \begin{frame} \frametitle{Pin numbers on DB25 Connector} \begin{itemize} \item This views the \alert{female} connector \item i.e., on the back of the computer \end{itemize} \begin{center} \includegraphics[width=\textwidth]{parallel-port} \end{center} \end{frame} \begin{frame}[fragile] \frametitle{Pin Numbers on Parallel Port DB25} \mode{\footnotesize} \renewcommand{\extrarowheight}{0pt}% \noindent% %@- \begin{tabularx}{\linewidth}{@{}YYYYlc@{}} %@+ \toprule% Pin No (D-Type 25) & Pin No \mbox{(Centronics)} & SPP Signal & Direction (In or Out) & Register & Inv?\\ \midrule 1 & 1 & \ob{STROBE}& In/Out & Control& Yes\\ 2 & 2 & D${}_{0}$ & Out & Data & \\ 3 & 3 & D${}_{1}$ & Out & Data & \\ 4 & 4 & D${}_{2}$ & Out & Data & \\ 5 & 5 & D${}_{3}$ & Out & Data & \\ 6 & 6 & D${}_{4}$ & Out & Data & \\ 7 & 7 & D${}_{5}$ & Out & Data & \\ 8 & 8 & D${}_{6}$ & Out & Data & \\ 9 & 9 & D${}_{7}$ & Out & Data & \\ 10 & 10 & \ob{ACK} & In & Status & \\ 11 & 11 & BUSY & In & Status & Yes \\ 12 & 12 & PE (PaperEnd) & In & Status & \\ 13 & 13 & SELECT & In & Status & \\ 14 & 14 &\ob{AUTOFEED} (\ob{Auto-Linefeed})&In/Out& Control& Yes \\ 15 & 32 &\ob{ERROR} / \ob{Fault}&In &Status& \\ 16 & 31 &\ob{INIT PRN} & In/Out & Control& \\ 17 & 36 &\ob{SELECT} \ob{Select-In}&In/Out&Control&Yes\\ 18 -- 25 & 19 -- 30 & Ground & GND & & \\ \bottomrule \end{tabularx} \end{frame} \section{Permissions} \begin{frame} \frametitle{Do not run your programs as root/Administrator} \begin{itemize} \item Normally, to access I/O ports requires administrator priveleges \item \ldots\,but it is a bad idea to do everything as the root or administrative user \begin{itemize} \item A small mistake can stop the system from functioning correctly \item In Windows XP/2000/NT, additionally, special unsupported software is required. \item Linux provides a \alert{system call} \texttt{ioperm()} that allows the root user to grant normal user access to particular ports \item The ports must be at port address 0x3ff or below \end{itemize} \end{itemize} \end{frame} \section{Performing I/O in Windows XP, 2000, NT} \label{sec:xp} \begin{frame} \frametitle{Performing I/O in Windows XP, 2000, NT} \begin{itemize} \item Port I/O on Windows XP, Windows 2000, Windows NT is a complex, barely supported mess. \item \sloppypar{}Use Linux if you want something simple, standardised and supported: \url{http://linuxgazette.net/112/radcliffe.html} \item Several people have built device drivers to work around the limitations of Windows: \begin{itemize} \item \texttt{inpout32.dll}: \sloppypar{}\url{http://www.logix4u.net/inpout32.htm} \item PortTalk: \sloppypar{}\url{http://www.beyondlogic.org/porttalk/porttalk.htm} \item \texttt{io.dll}: \sloppypar{}\url{http://www.geekhideout.com/iodll.shtml} \item \texttt{giveio.sys}: \sloppypar{}\url{http://www.physik.rwth-aachen.de/group/IIIphys/CMS/tracker/en/silicon/arcs_nt.html} \item directio: \sloppypar{}\url{http://www.direct-io.com/} \end{itemize} \item None of these are Open Source, but \texttt{inpout32.dll} seems to be best supported and have the most open license, so we will use that. \end{itemize} \end{frame} \section{Using Andy Eager's wrapper for logix4u inpout32.dll} \subsection{Installing Andy Eager's wrapper} \begin{frame} \frametitle{Installing Andy Eager's wrapper for logix4u inpout32.dll} Note: this is for use with Microsoft Windows. The procedure with Linux is different, simpler and faster: see the references. \begin{itemize} \item \sloppypar{}Download Andy's handy package from \url{http://www.linuxivr.com/c/week1/ioports.zip} \item Unzip this into a temporary directory \item execute \texttt{install.bat} from a command prompt in that directory as the Administrator \end{itemize} \end{frame} \subsection{Using Andy Eager's wrapper} \begin{frame} \frametitle{Using Andy Eager's wrapper} \begin{itemize} \item \sloppypar{}See the program \texttt{ledscan.c} in \sloppypar\url{http://www.linuxivr.com/c/week1/ioports.zip} --- use this as a model to see how to perform I/O \item Compile your program with the command:\linebreak% \texttt{g++ -Wall -lioports -o \meta{program} \meta{program}.cpp} \end{itemize} \end{frame} \subsection{Using inpout32.dll without Andy's wrapper} \label{inpout32.dll} \begin{frame} \frametitle{Using inpout32.dll without Andy's wrapper} \begin{itemize} \item This could (potentially) give better performance if you initialise the library once at the beginning and free the library once after all I/O is finished \begin{itemize} \item However, Andy says the difference in speed is not detectable \end{itemize} \item \sloppypar{}See the test program \sloppypar\url{http://www.hytherion.com/beattidp/comput/pport/test2.c}, and also the source to Andy's wrapper at \sloppypar\url{http://www.linuxivr.com/c/week1/install-io.html}, and use them as a model for your program. \end{itemize} \end{frame} % \section{} % \subsection{} % \begin{frame} % \frametitle{} % \begin{itemize} % \item % \end{itemize} % \end{frame} % \begin{frame} % \frametitle{} % \begin{itemize} % \item % \end{itemize} % \end{frame} % \begin{frame} % \frametitle{} % \begin{itemize} % \item % \end{itemize} % \end{frame} % \section{} % \subsection{} % \begin{frame} % \frametitle{} % \begin{itemize} % \item % \end{itemize} % \end{frame} % \begin{frame} % \frametitle{} % \begin{itemize} % \item % \end{itemize} % \end{frame} % \begin{frame} % \frametitle{} % \begin{itemize} % \item % \end{itemize} % \end{frame} \section{References} \begin{frame}[allowframebreaks] \frametitle{References --- Web} \begin{thebibliography}{99} %\beamertemplatebookbibitems% \beamertemplatearticlebibitems% \bibitem{logix4u} logix4u.net.% \newblock% \emph{Inpout32.dll for WIN NT/2000/XP --- logix4u}.% \newblock% \url{http://www.logix4u.net/inpout32.htm} \bibitem{Eag2006} Andrew Eager.% \newblock% \emph{Installing the logix4u IO interface}.% \newblock% \url{http://linuxivr.com/c/week1/install-io.html} \bibitem{logix4u2} logix4u.% \newblock% \emph{Parallel port Interfacing Tutorial}.% \newblock% \url{http://www.logix4u.net/parallelport1.htm} \bibitem{Ree2005} Joe D. Reeder. \newblock% \emph{Controlling The Real World With Computers} \newblock% \url{http://learn-c.com/} \bibitem{Saik2000} Riku Saikkonen. \newblock% \emph{Linux I/O port programming mini-HOWTO} \newblock% \url{http://www.tldp.org/HOWTO/IO-Port-Programming.html} % \bibitem{} % \newblock% % \newblock% % \newblock% % \url{} \bibitem{Rad2005} P. J. Radcliffe. \newblock% \emph{Linux: A Clear Winner for Hardware I/O}. \newblock% Linux Gazette, Issue 112, March 2005. \newblock% \url{http://linuxgazette.net/112/radcliffe.html} \bibitem{Cho2005} David Chong and Philip Chong \newblock% \emph{Linux Analog to Digital Converter}. \newblock% Linux Gazette, Issue 118, September 2005. \newblock% \url{http://linuxgazette.net/118/chong.html} \bibitem{Pea2005} Craig Peacock \newblock% \emph{Interfacing the Standard Parallel Port}. \newblock% \sloppypar\url{http://www.beyondlogic.org/spp/parallel.htm} \bibitem{Axe2005} Jan Axelson.% \newblock% \emph{The PC's Parallel Port}. \newblock% \url{http://www.lvr.com/parport.htm} \end{thebibliography} \end{frame} \begin{frame} \frametitle{References --- Books} \begin{thebibliography}{99} \beamertemplatebookbibitems \bibitem{Oual1993} Steve Oualline. \newblock% \emph{Practical C Programming}. \newblock% O'Reilly, 1993. \bibitem{Dav1995} Paul Davies. \newblock% \emph{The Indispensable Guide to C with Engineering Applications} \newblock% Addison-Wesley, 1995. \bibitem{AAM1998} Tom Adamson and James L. Antonakos and Kenneth C. Mansfield Jr. \newblock% \emph{Structured C for Engineering and Technology, Third Edition}. \newblock% Prentice Hall, 1998. \bibitem{Ker1988} Brian W. Kernighan and Dennis M. Ritchie. \newblock% \emph{The C Programming Language}. \newblock% Prentice Hall, 1988. \end{thebibliography} \end{frame} \section{License of this Document} \label{sec:license} \begin{frame} \frametitle{License covering this document} \label{sld:license} Copyright \copyright{} 2005, 2006 Nick Urbanik \par You can redistribute modified or unmodified copies of this document provided that this copyright notice and this permission notice are preserved on all copies under the terms of the GNU General Public License as published by the Free Software Foundation --- either version 2 of the License or (at your option) any later version. \end{frame} \end{document}