\documentclass[a4paper]{article}

\usepackage[margin=25mm]{geometry}
\usepackage{pdfpages}
\usepackage{cleveref}
\usepackage[hidelinks]{hyperref}
\usepackage{xcolor}

\title{Liquid Crystal Terminal documentation}
\author{Camil Staps}

\begin{document}

\pagestyle{empty}

\makeatletter\section*{\@title}\makeatother

\subsection*{Usage}
Apply 5V to the power jack.
The outer switch (S2) should be in `USE' state,
	or communication with other devices is impossible.
Other devices can control the terminal over UART as described below.

There is a trimmer potentiometer on the LCD board to change the brightness.

\subsection*{Protocol description}
The devices communicates 8-bit characters over a 115,200 baud UART link.
All characters are printed directly on the LCD display,
	with the exception of device control bytes (\verb$0x11$ through \verb$0x14$).

\subsubsection*{Characters}
HD44780-based LCD displays have a character set similar to ASCII,
	which can be found at \url{http://www.ekenrooi.net/lcd/lcd0.shtml#charset}.
Note that bytes \verb$0x00$ through \verb$0x07$ are user-defined characters.
They are set-up at compile-time in \verb$lcd.ino$ using \verb$createChar$ calls.
In \verb$lcd.h$, some examples of user-defined characters can be found.

\subsubsection*{LEDs}
To change the state of an LED, use device control 1 (\verb$0x11$) with an LED specification.
An LED specification is one byte and should look like below.
ID1 and ID2 identify the LED, whereas BLINK, RED and GRN indicate its state.
It is not possible to change the states of multiple LEDs at once;
	you need to re-issue device control 1.

\begin{center}
	\begin{tabular}{l c c c c c c c c}
		Bit      & 7 & 6 & 5   & 4   & 3 &     2 &   1 &   0 \\\hline
		Value    & 0 & 0 & ID1 & ID2 & 0 & BLINK & RED & GRN \\
	\end{tabular}
\end{center}

\subsubsection*{Backlight}
To change the state of the LCD backlight, use device control 2 (\verb$0x12$) with the backlight state.
The backlight state is one byte and should be 0, 1 or 2 to set the display, off, on or on flash, respectively.
When the backlight is set to flash, it turns on for some time and then turns off again.

\subsubsection*{Button (S1)}
It is not possible to get the button state.

\subsection*{Reprogramming}
To reprogram, 5V still has to be applied to the device.
\textcolor{red}{%
	Switch S2 should be in `PGM' state.
	Connecting the ICSP connector while S2 is in `USE' state \emph{will} break the device.}
Remove the Atmega328 chip from an Arduino Uno.
Connect the ICSP connector (J2; inside the device) to the Arduino board as below.
It should then be possible to reprogram the device from the Arduino IDE.

\begin{center}
	\begin{tabular}{l l}
		ICSP connector & Arduino pin \\\hline
		Brown          & GND   \\
		Yellow         & TX    \\
		Green          & RX    \\
		Blue           & RESET \\
	\end{tabular}
\end{center}

When communicating through an Arduino (during development), make sure to disable RTS and DTR lines.
These reset the device.
This is not an issue on the normal interface, where RTS and DTR are ignored.
On linux, the right settings can be achieved by using \verb$stty -F <PORT> -crtscts -hupcl$.

\includepdf[angle=90]{../schematic/schematic.pdf}

\end{document}
