tag:blogger.com,1999:blog-41553876381695324132024-03-05T06:35:57.012-08:00Homebrew ComputersMarek Karczhttp://www.blogger.com/profile/03281397436610614441noreply@blogger.comBlogger47125tag:blogger.com,1999:blog-4155387638169532413.post-13590986246294201552020-06-05T20:31:00.001-07:002020-06-05T20:31:39.935-07:00Reset And Panic Buttons, Buttons Debouncing<br />
<div style="margin-bottom: 0in;">
<b>Reset And Panic Buttons, Buttons
Debouncing</b></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
The monitor
program in my home brew computer has a nice debug feature. The NMI (Non-Maskable Interrupt) is
used to service the so called 'panic' button. The role of a panic button in a microprocessor system is simple - if your program gets stuck or runs away, you can press the panic button
connected to /NMI pin of the processor and the service routine
assigned for NMI will store the current program status on the stack, including the return address, dump CPU
registers and do whatever else you programmed it to do and then drop you back in the monitor program prompt thus giving
you back control without the need to reset the system. You can then
use monitor program functions to examine or alter memory of the faulty program and even
continue the faulty program execution from the moment of NMI
interrupt, if you think you corrected the cause of the problem.</div>
<div style="margin-bottom: 0in;">
I used that button often to recover
from failed / hung up code or to return from 3-rd party applications
I ran on my system (e.g.: Tiny Basic) to the monitor prompt. The
continuation of the execution didn't work too well though simply
because I didn't have the so called debouncing circuit implemented
for the panic button.</div>
<div style="margin-bottom: 0in;">
What is debouncing and why do I need to
debounce a button, you might ask?</div>
<div style="margin-bottom: 0in;">
When you deal with electronic circuits,
which involve fast switching signals, you need to realize that in
real life applications, things like buttons / switches, wires,
connectors, resistors, capacitors, inductors and so on are not
perfect. Wires have a resistance and capacitance. Resistors have a capacitance and inductance. Inductors have a resistance. If wires carry
high frequency signal, there is interference. In case of mechanical
switches the problem is that their contacts bounce off each other –
literally and very fast. When you press a button, two metal surfaces
come in contact with each other. These surfaces are not perfect. They
may be not aligned perfectly. They are not perfectly flat. Over a
very small amount of time there is a mechanical high frequency
oscillation when these surfaces come in contact and detach from each
other before they finally settle. This period of unstable / undefined connection between these surfaces is called bouncing.</div>
<div style="margin-bottom: 0in;">
To you this looks like a single button push. If
you had a battery and light bulb circuit that such button closes, you
would just see that the light comes on – and when you release
button, the light comes off. To a micro controller or a
microprocessor which are usually clocked with relatively high
frequency and process the data much quicker than human perception
allows to notice, the moment of you pressing the button appears like
tens, hundreds or even thousands of separate signal switching events.
However we want to register just one clean push. How to solve this
dilemma?</div>
<div style="margin-bottom: 0in;">
There are two major ways – solve it
with hardware or with software.</div>
<div style="margin-bottom: 0in;">
In our case software debouncing will
not work, because NMI signal is Non-Maskable (can't be turned off)
and is triggered by a low coming signal edge – button contacts
bouncing results in a series of high-to-low edges of signals which
will trigger a new NMI each time such edge is detected, assuming
there was enough time between them to be detected by CPU. Therefore
we cannot just mask interrupts at the entrance of NMI service and put
a delay on it to ignore the oscillations.</div>
<div style="margin-bottom: 0in;">
We have to debounce the button in
hardware.</div>
<div style="margin-bottom: 0in;">
One of the cheap and reliable methods
to do this which I used in my circuit is to combine RC filter with
hysteresis by the means of Schmitt trigger TTL gate, e.g.: inverting gates found inside 74LS14 or 74HC14 TTL chip. (it has 6 of such gates)</div>
<div style="margin-bottom: 0in;">
The RC circuit at input to the gate provides
low-pass filter to cut off high frequency oscillations resulting from bouncing and Schmitt
trigger gate ensures that the on / off levels are separated by a dead
zone – pretty much in the same manner that your A/C or heating
system thermostat does.</div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
Below is the result. Note that I also
debounced the Reset button, however this is not as critical as NMI
since /RES in MOS6502 is triggered (and held) by low level. You'll
notice though that the capacitor in RC circuit for Reset button is of
much higher value than for the Panic button. It is because there is
unstable period when you turn on the power to microprocessor system
when voltage and currents in the system oscillate before they reach
stabilized levels. It is critical that after you turn on the power to
the system, the initial reset pulse comes some time after power to
all the system components has stabilized. It (/RES signal) also needs
to come after any possible unstable oscillations from NMI debouncing
circuit, otherwise the system may freeze at startup. It also needs to be at TTL high level when stable, since /RES is active low - thus two inverting gates are used, while it does not matter for NMI sigal which is triggered by the signal's edge, not by its level.</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtoRklufzs8OZoUKIJmz5FVPr_NYkqdj2E4Ar_GIebL1MFq5tTQ2l5AKNm43rq4ZNkU0dOW5wHo25_mSYdVaDFSOwdhO988eBsF-gq7eSaqCOhaLo9IjqjU0VQ5bz02Yc_2N41ko3IYm9N/s1600/RTSNMIDebounce.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="442" data-original-width="1001" height="281" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtoRklufzs8OZoUKIJmz5FVPr_NYkqdj2E4Ar_GIebL1MFq5tTQ2l5AKNm43rq4ZNkU0dOW5wHo25_mSYdVaDFSOwdhO988eBsF-gq7eSaqCOhaLo9IjqjU0VQ5bz02Yc_2N41ko3IYm9N/s640/RTSNMIDebounce.png" width="640" /></a></div>
<br />
Now I can enjoy reliable panic button function to debug my software or temporarily switch to monitor program to load data, change memory contents etc.<br />
<br />
Thanks for reading.<br />
<br />
MK 6/5/2020<br />
<br />
Credits:<br />
<a href="https://hackaday.com/2015/12/09/embed-with-elliot-debounce-your-noisy-buttons-part-i/" target="_blank">Embed With Elliot: "DEBOUNCE YOUR NOISY BUTTONS, PART I"</a><br />
<br />
References:<br />
<a href="https://circuitdigest.com/electronic-circuits/schmitt-trigger-gate-circuit-diagram#:~:text=Schmitt%20Trigger%20gate%20is%20a,logic%20gate%2C%20OUTPUT%20goes%20HIGH." target="_blank">Schmitt Trigger Gate</a><br />
<a href="http://ee-classes.usc.edu/ee459/library/datasheets/DM74LS14.pdf" target="_blank">DM74LS14: Hex Inverter with Schmitt Trigger Inputs</a><br />
<br />
<br />Marek Karczhttp://www.blogger.com/profile/03281397436610614441noreply@blogger.com4tag:blogger.com,1999:blog-4155387638169532413.post-69961628687207681022019-04-22T23:08:00.000-07:002020-06-05T20:41:29.174-07:00I/O interface card for MKHBC-8-Rx computer<br />
(Updated on 6/5/2020, schematic diagram)<br />
<div style="font-family: Calibri; margin: 0in;">
<span style="font-size: x-small;">Finally work on the
I/O interface card has begun. I finished the circuit design and completed some parts
for a prototype. Of course first prototype will be built on a breadboard,
however I am thinking ahead about a more
permanent working prototype. I want to build it as a small daugtherboard that
will plug into a custom socket in the motherboard. The I/O chip used is
WDC65C22S. D2 is supposed to be a low voltage (<0.5 V) diode since IRQB is a
totem-pole output (unlike the classic MOS6522 with open drain output). I am
thinking a Schottky diode, but haven't decided on the type yet. Two 16-pin
ribbon sockets will be used as connectors for ports PA and PB. 20-pin single row DIP sized connector will be
a plug-in to the motherboard to connect the VIA chip to all necessary
microprocessor signals.</span></div>
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgxe3ANp5XaTehk8G7ne-ypkFMMRoEb6wBQVm6LL-5Kf6z1spYYeZuOVRJ8s7iGOpYCDAr7n9O3leOHG1MCTEyMjjCrYaAnY9JyV5-eIknJOzBMoVQNXkjwZBd6XKOIjRZCurB6YOLaHCFv/s1600/MKHBC-8-R2-IO6522.bmp" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1208" data-original-width="1600" height="482" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgxe3ANp5XaTehk8G7ne-ypkFMMRoEb6wBQVm6LL-5Kf6z1spYYeZuOVRJ8s7iGOpYCDAr7n9O3leOHG1MCTEyMjjCrYaAnY9JyV5-eIknJOzBMoVQNXkjwZBd6XKOIjRZCurB6YOLaHCFv/s640/MKHBC-8-R2-IO6522.bmp" width="640" /></a></div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhstDhGlwEuJGVFEGG0gocnIRxTAvb4oHtm7Vc8BBV0hqTaUxH3RqAR7uq1HfN_8B4Ss3hz_gVnkDOcKedQRK71rtZeCAfsmQPBkBbyb1xNGQamw9bbuFN9dQLHk2MpPEadxf9t6cOd-lQC/s1600/DSCN0039.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1200" data-original-width="1600" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhstDhGlwEuJGVFEGG0gocnIRxTAvb4oHtm7Vc8BBV0hqTaUxH3RqAR7uq1HfN_8B4Ss3hz_gVnkDOcKedQRK71rtZeCAfsmQPBkBbyb1xNGQamw9bbuFN9dQLHk2MpPEadxf9t6cOd-lQC/s640/DSCN0039.JPG" width="640" /></a></div>
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
<br /></div>
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
<br /></div>
<span style="font-size: x-small;">MK 4/23/2019</span>Marek Karczhttp://www.blogger.com/profile/03281397436610614441noreply@blogger.com0tag:blogger.com,1999:blog-4155387638169532413.post-14238008621523258872018-02-12T21:47:00.000-08:002018-02-12T21:47:04.389-08:00MKHBC-8-Rx, refactoring, development.<span style="font-family: Verdana, sans-serif; font-size: x-small;">Hello 8-bit computing enthusiasts!</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">In recent weeks I concentrate on the software part of my project. First I cleaned up my code and put in on <a href="https://github.com/makarcz/mkhbc8rx" target="_blank">github</a> as mentioned in previous blog update. Since then I added KbHit implementation and detection of RTC and Banked RAM to the firmware. I enhanced existing functions in enhshell.c to use added functionality. I also added small programs that provide one or few related functions in smaller package than the enhshell.c. Since I am still using serial port to load programs to the computer, I wanted to save on loading times.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;">I plan to create smaller standalone images of all functions currently implemented in enhshell.c.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;">I also plan to add few new tools that will help me to turn the computer into fully self hosting platform: text editor and on-line symbolic machine code assembler / disassembler.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;">Then I will move to further expand the hardware of my computer - build generic I/O card, control panel, local console (keyboard and CRT controller) and mass storage interface.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">Updated kernel jump table and system internals documentation:</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Programming API /
Kernal Jump Table:</div>
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
<br /></div>
<div style="direction: ltr;">
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse; border-color: #A3A3A3; border-style: solid; border-width: 1pt; direction: ltr;" summary="" title="" valign="top">
<tbody>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.2041in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Function</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: .8298in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Address (hex)</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.7784in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Parameters</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.9381in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Return</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.6847in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Description</div>
</td>
</tr>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.2041in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
CallDS1685Init</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: .8298in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
FFD2</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.7784in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
RegB, RegA, RegXB,
RegXA</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.9381in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
RegC in Acc</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.6847in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Initialize RTC
chip.</div>
</td>
</tr>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.2041in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
CallDS1685ReadClock</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: .8298in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
FFD5</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.7784in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
n/a</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.9381in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Data is returned
via hardware stack. Calling subroutine is responsible for allocating 8 bytes
on stack before calling this function. Clock data are stored in following
order below the subroutine return address: seconds, minutes, hours,
dayofweek, date, month, year, century. Valid return data on stack only if Acc
> 0 (Acc = # of bytes on stack). Calling subroutine still should
de-allocate stack space by calling PLA x 8 after reading or discarding
returned data.</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.8375in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Read RTC clock
data.</div>
</td>
</tr>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.2041in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
CallDS1685SetClock</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: .8298in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
FFD8</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.7902in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Parameters are
passed via hardware stack: seconds, minutes, hours, day of week, day of
month, month, year, century. Calling subroutine is responsible for allocating
8 bytes on stack and filling the space with valid input data before calling
this function. Calling subroutine is also responsible for freeing stack space
(PLA x 8).</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.9381in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
n/a</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.8791in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Set date/time of
RTC chip.</div>
</td>
</tr>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.2041in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
CallDS1685SetTime</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: .8298in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
FFDB</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.7784in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Parameters are
passed via hardware stack: seconds, minutes, hour. Calling subroutine is
responsible for allocating space on stack and filling it with valid input
data before calling this function.
Calling subroutine is also responsible for freeing stack space (PLA x
3).</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.9381in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
n/a</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.8361in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Set time of RTC
chip.</div>
</td>
</tr>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.2041in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
CallDS1685StoreRam</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: .8298in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
FFDE</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.7784in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
BankNum, RamAddr,
RamVal</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.9381in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
n/a</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.8902in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Store a value in
non-volatile RTC memory bank.</div>
</td>
</tr>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.2041in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
CallDS1685ReadRam</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: .8298in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
FFE1</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.7784in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
BankNum, RamAddr</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.9381in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
value in Acc</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.9506in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Read value from
non-volatile RTC memory bank.</div>
</td>
</tr>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.2041in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
CallReadMem</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: .8298in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
FFE4</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.7784in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
PromptLine
(contains hexadecimal address range)</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.9381in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
n/a (output)</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.8791in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Machine code
monitor function - read memory.</div>
</td>
</tr>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.2041in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
CallWriteMem</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: .8298in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
FFE7</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.7784in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
PromptLine
(contains hexadecimal address and values)</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.9381in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
n/a (memory is
modified)</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.8791in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Machine code
monitor function - write memory.</div>
</td>
</tr>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.2041in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
CallExecute</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: .8298in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
FFEA</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.7784in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
PromptLine
(contains hexadecimal address)</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.9381in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
n/a (code is
executed)</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.8791in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Machine code
monitor function - execute code in memory.</div>
</td>
</tr>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.2041in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
CallGetCh</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: .8298in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
FFED</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.7784in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
n/a</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.9381in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Character code in
Acc</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.8791in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Standard I/O
function - get character.</div>
</td>
</tr>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.2041in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
CallPutCh</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: .8298in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
FFF0</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.7784in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Character code in
Acc.</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.9381in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
n/a (output)</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.8791in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Standard I/O
function - put/print character.</div>
</td>
</tr>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.2041in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
CallGets</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: .8298in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
FFF3</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.7784in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
n/a (input)</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.9381in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
PromptLine,
PromptLen</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.8791in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Standard I/O
function - get string.</div>
</td>
</tr>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.2041in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
CallPuts</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: .8298in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
FFF6</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.7784in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
StrPtr</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.9381in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
n/a (output)</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.8791in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Standard I/O
function - put/print string.</div>
</td>
</tr>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.2041in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
CallBankRamSel</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: .8298in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
FFCF</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.7784in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Banked RAM bank #
in Acc. (0..7)</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.9381in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
n/a (selects RAM
bank, updates shadow register in RAM)</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.9236in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Banked RAM bank
selection.</div>
</td>
</tr>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.2041in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
CallKbHit</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: .8298in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
FFCC</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.7784in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
n/a</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.9381in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Character in Acc
or 0 if buffer empty.</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.9833in;">
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Check if there is
character in RX buffer (equivalent of check if key was pressed since this is
UART I/O).</div>
</td>
</tr>
</tbody></table>
</div>
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
<br /></div>
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
<span style="font-weight: bold;">WARNING:</span></div>
<div style="font-family: Calibri; font-size: 11.0pt; margin-left: .375in; margin: 0in;">
Disable
interrupts before calling any RTC function:</div>
<div style="font-family: Calibri; font-size: 11.0pt; margin-left: .375in; margin: 0in;">
SEI</div>
<div style="font-family: Calibri; font-size: 11.0pt; margin-left: .375in; margin: 0in;">
<call
to RTC API></div>
<div style="font-family: Calibri; font-size: 11.0pt; margin-left: .375in; margin: 0in;">
CLI</div>
<div style="font-family: Calibri; font-size: 11.0pt; margin-left: .375in; margin: 0in;">
<br /></div>
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Registers, buffers,
memory:</div>
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
<br /></div>
<div style="font-family: Calibri; font-size: 11.0pt; margin-left: .75in; margin: 0in;">
RTC
RAM shadow:</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
RegB = $F6</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
RegA = $F7</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
RegXB = $F8</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
RegXA = $F9</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
RegC = $FA</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
Temp = $FB</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
BankNum = $FC</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
RamAddr = $FD</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
RamVal = $FE</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
<br /></div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: .75in; margin: 0in;">
UART
Pointers</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: .75in; margin: 0in;">
<br /></div>
<div style="font-family: Calibri; font-size: 11.0pt; margin-left: 1.125in; margin: 0in;">
UartRxInPt = $F2 ; Rx head pointer, for chars placed
in buf</div>
<div style="font-family: Calibri; font-size: 11.0pt; margin-left: 1.125in; margin: 0in;">
UartRxOutPt
= $F3 ; Rx tail pointer, for
chars taken from buf</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: .75in; margin: 0in;">
<br /></div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: .75in; margin: 0in;">
Uart
Queues (after stack)</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
UartTxQue = $200 ; 256 byte output queue</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
UartRxQue = $300 ; 256 byte input queue</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
<br /></div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
MOS Prompt variables</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
PromptLine = $80 ; Prompt line (entered by user)</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
PromptMax = $50 ; An 80-character line is permitted</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
; ($80 to $CF)</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
PromptLen = $D0 ; Location of length variable</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
<br /></div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
MOS I/O Function variables</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
StrPtr = $E0 ; String pointer for I/O functions</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
<br /></div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: .75in; margin: 0in;">
Other variables:</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 1.125in; margin: 0in;">
Timer64Hz
= $E2 ; 4-byte (32-bit)
counter</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 1.125in; margin: 0in;">
<span style="font-size: 11pt;"> ; incremented 64 times / sec</span></div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 3.375in; margin: 0in;">
; $E2,$E3,$E4,$E5 (unsigned long,</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 3.375in; margin: 0in;">
; little
endian)</div>
<div lang="pl" style="font-family: Consolas; font-size: 11.0pt; margin-left: 3.375in; margin: 0in;">
<br /></div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 1.125in; margin: 0in;">
RamBankNum
= $E6 ; Current Banked
RAM bank#.</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 1.125in; margin: 0in;">
DetectedDevices = $E7 ; Flags indicating devices detected </div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 1.125in; margin: 0in;">
; by
system during startup.</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 1.125in; margin: 0in;">
<br /></div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 1.125in; margin: 0in;">
Detected
devices flags:</div>
<div style="direction: ltr;">
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse; border-color: #A3A3A3; border-style: solid; border-width: 1pt; direction: ltr; margin-left: 1.0833in;" summary="" title="" valign="top">
<tbody>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.8527in;">
<div lang="pl" style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
DEVPRESENT_RTC </div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 3.3493in;">
<div lang="pl" style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
%10000000</div>
</td>
</tr>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.8527in;">
<div lang="pl" style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
DEVPRESENT_NORTC </div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 3.3493in;">
<div lang="pl" style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
%01111111</div>
</td>
</tr>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.8527in;">
<div lang="pl" style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
DEVPRESENT_EXTRAM </div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 3.3493in;">
<div lang="pl" style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
%01000000</div>
</td>
</tr>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.8715in;">
<div lang="pl" style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
DEVPRESENT_NOEXTRAM
</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 3.3298in;">
<div lang="pl" style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
%10111111</div>
</td>
</tr>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.8527in;">
<div lang="pl" style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
DEVPRESENT_BANKRAM </div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 3.3493in;">
<div lang="pl" style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
100000</div>
</td>
</tr>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.8527in;">
<div lang="pl" style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
DEVPRESENT_NOBRAM </div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 3.3493in;">
<div lang="pl" style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
%11011111</div>
</td>
</tr>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.8527in;">
<div lang="pl" style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
DEVPRESENT_UART </div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 3.3493in;">
<div lang="pl" style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
010000</div>
</td>
</tr>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.8527in;">
<div lang="pl" style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
DEVPRESENT_NOUART </div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 3.3493in;">
<div lang="pl" style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
%11101111</div>
</td>
</tr>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.8527in;">
<div lang="pl" style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
DEVNOEXTRAM </div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 3.418in;">
<div lang="pl" style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
DEVPRESENT_NOEXTRAM
& DEVPRESENT_NOBRAM</div>
</td>
</tr>
</tbody></table>
</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 1.125in; margin: 0in;">
<br /></div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
Customizable jump vectors</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
Program loaded and run in RAM can
modify these vectors</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
to drive custom I/O console hardware
and attach/change</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
handler to IRQ procedure. Interrupt
flag should be</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
set before changes are applied and
cleared when ready.</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
Custom IRQ handler routine should
make a jump to standard</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
handler at the end. Custom I/O
function routine should</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
end with RTS.</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
<br /></div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
StoreAcc = $11 ;
Temporary Accumulator store.</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
IrqVect = $0012 ;
Customizable IRQ vector</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
GetChVect = $0014 ;
Custom GetCh function jump vector</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
PutChVect = $0016 ;
Custom PutCh function jump vector</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
GetsVect = $0018 ;
Custom Gets function jump vector</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
PutsVect = $001a ;
Custom Puts function jump vector</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
<br /></div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: .75in; margin: 0in;">
I/O
space / address range:</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: .75in; margin: 0in;">
<br /></div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 1.125in; margin: 0in;">
$C000
.. $C7FF, 8 pages (8 x 256 bytes):</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 1.125in; margin: 0in;">
<br /></div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 1.5in; margin: 0in;">
Internal
(non-buffered) I/O bus:</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 1.5in; margin: 0in;">
<br /></div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 1.5in; margin: 0in;">
$C000
.. $C0FF - slot 0 (RAM bank switching register)</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 1.5in; margin: 0in;">
$C100
.. $C1FF - slot 1 (RTC registers)</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 1.5in; margin: 0in;">
$C200
.. $C2FF - slot 2 (Reserved for Prioritized Interrupt Controller)</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 1.5in; margin: 0in;">
$C300
.. $C3FF - slot 3 (Reserved for built in I/O parallel interface PIA or VIA)</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 1.5in; margin: 0in;">
<br /></div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 1.5in; margin: 0in;">
External
(buffered/expansion) I/O bus:</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 1.5in; margin: 0in;">
<br /></div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 1.5in; margin: 0in;">
$C400
.. $C4FF - slot 4 (UART)</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 1.5in; margin: 0in;">
$C500
.. $C5FF - slot 5</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 1.5in; margin: 0in;">
$C600
.. $C6FF - slot 6</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 1.5in; margin: 0in;">
$C700
.. $C7FF - slot 7</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
<br /></div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: .75in; margin: 0in;">
RAM
bank switching.</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: .75in; margin: 0in;">
<br /></div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 1.125in; margin: 0in;">
NOTE:
Because RAM bank switching hardware register is write only, we cannot read from
it to determine<span style="font-size: 11pt;"> </span><span style="font-size: 11pt;">which bank is selected. The purpose of bank#
RAM register at $E6 is just that - remembering last</span><span style="font-size: 11pt;"> </span><span style="font-size: 11pt;">selected bank#.</span></div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: .75in; margin: 0in;">
<br /></div>
<div style="direction: ltr;">
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse; border-color: #A3A3A3; border-style: solid; border-width: 1pt; direction: ltr; margin-left: 1.0833in;" summary="" title="" valign="top">
<tbody>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.4034in;">
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
Address: </div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.2611in;">
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
$C000</div>
</td>
</tr>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.4034in;">
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
Value: </div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.2611in;">
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
$00 .. $07</div>
</td>
</tr>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.4034in;">
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
Banked memory: </div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.3305in;">
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
$8000 .. $BFFF</div>
</td>
</tr>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.4229in;">
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
Bank number RAM register:</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.2416in;">
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
$E6</div>
</td>
</tr>
</tbody></table>
</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 1.125in; margin: 0in;">
<br /></div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: .75in; margin: 0in;">
Memory
map:</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: .75in; margin: 0in;">
<br /></div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: .75in; margin: 0in;">
<span lang="en-US">$0000 - $7FFF: Base RAM, 32 kB.</span><span lang="pl"> $0000 - $03FF </span><span lang="en-US">space is used by the system.</span></div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: .75in; margin: 0in;">
$6000
- $7FFF: Optional Video RAM, 8 kB. (takes away from Base RAM, leaving 24 kB for
general purpose)</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: .75in; margin: 0in;">
$8000
- $BFFF: Banked RAM, 16 kB space x 8 banks = 128 kB.</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: .75in; margin: 0in;">
$C000
- $C7FF: I/O space, 8 slots x 256 Bytes = 2 kB.</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: .75in; margin: 0in;">
$C800
- $FFFF: EPROM, 14 kB.</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: .75in; margin: 0in;">
<br /></div>
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
<br /></div>
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
System programs:</div>
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
<br /></div>
<div style="font-family: Calibri; font-size: 11.0pt; margin-left: .375in; margin: 0in;">
<span lang="en-US">System programs currently consist</span><span lang="pl"> of:</span></div>
<div lang="pl" style="font-family: Calibri; font-size: 11.0pt; margin-left: .375in; margin: 0in;">
<br /></div>
<div style="font-family: Calibri; font-size: 11.0pt; margin-left: .75in; margin: 0in;">
enhshell.c
- combines rudimentary command line interface with additional functions for
RTC, Banked RAM and more.</div>
<div style="font-family: Calibri; font-size: 11.0pt; margin-left: .75in; margin: 0in;">
setdt.c
- program that allows to set and show date / time.</div>
<div style="font-family: Calibri; font-size: 11.0pt; margin-left: .75in; margin: 0in;">
date.c - programs that shows date / time.</div>
<div style="font-family: Calibri; font-size: 11.0pt; margin-left: .75in; margin: 0in;">
d2hexbin.c
- conversion tool from decimal to hexadecimal / binary code.</div>
<div lang="pl" style="font-family: Calibri; font-size: 11.0pt; margin-left: .75in; margin: 0in;">
<br /></div>
<div style="font-family: Calibri; font-size: 11.0pt; margin-left: .375in; margin: 0in;">
Programs
written in C (CC65) or CA65 assembly for MKHBC-8-Rx computer / MKHBC OS use
library written in C and assembly languages which implements standard C library
(CC65), I/O console and RTC functions and are compiled into library archive
mkhbcos.lib.</div>
<div style="font-family: Calibri; font-size: 11.0pt; margin-left: .375in; margin: 0in;">
Corresponding
C header files are:</div>
<div style="font-family: Calibri; font-size: 11.0pt; margin-left: .375in; margin: 0in;">
<br /></div>
<br />
<ul style="direction: ltr; margin-bottom: 0in; margin-left: .375in; margin-top: 0in; unicode-bidi: embed;" type="disc">
<li style="margin-bottom: 0; margin-top: 0; vertical-align: middle;"><span style="font-family: Calibri; font-size: 11.0pt;">mkhbcos_ansi.h - ANSI
terminal API</span></li>
<li style="margin-bottom: 0; margin-top: 0; vertical-align: middle;"><span style="font-family: Calibri; font-size: 11.0pt;">mkhbcos_ds1685.h - DS1685 RTC
API</span></li>
<li style="margin-bottom: 0; margin-top: 0; vertical-align: middle;"><span style="font-family: Calibri; font-size: 11.0pt;">mkhbcos_lcd.h - standard LCD
16x2 API</span></li>
<li style="margin-bottom: 0; margin-top: 0; vertical-align: middle;"><span lang="en-US" style="font-family: Calibri; font-size: 11.0pt;">mkhbcos_ml.h -</span><span lang="pl" style="font-family: Calibri; font-size: 11.0pt;"> C</span><span lang="en-US" style="font-family: Calibri; font-size: 11.0pt;"> </span><span lang="pl" style="font-family: Calibri; font-size: 11.0pt;">header with
definitions</span><span lang="en-US" style="font-family: Calibri; font-size: 11.0pt;"> </span><span lang="pl" style="font-family: Calibri; font-size: 11.0pt;">of MKHBCOS</span><span lang="en-US" style="font-family: Calibri; font-size: 11.0pt;"> API</span><span lang="pl" style="font-family: Calibri; font-size: 11.0pt;"> and internals</span></li>
<li lang="pl" style="margin-bottom: 0; margin-top: 0; vertical-align: middle;"><span style="font-family: Calibri; font-size: 11.0pt;">mkhbcos_ml.inc - assembly
header with definitions for MKHBCOS API and internals </span></li>
<li style="margin-bottom: 0; margin-top: 0; vertical-align: middle;"><span style="font-family: Calibri; font-size: 11.0pt;">mkhbcos_serialio.h - serial
I/O API</span></li>
</ul>
<div>
<span style="font-family: Calibri;"><span style="font-size: 14.6667px;"><br /></span></span></div>
<div>
<span style="font-family: Verdana, sans-serif; font-size: xx-small;">Thank you for visiting my blog.</span></div>
<div>
<span style="font-family: Verdana, sans-serif; font-size: xx-small;"><br /></span></div>
<div>
<span style="font-family: Verdana, sans-serif; font-size: xx-small;">---</span></div>
<div>
<span style="font-family: Verdana, sans-serif; font-size: xx-small;">MK</span></div>
<div>
<span style="font-family: Verdana, sans-serif; font-size: xx-small;">Feb 13 2018</span></div>
Marek Karczhttp://www.blogger.com/profile/03281397436610614441noreply@blogger.com0tag:blogger.com,1999:blog-4155387638169532413.post-23100347448204274152018-02-03T22:58:00.001-08:002018-02-04T08:06:41.530-08:00RTC library moved to EPROM, kernel jump table extended.<span style="font-family: "verdana" , sans-serif;">Hello 8-bit computing enthusiasts.</span><br />
<span style="font-family: "verdana" , sans-serif;"><br /></span>
<span style="font-family: "verdana" , sans-serif;">A little update on the MKHBC-8-Rx project.</span><br />
<span style="font-family: "verdana" , sans-serif;">Recently having (mostly) completed my home improvement projects, I have some more time to play with my pet project.</span><br />
<span style="font-family: "verdana" , sans-serif;">I have been mainly working on code, cleaning it up and moving some essential parts to EPROM. It is still a mess, but I think it is good enough to be published, so I put it on <a href="https://github.com/makarcz/mkhbc8rx" target="_blank">github</a>.</span><br />
<span style="font-family: "verdana" , sans-serif;"><br /></span>
<span style="font-family: "verdana" , sans-serif;">I moved assembly code of RTC DS-1685 driver to EPROM, enabled periodic interrupts from RTC and added interrupt routine for RTC. I also expanded kernel jump table and added some new functions to my so called 'enhanced shell', although calling this program a shell is a bit of an overkill. :-)</span><br />
<span style="font-family: "verdana" , sans-serif;"><br /></span>
<span style="font-family: "verdana" , sans-serif;">Below I present the current documentation of the OS / firmware fir this system:</span><br />
<span style="font-family: "verdana" , sans-serif;"><br /></span>
<br />
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
System programming /
Operating System of MKHBC-8-Rx is divided into 2 parts:</div>
<div style="font-family: Calibri; font-size: 11.0pt; margin-left: .375in; margin: 0in;">
<br /></div>
<ul style="direction: ltr; margin-bottom: 0in; margin-left: .375in; margin-top: 0in; unicode-bidi: embed;" type="disc">
<li style="margin-bottom: 0; margin-top: 0; vertical-align: middle;"><span style="font-family: "calibri"; font-size: 11.0pt;">Firmware, which resides in
EPROM.</span></li>
<li style="margin-bottom: 0; margin-top: 0; vertical-align: middle;"><span style="font-family: "calibri"; font-size: 11.0pt;">System programs, which are
loaded to RAM via serial port.</span></li>
</ul>
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
<br /></div>
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Firmware consists of
hexadecimal machine code monitor, hardware drivers code, MOS-6502 mandatory
vectors: Reset, NMI, IRQ and Kernel Jump Table.</div>
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Firmware is
implemented in MOS 6502 assembly language.</div>
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Kernel Jump Table is
a series of jump commands that redirect to code performing certain system
functions.</div>
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
These jump commands
are guaranteed to be always at the same memory locations, so the system
programs using them don't have to be rebuilt each time the implementation of
firmware is changed and some internal addresses has moved. The jump table is
always in the same place jumping from the same locations to the same functions
that they should perform, even if the functions themselves change the location
in the EPROM due to code refactoring or relocation of binary code.</div>
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
The new entries can
be added to the Kernel Jump Table though, so it is guaranteed to be backwards
compatible.</div>
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
<br /></div>
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Theory of operation:</div>
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
<br /></div>
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
When computer is
started, the reset circuit holds the reset line low long enough for CPU to
initialize, then the CPU performs startup routine which consists of reading the
Reset vector from the EPROM memory (which must be at fixed address) and
executes the routine pointed by that vector.</div>
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
The routine contains
initialization code for OS and then goes into the eternal loop which sends the
output via serial port and expects input on the serial port. By connecting text
serial terminal device configured to be the same speed as computer's UART speed,
it is possible to interface with the computer to send commands and receive
output.</div>
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
<br /></div>
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
The command UI is
very simple and consists of very rudimentary hexadecimal machine code monitor
which allows to read/dump values in computer's memory, write/modify values in
Random Access Memory and execute code at provided address.</div>
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
This UI is
rudimentary but sufficient for entering code into computer's RAM and executing
it.</div>
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
<br /></div>
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Programming API /
Kernal Jump Table:</div>
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
<br /></div>
<div style="direction: ltr;">
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse; border-color: #A3A3A3; border-style: solid; border-width: 1pt; direction: ltr;" summary="" title="" valign="top">
<tbody>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.2041in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Function</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: .8326in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Address (hex)</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.7784in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Parameters</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.9381in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Return</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.6819in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Description</div>
</td>
</tr>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.2041in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
CallDS1685Init</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: .8326in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
FFD2</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.7784in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
RegB, RegA, RegXB,
RegXA</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.9381in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
RegC in Acc</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.6819in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Initialize RTC
chip.</div>
</td>
</tr>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.2041in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
CallDS1685ReadClock</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: .8326in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
FFD5</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.7784in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
n/a</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.9381in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Data is returned
via hardware stack. Calling subroutine is responsible for allocating 8 bytes
on stack before calling this function. Clock data are stored in following
order below the subroutine return address: seconds, minutes, hours,
dayofweek, date, month, year, century. Valid return data on stack only if Acc
> 0 (Acc = # of bytes on stack). Calling subroutine still should
de-allocate stack space by calling PLA x 8 after reading or discarding
returned data.</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.8375in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Read RTC clock
data.</div>
</td>
</tr>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.2041in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
CallDS1685SetClock</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: .8326in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
FFD8</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.7902in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Parameters are
passed via hardware stack: seconds, minutes, hours, day of week, day of
month, month, year, century. Calling subroutine is responsible for allocating
8 bytes on stack and filling the space with valid input data before calling
this function. Calling subroutine is also responsible for freeing stack space
(PLA x 8).</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.9381in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
n/a</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.877in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Set date/time of
RTC chip.</div>
</td>
</tr>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.2041in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
CallDS1685SetTime</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: .8326in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
FFDB</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.7784in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Parameters are
passed via hardware stack: seconds, minutes, hour. Calling subroutine is
responsible for allocating space on stack and filling it with valid input
data before calling this function.
Calling subroutine is also responsible for freeing stack space (PLA x
3).</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.9381in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
n/a</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.8361in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Set time of RTC
chip.</div>
</td>
</tr>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.2041in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
CallDS1685StoreRam</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: .8326in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
FFDE</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.7784in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
BankNum, RamAddr,
RamVal</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.9381in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
n/a</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.8902in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Store a value in
non-volatile RTC memory bank.</div>
</td>
</tr>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.2041in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
CallDS1685ReadRam</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: .8326in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
FFE1</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.7784in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
BankNum, RamAddr</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.9381in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
value in Acc</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.9506in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Read value from
non-volatile RTC memory bank.</div>
</td>
</tr>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.2041in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
CallReadMem</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: .8326in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
FFE4</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.7784in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
PromptLine
(contains hexadecimal address range)</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.9381in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
n/a (output)</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.877in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Machine code
monitor function - read memory.</div>
</td>
</tr>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.2041in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
CallWriteMem</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: .8326in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
FFE7</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.7784in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
PromptLine
(contains hexadecimal address and values)</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.9381in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
n/a (memory is
modified)</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.877in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Machine code
monitor function - write memory.</div>
</td>
</tr>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.2041in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
CallExecute</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: .8326in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
FFEA</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.7784in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
PromptLine
(contains hexadecimal address)</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.9381in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
n/a (code is
executed)</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.877in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Machine code
monitor function - execute code in memory.</div>
</td>
</tr>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.2041in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
CallGetCh</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: .8326in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
FFED</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.7784in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
n/a</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.9381in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Character code in
Acc</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.877in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Standard I/O
function - get character.</div>
</td>
</tr>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.2041in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
CallPutCh</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: .8326in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
FFF0</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.7784in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Character code in
Acc.</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.9381in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
n/a (output)</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.877in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Standard I/O
function - put/print character.</div>
</td>
</tr>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.2041in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
CallGets</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: .8326in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
FFF3</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.7784in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
n/a (input)</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.9381in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
PromptLine,
PromptLen</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.877in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Standard I/O
function - get string.</div>
</td>
</tr>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.2041in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
CallPuts</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: .8326in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
FFF6</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.7784in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
StrPtr</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.9381in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
n/a (output)</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.877in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Standard I/O
function - put/print string.</div>
</td>
</tr>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.2041in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
CallBankRamSel</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: .8326in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
FFCF</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.7784in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Banked RAM bank #
in Acc. (0..7)</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.9381in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
n/a (selects RAM
bank, updates shadow register in RAM)</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.9236in;"><div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Banked RAM bank
selection.</div>
</td>
</tr>
</tbody></table>
</div>
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
<br /></div>
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
<span style="font-weight: bold;">WARNING:</span></div>
<div style="font-family: Calibri; font-size: 11.0pt; margin-left: .375in; margin: 0in;">
Disable
interrupts before calling any RTC function:</div>
<div style="font-family: Calibri; font-size: 11.0pt; margin-left: .375in; margin: 0in;">
SEI</div>
<div style="font-family: Calibri; font-size: 11.0pt; margin-left: .375in; margin: 0in;">
<call
to RTC API></div>
<div style="font-family: Calibri; font-size: 11.0pt; margin-left: .375in; margin: 0in;">
CLI</div>
<div style="font-family: Calibri; font-size: 11.0pt; margin-left: .375in; margin: 0in;">
<br /></div>
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
Registers, buffers,
memory:</div>
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
<br /></div>
<div style="font-family: Calibri; font-size: 11.0pt; margin-left: .75in; margin: 0in;">
RTC
RAM shadow:</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
RegB = $F6</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
RegA = $F7</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
RegXB = $F8</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
RegXA = $F9</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
RegC = $FA</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
Temp = $FB</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
BankNum = $FC</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
RamAddr = $FD</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
RamVal = $FE</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
<br /></div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: .75in; margin: 0in;">
Uart
Queues (after stack)</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
UartTxQue = $200 ; 256 byte output queue</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
UartRxQue = $300 ; 256 byte input queue</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
<br /></div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
MOS Prompt variables</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
PromptLine = $80 ; Prompt line (entered by user)</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
PromptMax = $50 ; An 80-character line is permitted
($80 to $CF)</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
PromptLen = $D0 ; Location of length variable</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
<br /></div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
MOS I/O Function variables</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
StrPtr = $E0 ; String pointer for I/O functions</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
<br /></div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: .75in; margin: 0in;">
Other variables:</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 1.125in; margin: 0in;">
Timer64Hz
= $E2 ; 4-byte (32-bit)
counter incremented 64 times / sec</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 3.375in; margin: 0in;">
; $E2,$E3,$E4,$E5 (unsigned long, little
endian)</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
<br /></div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
Customizable jump
vectors</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
Program loaded and run in RAM can
modify these vectors</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
to drive custom I/O console hardware
and attach/change</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
handler to IRQ procedure. Interrupt
flag should be</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
set before changes are applied and
cleared when ready.</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
Custom IRQ handler routine should
make a jump to standard</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
handler at the end. Custom I/O
function routine should</div>
<br />
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
end with RTS.</div>
</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
<br /></div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
StoreAcc = $11 ;
Temporary Accumulator store.</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
IrqVect = $0012 ;
Customizable IRQ vector</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
GetChVect = $0014 ;
Custom GetCh function jump vector</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
PutChVect = $0016 ;
Custom PutCh function jump vector</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
GetsVect = $0018 ;
Custom Gets function jump vector</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
PutsVect = $001a ;
Custom Puts function jump vector</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
<br /></div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: .75in; margin: 0in;">
I/O
space / address range:</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: .75in; margin: 0in;">
<br /></div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 1.125in; margin: 0in;">
$C000
.. $C7FF, 8 pages (8 x 256 bytes):</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 1.125in; margin: 0in;">
<br /></div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 1.5in; margin: 0in;">
Internal
(non-buffered) I/O bus:</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 1.5in; margin: 0in;">
<br /></div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 1.5in; margin: 0in;">
$C000
.. $C0FF - slot 0 (RAM bank switching register)</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 1.5in; margin: 0in;">
$C100
.. $C1FF - slot 1 (RTC registers)</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 1.5in; margin: 0in;">
$C200
.. $C2FF - slot 2 (Reserved for Prioritized Interrupt Controller)</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 1.5in; margin: 0in;">
$C300
.. $C3FF - slot 3 (Reserved for built in I/O parallel interface PIA or VIA)</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 1.5in; margin: 0in;">
<br /></div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 1.5in; margin: 0in;">
External
(buffered/expansion) I/O bus:</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 1.5in; margin: 0in;">
<br /></div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 1.5in; margin: 0in;">
$C400
.. $C4FF - slot 4 (UART)</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 1.5in; margin: 0in;">
$C500
.. $C5FF - slot 5</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 1.5in; margin: 0in;">
$C600
.. $C6FF - slot 6</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 1.5in; margin: 0in;">
$C700
.. $C7FF - slot 7</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
<br /></div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: .75in; margin: 0in;">
RAM
bank switching.</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: .75in; margin: 0in;">
<br /></div>
<div style="direction: ltr;">
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse; border-color: #A3A3A3; border-style: solid; border-width: 1pt; direction: ltr; margin-left: 1.0833in;" summary="" title="" valign="top">
<tbody>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.4034in;"><div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
Address: </div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.2611in;"><div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
$C000</div>
</td>
</tr>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.4034in;"><div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
Value: </div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.2611in;"><div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
$00 .. $07</div>
</td>
</tr>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.4034in;"><div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
Banked memory: </div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.3305in;"><div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
$8000 .. $BFFF</div>
</td>
</tr>
<tr>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 2.4229in;"><div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
Bank number RAM register:</div>
</td>
<td style="border-color: #A3A3A3; border-style: solid; border-width: 1pt; padding: 4pt 4pt 4pt 4pt; vertical-align: top; width: 1.2416in;"><div style="font-family: Consolas; font-size: 11.0pt; margin: 0in;">
$E6</div>
</td>
</tr>
</tbody></table>
</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: 1.125in; margin: 0in;">
<br /></div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: .75in; margin: 0in;">
Memory
map:</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: .75in; margin: 0in;">
<br /></div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: .75in; margin: 0in;">
$0000
- $7FFF: Base RAM, 32 kB.</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: .75in; margin: 0in;">
$6000
- $7FFF: Optional Video RAM, 8 kB.</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: .75in; margin: 0in;">
$8000
- $BFFF: Banked RAM, 16 kB space x 8 banks = 128 kB.</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: .75in; margin: 0in;">
$C000
- $C7FF: I/O space, 8 slots x 256 Bytes = 2 kB.</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: .75in; margin: 0in;">
$C800
- $FFFF: EPROM, 14 kB.</div>
<div style="font-family: Consolas; font-size: 11.0pt; margin-left: .75in; margin: 0in;">
<br /></div>
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
<br /></div>
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
System programs:</div>
<div style="font-family: Calibri; font-size: 11.0pt; margin: 0in;">
<br /></div>
<div style="font-family: Calibri; font-size: 11.0pt; margin-left: .375in; margin: 0in;">
System
programs currently consist only one - enhanced shell.</div>
<div style="font-family: Calibri; font-size: 11.0pt; margin-left: .375in; margin: 0in;">
It
is written in C and compiled with CC65.</div>
<div style="font-family: Calibri; font-size: 11.0pt; margin-left: .375in; margin: 0in;">
Programs
written in C (CC65) or CA65 assembly for MKHBC-8-Rx computer / MKHBC OS use
library written in C and assembly languages which implements standard C library
(CC65), I/O console and RTC functions and are compiled into library archive
mkhbcos.lib.</div>
<div style="font-family: Calibri; font-size: 11.0pt; margin-left: .375in; margin: 0in;">
Corresponding
C header files are:</div>
<div style="font-family: Calibri; font-size: 11.0pt; margin-left: .375in; margin: 0in;">
<br /></div>
<br />
<ul style="direction: ltr; margin-bottom: 0in; margin-left: .375in; margin-top: 0in; unicode-bidi: embed;" type="disc">
<li style="margin-bottom: 0; margin-top: 0; vertical-align: middle;"><span style="font-family: "calibri"; font-size: 11.0pt;">mkhbcos_ansi.h - ANSI
terminal API</span></li>
<li style="margin-bottom: 0; margin-top: 0; vertical-align: middle;"><span style="font-family: "calibri"; font-size: 11.0pt;">mkhbcos_ds1685.h - DS1685 RTC
API</span></li>
<li style="margin-bottom: 0; margin-top: 0; vertical-align: middle;"><span style="font-family: "calibri"; font-size: 11.0pt;">mkhbcos_lcd.h - standard LCD
16x2 API</span></li>
<li style="margin-bottom: 0; margin-top: 0; vertical-align: middle;"><span style="font-family: "calibri"; font-size: 11.0pt;">mkhbcos_ml.h - machine code
monitor API</span></li>
<li style="margin-bottom: 0; margin-top: 0; vertical-align: middle;"><span style="font-family: "calibri"; font-size: 11.0pt;">mkhbcos_serialio.h - serial
I/O API</span></li>
</ul>
<br />
<span style="font-family: "verdana" , sans-serif;">That's all for today.</span><br />
<span style="font-family: "verdana" , sans-serif;">Thank you for visiting my blog.</span><br />
<span style="font-family: "verdana" , sans-serif;"><br /></span>
<span style="font-family: "verdana" , sans-serif;">Marek K. 2/4/2018.</span>Marek Karczhttp://www.blogger.com/profile/03281397436610614441noreply@blogger.com0tag:blogger.com,1999:blog-4155387638169532413.post-36696961080613595682017-06-19T11:28:00.001-07:002017-06-19T11:28:22.635-07:00Update on MKHBC-8-Rx : NV RAM access added to DS1685 driver.<span style="font-family: Verdana, sans-serif;">DS1685 chip has non-volatile (battery sustained) RAM in two banks. Total of 242 bytes are available for user to store data or code that will be persistent between system power cycles (assuming external 3V battery is used).</span><br />
<span style="font-family: Verdana, sans-serif;">I have plans regarding this memory for future iterations of the operating system, so right after I finished the RTC / BRAM card I got to working on enhancing the driver to have read / write access to this memory.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">The new API:</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">/*</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * File: <span class="Apple-tab-span" style="white-space: pre;"> </span>mkhbcos_ds1685.h</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * Purpose:<span class="Apple-tab-span" style="white-space: pre;"> </span>Declarations and definitions for</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * DS1685 RTC (Real Time Clock) chip API.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * Author:<span class="Apple-tab-span" style="white-space: pre;"> </span>Marek Karcz</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * Created:<span class="Apple-tab-span" style="white-space: pre;"> </span>02/05/2012</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> *</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * Revision history:</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> *</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> *</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> */</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#ifndef MKHBCOS_DS1685</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define MKHBCOS_DS1685</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">// DS RTC registers mask bits</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">// reg. A</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define DSC_REGA_UIP<span class="Apple-tab-span" style="white-space: pre;"> </span>0x80<span class="Apple-tab-span" style="white-space: pre;"> </span>// %10000000</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define DSC_REGA_DV2<span class="Apple-tab-span" style="white-space: pre;"> </span>0x40<span class="Apple-tab-span" style="white-space: pre;"> </span>// %01000000</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define DSC_REGA_DV1<span class="Apple-tab-span" style="white-space: pre;"> </span>0x20<span class="Apple-tab-span" style="white-space: pre;"> </span>// 100000</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define DSC_REGA_DV0<span class="Apple-tab-span" style="white-space: pre;"> </span>0x10<span class="Apple-tab-span" style="white-space: pre;"> </span>// 010000</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define DSC_REGA_RS3<span class="Apple-tab-span" style="white-space: pre;"> </span>0x08<span class="Apple-tab-span" style="white-space: pre;"> </span>// 001000</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define DSC_REGA_RS2<span class="Apple-tab-span" style="white-space: pre;"> </span>0x04<span class="Apple-tab-span" style="white-space: pre;"> </span>// 000100</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define DSC_REGA_RS1<span class="Apple-tab-span" style="white-space: pre;"> </span>0x02<span class="Apple-tab-span" style="white-space: pre;"> </span>// 000010</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define DSC_REGA_RS0<span class="Apple-tab-span" style="white-space: pre;"> </span>0x01<span class="Apple-tab-span" style="white-space: pre;"> </span>// 000001</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">// aliases</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define DSC_REGA_CTDWN<span class="Apple-tab-span" style="white-space: pre;"> </span>DSC_REGA_DV2</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define DSC_REGA_OSCEN<span class="Apple-tab-span" style="white-space: pre;"> </span>DSC_REGA_DV1</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define DSC_REGA_BSEL<span class="Apple-tab-span" style="white-space: pre;"> </span>DSC_REGA_DV0</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define DSC_REGA_BANK0<span class="Apple-tab-span" style="white-space: pre;"> </span>0xEF</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define DSC_REGA_BANK1<span class="Apple-tab-span" style="white-space: pre;"> </span>0x10</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">// reg. B</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define DSC_REGB_SET<span class="Apple-tab-span" style="white-space: pre;"> </span>0x80<span class="Apple-tab-span" style="white-space: pre;"> </span>// %10000000</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define DSC_REGB_PIE<span class="Apple-tab-span" style="white-space: pre;"> </span>0x40<span class="Apple-tab-span" style="white-space: pre;"> </span>// %01000000</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define DSC_REGB_AIE<span class="Apple-tab-span" style="white-space: pre;"> </span>0x20<span class="Apple-tab-span" style="white-space: pre;"> </span>// 100000</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define DSC_REGB_UIE<span class="Apple-tab-span" style="white-space: pre;"> </span>0x10<span class="Apple-tab-span" style="white-space: pre;"> </span>// 010000</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define DSC_REGB_SQWE<span class="Apple-tab-span" style="white-space: pre;"> </span>0x08<span class="Apple-tab-span" style="white-space: pre;"> </span>// 001000</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define DSC_REGB_DM<span class="Apple-tab-span" style="white-space: pre;"> </span>0x04<span class="Apple-tab-span" style="white-space: pre;"> </span>// 000100</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define DSC_REGB_24o12<span class="Apple-tab-span" style="white-space: pre;"> </span>0x02<span class="Apple-tab-span" style="white-space: pre;"> </span>// 000010</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define DSC_REGB_DSE<span class="Apple-tab-span" style="white-space: pre;"> </span>0x01<span class="Apple-tab-span" style="white-space: pre;"> </span>// 000001</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">// aliases</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define DSC_REGB_UNSET<span class="Apple-tab-span" style="white-space: pre;"> </span>0x7F<span class="Apple-tab-span" style="white-space: pre;"> </span>// %01111111</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">struct ds1685_clkdata</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>unsigned char seconds;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>unsigned char minutes;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>unsigned char hours;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>unsigned char dayofweek;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>unsigned char date; // day</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>unsigned char month;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>unsigned char year;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>unsigned char century;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">};</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">unsigned char __fastcall__ ds1685_init (unsigned char regb,</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> unsigned char rega,</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> unsigned char regextb,</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> unsigned char regexta);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">struct <span class="Apple-tab-span" style="white-space: pre;"> </span>ds1685_clkdata *ds1685_rdclock <span class="Apple-tab-span" style="white-space: pre;"> </span>(struct ds1685_clkdata *buf);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">void <span class="Apple-tab-span" style="white-space: pre;"> </span>ds1685_setclock (struct ds1685_clkdata *buf);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">void <span class="Apple-tab-span" style="white-space: pre;"> </span>ds1685_settime <span class="Apple-tab-span" style="white-space: pre;"> </span>(struct ds1685_clkdata *buf);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">/* bank - 0 or 1, addr - $00 - $7f ($0e - $7f for Bank 0), data - 0..255 */</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">void<span class="Apple-tab-span" style="white-space: pre;"> </span>ds1685_storeram (unsigned char bank,</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> unsigned char addr,</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> unsigned char data);<span class="Apple-tab-span" style="white-space: pre;"> </span> </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">unsigned char __fastcall__ ds1685_readram(unsigned char bank,</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> unsigned char addr);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#endif</span><br />
<br />
<span style="font-family: Verdana, sans-serif;">and the code:</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;------------------------------------------------------------------</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; File: <span class="Apple-tab-span" style="white-space: pre;"> </span>mkhbcos_ds1685.s</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; Author:<span class="Apple-tab-span" style="white-space: pre;"> </span>Marek Karcz</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; Purpose:<span class="Apple-tab-span" style="white-space: pre;"> </span>Implements initialization routines and API for</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;<span class="Apple-tab-span" style="white-space: pre;"> </span>Real Time Clock chip DS1685 with multiplexed</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; address bus connected to buffered I/O bus as an I/O</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; device.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; Revision history:</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;<span class="Apple-tab-span" style="white-space: pre;"> </span>2012-01-31:</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;<span class="Apple-tab-span" style="white-space: pre;"> </span>Initial revision.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; (NOTE: These routines will eventually make their way</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; to EPROM as a part of firmware. At that time,</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; this file will be revised to call up the API</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; functions in the kernal table, instead of</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; being full implementation.)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;<span class="Apple-tab-span" style="white-space: pre;"> </span>2012-02-06:</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;<span class="Apple-tab-span" style="white-space: pre;"> </span>Implementation.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; 2015-11-29</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; I/O slot assignment changed.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; 2015-12-5</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; Modification due to hardware changes (Chris Ward variant):</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; DSCALADDR and DSCALDATA order changed.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; 2017-06-15:</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; Added functions to store and read non-volatile RAM.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;------------------------------------------------------------------</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; M.O.S. API defines (kernal)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">.define <span class="Apple-tab-span" style="white-space: pre;"> </span>mos_StrPtr<span class="Apple-tab-span" style="white-space: pre;"> </span>$E0</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">.define<span class="Apple-tab-span" style="white-space: pre;"> </span>tmp_zpgPt<span class="Apple-tab-span" style="white-space: pre;"> </span>$F6</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">.define<span class="Apple-tab-span" style="white-space: pre;"> </span>IOBase<span class="Apple-tab-span" style="white-space: pre;"> </span>$C000</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">.define <span class="Apple-tab-span" style="white-space: pre;"> </span>RTC<span class="Apple-tab-span" style="white-space: pre;"> </span>IOBase+256</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;.define<span class="Apple-tab-span" style="white-space: pre;"> </span>RTC<span class="Apple-tab-span" style="white-space: pre;"> </span>IOBase+7*256</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">.define <span class="Apple-tab-span" style="white-space: pre;"> </span>DSCALADDR<span class="Apple-tab-span" style="white-space: pre;"> </span>RTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">.define<span class="Apple-tab-span" style="white-space: pre;"> </span>DSCALDATA<span class="Apple-tab-span" style="white-space: pre;"> </span>RTC+1</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">.setcpu<span class="Apple-tab-span" style="white-space: pre;"> </span>"6502"</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">.import ldaxysp,pushax,popax,pusha,popa,staspidx</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">.import incsp2,incsp3,incsp4,ldauidx</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">.define<span class="Apple-tab-span" style="white-space: pre;"> </span>sp<span class="Apple-tab-span" style="white-space: pre;"> </span>$20</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;RegB<span class="Apple-tab-span" style="white-space: pre;"> </span>=<span class="Apple-tab-span" style="white-space: pre;"> </span>tmp_zpgPt</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;RegA<span class="Apple-tab-span" style="white-space: pre;"> </span>=<span class="Apple-tab-span" style="white-space: pre;"> </span>tmp_zpgPt+1</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;RegXB<span class="Apple-tab-span" style="white-space: pre;"> </span>=<span class="Apple-tab-span" style="white-space: pre;"> </span>tmp_zpgPt+2</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;RegXA<span class="Apple-tab-span" style="white-space: pre;"> </span>=<span class="Apple-tab-span" style="white-space: pre;"> </span>tmp_zpgPt+3</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;RegC<span class="Apple-tab-span" style="white-space: pre;"> </span>=<span class="Apple-tab-span" style="white-space: pre;"> </span>tmp_zpgPt+4</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;Temp<span class="Apple-tab-span" style="white-space: pre;"> </span>=<span class="Apple-tab-span" style="white-space: pre;"> </span>tmp_zpgPt+5</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;BankNum = tmp_zpgPt</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;RamAddr = tmp_zpgPt+1</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;RamVal = tmp_zpgPt+2 </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">.segment "DATA"</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">RegB: .byte $00</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">RegA: .byte $00</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">RegXB: .byte $00</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">RegXA: .byte $00</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">RegC: .byte $00</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">Temp: .byte $00</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">BankNum: .byte $00</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">RamAddr: .byte $00</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">RamVal: .byte $00</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">ExtRamAddr = $50</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">ExtRamPort = $53</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; DS RTC registers mask bits</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; reg. A</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">DSC_REGA_UIP<span class="Apple-tab-span" style="white-space: pre;"> </span>=<span class="Apple-tab-span" style="white-space: pre;"> </span>%10000000</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">DSC_REGA_DV2<span class="Apple-tab-span" style="white-space: pre;"> </span>=<span class="Apple-tab-span" style="white-space: pre;"> </span>%01000000</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">DSC_REGA_DV1<span class="Apple-tab-span" style="white-space: pre;"> </span>=<span class="Apple-tab-span" style="white-space: pre;"> </span>100000</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">DSC_REGA_DV0<span class="Apple-tab-span" style="white-space: pre;"> </span>=<span class="Apple-tab-span" style="white-space: pre;"> </span>010000</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">DSC_REGA_RS3<span class="Apple-tab-span" style="white-space: pre;"> </span>=<span class="Apple-tab-span" style="white-space: pre;"> </span>001000</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">DSC_REGA_RS2<span class="Apple-tab-span" style="white-space: pre;"> </span>=<span class="Apple-tab-span" style="white-space: pre;"> </span>000100</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">DSC_REGA_RS1<span class="Apple-tab-span" style="white-space: pre;"> </span>=<span class="Apple-tab-span" style="white-space: pre;"> </span>000010</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">DSC_REGA_RS0<span class="Apple-tab-span" style="white-space: pre;"> </span>=<span class="Apple-tab-span" style="white-space: pre;"> </span>000001</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; aliases</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">DSC_REGA_CTDWN<span class="Apple-tab-span" style="white-space: pre;"> </span>=<span class="Apple-tab-span" style="white-space: pre;"> </span>DSC_REGA_DV2</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">DSC_REGA_OSCEN<span class="Apple-tab-span" style="white-space: pre;"> </span>=<span class="Apple-tab-span" style="white-space: pre;"> </span>DSC_REGA_DV1</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">DSC_REGA_BSEL<span class="Apple-tab-span" style="white-space: pre;"> </span>=<span class="Apple-tab-span" style="white-space: pre;"> </span>DSC_REGA_DV0</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">DSC_REGA_BANK0<span class="Apple-tab-span" style="white-space: pre;"> </span>=<span class="Apple-tab-span" style="white-space: pre;"> </span>$EF</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">DSC_REGA_BANK1<span class="Apple-tab-span" style="white-space: pre;"> </span>=<span class="Apple-tab-span" style="white-space: pre;"> </span>$10</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; reg. B</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">DSC_REGB_SET<span class="Apple-tab-span" style="white-space: pre;"> </span>=<span class="Apple-tab-span" style="white-space: pre;"> </span>%10000000</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">DSC_REGB_PIE<span class="Apple-tab-span" style="white-space: pre;"> </span>=<span class="Apple-tab-span" style="white-space: pre;"> </span>%01000000</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">DSC_REGB_AIE<span class="Apple-tab-span" style="white-space: pre;"> </span>=<span class="Apple-tab-span" style="white-space: pre;"> </span>100000</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">DSC_REGB_UIE<span class="Apple-tab-span" style="white-space: pre;"> </span>=<span class="Apple-tab-span" style="white-space: pre;"> </span>010000</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">DSC_REGB_SQWE<span class="Apple-tab-span" style="white-space: pre;"> </span>=<span class="Apple-tab-span" style="white-space: pre;"> </span>001000</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">DSC_REGB_DM<span class="Apple-tab-span" style="white-space: pre;"> </span>=<span class="Apple-tab-span" style="white-space: pre;"> </span>000100</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">DSC_REGB_24o12<span class="Apple-tab-span" style="white-space: pre;"> </span>=<span class="Apple-tab-span" style="white-space: pre;"> </span>000010</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">DSC_REGB_DSE<span class="Apple-tab-span" style="white-space: pre;"> </span>=<span class="Apple-tab-span" style="white-space: pre;"> </span>000001</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; aliases</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">DSC_REGB_UNSET<span class="Apple-tab-span" style="white-space: pre;"> </span>=<span class="Apple-tab-span" style="white-space: pre;"> </span>%01111111</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; code</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">.export _ds1685_init,_ds1685_rdclock,_ds1685_setclock,_ds1685_settime</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">.export _ds1685_readram,_ds1685_storeram</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;,_read</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">.segment "CODE"</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; Initialize DS1685 RTC chip.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; unsigned char __fastcall__ ds1685_init (unsigned char regb,</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; unsigned char rega,</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; unsigned char regextb,</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; unsigned char regexta)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">.proc _ds1685_init: near</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">.segment "CODE"</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>; get parameters, put them in temp. buffer</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr pusha</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ldy #$03</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>;ldx #$00</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda (sp),y</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>sta RegB</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ldy #$02</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>;ldx #$00</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda (sp),y</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>sta RegA</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ldy #$01</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>;ldx #$00</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda (sp),y</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>sta RegXB</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ldy #$00</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>;ldx #$00</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda (sp),y</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>sta RegXA</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>; initialize control register B</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ldx RegB</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$0b</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr WrRTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>; read status register C</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$0c</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr RdRTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>sta RegC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>; initialize control register A, switch to bank 1</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda RegA</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ora #DSC_REGA_BANK1<span class="Apple-tab-span" style="white-space: pre;"> </span>; switch to bank 1</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>tax</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$0a</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr WrRTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>; initialize extended control register B</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ldx RegXB</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$4b</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr WrRTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>; initialize extended control register A</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ldx RegXA</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$4a</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr WrRTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>; switch to bank 0</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> jsr Switch2Bank0</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ldx #$00</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda RegC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> jsr incsp4</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>rts</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">.endproc</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">.segment "CODE"</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; read clock data</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; struct ds1685_clkdata *ds1685_rdclock(struct ds1685_clkdata *buf);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; struct ds1685_clkdata</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; {</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;<span class="Apple-tab-span" style="white-space: pre;"> </span>unsigned char seconds;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;<span class="Apple-tab-span" style="white-space: pre;"> </span>unsigned char minutes;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;<span class="Apple-tab-span" style="white-space: pre;"> </span>unsigned char hours;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;<span class="Apple-tab-span" style="white-space: pre;"> </span>unsigned char dayofweek;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;<span class="Apple-tab-span" style="white-space: pre;"> </span>unsigned char date; // day</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;<span class="Apple-tab-span" style="white-space: pre;"> </span>unsigned char month;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;<span class="Apple-tab-span" style="white-space: pre;"> </span>unsigned char year;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;<span class="Apple-tab-span" style="white-space: pre;"> </span>unsigned char century;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; };</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">.proc _ds1685_rdclock:near</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">.segment "CODE"</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; disable update transfers</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$0b</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr RdRTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>sta RegB<span class="Apple-tab-span" style="white-space: pre;"> </span>; save register B for later</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ora #DSC_REGB_SET</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>tax</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$0b</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr WrRTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; determine mode (BCD or BIN)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #DSC_REGB_DM</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>sta Temp</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda RegB</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>bit Temp</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>bne binmoderead</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; can't do BCD mode yet, return</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ldy #$01</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr ldaxysp</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr incsp2</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>rts</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">binmoderead:</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>; binary mode read</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$00<span class="Apple-tab-span" style="white-space: pre;"> </span>; load register address of seconds</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr RdRTC<span class="Apple-tab-span" style="white-space: pre;"> </span>; read register value to Acc</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>and #111111<span class="Apple-tab-span" style="white-space: pre;"> </span>; mask 2 upper bits</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ldy #$00</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr Tfer2RetBuf<span class="Apple-tab-span" style="white-space: pre;"> </span>; transfer to return buffer at index 0 (seconds)</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$02<span class="Apple-tab-span" style="white-space: pre;"> </span>; load register address of minutes</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr RdRTC<span class="Apple-tab-span" style="white-space: pre;"> </span>; read register value to Acc</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>and #111111<span class="Apple-tab-span" style="white-space: pre;"> </span>; mask 2 upper bits</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ldy #$01</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr Tfer2RetBuf<span class="Apple-tab-span" style="white-space: pre;"> </span>; transfer to return buffer at index 1 (minutes)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$04<span class="Apple-tab-span" style="white-space: pre;"> </span>; load register address of hours</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr RdRTC<span class="Apple-tab-span" style="white-space: pre;"> </span>; read register value to Acc</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>pha</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #DSC_REGB_24o12</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>sta Temp</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda RegB<span class="Apple-tab-span" style="white-space: pre;"> </span>; determine which hours mode (12/24 hours)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>bit Temp</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>beq mode12hbin</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>pla</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>and #011111<span class="Apple-tab-span" style="white-space: pre;"> </span>; mask 3 upper bits for 24H mode read</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>clc</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>bcc storehours</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">mode12hbin:</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>pla</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>and #001111<span class="Apple-tab-span" style="white-space: pre;"> </span>; mask 4 upper bits for 12H mode read</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">storehours:</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ldy #$02</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr Tfer2RetBuf<span class="Apple-tab-span" style="white-space: pre;"> </span>; transfer to return buffer at index 2 (hours)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$06<span class="Apple-tab-span" style="white-space: pre;"> </span>; load register address of day (of week)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr RdRTC<span class="Apple-tab-span" style="white-space: pre;"> </span>; read register value to Acc</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>and #000111<span class="Apple-tab-span" style="white-space: pre;"> </span>; mask 5 upper bits</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ldy #$03</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr Tfer2RetBuf<span class="Apple-tab-span" style="white-space: pre;"> </span>; transfer to return buffer at index 3 (dayofweek)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$07<span class="Apple-tab-span" style="white-space: pre;"> </span>; load register address of date (day of month)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr RdRTC<span class="Apple-tab-span" style="white-space: pre;"> </span>; read register value to Acc</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>and #011111<span class="Apple-tab-span" style="white-space: pre;"> </span>; mask 3 upper bits</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ldy #$04</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr Tfer2RetBuf<span class="Apple-tab-span" style="white-space: pre;"> </span>; transfer to return buffer at index 4 (date)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$08<span class="Apple-tab-span" style="white-space: pre;"> </span>; load register address of month</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr RdRTC<span class="Apple-tab-span" style="white-space: pre;"> </span>; read register value to Acc</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>and #001111<span class="Apple-tab-span" style="white-space: pre;"> </span>; mask 4 upper bits</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ldy #$05</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr Tfer2RetBuf<span class="Apple-tab-span" style="white-space: pre;"> </span>; transfer to return buffer at index 5 (month)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$09<span class="Apple-tab-span" style="white-space: pre;"> </span>; load register address of year</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr RdRTC<span class="Apple-tab-span" style="white-space: pre;"> </span>; read register value to Acc</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>and #%011111111<span class="Apple-tab-span" style="white-space: pre;"> </span>; mask the highest bit</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ldy #$06</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr Tfer2RetBuf<span class="Apple-tab-span" style="white-space: pre;"> </span>; transfer to return buffer at index 6 (year)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> jsr Switch2Bank1</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$48<span class="Apple-tab-span" style="white-space: pre;"> </span>; load register address of century</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr RdRTC<span class="Apple-tab-span" style="white-space: pre;"> </span>; read register value to Acc</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ldy #$07</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr Tfer2RetBuf<span class="Apple-tab-span" style="white-space: pre;"> </span>; transfer to return buffer at index 7 (century)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> jsr Switch2Bank0</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>; enable update transfers</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$0b</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr RdRTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>and #DSC_REGB_UNSET</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>tax</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$0b</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr WrRTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ldy #$01</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr ldaxysp</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr incsp2</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>rts</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">.endproc</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">.segment "CODE"</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; set clock data</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; void ds1685_setclock (struct ds1685_clkdata *buf);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">.proc _ds1685_setclock:near</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">.segment "CODE"</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>; disable update transfers</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>; set binary mode</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$0b</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr RdRTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ora #DSC_REGB_SET</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ora #DSC_REGB_DM</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>tax</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$0b</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr WrRTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ldy #$00<span class="Apple-tab-span" style="white-space: pre;"> </span>; get argument 0 (seconds)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr GetParFromSpIdx</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>tax</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$00<span class="Apple-tab-span" style="white-space: pre;"> </span>; write to DS1685 seconds register</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr WrRTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ldy #$01<span class="Apple-tab-span" style="white-space: pre;"> </span>; get argument 1 (minutes)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr GetParFromSpIdx</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>tax</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$02<span class="Apple-tab-span" style="white-space: pre;"> </span>; write to DS1685 minutes register</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr WrRTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ldy #$02<span class="Apple-tab-span" style="white-space: pre;"> </span>; hours</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr GetParFromSpIdx </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>tax</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$04</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr WrRTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ldy #$03<span class="Apple-tab-span" style="white-space: pre;"> </span>; day of week</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr GetParFromSpIdx</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>tax</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$06</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr WrRTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ldy #$04<span class="Apple-tab-span" style="white-space: pre;"> </span>; date (day of month)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr GetParFromSpIdx</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>tax</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$07</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr WrRTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ldy #$05<span class="Apple-tab-span" style="white-space: pre;"> </span>; month</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr GetParFromSpIdx</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>tax</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$08</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr WrRTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ldy #$06<span class="Apple-tab-span" style="white-space: pre;"> </span>; year</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr GetParFromSpIdx</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>tax</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$09</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr WrRTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>; enable update transfers</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$0b</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr RdRTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>and #DSC_REGB_UNSET</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>tax</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$0b</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr WrRTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>; disable update transfers</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$0b</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr RdRTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ora #DSC_REGB_SET</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>tax</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$0b</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr WrRTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$0a<span class="Apple-tab-span" style="white-space: pre;"> </span>; get reg. A</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr RdRTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ora #DSC_REGA_BANK1<span class="Apple-tab-span" style="white-space: pre;"> </span>; switch to bank 1</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>tax</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$0a</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr WrRTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ldy #$07<span class="Apple-tab-span" style="white-space: pre;"> </span>; century</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr GetParFromSpIdx</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>tax</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$48</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr WrRTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> jsr Switch2Bank0</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>; enable update transfers</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$0b</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr RdRTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>and #DSC_REGB_UNSET</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>tax</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$0b</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr WrRTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr incsp2</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>rts</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">.endproc</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">.segment "CODE"</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; set clock data</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; void ds1685_settime (struct ds1685_clkdata *buf);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">.proc _ds1685_settime:near</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">.segment "CODE"</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> jsr Switch2Bank0</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>; disable update transfers</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>; set binary mode</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$0b</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr RdRTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ora #DSC_REGB_SET</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ora #DSC_REGB_DM</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>tax</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$0b</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr WrRTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ldy #$00<span class="Apple-tab-span" style="white-space: pre;"> </span>; get argument 0 (seconds)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr GetParFromSpIdx</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>tax</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$00<span class="Apple-tab-span" style="white-space: pre;"> </span>; write to DS1685 seconds register</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr WrRTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ldy #$01<span class="Apple-tab-span" style="white-space: pre;"> </span>; get argument 1 (minutes)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr GetParFromSpIdx</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>tax</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$02<span class="Apple-tab-span" style="white-space: pre;"> </span>; write to DS1685 minutes register</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr WrRTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ldy #$02<span class="Apple-tab-span" style="white-space: pre;"> </span>; hours</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr GetParFromSpIdx </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>tax</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$04</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr WrRTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>; enable update transfers</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$0b</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr RdRTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>and #DSC_REGB_UNSET</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>tax</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$0b</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr WrRTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr incsp2</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>rts</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">.endproc</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">.segment "CODE"</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; store value in non-volatile RAM</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; void<span class="Apple-tab-span" style="white-space: pre;"> </span>ds1685_storeram (unsigned char bank,</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;<span class="Apple-tab-span" style="white-space: pre;"> </span> <span class="Apple-tab-span" style="white-space: pre;"> </span> unsigned char addr,</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;<span class="Apple-tab-span" style="white-space: pre;"> </span> <span class="Apple-tab-span" style="white-space: pre;"> </span> unsigned char data);<span class="Apple-tab-span" style="white-space: pre;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">.proc _ds1685_storeram: near</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">.segment "CODE"</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>; get parameters, put them in temp. buffer</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>;jsr pusha</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ldy #$02</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>;ldx #$00</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda (sp),y</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>sta BankNum</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ldy #$01</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>;ldx #$00</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda (sp),y</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>sta RamAddr</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ldy #$00</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>;ldx #$00</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda (sp),y</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>sta RamVal</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; if Bank #1, jump to lwrextram</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> lda BankNum</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> bne lwrextram</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; switch to Bank 0</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> jsr Switch2Bank0</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; A = address</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; X = value</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; write RAM</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> lda RamAddr</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> ldx RamVal</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> jsr WrRTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; exit</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> jsr incsp3</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> rts</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; Write RAM in Bank 1</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">lwrextram:</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> jsr Switch2Bank1</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; load RAM addr. into extended ram address register</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> ldx RamAddr</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> lda #ExtRamAddr</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> jsr WrRTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; load RAM value into extended RAM port</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> ldx RamVal</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> lda #ExtRamPort</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> jsr WrRTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; switch to Bank 0</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> jsr Switch2Bank0</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; exit</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> jsr incsp3</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> rts</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">.endproc</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">.segment "CODE"</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; read value from non-volatile RAM</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; unsigned char __fastcall__<span class="Apple-tab-span" style="white-space: pre;"> </span>ds1685_readram (unsigned char bank,</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;<span class="Apple-tab-span" style="white-space: pre;"> </span> unsigned char addr);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">.proc _ds1685_readram: near</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">.segment "CODE"</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>; get parameters, put them in temp. buffer</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr pusha</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ldy #$01</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>;ldx #$00</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda (sp),y</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>sta BankNum</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ldy #$00</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>;ldx #$00</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda (sp),y</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>sta RamAddr</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; if Bank #1, jump to lwrextram</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> lda BankNum</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> bne lrdextram</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; switch to Bank 0</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> jsr Switch2Bank0</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; A = address</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; read RAM</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> lda RamAddr</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> jsr RdRTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> sta Temp</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; exit</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> lda Temp</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> ldx #00</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> jsr incsp2</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> rts</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; read RAM from Bank 1</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">lrdextram:</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> jsr Switch2Bank1</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; load RAM addr. into extended ram address register</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> ldx RamAddr</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> lda #ExtRamAddr</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> jsr WrRTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; load RAM value into extended RAM port</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> lda #ExtRamPort</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> jsr RdRTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> sta Temp</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; switch to Bank 0</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> jsr Switch2Bank0</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; exit</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> lda Temp</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> ldx #00</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> jsr incsp2</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> rts</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">.endproc</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">.segment "CODE"</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; helper procedures</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;-------------------------------------------------------------------------------</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; Write DS1685 address (Acc).</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;-------------------------------------------------------------------------------</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">WrRTCAddr:</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>sta DSCALADDR</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>rts</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;-------------------------------------------------------------------------------</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; Write DS1685 data (Acc).</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;-------------------------------------------------------------------------------</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">WrRTCData:</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>sta DSCALDATA</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>rts</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;-------------------------------------------------------------------------------</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; Read DS1685 data (-> Acc).</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;-------------------------------------------------------------------------------</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">RdRTCData:</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda DSCALDATA</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>rts</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;-------------------------------------------------------------------------------</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; Write DS1685 Acc = Addr, X = Data</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;-------------------------------------------------------------------------------</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">WrRTC:</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr WrRTCAddr</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>txa</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr WrRTCData</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>rts</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;-------------------------------------------------------------------------------</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; Read DS1685 Acc = Addr -> A = Data</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;-------------------------------------------------------------------------------</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">RdRTC:</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr WrRTCAddr</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr RdRTCData</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>rts</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;-------------------------------------------------------------------------------</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; Transfer A to return buffer at index Y.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;-------------------------------------------------------------------------------</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">Tfer2RetBuf:</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>pha</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>tya</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>pha</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> ldy #$01<span class="Apple-tab-span" style="white-space: pre;"> </span>; transfer to return buffer</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> jsr ldaxysp</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> <span class="Apple-tab-span" style="white-space: pre;"> </span>jsr pushax</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> <span class="Apple-tab-span" style="white-space: pre;"> </span>ldx #$00</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>pla</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>tay</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>pla</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> jsr staspidx</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>rts</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;-------------------------------------------------------------------------------</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; Load to A from arguments buffer/stack at index Y.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;-------------------------------------------------------------------------------</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">GetParFromSpIdx:</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>tya</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>pha</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> ldy #$01<span class="Apple-tab-span" style="white-space: pre;"> </span>; get buffer</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> jsr ldaxysp</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>sta<span class="Apple-tab-span" style="white-space: pre;"> </span>Temp</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>pla</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>tay</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda<span class="Apple-tab-span" style="white-space: pre;"> </span>Temp</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> jsr ldauidx</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>rts</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;-------------------------------------------------------------------------------</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; Swicth to RTC registers in bank 0.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;-------------------------------------------------------------------------------</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">Switch2Bank0:</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> lda #$0a ; get register A</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr RdRTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>and #DSC_REGA_BANK0 ; switch to bank 0</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>tax</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$0a ; write register A</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr WrRTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> rts</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;-------------------------------------------------------------------------------</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">; Swicth to RTC registers in bank 0.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;-------------------------------------------------------------------------------</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">Switch2Bank1:</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$0a<span class="Apple-tab-span" style="white-space: pre;"> </span>; get reg. A</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr RdRTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>ora #DSC_REGA_BANK1<span class="Apple-tab-span" style="white-space: pre;"> </span>; switch to bank 1</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>tax</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lda #$0a ; write reg. A</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>jsr WrRTC</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> rts</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">;------------------------------ END OF FILE -------------------------------------</span><br />
<div>
<br /></div>
<div>
<span style="font-family: Verdana, sans-serif;">Presented below is the computer now in full glory with PropTermMK device, PC keyboard and small VGA display.</span></div>
<div>
<span style="font-family: Verdana, sans-serif;">I also added few screenshots of the PropTermMK features and NV RAM access functions in action.</span></div>
<div>
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3Ixky8ogAYPvmfhxfBlBdDOxXbc29Dp9yDs0Q-RyTFras8vP8dU9YpukkVcih9TnvJkmHwLleXzj2vNroFpCkE8f0ZtVldaJYwdXT1RHAfNhQlK56fzENrs-bKFpE9cd_CkieFnndG5jq/s1600/DSCN7670.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1200" data-original-width="1600" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3Ixky8ogAYPvmfhxfBlBdDOxXbc29Dp9yDs0Q-RyTFras8vP8dU9YpukkVcih9TnvJkmHwLleXzj2vNroFpCkE8f0ZtVldaJYwdXT1RHAfNhQlK56fzENrs-bKFpE9cd_CkieFnndG5jq/s640/DSCN7670.JPG" width="640" /></a></div>
<div>
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg17h-I5SEwhHTWb7_xS3T86nKO4wFaF0icPSCd1TpsOimkAfRQWLMVqEXg2ODV7xEpzBw9rkhZSbBMwbtGhpDom8rNKny0izcCrFQyO3uU-wX4RU2CuXoneQ1RrWFXc2_rXMpyHNTgIh39/s1600/DSCN7635.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1200" data-original-width="1600" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg17h-I5SEwhHTWb7_xS3T86nKO4wFaF0icPSCd1TpsOimkAfRQWLMVqEXg2ODV7xEpzBw9rkhZSbBMwbtGhpDom8rNKny0izcCrFQyO3uU-wX4RU2CuXoneQ1RrWFXc2_rXMpyHNTgIh39/s640/DSCN7635.JPG" width="640" /></a></div>
<div>
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZmOIBEb-ztecu2mw-IynNJclYPXfoEBJJAZwzVCOd1VJtus2x6saQY3RpCKiLw31AOWonmwb94VAxO-GkBZv556C9nBbNIrMi8oNlhW5XLPp0WUcd-UIoTXVNJkRq-ah8Smr78AI7QfK1/s1600/DSCN7648.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1200" data-original-width="1600" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiZmOIBEb-ztecu2mw-IynNJclYPXfoEBJJAZwzVCOd1VJtus2x6saQY3RpCKiLw31AOWonmwb94VAxO-GkBZv556C9nBbNIrMi8oNlhW5XLPp0WUcd-UIoTXVNJkRq-ah8Smr78AI7QfK1/s640/DSCN7648.JPG" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipN2kg4fH8HrJ2-EjtW9FaWY70g6gIaAdNuKFIXGfzE8qrnXHMgaAlARBw11OfzC26JdTEtchYcR-rY9vO8-8I0FlVg8ajS-_fFlNfdD_KGo9YbTTmfs4qxqicazsD6tSb8cav2tN8aRc-/s1600/DSCN7663.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1200" data-original-width="1600" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipN2kg4fH8HrJ2-EjtW9FaWY70g6gIaAdNuKFIXGfzE8qrnXHMgaAlARBw11OfzC26JdTEtchYcR-rY9vO8-8I0FlVg8ajS-_fFlNfdD_KGo9YbTTmfs4qxqicazsD6tSb8cav2tN8aRc-/s640/DSCN7663.JPG" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGX1vI30cAp6N1XA1uKzkIYqhKsEIgvS2RnpslpxDU1E3uMenF2KBAsvyBVsITtpi1bQb-wldio131urAUmRKCMD4vp2CfERQ5ffzESb8eQpMnTy0P1NT2ygaKZzQlqzCX-qoNaoIchBHU/s1600/DSCN7665.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1200" data-original-width="1600" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGX1vI30cAp6N1XA1uKzkIYqhKsEIgvS2RnpslpxDU1E3uMenF2KBAsvyBVsITtpi1bQb-wldio131urAUmRKCMD4vp2CfERQ5ffzESb8eQpMnTy0P1NT2ygaKZzQlqzCX-qoNaoIchBHU/s640/DSCN7665.JPG" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-i4_uEsFX9nFYtA4GSZeCvrQvEKMD4N3uzbLq0lgfwKSE7x9vkQPXvXKTmQYNUkL4cW3_CpvIH_JCc_Nbqy-Em5MzvZDVfRKUOfW2hCjdd9Q-ww3uKvcYr2NclpZN4zNZsccs35dHxcVz/s1600/DSCN7666.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1200" data-original-width="1600" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-i4_uEsFX9nFYtA4GSZeCvrQvEKMD4N3uzbLq0lgfwKSE7x9vkQPXvXKTmQYNUkL4cW3_CpvIH_JCc_Nbqy-Em5MzvZDVfRKUOfW2hCjdd9Q-ww3uKvcYr2NclpZN4zNZsccs35dHxcVz/s640/DSCN7666.JPG" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjg5nEhiW0H_5QFAl5p3zNChGYO39vqEEx45wnN20rlfrQZf5H89pxBAP3c6ojeUbcTWkqWCY4rr05UVJ5Pb7bcCSUwcjoreOxlF_i0Gvt2uaNtl9IbOQ6RgTcUsMY5xaezln1VbyTGmM1r/s1600/DSCN7668.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1200" data-original-width="1600" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjg5nEhiW0H_5QFAl5p3zNChGYO39vqEEx45wnN20rlfrQZf5H89pxBAP3c6ojeUbcTWkqWCY4rr05UVJ5Pb7bcCSUwcjoreOxlF_i0Gvt2uaNtl9IbOQ6RgTcUsMY5xaezln1VbyTGmM1r/s640/DSCN7668.JPG" width="640" /></a></div>
<div>
<br /></div>
<div>
<span style="font-family: Verdana, sans-serif;">This is all I have time for today. I know I promised to finally publish all firmware code and blueprints to GitHub, but I need to clean up the code some more before I do that and some pressing home improvement projects are now pulling me away from this one.</span></div>
<div>
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Verdana, sans-serif;">Thank you for visiting my blog.</span></div>
<div>
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Verdana, sans-serif;">MK 6/19/2017</span></div>
Marek Karczhttp://www.blogger.com/profile/03281397436610614441noreply@blogger.com0tag:blogger.com,1999:blog-4155387638169532413.post-18047047308474672942017-06-13T22:14:00.000-07:002017-06-13T22:14:31.982-07:00MKHBC-8-Rx : Finished building the RTC / Banked RAM card.<span style="background-color: #f3f3f3; font-family: Proxima-Nova, "Proxima Nova", HelveticaNeue-Light, "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px;">Ufff! Took me 2 weeks, but finally finished my combined RTC and banked RAM card. As usual I used prototyping PCB and point to point soldering using enameled magnet wire. I used this part of project as opportunity to enhance my workbench with better soldering tools - quality soldering station, better wire cutters, PCB holder, solder wick, chisel tips, you name it. The job was more enjoyable thanks to that. I had a little scare at the end because the card didn't work right away, but it turned out to be a missed connection. Fixed it and it works now. I am pleased with the result and I'm looking forward to design and implementation of the User Interface I/O card. (keyboard, display, joystick, sound, mass storage etc.)</span><br />
<span style="background-color: #f3f3f3; font-family: Proxima-Nova, "Proxima Nova", HelveticaNeue-Light, "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px;"><br /></span>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiId6cZ3tF-CxWgwJtCYml4jgdlwe_3kEPfXEVFgEjqXwccdJ0rwOA2DVFF8y4n1-fqgPuUkTWMPZI_Zr9nknEnQEcu6Q5nLVMs3fZOazj_AyZ3tWP-kvxRVlKSQP_i-D8lLQeXajfenZnc/s1600/DSCN7611.JPG" imageanchor="1" style="background-color: #f3f3f3; margin-left: auto; margin-right: auto;"><img border="0" data-original-height="1200" data-original-width="1600" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiId6cZ3tF-CxWgwJtCYml4jgdlwe_3kEPfXEVFgEjqXwccdJ0rwOA2DVFF8y4n1-fqgPuUkTWMPZI_Zr9nknEnQEcu6Q5nLVMs3fZOazj_AyZ3tWP-kvxRVlKSQP_i-D8lLQeXajfenZnc/s640/DSCN7611.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="background-color: #f3f3f3;">Ready to populate with IC-s and battery.</span></td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgxJDr6EuJDasAsn4TdOWaXSxfI7fgVRlWPX7uadYKNiKUH1ePrYptPoB48f7Sp3kS0Z3cYQdcko9RDVVu2adzSSz52lIYK6SW2mdTHe1sull1VWnj8IKnmscGbAMBjjlbbcysfZbF0b1y5/s1600/DSCN7614.JPG" imageanchor="1" style="background-color: #f3f3f3; margin-left: auto; margin-right: auto;"><img border="0" data-original-height="1200" data-original-width="1600" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgxJDr6EuJDasAsn4TdOWaXSxfI7fgVRlWPX7uadYKNiKUH1ePrYptPoB48f7Sp3kS0Z3cYQdcko9RDVVu2adzSSz52lIYK6SW2mdTHe1sull1VWnj8IKnmscGbAMBjjlbbcysfZbF0b1y5/s640/DSCN7614.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="background-color: #f3f3f3;">Almost 300 soldering points. Thanks to good tools and supplies this was quite pleasant work.</span></td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5t5SLSfmwHXSnTPi4PbcWo23lVB4OzntWFdwxFaXnuNuAw44oArilX6Jwt5zhZ0y1TSVNAhjGbGffNOw0BkO7uK7b2jFf-Qtqf2ObEgf3UYCsRWhpvNLGC7D90ey3hN6J3EwKvrZ0mZ3s/s1600/DSCN7625.JPG" imageanchor="1" style="background-color: #f3f3f3; margin-left: auto; margin-right: auto;"><img border="0" data-original-height="1200" data-original-width="1600" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5t5SLSfmwHXSnTPi4PbcWo23lVB4OzntWFdwxFaXnuNuAw44oArilX6Jwt5zhZ0y1TSVNAhjGbGffNOw0BkO7uK7b2jFf-Qtqf2ObEgf3UYCsRWhpvNLGC7D90ey3hN6J3EwKvrZ0mZ3s/s640/DSCN7625.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="background-color: #f3f3f3;">Card is now in the motherboard. All seems working fine, there is no smoke.</span></td></tr>
</tbody></table>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinJZifJYsOzbhGpHilzR_0R-b8OljPaVsqYm9W2Fj14jI3OsR_HyiTjW9C8tLpfU_I-Sbc2VoWgfI7gxLuvsiSSW579qYjcxCXc8s0n13g9ZijoleC78aXBTsi1UobKW0dzzKdFi8Rn17Q/s1600/DSCN7626.JPG" imageanchor="1" style="background-color: #f3f3f3; margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1200" data-original-width="1600" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinJZifJYsOzbhGpHilzR_0R-b8OljPaVsqYm9W2Fj14jI3OsR_HyiTjW9C8tLpfU_I-Sbc2VoWgfI7gxLuvsiSSW579qYjcxCXc8s0n13g9ZijoleC78aXBTsi1UobKW0dzzKdFi8Rn17Q/s640/DSCN7626.JPG" width="640" /></a></div>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHqp-Bfawa2g6QvH_s29kJpWBp1Bx7aTQf9tN7cA0RNMMtgJdgaHGoE4tSZdz_toStK_AnZkybvIbIUeKy_VKTOMhxYh2ilkPfDJDBg4OmNSEbnGI7D5pOezvDM5v5aScN1ELbJpkzM9rZ/s1600/DSCN7628.JPG" imageanchor="1" style="background-color: #f3f3f3; margin-left: auto; margin-right: auto;"><img border="0" data-original-height="1200" data-original-width="1600" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHqp-Bfawa2g6QvH_s29kJpWBp1Bx7aTQf9tN7cA0RNMMtgJdgaHGoE4tSZdz_toStK_AnZkybvIbIUeKy_VKTOMhxYh2ilkPfDJDBg4OmNSEbnGI7D5pOezvDM5v5aScN1ELbJpkzM9rZ/s640/DSCN7628.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="background-color: #f3f3f3;">Testing shows time keeping and memory banking functioning properly.</span></td></tr>
</tbody></table>
<span style="background-color: #f3f3f3; font-family: Proxima-Nova, "Proxima Nova", HelveticaNeue-Light, "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px;">I am pleased with the results and looking forward to design and implementation of the User Interface and I/O card - keyboard, display, joystick port, sound, mass storage etc.</span><br />
<span style="background-color: #f3f3f3; font-family: Proxima-Nova, "Proxima Nova", HelveticaNeue-Light, "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px;"><br /></span>
<span style="background-color: #f3f3f3; font-family: Proxima-Nova, "Proxima Nova", HelveticaNeue-Light, "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px;">Thank you for your interest.</span><br />
<span style="background-color: #f3f3f3; font-family: Proxima-Nova, "Proxima Nova", HelveticaNeue-Light, "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px;"><br /></span>
<span style="background-color: #f3f3f3; font-family: Proxima-Nova, "Proxima Nova", HelveticaNeue-Light, "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px;">MK 6/14/2017</span>Marek Karczhttp://www.blogger.com/profile/03281397436610614441noreply@blogger.com0tag:blogger.com,1999:blog-4155387638169532413.post-36506812006026942192017-05-31T18:56:00.003-07:002018-04-02T21:04:44.050-07:00MKHBC-8-Rx, RTC / Banked RAM PCB.<span style="font-family: "verdana" , sans-serif; font-size: x-small;">Finally!</span><br />
<span style="font-family: "verdana" , sans-serif; font-size: x-small;">I started to work on RTC / Banked RAM PCB.</span><br />
<span style="font-family: "verdana" , sans-serif; font-size: x-small;">I use the same technique as before - point to point soldering on a prototype PCB. I have been thinking of perhaps doing the first ever PCB project in software (e.g.: Express PCB) and having my PCB done in China, but I decided this is relatively easy with only 139 connections / 278 or so solder points :-)</span><br />
<span style="font-family: "verdana" , sans-serif; font-size: x-small;">Anyway, now I have a nice gadget that makes this work a bit easier and more pleasant - a PCB holder. Check it out!</span><br />
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgsdkuQgt0zUGTB_T1aKdBbaW70vsvb09IyYRHFfbuo1BO5XFx-2HvwOzbzn5gvwKL5AWP0AijUh_iJsEnbu4vyQj-usBto6zL7nlurRsbeOQv35mHVk-LcOpLh-MZj6zhn4YBp6_3d5tfI/s1600/DSCN7594.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1200" data-original-width="1600" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgsdkuQgt0zUGTB_T1aKdBbaW70vsvb09IyYRHFfbuo1BO5XFx-2HvwOzbzn5gvwKL5AWP0AijUh_iJsEnbu4vyQj-usBto6zL7nlurRsbeOQv35mHVk-LcOpLh-MZj6zhn4YBp6_3d5tfI/s640/DSCN7594.JPG" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinWWFDmS683i_fXjLGyosBmlPaaa2__2BkY9uWJlJITj-J4JOhRb5QzoPwg5o64GvX39XG5Ta6w85MPWx8UKArUd4nrBZl6O6WOtuAkgZunFOkiwvJikzrF5s4xZE1Efr_Mtb0RWiKyoNG/s1600/DSCN7597.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" data-original-height="1200" data-original-width="1600" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinWWFDmS683i_fXjLGyosBmlPaaa2__2BkY9uWJlJITj-J4JOhRb5QzoPwg5o64GvX39XG5Ta6w85MPWx8UKArUd4nrBZl6O6WOtuAkgZunFOkiwvJikzrF5s4xZE1Efr_Mtb0RWiKyoNG/s640/DSCN7597.JPG" width="640" /></a></div>
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: "verdana" , sans-serif; font-size: x-small;">I also made many updates to my Parallax Propeller based character terminal device. I even implemented small subset of ANSI terminal commands (really small subset - just clear screen and locate cursor commands) and mass storage on micro SD card. The mass storage is quite primitive, allowing to load / save plain text files (with monitor commands or BASIC listings), but it works. This method allows </span><span style="background-color: white; font-family: "verdana" , sans-serif; font-size: x-small;">sending contents of the text file from SD card to the serial port or dumping memory of MKHBC-8-R2 system to a file on SD card in the form of monitor memory write commands. Thus I can prepare file with monitor memory write commands on a PC or this system, store on SD card and then send them to the MKHBC-8-R2 system - quite slow method of loading or saving data, but effective, until I have a real mass storage device implemented.</span><br />
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: "verdana" , sans-serif; font-size: x-small;">The project comes together very nicely.</span><br />
<span style="font-family: "verdana" , sans-serif; font-size: x-small;">Here is the SPIN code (only the main part, not the drivers) for character terminal device:</span><br />
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span>
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;">{{</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> Homebrew Serial Keyboard + VGA Terminal (80x40) and SD card.</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> Marek Karcz (C) 2016, 2017. All rights reserved.</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> Free for personal and educational use. </span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> Serial keyboard consists of matrix retro keyboard (TI 99/4A)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> and AT89S52 controller + open collector clock and data output,</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> pretty much like a PS/2 keyboard, but the protocol is different.</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> See documentation in serkb_recv object.</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> This configuration uses P8X32A QuickStart Board + Human Interface Board</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> from Parallax INC.</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> Terminal will also work with PC keyboard and Keyboard object.</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> </span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;">}}</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;">CON</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> _clkmode = xtal1 + pll16x 'Use low crystal gain, wind up 16x</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> _xinfreq = 5_000_000 'External 5 MHz crystal on XI & XO</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ''_CLKFREQ = 80_000_000</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> SDA_pin = 26 'keyboard port on human interface board</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> SCL_pin = 27</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> 'SDA_pin = 24 'keyboard port on human interface board</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> 'SCL_pin = 25 </span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> SerialTx_pin = 5</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> SerialRx_pin = 7</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> SerialBaud = 9600</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> SerialMode = 11</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> MAX_col = scr#cols - 1</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> MAX_row = scr#rows - 1</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> chrs = scr#cols * scr#rows </span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> 'MAX_col = 31</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> 'MAX_row = 14</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> CRSBLDEL = 3000</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> BKSPC = 8</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> BKSPC_PC = $C8</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> CTRL_H_PC = $268</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> NUMLOCK_PC = $DF</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> NL = $0D</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> CR = $0A</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> CTRL_C = 3 ' CTRL-C from TI99/4A keyboard driver</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> CTRL_C_PC = $263 ' CTRL-C from PS/2 keyboard driver</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> CTRL_Z = 26</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> CTRL_Z_PC = $27A</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> SPC = $20</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ESC_PC = $CB</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ESC = $1B</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> F1_PC = $D0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> CTRL_Q_PC = $271</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> CTRL_Q = $11</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ' Micro SD connections</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> </span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> CS = 3 ' Propeller Pin 3 - Set up these pins to match the Parallax Micro SD Card adapter connections.</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> DI = 2 ' Propeller Pin 2 - For additional information, download and refer to the Parallax PDF file for the Micro SD Adapter. </span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> CLK = 1 ' Propeller Pin 1 - The pins shown here are the correct pin numbers for my Micro SD Card adapter from Parallax </span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> D0 = 0 ' Propeller Pin 0 - In addition to these pins, make the power connections as shown in the following comment block. </span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;">OBJ</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> scr : "vga_hires_text_mk"</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> serkb : "serkb_recv" ' serkb_recv object is interchangeable</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> 'serkb : "keyboard" ' with keyboard object - no more code</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ' changes are required, just swap them here</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> rs232 : "FullDuplexSerial_mk"</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> 'serial : "Parallax Serial Terminal"</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> 'Num : "numbers"</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> sdfat : "fsrw" ' r/w file system</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> streng : "ASCII0_STREngine_1" ' string library</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;">DAT</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> str01 BYTE "Serial Keyboard + VGA Terminal (80x40).",NL,0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> strFmVer BYTE "Firmware version 2.0.",NL,0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> strCpr01 BYTE "Copyright (C) by Marek Karcz 2016,2017.",NL,0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> strCpr02 BYTE "All rights reserved.",NL,0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> str01_1 BYTE NL,"Press (at any time):",NL,NL,0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> str02 BYTE " CTRL-C to Clear Screen,",NL,0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> str03 BYTE " CTRL-H to Backspace/Delete,",NL,0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> str04 BYTE " CTRL-Z to open Terminal Menu,",NL,0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> str05 BYTE " CTRL-Q (F1) to see this help.",NL,0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> strSdFnd BYTE NL,"SD card found. Open Terminal Menu to mount.",NL,0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> strNoSd BYTE NL,"ERROR: There is no SD card.",NL,0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> strSpaces BYTE " ",0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> rdcmd BYTE "r ",0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;">VAR </span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> long col, row</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> long rcv, key, prevkey</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> 'long crsct</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> 'sync long - written to -1 by VGA driver after each screen refresh</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> long sync</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> 'screen buffer - could be bytes, but longs allow more efficient scrolling</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> long screen[chrs/4]</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> 'row colors</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> word colors[MAX_row+1]</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> 'cursor control bytes</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> byte cx0, cy0, cm0, cx1, cy1, cm1</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> byte fname[13]</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> byte staddr[5], endaddr[5]</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> byte memrdcmd[16], buf[80]</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> long sdcard_found</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> </span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;">PUB Main | i</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> sdcard_found := -1</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> prevkey := 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> 'crsct := CRSBLDEL</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> col := 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> row := 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> 'Num.init</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> 'serial.Start(115200)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> rs232.Start(SerialRx_pin, SerialTx_pin, SerialMode, SerialBaud)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> serkb.Start(SDA_pin, SCL_pin) ' Start the serial keyboard object</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> scr.start(16, @screen, @colors, @cx0, @sync)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> 'set up colors, clear screen</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> repeat i from 0 to MAX_row</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> colors[i] := %%0100_1310</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> repeat i from 0 to chrs - 1</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> screen.byte[i] := $20 </span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrStr(@str01)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrStr(@strFmVer)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrStr(@strCpr01)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrStr(@strCpr02)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> HelpInfo</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> waitcnt(cnt + clkfreq)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> MountSD(FALSE)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> 'sdcard_found := \sdfat.mount_explicit(D0, CLK, DI, CS) ' Here we call the 'mount' method using the 4 pins described in the 'CON' section.</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if sdcard_found => 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrStr(@strSdFnd)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> UnmountSD(FALSE) </span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> rs232.RxFlush</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> repeat</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> key := serkb.Key</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ' conversions related to used driver (ti99/4a a.k.a. serkb_recv or ps/2 a.k.a. keyboard)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if key > 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if key == CR</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> key := NL</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if key == CTRL_C_PC</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> key := CTRL_C</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if key == CTRL_Z_PC</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> key := CTRL_Z</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if key == BKSPC_PC or key == CTRL_H_PC</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> key := BKSPC</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if key == NUMLOCK_PC</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> key := 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if key == ESC_PC</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> key := ESC</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if key == CTRL_Q_PC or key == F1_PC</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> key := CTRL_Q</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if key > 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> rs232.Tx(key & $ff)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> 'rcv := rs232.RxCheck</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> rcv := rs232.RxTime(20)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if rcv => 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> 'serial.Str(STRING("Received character from RS232:"))</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> 'serial.Dec(rcv)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> 'serial.NewLine</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> PrnChar(rcv & $ff)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> prevkey := rcv & $ff</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> Cursor</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;">PUB UnmountSD(verbose)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if verbose == TRUE </span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> PrnChar(NL)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if sdcard_found => 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> sdfat.unmount</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> sdcard_found := -1</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if verbose == TRUE</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrStr(String("SD card has been unmounted successfully.",NL))</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> else</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if verbose == TRUE</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrStr(String("ERROR: Nothing to unmount. (already unmounted?)",NL))</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;">PUB MountSD(verbose)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if verbose == TRUE</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> PrnChar(NL)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if sdcard_found < 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> sdcard_found := \sdfat.mount_explicit(D0, CLK, DI, CS) ' Here we call the 'mount' method using the 4 pins described in the 'CON' section.</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if verbose == TRUE</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if sdcard_found => 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrStr(String("SD card has been mounted successfully.",NL))</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> else</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrStr(String("ERROR: Unable to mount SD card, error code="))</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrStr(streng.integerToHexadecimal(sdcard_found, 8))</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> PrnChar(NL)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> else</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if verbose == TRUE</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrStr(String("ERROR: Nothing to mount. (already mounted?)",NL)) </span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;">PUB HelpInfo</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> StrOut(@str01_1)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> StrOut(@str02)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> StrOut(@str03)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> StrOut(@str04)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> StrOut(@str05)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> Cursor </span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;">PUB ScrStr(strptr)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> repeat StrSize(strptr)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> PrnChar(byte[strptr++])</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;">PUB ScrOut(c)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> screen.byte[row*(MAX_col+1) + col] := c</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;">PUB StrOut(strptr)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> repeat StrSize(strptr)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if byte[strptr] == NL</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> col := 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> IncRow</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> strptr++</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> else</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrOut(byte[strptr++])</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> IncCol</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;">PUB Cursor</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> cx0 := col</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> cy0 := row</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> cm0 := %010</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ' uncomment code below to enable own cursor implementation</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ' and comment code above</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> {{</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> crsct--</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if crsct > CRSBLDEL / 2</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrOut("|")</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> else</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrOut("_")</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if crsct == 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> crsct := CRSBLDEL</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> }}</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;">PUB IncRow</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> row := row + 1</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if row > MAX_row</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> row := MAX_row</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ByteMove(@screen, @screen+MAX_col+1, chrs-MAX_col-1)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ByteFill(@screen+chrs-MAX_col-1, 32, MAX_col+1)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;">PUB IncCol</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> col := col + 1</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if col > MAX_col</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> col := 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> IncRow</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;">PUB DecCol</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if col > 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> col := col - 1</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;">PUB ReadSerialAndPrint(rdw)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> repeat</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> 'rcv := rs232.RxCheck</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> rcv := rs232.RxTime(rdw)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if rcv < 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> Quit</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> PrnChar(rcv & $ff)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;">PUB SDDir | n</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if sdcard_found < 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrStr(@strNoSd)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> return</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> PrnChar(NL)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> PrnChar(NL)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrStr(String("Directory:",NL))</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> PrnChar(NL)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> sdfat.opendir</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> repeat</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> n := sdfat.nextfile(@fname)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if n < 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> Quit</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrStr(@fname)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> PrnChar(NL)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;">PUB GetStr(pstr, size) | n, q</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> n := 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> q := FALSE</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> repeat until q == TRUE</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> key := serkb.Key</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if key > 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if key == CR</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> key := NL</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if key == CTRL_C_PC</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> key := CTRL_C</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if key == CTRL_Z_PC</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> key := CTRL_Z</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if key == BKSPC_PC</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> key := BKSPC</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if key == NUMLOCK_PC</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> key := 0 </span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> case key</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> NL: byte[pstr+n] := 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> q := TRUE</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> BKSPC: if n > 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> n := n - 1</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> byte[pstr+n] := 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> OTHER: if key > 0 and n < size-1</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> byte[pstr+n] := key</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> n := n + 1</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> byte[pstr+n] := 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> col := 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrStr(@strSpaces)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrOut(SPC)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> col := 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrStr(pstr)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> Cursor </span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;">PUB EnterFileName '| n, q</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> PrnChar(NL)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrStr(String("Enter file name:",NL))</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> PrnChar(NL)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> Cursor</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> GetStr(@fname, 13)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;">PUB SendFileFromSD2Serial | n, q</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if sdcard_found < 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrStr(@strNoSd)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> return</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> SDDir</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> EnterFileName</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> PrnChar(NL)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ReadSerialAndPrint(0)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrStr(String("*** Loading file ***", NL))</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> waitcnt(cnt + clkfreq)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> sdfat.popen(@fname, "r")</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> key := NL</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> rs232.Tx(key & $ff)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ReadSerialAndPrint(0)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> repeat</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> key := sdfat.pgetc</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if key < 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> Quit</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if key == NL</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> key := 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if key == CR</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> key := NL</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if key > 0 </span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> rs232.Tx(key & $ff)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> waitcnt(cnt + clkfreq/250)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if key == NL</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> waitcnt(cnt + clkfreq/6)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ReadSerialAndPrint(0)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ReadSerialAndPrint(0)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> PrnChar(NL)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> sdfat.pclose</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;">PUB SaveMemory2FileSD | m, adrbeg, adrend, curaddr</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if sdcard_found < 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrStr(@strNoSd)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> return</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> EnterFileName</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> PrnChar(NL)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrStr(String("Enter start address (hex DDDD, e.g: 0400):",NL))</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> PrnChar(NL)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> Cursor</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> GetStr(@staddr, 5)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> adrbeg := streng.hexadecimalToInteger(@staddr)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> PrnChar(NL)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrStr(String("Enter end address (hex DDDD, e.g: 1000):",NL))</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> PrnChar(NL)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> Cursor</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> GetStr(@endaddr, 5)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> adrend := streng.hexadecimalToInteger(@endaddr)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> PrnChar(NL)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> Cursor</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if adrend - adrbeg < 15</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrStr(String("Address range must be greater than 14 bytes.",NL))</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> return</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> curaddr := adrbeg</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> sdfat.popen(@fname, "w")</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> repeat</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> memrdcmd[0] := 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> streng.stringCopy(@memrdcmd, @rdcmd)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> streng.stringConcatenate(@memrdcmd, @staddr)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> streng.stringConcatenate(@memrdcmd, String("-"))</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> curaddr := curaddr + 16</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> streng.stringConcatenate(@memrdcmd, streng.integerToHexadecimal(curaddr-1, 4))</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> streng.stringConcatenate(@memrdcmd, String(" ",NL))</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ' Send the memory read command</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> streng.stringToLowerCase(@memrdcmd)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrStr(String("Command: "))</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrStr(@memrdcmd) </span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> rs232.str(@memrdcmd)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ' Read response from memory read command and save it to file</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ' line by line</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> m := 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> repeat</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> rcv := rs232.RxTime(20)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if rcv < 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> Quit</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if rcv <> NL</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> buf[m++] := rcv</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if m > 79</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> m := 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> buf[m] := 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> else</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> buf[m++] := NL</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if m > 79</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> m := 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> buf[m++] := CR</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if m > 79</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> m := 0 </span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> buf[m] := 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if buf[0] == "w"</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> sdfat.pputs(@buf)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrStr(String("buf="))</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrStr(@buf)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> m := 0 </span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ' End of address range</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if curaddr > adrend</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> Quit</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> streng.stringCopy(@staddr, streng.integerToHexadecimal(curaddr, 4))</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> sdfat.pclose</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> PrnChar(NL)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrStr(String("File saved.",NL))</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;">PUB ListFileSD</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if sdcard_found < 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrStr(@strNoSd)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> return</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> EnterFileName</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> PrnChar(NL)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> sdfat.popen(@fname, "r")</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> repeat</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> rcv := sdfat.pgetc</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if rcv < 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> Quit</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> PrnChar(rcv & $ff)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> sdfat.pclose </span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> </span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;">PUB TermMenu | q</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> q := FALSE</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> MountSD(TRUE) ' SD card us mounted only while in Terminal Menu</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> repeat until q == TRUE</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrStr(String("Terminal Menu:",NL))</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> PrnChar(NL) </span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrStr(String(" 1 - Send file from SD card to serial port.",NL))</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrStr(String(" 2 - Save memory write commands to file on SD card.",NL))</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrStr(String(" 3 - SD card directory.",NL))</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrStr(String(" 4 - List file contents.",NL))</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrStr(String(" 5 - Unmount SD card.",NL))</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrStr(String(" 6 - Mount SD card.",NL))</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrStr(String(" Q - Exit Menu",NL))</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> PrnChar(NL)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrStr(String("Your selection ? "))</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> repeat</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> key := serkb.Key</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if key > 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> case key</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> "1" : SendFileFromSD2Serial</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> q := TRUE</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> "2" : SaveMemory2FileSD</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> q := TRUE</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> "3" : SDDir</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> "4" : ListFileSD</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> "5" : UnmountSD(TRUE)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> "6" : MountSD(TRUE)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> "q" : ScrStr(String("Quit.",NL))</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> q := TRUE</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> OTHER: ScrStr(String("Unknown menu option.",NL))</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> PrnChar(NL)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> Quit</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> Cursor</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrOut(SPC)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> UnmountSD(TRUE) ' SD card is only mounted while in Terminal Menu</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;">PUB ClrScr</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ByteFill(@screen, SPC, chrs) </span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> col := 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> row := 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;">PUB IsDigit(c)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if c => "0" and c =< "9"</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> return TRUE</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> return FALSE</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;">' Read digits from rs232, convert to number and return value.</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;">' The last read non-digit character code is remembered in key variable.</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;">' </span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;">PUB RdNumSer(chars) : numval | c, ba</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> numval := -1</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ba := chars</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> byte[chars] := 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> c := rs232.RxTime(20)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if IsDigit(c) == TRUE</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> repeat while IsDigit(c) == TRUE</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> byte[chars++] := c</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> byte[chars] := 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> c := rs232.RxTime(20)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> key := c</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> numval := streng.decimalToInteger(ba) </span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"><br /></span>
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;">PUB PrnChar(c) | n, lcol, lrow</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if c == "[" and prevkey == ESC</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> lrow := RdNumSer(@buf)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if lrow => 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> case key</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> </span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> "J" : case lrow</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> 0 : ' write code here to clear from cursor to end of screen</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> return</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> 1 : ' write code here to clear from cursor to begin of screen</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> return</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> 2 :</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> 'StrOut(String("[CLS]"))</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ClrScr</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> return</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> </span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> OTHER : return</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> </span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ";" : 'StrOut(String("[;]"))</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> lcol := RdNumSer(@buf)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if lcol => 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if key == "H" or key == "f"</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> col := lcol - 1</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> row := lrow - 1</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if col < 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> col := 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if row < 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> row := 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> return</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> </span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> OTHER : return</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if c == NL</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> 'ScrOut(SPC) 'uncomment only if own cursor impl. is used</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> col := 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> IncRow</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if c == CTRL_C 'CTRL-C, Clear Screen</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> rs232.Tx(BKSPC) 'Send backspace to delete control character</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ClrScr</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> rs232.Tx(NL) 'Send NL to serial</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if c == CTRL_Q</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> HelpInfo</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> rs232.Tx(NL) 'Send NL to serial </span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if c == BKSPC</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrOut(SPC)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> DecCol</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if c == CTRL_Z 'CTRL-Z, Menu</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> rs232.Tx(BKSPC) 'Send backspace to delete control character</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrOut(SPC)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> col := 0</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> IncRow</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> IncRow</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> TermMenu</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> IncRow</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> rs232.Tx(NL) 'Send NL to serial </span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if c > 31 and c < 127</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> ScrOut(c)</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> IncCol</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> {{</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> if c == ESC</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> StrOut(String("[ESC]"))</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> }}</span><br />
<span style="background-color: #eeeeee; font-family: "courier new" , "courier" , monospace; font-size: xx-small;"> Cursor</span><br />
<br />
<span style="font-family: "courier new" , "courier" , monospace; font-size: x-small;"> </span><br />
<span style="background-color: white; font-family: "verdana" , sans-serif; font-size: x-small;">I didn't yet publish my code on GitHub, but will do soon, please stay tuned.</span><br />
<span style="background-color: white; font-family: "verdana" , sans-serif; font-size: x-small;">I develop / test the software on Parallax Propeller QuickStart board with Parallax Human Interface + serial port shield. However the final device will be assembled on a Parallax Propeller USB Project Board. The final version of the I/O device I actually want to implement as a card interfacing with the system via I/O expansion bus rather than serial port. This is not the last word in this regard, but I needed to start with something simpler to implement to get familiar with the Propeller chip.</span><br />
<span style="background-color: white; font-family: "verdana" , sans-serif; font-size: x-small;"><br /></span>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdvP4qU-iOVgANnWQcoks5TCOcLw8bt-yL6AQvms4TedCtAz5Pw4p8JLbxiULGMaM5ma0jkusL0vLxCIRHNArbZnr6ecP4wgxHaBeWw5QZ_NgmRm7YYahceyvNLKmFzRy6dGnTyg-eI8Xi/s1600/DSCN7544.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" data-original-height="1200" data-original-width="1600" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjdvP4qU-iOVgANnWQcoks5TCOcLw8bt-yL6AQvms4TedCtAz5Pw4p8JLbxiULGMaM5ma0jkusL0vLxCIRHNArbZnr6ecP4wgxHaBeWw5QZ_NgmRm7YYahceyvNLKmFzRy6dGnTyg-eI8Xi/s640/DSCN7544.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Startup message of character device, high resolution VGA.</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjrFM0318P6tRh0nkGVFJUFK3O5EyRzSKgQsNiEXm3wTrp8rDXdBKXkoTaX9JLBN3VKwBpQe-Un-Cl0RVxEoTcbDAMGaK0yxHBD_A7ROTd8mIfqHFqF-P5mhbUZadhToi7VYXd7kxORcYUK/s1600/DSCN7562.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" data-original-height="1200" data-original-width="1600" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjrFM0318P6tRh0nkGVFJUFK3O5EyRzSKgQsNiEXm3wTrp8rDXdBKXkoTaX9JLBN3VKwBpQe-Un-Cl0RVxEoTcbDAMGaK0yxHBD_A7ROTd8mIfqHFqF-P5mhbUZadhToi7VYXd7kxORcYUK/s640/DSCN7562.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Development / test system.</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQ2UAyw4XclhW0ulF-6AUTl69uvExth3tWwyJ45av4bfJozs73swBKhTmGLk6VGu3vzrqTqPOEwZhCrHbOiD1kvn_Hjqj-i27Leby1YEu4bDmSP0k3ByGRPKUDuXaj05HsCFuVaYXtIc7w/s1600/DSCN7580.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" data-original-height="1200" data-original-width="1600" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhQ2UAyw4XclhW0ulF-6AUTl69uvExth3tWwyJ45av4bfJozs73swBKhTmGLk6VGu3vzrqTqPOEwZhCrHbOiD1kvn_Hjqj-i27Leby1YEu4bDmSP0k3ByGRPKUDuXaj05HsCFuVaYXtIc7w/s640/DSCN7580.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Serial port shield for Parallax Human Interface board.</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjC_OhvSRcr7Wq_m2DcMdkJDlTKno_7-sFICaHKvbUJwcxgkpDyWFzx_Pl8SooyxMblQsBWUSiAAdDTOHfayaQqViKHBiTGU3_TLFeTQY2njLNRFj77cONA1yFXh-rtqLAmB1WVa5mA3TK9/s1600/DSCN7581.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" data-original-height="1200" data-original-width="1600" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjC_OhvSRcr7Wq_m2DcMdkJDlTKno_7-sFICaHKvbUJwcxgkpDyWFzx_Pl8SooyxMblQsBWUSiAAdDTOHfayaQqViKHBiTGU3_TLFeTQY2njLNRFj77cONA1yFXh-rtqLAmB1WVa5mA3TK9/s640/DSCN7581.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Loading Tiny BASIC from SD card. The file 'tinybas' is just a plain text file with monitor memory write commands generated by my utility on a PC from the TB binary image.</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-XEeq2HbhQl6GmIL0qS7LRlQrVz8H-xljQO-o9AmaAoXvZkkwCamd1LsUVr3T7aJL9s77brW5bA2t2YF9dOJrvy7XAuRpZpp8hlHSOklJrwpY_bMj-YX4L5FXyrznQQczrFlmb5Fp51Th/s1600/DSCN7586.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" data-original-height="1200" data-original-width="1600" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-XEeq2HbhQl6GmIL0qS7LRlQrVz8H-xljQO-o9AmaAoXvZkkwCamd1LsUVr3T7aJL9s77brW5bA2t2YF9dOJrvy7XAuRpZpp8hlHSOklJrwpY_bMj-YX4L5FXyrznQQczrFlmb5Fp51Th/s640/DSCN7586.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Tiny BASIC loaded.</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQWqK1JP-f0LIcB73py4FdbZYytJZLSIQGw9Othw_lc33QENOC_2GpM0VtrTE5Ue3gWMQh7uKnRfYa6FxrEkPPKkxsPFI8UvAEvSJNOS0kuzEAClv2ZZQpaOHqgLTGc_YcsbTYyrlTnecd/s1600/DSCN7590.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" data-original-height="1200" data-original-width="1600" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgQWqK1JP-f0LIcB73py4FdbZYytJZLSIQGw9Othw_lc33QENOC_2GpM0VtrTE5Ue3gWMQh7uKnRfYa6FxrEkPPKkxsPFI8UvAEvSJNOS0kuzEAClv2ZZQpaOHqgLTGc_YcsbTYyrlTnecd/s640/DSCN7590.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Loaded BASIC listing of a game from another file on SD card.</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjtntgy3Xw4UXik0LVqhaTRbhaPJZtRnKYBMFtx4eBMhSsoOv6PRJdxW5_QMcSpyrZNPBXBZGSJD4fSSDsb15M3yYhM9Jk53hSMXf5ptUgqvF4IOXw0823KD49R1fP0tW-o7Sve9ygkPap5/s1600/DSCN7591.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" data-original-height="1200" data-original-width="1600" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjtntgy3Xw4UXik0LVqhaTRbhaPJZtRnKYBMFtx4eBMhSsoOv6PRJdxW5_QMcSpyrZNPBXBZGSJD4fSSDsb15M3yYhM9Jk53hSMXf5ptUgqvF4IOXw0823KD49R1fP0tW-o7Sve9ygkPap5/s640/DSCN7591.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">I have a kingdom to run. See ya later! ;-)</td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVvgPt6JnzWinomWMzHPlvzeva9Utptj-hZ2-HSR4xfzmA6qHAaxKMITaysKZY6kNPdU3bFt6GlER4sgjzR7mrcZsqjhpOvfbOupM6NwUMkKdebPxIyiwWxAiVbZQBqlJ6q_8mNm-BNawX/s1600/DSCN7560.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" data-original-height="1200" data-original-width="1600" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjVvgPt6JnzWinomWMzHPlvzeva9Utptj-hZ2-HSR4xfzmA6qHAaxKMITaysKZY6kNPdU3bFt6GlER4sgjzR7mrcZsqjhpOvfbOupM6NwUMkKdebPxIyiwWxAiVbZQBqlJ6q_8mNm-BNawX/s640/DSCN7560.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Parallax Propeller Project USB board with some of my additions like serial port, keyboard connector port, uSD card socket (on the bottom, but connections header is on top) where terminal will be implemented.</td></tr>
</tbody></table>
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><span style="background-color: white;">This is it for today.</span></span><br />
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><span style="background-color: white;">Thank you for visiting my blog and see you in the next episode (sooner rather than later, hopefully).</span></span><br />
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: "verdana" , sans-serif; font-size: x-small;"><span style="background-color: white;">MK 2017-06-01</span></span>Marek Karczhttp://www.blogger.com/profile/03281397436610614441noreply@blogger.com0tag:blogger.com,1999:blog-4155387638169532413.post-42360303692461280822016-11-20T23:13:00.001-08:002016-11-20T23:13:37.534-08:00Video, keyboard, sound for MKHBC-8-Rx.<span style="font-family: Verdana, sans-serif; font-size: x-small;">Update on MKHBC-8-Rx project.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">While I still need to put RTC + Banked RAM circuit to the more permanent prototyping board (currently on a breadboard), I am already thinking about next step - a user I/O for my system, so it becomes a fully self contained system without the need of a PC host.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;">I recently re-discovered Parallax Propeller chip and it seems to be a very good candidate for this application.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;">With 8 independent cores (called cogs in Parallax documentation), fast 32-bit architecture and built in video generating capabilities, it should make the task not too difficult.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;">I already had a QuickStart board from Parallax, which is a starter/demo board for showing of Parallax Propeller (P8X32A) chip capabilities.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;">The board is equipped with a header providing access to all GPIO pins. I purchased a Human Interface Board/shield for QuickStart that has VGA port, PS/2 keyboard/mouse ports and other features and started experimenting.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;">First I interfaced my retro keyboard controller to it. You may read about my TI99/4A keyboard controller in my earlier blog updates (titled: "I2C keyboard controller"), although I simplified the firmware as I didn't need I2C support in this particular application. Now it is a much simpler serial keyboard similar to PS/2 but it is not a PS/2 compatible protocol, just voltage levels and pins are PS/2-like. The driver for Propeller chip was easy to implement and this experiment was a success. I could use PS/2 interface on Human Interface board to hook my keyboard up to the Propeller.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;">Next I went a step further and created a character terminal application out of this setup.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;">I since switched to Propeller Project Board USB with my terminal application, after adding VGA, keyboard and serial port sockets to it. The software remains the same.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;">When I add mass storage capability (micro-SD card) to the application, I shall have a fully standalone computer system that will not need a host PC to upload software. The software will be transferred via files on micro-SD card.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">On the pictures below my first experiments with composite video and making my keyboard controller talk to Parallax board:</span><br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5c9RWhBibBvQn6z6lDEam9ZLFgvi4MQmUvsKaOgJl4jpCwVTwQGA-IvOIKB71-5NgFLFY2V2FeCozc71TX532e6FkZKlwfFrpiRFVQ3um7UNBZ2soe0LKKOiYJwmg1QOpyXIa5zBnkyl5/s1600/DSCN7315.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5c9RWhBibBvQn6z6lDEam9ZLFgvi4MQmUvsKaOgJl4jpCwVTwQGA-IvOIKB71-5NgFLFY2V2FeCozc71TX532e6FkZKlwfFrpiRFVQ3um7UNBZ2soe0LKKOiYJwmg1QOpyXIa5zBnkyl5/s640/DSCN7315.JPG" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhlLcI4I1n1pS9jgOaQrf_8QMU1fg7_f7t0jJ6zGfvgInXT_nfIfqPlk1x77EIDgWMi-IHr_I3sOuQr9Pqq8tFG7K2aa57FZpoP1G0MDkhSgSMbHn_-_pAi8Fol8UbUr7B02Gun7I5jxcMk/s1600/DSCN7316.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhlLcI4I1n1pS9jgOaQrf_8QMU1fg7_f7t0jJ6zGfvgInXT_nfIfqPlk1x77EIDgWMi-IHr_I3sOuQr9Pqq8tFG7K2aa57FZpoP1G0MDkhSgSMbHn_-_pAi8Fol8UbUr7B02Gun7I5jxcMk/s640/DSCN7316.JPG" width="640" /></a></div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">This screenshot shows working character terminal with video generated by Parallax Propeller on VGA display. On the bottom an experimental code of terminal menu, which I will use to invoke various special functions, like terminal setup or access to mass storage:</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4dmmdkGWjE2-sKiej00UnAeGNic1iOTZslSIlt_C8tP2XuDPIEploISGHiod3ILX-f3gmeyQszrGDD0HfJaW95KCWfmnOE1H0ius3DaFTNQ1WQTVBiPVGKECCi7TXZf2NCX2fIAXgz5xb/s1600/DSCN7412.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4dmmdkGWjE2-sKiej00UnAeGNic1iOTZslSIlt_C8tP2XuDPIEploISGHiod3ILX-f3gmeyQszrGDD0HfJaW95KCWfmnOE1H0ius3DaFTNQ1WQTVBiPVGKECCi7TXZf2NCX2fIAXgz5xb/s640/DSCN7412.JPG" width="640" /></a></div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">The character terminal application on Parallax Project board:</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikuwHEjhV7Adz7oAvSOIlNrRUHs2M-x2kVRdpeUNHFu-0kniL7MZ1YG8EaPiiWcM1DGVkkUQbTbkwH9WiL9rrj-mgpFYLKHXanjRPRZli2MuReEBb74F2J95DNLboTF2mUuan5EWKJz0OW/s1600/DSCN7429.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEikuwHEjhV7Adz7oAvSOIlNrRUHs2M-x2kVRdpeUNHFu-0kniL7MZ1YG8EaPiiWcM1DGVkkUQbTbkwH9WiL9rrj-mgpFYLKHXanjRPRZli2MuReEBb74F2J95DNLboTF2mUuan5EWKJz0OW/s640/DSCN7429.JPG" width="640" /></a></div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">I will publish the software for Parallax Propeller once it is finished.</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">11/21/2016</span><br />
<span style="font-family: Verdana, sans-serif; font-size: x-small;">M.K.</span>Marek Karczhttp://www.blogger.com/profile/03281397436610614441noreply@blogger.com0tag:blogger.com,1999:blog-4155387638169532413.post-1896575585592524392016-08-23T23:07:00.000-07:002016-08-23T23:07:32.050-07:00The iRobot Create and STM32 Nucleo F411RE board.<br />
<span style="font-family: Verdana, sans-serif;">It's been a while since I did any project related to robotics. I have never done anything advanced, but some time ago (about 10 years) me and few friends from work got interested in the topic of making our own autonomous robot and programming it for fun and ultimately entering some competition with it.</span><br />
<span style="font-family: Verdana, sans-serif;">We have never got that far, but what we ended up with was buying <a href="https://en.wikipedia.org/wiki/IRobot_Create" target="_blank">iRobot Create</a> and <a href="http://blog.trossenrobotics.com/2006/12/08/qwerk-robotic-computer-from-charmed-labs/" target="_blank">Qwerk</a> 1.2b robotic controller module from <a href="http://charmedlabs.com/default/" target="_blank">Charmed Labs</a> for a considerable cost (at that time all that single board cheap computers, boards and shields were not as readily and cheaply available as they are today).</span><br />
<span style="font-family: Verdana, sans-serif;">I don't think that Charmed Labs carry this module anymore. It was a single board computer powered by </span><span style="background-color: white; color: #333333; text-align: justify;"><span style="font-family: Verdana, sans-serif;">200 MHz ARM9 RISC processor</span></span><span style="font-family: Verdana, sans-serif;"> and Linux O.S. with multitude of I/O pins already built in and useful for robotic applications (digital I/O, analog I/O, servos, motors). It's been advertised as a Telepresence Robot Kit (TeRK). On top of Linux ran a server that used CORBA like protocol (ICE) to which client application written in Java, C# or C++ could connect remotely to control the hardware connected to the controller.</span><br />
<br />
<span style="font-family: Verdana, sans-serif;">Here is the actual module that I still have:</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6mBsBYA0aNhnAFfhSn0n0dQXoSmrgSgElUz98FN_020JkFe_iQaARsYVxgwnQJBRBeOF9LDAWh6BPVAJ3-Jk02HBNgGhyphenhyphene0txcgyls-3UQlQrv7XNJTLornzJ_Hvm99mMjz0mYvRn8J6C/s1600/DSCN7278.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg6mBsBYA0aNhnAFfhSn0n0dQXoSmrgSgElUz98FN_020JkFe_iQaARsYVxgwnQJBRBeOF9LDAWh6BPVAJ3-Jk02HBNgGhyphenhyphene0txcgyls-3UQlQrv7XNJTLornzJ_Hvm99mMjz0mYvRn8J6C/s640/DSCN7278.JPG" width="640" /></a></div>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">and below are some of our (mostly mine as my friends lost interest quite quickly) clumsy attempts at making a robot based on iRobot Create platform and the Qwerk controller:</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3NA6S-Jl65RMOKfA4UVxuwp-j_ClQmcX6tF3Uwcra_ViyimQpFUUrnFTnDCRZ6vnTT2eknn0QPZdsbFLQ_cXqlpiPo7ZLDMdelMWU50Gb0Uekwu61SIEtAZhPGUTPO13ylzFDxvvCdcV9/s1600/QwerkPhaseII20071218__006.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3NA6S-Jl65RMOKfA4UVxuwp-j_ClQmcX6tF3Uwcra_ViyimQpFUUrnFTnDCRZ6vnTT2eknn0QPZdsbFLQ_cXqlpiPo7ZLDMdelMWU50Gb0Uekwu61SIEtAZhPGUTPO13ylzFDxvvCdcV9/s640/QwerkPhaseII20071218__006.JPG" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSdRgiWRHo3kGfdHsVEZu-8DeW63uXlZpTlVIexNbM7JnS5gcQFx3UeMJViKzjO6wkVR4lJ1Xvb_oOKr45YsGAOwX3dlmgj6jPGGnU0lTRJJ_xC6QOhP_fSTPV6u0vTDL1Rj0hzxlxouCQ/s1600/QwerkPhaseII20071218__007.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSdRgiWRHo3kGfdHsVEZu-8DeW63uXlZpTlVIexNbM7JnS5gcQFx3UeMJViKzjO6wkVR4lJ1Xvb_oOKr45YsGAOwX3dlmgj6jPGGnU0lTRJJ_xC6QOhP_fSTPV6u0vTDL1Rj0hzxlxouCQ/s640/QwerkPhaseII20071218__007.JPG" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTRU81tzBBtCOOiKQ2DWodd4IpJ2OFyTxX2gIMhFeqZ_ynv4ZDoujxCQ6WCqMFamMjiPHfc1jknHYVoNbaMLQ58X8_PyznG3W4ggYXC8DbL58_zkBcKWtyYkIeC05HTv5BW7WdQeDQSNKH/s1600/QwerkPhaseII20071218__003.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhTRU81tzBBtCOOiKQ2DWodd4IpJ2OFyTxX2gIMhFeqZ_ynv4ZDoujxCQ6WCqMFamMjiPHfc1jknHYVoNbaMLQ58X8_PyznG3W4ggYXC8DbL58_zkBcKWtyYkIeC05HTv5BW7WdQeDQSNKH/s640/QwerkPhaseII20071218__003.JPG" width="480" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgWH8S_7W_IzjMsWMk6qT-wLowdlFjeT9Q6bPsDBXY_8jOxkxBcyJVOFxI_E-NJpnbJCFxilvvSFvYknhiEICH8ltFdhgPcN6-1ZWszQW6Yh4UBIQ9GEa0uC5eC4PBT1fEq4UB_QG0jb1bM/s1600/QwerkCreateDLink_20091203_0004.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgWH8S_7W_IzjMsWMk6qT-wLowdlFjeT9Q6bPsDBXY_8jOxkxBcyJVOFxI_E-NJpnbJCFxilvvSFvYknhiEICH8ltFdhgPcN6-1ZWszQW6Yh4UBIQ9GEa0uC5eC4PBT1fEq4UB_QG0jb1bM/s640/QwerkCreateDLink_20091203_0004.JPG" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXwyWojYCoEi5qHCM-R2_A-Uv0PfrRp8k0P5L6LR_d0PVVaQxrOkmHug7EVmAQWxfJaVTW_KKGnEDR675nLi1MdykuHUM4nSItnJgrJ4v2LNCGoeUPD_u-_z_kWFpHmXhahKDESEot2LcO/s1600/QwerkCreateDLink_20091203_0005.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXwyWojYCoEi5qHCM-R2_A-Uv0PfrRp8k0P5L6LR_d0PVVaQxrOkmHug7EVmAQWxfJaVTW_KKGnEDR675nLi1MdykuHUM4nSItnJgrJ4v2LNCGoeUPD_u-_z_kWFpHmXhahKDESEot2LcO/s640/QwerkCreateDLink_20091203_0005.JPG" width="640" /></a></div>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">That robot's main function was to <a href="https://www.facebook.com/marek.karcz.7/videos/vb.100001053902986/146230418755421/?type=2&theater" target="_blank">autonomously ride</a> around the house, avoid obstacles and take pictures. It could also talk. The iRobot Create has its own controller and default programs for navigating autonomously of course, because it is basically Samba vacuum cleaner with the vacuum hardware removed to make a space/cargo bay for a controller, sensors and other junk to be able to piggy back on it. Thanks to iRobot's Open Interface, accessible via serial port, the platform could be controlled by external computer which was desirable and much more interesting than just running built in programs of a robotic vacuum cleaner.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">Anyway, long story short, the Qwerk controller proved to be buggy and clumsy to use. It crashed constantly, WiFi often froze, etc. I ran out of ideas and didn't have proper skills to develop anything more interesting out of this robot.</span><br />
<span style="font-family: Verdana, sans-serif;">After few more failed attempts at image (from camera) processing and light following (servo turret, now I have enough knowledge to know that this should be done with <a href="https://en.wikipedia.org/wiki/PID_controller" target="_blank">PID </a>method) </span><span style="font-family: Verdana, sans-serif;">I finally got bored with it and moved on to other projects. Robot has been dismantled and stored.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">In recent days I took the iRobot Create out of the box and charged it. The plan is to use one of the modern (Arduino or similar) SBC-s to control it via iRobot's Open Interface. I had an unused and untested yet STM32 Nucleo F411RE board. With some extra hardware and <a href="https://developer.mbed.org/" target="_blank">mbed IDE</a> I have been able to write short program that sends data via Open Interface to play short melody via robot's internal speaker. That's a start. I will expand upon that code by implementing more commands and ultimately a library to create a skeleton for an autonomous robot, similar to the one I made before. I want it to be able to follow the light, ask to be recharged, avoid obstacles and bring me beer from the fridge (well, maybe this is too far for my skill, but who knows where this project will lead me?)</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">Here is the code:</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">#include "mbed.h"</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">Serial pc(PB_6, PB_7); // TX, RX : UART1</span><br />
<span style="font-family: Courier New, Courier, monospace;">DigitalOut myled1(LED1);</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">/*</span><br />
<span style="font-family: Courier New, Courier, monospace;"> Hardware:</span><br />
<span style="font-family: Courier New, Courier, monospace;"> </span><br />
<span style="font-family: Courier New, Courier, monospace;"> STM32 Nucleo-F411RE board.</span><br />
<span style="font-family: Courier New, Courier, monospace;"> RS232-TTL module.</span><br />
<span style="font-family: Courier New, Courier, monospace;"> DB9 NULL MODEM connector.</span><br />
<span style="font-family: Courier New, Courier, monospace;"> DB9 GENDER CHANGER.</span><br />
<span style="font-family: Courier New, Courier, monospace;"> iRobot Create.</span><br />
<span style="font-family: Courier New, Courier, monospace;"> iRobot Serial Mini DIN to DB9 converter/adapter.</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;"> Connections:</span><br />
<span style="font-family: Courier New, Courier, monospace;"> </span><br />
<span style="font-family: Courier New, Courier, monospace;"> Pin PB_6 (TX, CN5.3, Arduino D10) -> RS232-TTL RXD</span><br />
<span style="font-family: Courier New, Courier, monospace;"> Pin PB_7 (RX, CN7.21, Morpho) -> RS232-TTL TXD</span><br />
<span style="font-family: Courier New, Courier, monospace;"> Pin GND (CN7.22, Morpho) -> RS232-TTL GND</span><br />
<span style="font-family: Courier New, Courier, monospace;"> Pin +5V (CN7.18, Morpho) -> RS232-TTL VCC</span><br />
<span style="font-family: Courier New, Courier, monospace;"> iRobot Create Mini DIN -> Serial Converter -> NULL MODEM -> </span><br />
<span style="font-family: Courier New, Courier, monospace;"> -> Gender Changer -> RS232</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">*/</span><br />
<br />
<span style="font-family: Courier New, Courier, monospace;">int main() {</span><br />
<span style="font-family: Courier New, Courier, monospace;"> // play melody on iRobot Create every 10 seconds via Open Interface</span><br />
<span style="font-family: Courier New, Courier, monospace;"> int data[20] = {128, 132, 140, 0, 4, 62, 12, 66, 12, 69, 12, 74, 36, 141, 0, </span><br />
<span style="font-family: Courier New, Courier, monospace;"> -1};</span><br />
<span style="font-family: Courier New, Courier, monospace;"> pc.baud(57600);</span><br />
<span style="font-family: Courier New, Courier, monospace;"> wait(1.0);</span><br />
<span style="font-family: Courier New, Courier, monospace;"> myled1 = 0;</span><br />
<span style="font-family: Courier New, Courier, monospace;"> while(1) {</span><br />
<span style="font-family: Courier New, Courier, monospace;"> int i = 0;</span><br />
<span style="font-family: Courier New, Courier, monospace;"> while(data[i] >= 0) {</span><br />
<span style="font-family: Courier New, Courier, monospace;"> pc.putc(data[i]);</span><br />
<span style="font-family: Courier New, Courier, monospace;"> i++;</span><br />
<span style="font-family: Courier New, Courier, monospace;"> }</span><br />
<span style="font-family: Courier New, Courier, monospace;"> wait(10.0);</span><br />
<span style="font-family: Courier New, Courier, monospace;"> myled1 = !myled1.read();</span><br />
<span style="font-family: Courier New, Courier, monospace;"> }</span><br />
<span style="font-family: Courier New, Courier, monospace;">}</span><br />
<br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Verdana, sans-serif;">The RTOS variant of the code which executes 3 tasks in parallel:</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">#include "mbed.h"</span><br />
<span style="font-family: Courier New, Courier, monospace;">#include "rtos.h"</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">#define NL "\n\r"</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">using namespace rtos;</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">void print_char(char c = '*')</span><br />
<span style="font-family: Courier New, Courier, monospace;">{</span><br />
<span style="font-family: Courier New, Courier, monospace;"> printf("%c", c);</span><br />
<span style="font-family: Courier New, Courier, monospace;"> fflush(stdout);</span><br />
<span style="font-family: Courier New, Courier, monospace;">}</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">DigitalOut led1(LED1);</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">void print_thread(void const *argument)</span><br />
<span style="font-family: Courier New, Courier, monospace;">{</span><br />
<span style="font-family: Courier New, Courier, monospace;"> int n = 20;</span><br />
<span style="font-family: Courier New, Courier, monospace;"> while (true) {</span><br />
<span style="font-family: Courier New, Courier, monospace;"> Thread::wait(1000);</span><br />
<span style="font-family: Courier New, Courier, monospace;"> print_char();</span><br />
<span style="font-family: Courier New, Courier, monospace;"> n--;</span><br />
<span style="font-family: Courier New, Courier, monospace;"> if (n == 0) {</span><br />
<span style="font-family: Courier New, Courier, monospace;"> n = 20;</span><br />
<span style="font-family: Courier New, Courier, monospace;"> printf(NL "... and again ..." NL);</span><br />
<span style="font-family: Courier New, Courier, monospace;"> }</span><br />
<span style="font-family: Courier New, Courier, monospace;"> }</span><br />
<span style="font-family: Courier New, Courier, monospace;">}</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">Serial pc(PB_6, PB_7); // TX, RX : UART1</span><br />
<span style="font-family: Courier New, Courier, monospace;">int data[20] = {128, 132, 140, 0, 4, 62, 12, 66, 12, 69, 12, 74, 36, 141, 0, </span><br />
<span style="font-family: Courier New, Courier, monospace;"> -1};</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">void irobot_thread(void const *argument)</span><br />
<span style="font-family: Courier New, Courier, monospace;">{</span><br />
<span style="font-family: Courier New, Courier, monospace;"> pc.baud(57600);</span><br />
<span style="font-family: Courier New, Courier, monospace;"> Thread::wait(1000);</span><br />
<span style="font-family: Courier New, Courier, monospace;"> while(1) {</span><br />
<span style="font-family: Courier New, Courier, monospace;"> int i = 0;</span><br />
<span style="font-family: Courier New, Courier, monospace;"> while(data[i] >= 0) {</span><br />
<span style="font-family: Courier New, Courier, monospace;"> pc.putc(data[i]);</span><br />
<span style="font-family: Courier New, Courier, monospace;"> i++;</span><br />
<span style="font-family: Courier New, Courier, monospace;"> }</span><br />
<span style="font-family: Courier New, Courier, monospace;"> Thread::wait(60000);</span><br />
<span style="font-family: Courier New, Courier, monospace;"> } </span><br />
<span style="font-family: Courier New, Courier, monospace;">}</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">int main()</span><br />
<span style="font-family: Courier New, Courier, monospace;">{</span><br />
<span style="font-family: Courier New, Courier, monospace;"> printf(NL NL "*** RTOS basic example ***" NL);</span><br />
<span style="font-family: Courier New, Courier, monospace;"> Thread t1(print_thread);</span><br />
<span style="font-family: Courier New, Courier, monospace;"> Thread t2(irobot_thread);</span><br />
<span style="font-family: Courier New, Courier, monospace;"> while (true) {</span><br />
<span style="font-family: Courier New, Courier, monospace;"> led1 = !led1;</span><br />
<span style="font-family: Courier New, Courier, monospace;"> Thread::wait(125);</span><br />
<span style="font-family: Courier New, Courier, monospace;"> }</span><br />
<span style="font-family: Courier New, Courier, monospace;">}</span><br />
<br />
<span style="font-family: Verdana, sans-serif;">and some pics and a video:</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDwoY1VJoP8uZ4JOuMXyc825jR67gEKPonKxL1EmpYrNjT5J3KGu1zOvDsiN9QBLlQfDTYrKjQCcQvrPGAM5p-LlzHleiHfbvB0S5Sqdc6xWdv7uHtVS-NOjP3kUfS87ZC_c4pcWpycdO-/s1600/DSCN7274.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDwoY1VJoP8uZ4JOuMXyc825jR67gEKPonKxL1EmpYrNjT5J3KGu1zOvDsiN9QBLlQfDTYrKjQCcQvrPGAM5p-LlzHleiHfbvB0S5Sqdc6xWdv7uHtVS-NOjP3kUfS87ZC_c4pcWpycdO-/s640/DSCN7274.JPG" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-_CC10ZJnyFoGkKKuGTgzSlNWPwAFwQPaZtF-JGziFveptT-AHw3Q1qsKPmXoy5PzartEg_iPGTUZY6khaFvTGSqjELbf7g-ZiR-oEu1R9QajbzciRrekYgTo96Rw-OhtPC3NGdq8BNZf/s1600/DSCN7276.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-_CC10ZJnyFoGkKKuGTgzSlNWPwAFwQPaZtF-JGziFveptT-AHw3Q1qsKPmXoy5PzartEg_iPGTUZY6khaFvTGSqjELbf7g-ZiR-oEu1R9QajbzciRrekYgTo96Rw-OhtPC3NGdq8BNZf/s640/DSCN7276.JPG" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<iframe allowfullscreen='allowfullscreen' webkitallowfullscreen='webkitallowfullscreen' mozallowfullscreen='mozallowfullscreen' width='320' height='266' src='https://www.blogger.com/video.g?token=AD6v5dzPPWM6OGaSqCjRt-CiEqfxg2dSCC9sBzt6kvxzJgj39Fj2BXoRfdU6RiGd2YkNP8IFFUtRRGBIAHLcm9Z4Ew' class='b-hbp-video b-uploaded' frameborder='0'></iframe></div>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">Hopefully I will find time for this project and some more updates will come soon.</span><br />
<span style="font-family: Verdana, sans-serif;">Thank you for visiting.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">M.K.</span><br />
<span style="font-family: Verdana, sans-serif;">8/24/2016</span>Marek Karczhttp://www.blogger.com/profile/03281397436610614441noreply@blogger.com0tag:blogger.com,1999:blog-4155387638169532413.post-64858729987022014892016-02-07T20:11:00.001-08:002020-10-06T23:25:29.670-07:00Update on MKHBC-8-R2 6502 computer - prototyping banked RAM - revision 2.<span face="Verdana, sans-serif">I promised an update when I figure out the solution to my problem with RAM bank switching side effect when reading from the I/O mapped area $C000..$C0FF.</span><br />
<span face="Verdana, sans-serif">Well, I think I fixed it, but the glue logic is a bit more elaborate than I expected. Since the desired function was to generate rising edge on CLK input of 74LS374 latch only when /IO0 = 0 and R/W = 0 and Phi2 goes from HI to LO, I had to come up with the circuit with following truth table:</span><br />
<span face="Verdana, sans-serif"><br /></span>
<span style="font-family: Courier New, Courier, monospace;">/IO0 R/W Phi2 | CLK</span><br />
<span style="font-family: Courier New, Courier, monospace;">----------------------------------</span><br />
<span style="font-family: Courier New, Courier, monospace;"> 0 0 0 | 1</span><br />
<span style="font-family: Courier New, Courier, monospace;"> 0 0 1 | 0</span><br />
<span style="font-family: Courier New, Courier, monospace;"> 0 1 0 | 0</span><br />
<span style="font-family: Courier New, Courier, monospace;"> 0 1 1 | 0</span><br />
<span style="font-family: Courier New, Courier, monospace;"> 1 0 0 | 0</span><br />
<span style="font-family: Courier New, Courier, monospace;"> 1 0 1 | 0</span><br />
<span style="font-family: Courier New, Courier, monospace;"> 1 1 0 | 0</span><br />
<span style="font-family: Courier New, Courier, monospace;"> 1 1 1 | 0</span><br />
<span style="font-family: Courier New, Courier, monospace;">----------------------------------</span><br />
<span style="font-family: Courier New, Courier, monospace;"><br /></span>
<span face="Verdana, sans-serif">I'm sure you can see a familiar pattern here. This is like 3-input AND with output flipped over. Above function is realized with 3-input AND with its inputs negated:</span><br />
<span face="Verdana, sans-serif"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-4AnXJnDxOY5RQGKnWGwmO9gDDuQB2QgLk0sqwqje5EfLAERE2LQIhv36dgEx6gQGzfW3Fgyfz3hPP7tB-hGTe-BNJbk7uuaE7XxKUAB2j3FGgijZ5vi1_s_EMNNEg7v12gUoRJOYPzei/s1600/ThreeInputNotAnd.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj-4AnXJnDxOY5RQGKnWGwmO9gDDuQB2QgLk0sqwqje5EfLAERE2LQIhv36dgEx6gQGzfW3Fgyfz3hPP7tB-hGTe-BNJbk7uuaE7XxKUAB2j3FGgijZ5vi1_s_EMNNEg7v12gUoRJOYPzei/s1600/ThreeInputNotAnd.jpg" /></a></div>
<span face="Verdana, sans-serif">Since I have no IC with 3-input AND, I transformed that circuit to NAND-s only equivalent and came up with this:</span><br />
<span face="Verdana, sans-serif"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGUGyrGsmiD0jfeRt_iAJ4Zj49wc2GmoFYV6C8nibxYrUrPmM6GTfcb2FB8sKvu5tW3GtjC768_fTEfXceJ7yD5YKLq1mbqLr7B5bCtcXHGyxE89_yrXas_aTs9VNCkfuHqhZqL4YG7dST/s1600/GlueLogicBRAM.jpg" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="212" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGUGyrGsmiD0jfeRt_iAJ4Zj49wc2GmoFYV6C8nibxYrUrPmM6GTfcb2FB8sKvu5tW3GtjC768_fTEfXceJ7yD5YKLq1mbqLr7B5bCtcXHGyxE89_yrXas_aTs9VNCkfuHqhZqL4YG7dST/s400/GlueLogicBRAM.jpg" width="400" /></a></div>
<span face="Verdana, sans-serif">It looks like I will be needing this extra 74LS00 chip that I saved (see my previous blog update). Here is the final circuit for banked RAM:</span><br />
<span face="Verdana, sans-serif"><br /></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0UFHK4Exgh412mmcVNoiwHoXqRuWMiC_10MHo0YuDFq2u0S8PcDhNHSny-i_dFiOA4Sz1byVZsY8StDs6gjtSJDvqeMpzlZqW_U2awTw36BBtmxL6SsbvwNLZoQuW3UU5yje6bOTVHtcq/s1600/MKHBC-8-R2-BankedRAM.bmp" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="482" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj0UFHK4Exgh412mmcVNoiwHoXqRuWMiC_10MHo0YuDFq2u0S8PcDhNHSny-i_dFiOA4Sz1byVZsY8StDs6gjtSJDvqeMpzlZqW_U2awTw36BBtmxL6SsbvwNLZoQuW3UU5yje6bOTVHtcq/s640/MKHBC-8-R2-BankedRAM.bmp" width="640" /></a></div>
<span face="Verdana, sans-serif"><br /></span>
<span face="Verdana, sans-serif">Now the bank register is not switching to bank 0 when reading operation is performed on address from I/O 0 range ($C000..$C0FF).</span><br />
<span face="Verdana, sans-serif"><br /></span>
<span face="Verdana, sans-serif">2/7/2016</span><br />
<span face="Verdana, sans-serif">M.K.</span>Marek Karczhttp://www.blogger.com/profile/03281397436610614441noreply@blogger.com0tag:blogger.com,1999:blog-4155387638169532413.post-21643455583882996922015-12-09T19:23:00.002-08:002015-12-09T19:23:30.284-08:00Update on MKHBC-8-R 6502 computer (now on revision #2) - prototyping RTC and banked RAM.
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">I had
very productive 2 weeks or so with this project. </span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">To make long story
short:</span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<ul>
<li><span style="font-family: Verdana, sans-serif;">I
assembled CPU and UART cards.</span></li>
<li><span style="font-family: Verdana, sans-serif;">I
discovered and mostly corrected errors in my design and technical
problems in manufactured boards (bus contention, wrong address
decoding scheme, bad solder joints/electrical contact problem on CPU
bus, connector B2).</span></li>
<li><span style="font-family: Verdana, sans-serif;">I
built and tested RTC circuit prototype (based on DS1685 and Chris
Ward's design of connecting this multiplexed bus type chip to 6502
bus).</span></li>
<li><span style="font-family: Verdana, sans-serif;">I built
and tested prototype of RAM bank switching register (based on 74LS374
latch register).</span></li>
</ul>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">More
details in my YouTube video: <a href="https://youtu.be/em1GlzjnQbM" target="_blank">MKHBC-8-R2 - part 4.</a></span>
</div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">My
address decoding circuits design incorporated <i>Phi2</i> signal in the
decoding scheme. I consulted literature and expertise of
knowledgeable people on the 6502 subject and decided this is not the correct approach. I removed the <i>Phi2</i> signal from address decoders
input. The <i>Phi2 </i>signal is now only used to synchronize
reading/writing access cycles.</span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEge1LCDdsd3-0dxUI3Nm98fIsobAj6fwBOX_dhu4NAgj-erUiRu2w4aJNd1R37JjQiPFEf1W-RUCHT3MjJ8ztGOEis52AepjIL31C-vOWI2xklxD5P7nrXz7VnBVqvwjE89QtljIpsp7ZpA/s1600/MKHBC-8-R2-CPU-card.bmp" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="442" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEge1LCDdsd3-0dxUI3Nm98fIsobAj6fwBOX_dhu4NAgj-erUiRu2w4aJNd1R37JjQiPFEf1W-RUCHT3MjJ8ztGOEis52AepjIL31C-vOWI2xklxD5P7nrXz7VnBVqvwjE89QtljIpsp7ZpA/s640/MKHBC-8-R2-CPU-card.bmp" width="640" /></a></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"> </span>
</div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">I
tested two variants of RTC circuit:</span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
</div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijbQy4eUWaq7NgdtJtxWhPYiz0pZavCVsO_znoN85HGhHL5lLNvGO0EJxT6S6aVvwLxemK4jrKXEqm3t7MWa9wnrJLAOqtq5A595EMzsaMKJyiZ_N9nh_wwOVlVrwP7JjvlVXEielVKuRt/s1600/MKHBC-8-R1-RTC.bmp" imageanchor="1"><img border="0" height="482" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijbQy4eUWaq7NgdtJtxWhPYiz0pZavCVsO_znoN85HGhHL5lLNvGO0EJxT6S6aVvwLxemK4jrKXEqm3t7MWa9wnrJLAOqtq5A595EMzsaMKJyiZ_N9nh_wwOVlVrwP7JjvlVXEielVKuRt/s640/MKHBC-8-R1-RTC.bmp" width="640" /></a> </span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"> </span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfbZpQidq8Cwk1LLA9pFGm7XxMFM8JHc_CFLcjK-ZN5N_brfqTI8w3j8-4ka_ihTxP0qusA4fOH4I6U7TsTIYhwFNtIpkKd0k3KHs8EO7Lrch4sCK36op3cL9b9TlJ1WbLSr0AxoTKMjlQ/s1600/MKHBC-8-R2-RTC.bmp" imageanchor="1"><img border="0" height="482" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjfbZpQidq8Cwk1LLA9pFGm7XxMFM8JHc_CFLcjK-ZN5N_brfqTI8w3j8-4ka_ihTxP0qusA4fOH4I6U7TsTIYhwFNtIpkKd0k3KHs8EO7Lrch4sCK36op3cL9b9TlJ1WbLSr0AxoTKMjlQ/s640/MKHBC-8-R2-RTC.bmp" width="640" /></a></span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">and
decided to go with 2-nd one (seems to be more reliable and less
susceptible to problems resulting from long propagation times).</span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">My I/O
bus (data lines) was not properly separated from CPU bus resulting in
bus contention and data corruption. Here is the corrected circuit:</span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjI6xUfzX3wvv0dvXJOL7tLFjJTP-JcJxwQdBJ_eXtF6AlU6BMIr18QAdCAalPnlRqbLKs-hsLLv3rbrOCr0DVBsR62UOSbl6VOATljXaVkq7bgFtkIBZohjMCcqHsWXiSzmwrHYMcaS5IJ/s1600/MKHBC-8-R2-IO-bus.bmp" imageanchor="1"><img border="0" height="442" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjI6xUfzX3wvv0dvXJOL7tLFjJTP-JcJxwQdBJ_eXtF6AlU6BMIr18QAdCAalPnlRqbLKs-hsLLv3rbrOCr0DVBsR62UOSbl6VOATljXaVkq7bgFtkIBZohjMCcqHsWXiSzmwrHYMcaS5IJ/s640/MKHBC-8-R2-IO-bus.bmp" width="640" /></a><br />
</div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">I also
have a concept of banked RAM:</span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<img alt="" height="519" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAABH0AAAOlCAIAAAB/vgwvAAAgAElEQVR4nOydvU4rS9NGfRNIBEhOnOBgS0SbiJ2TIkISEjIkUiTEDUCACJ07QFyAJQISiytwehLfyPmC59319emeabdnxtPzs0ZLR/uY8bjnr7ueruqqydc//wIAAAAAAMDhmGRvAQAAAAAAwLBBdwEAAAAAABwWdBcAAAAAAMBhQXcBAAAAAAAcFnQXAABk42X5PZ3NszcDAADg0KC7AAAgG5PJZDJhJAIAgOHDaAcAANmQ7lqut9lbAgAAcFDQXQAAkA3prqf3j+wtAQAAOCjoLgAA2IPFatPg0aazeWXd9fT+cXF5fXF53WyTWuDt8yd7GwAAoGXQXQAAnePp/ePp/ePu8fXm/lnSIsLp2Xn4Yfjdst3st57eP65uH65uH0zPFB6hWQ+VDnhxef30/vH2+XP3+JqiSZbr7dHxyeS/W8tOs5v752pfnEwmd4+vuR4tAADIBboLAKATXN0+TPqzNaIclu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ZLvdWR+5Juvt85DdwjTJOchcAAABuwWK1teq+9PjbAtXZnSgLZfXnSLNEl/5n8SPakqfIG67Uit27nOC00rdTVtGFaIlagVmmkkcvf6D17mgLw0q+sMtD7gIAAMAtcCvoguPvPHHFrf1z69PiDeXv7h+C01baW9a3LNplTXnZCXiJLs8pmZfNx/BxXEOjeTtVr7NIPT3u17vjZLYsmUW9XvaT2VKquT813AUAAACgBvH3DmseIz55pcxgw3f3XcYFSs7iK7i8tx6rZ7q1u3CboQcv5GwN5Nv7pyadaphuSreAbzRbo+n8X5uUi/Delx3Z1MHSrc/Ub2O9O9obn9MVm+QuAAAA3IjIUqu9MyET2YMCj/vJ5nCy6HXp8iedTzz2eCV56SF+Oly5bfr0eiv3r4pb1u2j2kbzWewWKW7Vc9Bq2VPo9gfW6TFnEktvgaLTb79CAAAAoBJWahip+ounoGD3hfhu4/TF9e4Yn/nRJInVubU7vXanF6lw89q+BzetUqvnzuv8v/HRX5UVHLrPKLIFbwW5CwAAALdD4arRbKUjR5nWC+vdUV+/tNeCLeKqtknD/quPSHDcX+DVWyhAr5kWvRns6fk1q/iT3AUAAIDboRVZwXClCFTsXcO2hwKd1kv2Z8+zf7nqUVASuQsAAAC/hVX9ffuZ4LchdwEAAOC3sCkvohdqRu4CAADAL6IXTJG7UDNyFwAAAABcF7kLAAAAAK7rP4d2N2eo5S7xAAAAAElFTkSuQmCC" width="640" />
</div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">The
code testing the 74LS374 latch register alone (I just had LED-s
connected to the data outputs):</span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;">#include
<stdlib.h></span></div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;">#include
<stdint.h></span></div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;">#include
<string.h></span></div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;">#include
<peekpoke.h></span></div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;">#include
"mkhbcos_serialio.h"</span></div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;"><br /></span>
</div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;">char
buf1[10], buf2[10];</span></div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;"><br /></span>
</div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;">void
my_pause(uint16_t delay)</span></div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;">{</span></div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;"> int i
= 0;</span></div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;"><br /></span>
</div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;"> for(i=0;
i < delay; i++);</span></div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;">}</span></div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;"><br /></span>
</div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;">int
main(void)</span></div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;">{</span></div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;"> int i
= 0;</span></div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;"> unsigned
char n = 0;</span></div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;"> char
buf[5] = {0};</span></div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;"><br /></span>
</div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;"> POKE(0xC000,n);</span></div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;"> puts
("Hello! Testing port I/O #0 and latch 74LS374.\n\r");</span></div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;"> puts
("Press ENTER and observe the blinking lights...\n\r");</span></div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;"><br /></span>
</div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;"> gets(buf1);</span></div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;"><br /></span>
</div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;"> for
(n=1, i=1; i<256; n++,i++) {</span></div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;"> buf1[0]
= buf2[0] = 0;</span></div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;"> strcpy(buf1,
itoa (i, buf2, 10));</span></div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;"> puts(buf1);
puts("\r");</span></div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;"> POKE(0xC000,n);</span></div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;"> my_pause(2000);</span></div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;"> }</span></div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;"><br /></span>
</div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;"> for
(i=0; i<10; i++) {</span></div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;"> POKE(0xC000,0);</span></div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;"> my_pause(2000); </span></div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;"> POKE(0xC000,0xFF);</span></div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;"> my_pause(2000); </span></div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;"> }</span></div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;"> POKE(0xC000,0);</span></div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;"><br /></span>
</div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;"> puts
("Test finished.\n\r");</span></div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;"><br /></span>
</div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;"> return
0;</span></div>
<span style="font-family: "Courier New",Courier,monospace;">
</span><div style="margin-bottom: 0in;">
<span style="font-family: "Courier New",Courier,monospace;">}</span></div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<br />
</div>
<span style="font-family: Verdana, sans-serif;">Pictures of my prototype for your enjoyment (electronics hardware porn :-)) and some screenshots of serial command interface:</span>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkjxxM42hfqgjXYXEe2Wd2Do8h9m5W2vGrTIa18pTBcs_bH4VJkqxqXSLbXBcAkSsJvsqCK2tQDM9sUFgHULMTpYtQRpIXLIhyx2lgYNV1AbOfVNS-cYJPKyaR3phLFAovHulW535C57qm/s1600/DSCN6427.JPG" imageanchor="1"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjkjxxM42hfqgjXYXEe2Wd2Do8h9m5W2vGrTIa18pTBcs_bH4VJkqxqXSLbXBcAkSsJvsqCK2tQDM9sUFgHULMTpYtQRpIXLIhyx2lgYNV1AbOfVNS-cYJPKyaR3phLFAovHulW535C57qm/s640/DSCN6427.JPG" width="640" /> </a></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjb-FOInS5x2JpYuBTW9SRdnIEBFi5u8Z5iAgOL8mdOkfFXL-458u-HWIxoTlwgnTq6QMBwQZTN1kVeSJi3iHF9DKIBFlSWld66BSt8Vmpd8vRSnEW7Eh7CF8HpjHnk8O229dqCaXP9XWfb/s1600/DSCN6436.JPG" imageanchor="1"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjb-FOInS5x2JpYuBTW9SRdnIEBFi5u8Z5iAgOL8mdOkfFXL-458u-HWIxoTlwgnTq6QMBwQZTN1kVeSJi3iHF9DKIBFlSWld66BSt8Vmpd8vRSnEW7Eh7CF8HpjHnk8O229dqCaXP9XWfb/s640/DSCN6436.JPG" width="640" /></a><br />
</div>
<div style="margin-bottom: 0in;">
<br />
</div>
<div style="margin-bottom: 0in;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvLUfqNNP-rqjeWdtTiFlaRlaOjwJZFxoqBejK9EJbgoXWvFDTXiYJnD5aWrP8kdVCR7rpROJSWGAmyet0e6RB4vJsy0R-xRbBX2-CXd_Ii8yLJkJ9GOyqfuHihNBK6qY-CkYNtsgfz0jT/s1600/DSCN6446.JPG" imageanchor="1"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvLUfqNNP-rqjeWdtTiFlaRlaOjwJZFxoqBejK9EJbgoXWvFDTXiYJnD5aWrP8kdVCR7rpROJSWGAmyet0e6RB4vJsy0R-xRbBX2-CXd_Ii8yLJkJ9GOyqfuHihNBK6qY-CkYNtsgfz0jT/s640/DSCN6446.JPG" width="640" /> </a></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYp10rzd9Np5q3UhhulBAqhDNinx1kJ9cYj-L98IuZmaoshXnSJVNOhjniDTv7jEGrD6xHrSzzB-FVgDoOvrfn7N7x1ZUnGj8eTFnnpnf-2aRgusMNJfzHx8CwxnuBvbNovAtQcoAYcAK1/s1600/DSCN6437.JPG" imageanchor="1"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYp10rzd9Np5q3UhhulBAqhDNinx1kJ9cYj-L98IuZmaoshXnSJVNOhjniDTv7jEGrD6xHrSzzB-FVgDoOvrfn7N7x1ZUnGj8eTFnnpnf-2aRgusMNJfzHx8CwxnuBvbNovAtQcoAYcAK1/s640/DSCN6437.JPG" width="480" /></a> </div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCOJzlsGAbPR3uWc7wQpAghXRqMTon3rHevf57tt2wxuSOCxDROkuTh6zYjVSkgv7ksCcjlKTtQAZ0Bd5yFdKPJLLE0noOAIdn0pyp7auZm7A2I18CSRr1rudo9wEl1kewyAFB-I4PPxYM/s1600/DSCN6445.JPG" imageanchor="1"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgCOJzlsGAbPR3uWc7wQpAghXRqMTon3rHevf57tt2wxuSOCxDROkuTh6zYjVSkgv7ksCcjlKTtQAZ0Bd5yFdKPJLLE0noOAIdn0pyp7auZm7A2I18CSRr1rudo9wEl1kewyAFB-I4PPxYM/s640/DSCN6445.JPG" width="480" /></a> </div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidob1U9TwVrJ8mAitTeWxO5t1Gh49ZjOWjAVJIjD7_yglNURWYB_OnnEKTYKROp-uKRO2RmBzsG9i7zB2Pw01-M2-Kd3QtphPPNwda3eTeStZZr6d-Mge2aRluBr7d1If4bxEucLlXiaYZ/s1600/DSCN6449.JPG" imageanchor="1"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEidob1U9TwVrJ8mAitTeWxO5t1Gh49ZjOWjAVJIjD7_yglNURWYB_OnnEKTYKROp-uKRO2RmBzsG9i7zB2Pw01-M2-Kd3QtphPPNwda3eTeStZZr6d-Mge2aRluBr7d1If4bxEucLlXiaYZ/s640/DSCN6449.JPG" width="480" /> </a></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
That would be all for today.</div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
Thanks for visiting my blog.</div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
12/9/2015</div>
<div style="margin-bottom: 0in;">
MK </div>
Marek Karczhttp://www.blogger.com/profile/03281397436610614441noreply@blogger.com0tag:blogger.com,1999:blog-4155387638169532413.post-45572133028151391472015-11-25T01:32:00.000-08:002015-11-25T01:32:51.515-08:00Update on MKHBC-R1, 6502 based home-brew computer: UART - finished!I finished assembling the UART card. At this time I test the system outside of the mother-board. I also added (temporarily) ZIF sockets to CPU card for EPROM (since the system is still in development, this will be very useful) and for CPU. You may be wondering why did I have a need to have a ZIF socket for a CPU? Well, some time ago I bought from e-bay a lot of eighteen R6502P chips very cheap. I have never had a chance to test them. Now came their time. I dropped each in the ZIF socket and tested them in my system. All worked fine, so future looks bright for any new 6502 based projects.<br />
I've published a short demo on <a href="https://youtu.be/_Sm0_Q8eAT8" target="_blank">youtube</a> of my working system.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEji9V5jJR4j0kf4Fxr-BbEsOkLykVUjDYib4EoNfqBrIxkktCOhFmsvnz7P1JzBwyeotkcsi9hKIenjG-ilExJQOoL55PzByL7cybkEnl8LmOm1BLFyazE5oO-44MM67xmq8-Koi7wbU1gD/s1600/DSCN6422.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEji9V5jJR4j0kf4Fxr-BbEsOkLykVUjDYib4EoNfqBrIxkktCOhFmsvnz7P1JzBwyeotkcsi9hKIenjG-ilExJQOoL55PzByL7cybkEnl8LmOm1BLFyazE5oO-44MM67xmq8-Koi7wbU1gD/s640/DSCN6422.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Working system with one of R6502P CPU-s I've been testing in the ZIF socket and CPU speed jumper set to 0.9 MHz (my standard configuration is R6502AP with 1.8 MHz clock). The voltage is a bit low here (4.6V). I improved the connections a little bit and later got 4.8V, a bit more acceptable and within tolerance.</td><td class="tr-caption" style="text-align: center;"><br /></td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEguvpsxxs4TNynjDhKNgSzFcb0pHnv76LE595CpBddIvqNOtfzY8ZY1-1yhtEG80Ayy2trkkOVBT5aNWVWOyKH-T8_uMd2EzyL7FIEIBmHoNdyifMtjSMF48cqgJhfIs2IQc-0DY1ia5CvK/s1600/DSCN6420.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEguvpsxxs4TNynjDhKNgSzFcb0pHnv76LE595CpBddIvqNOtfzY8ZY1-1yhtEG80Ayy2trkkOVBT5aNWVWOyKH-T8_uMd2EzyL7FIEIBmHoNdyifMtjSMF48cqgJhfIs2IQc-0DY1ia5CvK/s640/DSCN6420.JPG" width="480" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">I use my port of Meadow Operating System (which is really a monitor program working over serial port) to control the system, upload and run programs on it. Above - Tiny BASIC is being uploaded to RAM.</td><td class="tr-caption" style="text-align: center;"><br /></td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZYxgLu6YI2HRts6OZtfpn3akRyo6eYkg6DQkFqj3-72HL_AVnovKgV_niOh34Ps54yYGDbOGsEWnZEZjfY1wwKO7u3fN8C37PQjJyC42xswOqD9g7dgacxZzpcgP2IfpjHz8SFuJ9KzVf/s1600/DSCN6423.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgZYxgLu6YI2HRts6OZtfpn3akRyo6eYkg6DQkFqj3-72HL_AVnovKgV_niOh34Ps54yYGDbOGsEWnZEZjfY1wwKO7u3fN8C37PQjJyC42xswOqD9g7dgacxZzpcgP2IfpjHz8SFuJ9KzVf/s640/DSCN6423.JPG" width="480" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Tiny BASIC uploaded and running. Time to play some game. Euphoria is a small kingdom simulator written in Tiny BASIC.</td><td class="tr-caption" style="text-align: center;"><br /></td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcqbMwbPacmj618htZy17stzzZfsuuf-RKcj6XiO9rHii3CLNSwovDMqqV2eazOV0C8fcCa2F8uU6lLGnWmWwTB7VQO_hJR0-poNsbUJekY6kyPpjshp0M7Du7BfKKyduRl4srJ-qhUdoO/s1600/DSCN6425.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjcqbMwbPacmj618htZy17stzzZfsuuf-RKcj6XiO9rHii3CLNSwovDMqqV2eazOV0C8fcCa2F8uU6lLGnWmWwTB7VQO_hJR0-poNsbUJekY6kyPpjshp0M7Du7BfKKyduRl4srJ-qhUdoO/s640/DSCN6425.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Lot of 18 6502 CPU-s.</td></tr>
</tbody></table>
11/25/2015<br />
MKMarek Karczhttp://www.blogger.com/profile/03281397436610614441noreply@blogger.com0tag:blogger.com,1999:blog-4155387638169532413.post-21885261282510768422015-11-23T00:30:00.001-08:002015-11-23T00:30:23.501-08:00Update on MKHBC-R1, 6502 based home-brew computer: UARTI made some changes to the circuit diagram. In order to generate proper net list, I replaced labels connected to CPU bus with labels connected to buffered I/O bus in slot #4. I included detailed comments on the diagram drawing. The UART card of course can be connected to any I/O slot or directly to the CPU card, with proper programming changes. The concept is explained in design document that I referenced earlier in this blog.<br />
I also corrected PCB layout as I missed two components when I updated it last time: jumper JP8 and resistor R7.<br />
I started to assemble the board, it should be finished soon. I made most of the GND connections for now. Updated circuit diagram, PCB layout and pictures of the board are included below.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhO7HgGcB75lXn-301o-zyq0Py1VieV3ZAgObOnDYkcQ3GzmtOM-3P9jw1Lo9Vn9nnTjOfYFxpijKe_6IZxHDNNT6UIfgjiER7ydC1Nqqlz4AHx-Els5aVyTytepi1cQgv_2ozJfrQXgPmO/s1600/MKHBC-8-R1-UART.bmp" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="482" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhO7HgGcB75lXn-301o-zyq0Py1VieV3ZAgObOnDYkcQ3GzmtOM-3P9jw1Lo9Vn9nnTjOfYFxpijKe_6IZxHDNNT6UIfgjiER7ydC1Nqqlz4AHx-Els5aVyTytepi1cQgv_2ozJfrQXgPmO/s640/MKHBC-8-R1-UART.bmp" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDcIqMRScjKbNyexJSv5f6IvowpzoNal92CMlu397ARqQ9p7sB6DkgiJQG6zolECHWJSAAF-zQXkDRchqhzd-jLJkWfobkFBUJHdmKWyRMBMmtWEp_ha6kGZCHOxF8xJ1spwd8W140RlEC/s1600/MKHBC-8-R1-UART.bmp" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="374" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjDcIqMRScjKbNyexJSv5f6IvowpzoNal92CMlu397ARqQ9p7sB6DkgiJQG6zolECHWJSAAF-zQXkDRchqhzd-jLJkWfobkFBUJHdmKWyRMBMmtWEp_ha6kGZCHOxF8xJ1spwd8W140RlEC/s640/MKHBC-8-R1-UART.bmp" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_ZsvizTcDSwrg942t375DJMhjn5LcfXW36VVfZYKSqH41Kp_-ZBHSDz6-PLPNUvfQCEfbvQPuRpOkdAt0FzmiIsIct2WDy2f50tvW5rqavxn5-3NZmZceso4I4f3DWLgZrW860VHGERsi/s1600/DSCN6419.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_ZsvizTcDSwrg942t375DJMhjn5LcfXW36VVfZYKSqH41Kp_-ZBHSDz6-PLPNUvfQCEfbvQPuRpOkdAt0FzmiIsIct2WDy2f50tvW5rqavxn5-3NZmZceso4I4f3DWLgZrW860VHGERsi/s640/DSCN6419.JPG" width="640" /></a></div>
<br />
11/23/2015<br />
MKMarek Karczhttp://www.blogger.com/profile/03281397436610614441noreply@blogger.com0tag:blogger.com,1999:blog-4155387638169532413.post-46726404571667254482015-11-12T01:04:00.000-08:002015-11-12T01:04:20.525-08:00Update on MKHBC-R1, 6502 based home-brew computer: UART<span style="font-family: Verdana, sans-serif;">I made some modifications to the circuit diagram (added jumper switches) and created a PCB component layout for my UART card. The layout is not too elegant and appears wasteful, because I will make the circuit on the slightly over-sized prototyping board which has some traces and padded holes on the bottom side. I originally planned to make all expansion cards for my computer on such boards, since they have some traces in addition to pads and padded holes (which BTW do not cover all the board's surface evenly). Due to that they are suitable for less dense component placement than is required on CPU bus cards. If you care to compare this one to my CPU card board, which is made on the different prototyping board, smaller but equipped with padded holes spread evenly across the entire surface and no traces, you will understand why. I simply can make more point to point connections and pack components closer together on the board with padded holes only versus a bigger board but with less holes and with some traces on the bottom.</span><br />
<span style="font-family: Verdana, sans-serif;">Next step - point to point soldering of the UART card. This should be far less work than CPU card.</span><br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjC5q7dHjYYCZ35_H8xd1TjwQIu__ucYJGrHirtE0XLKYuvWPAhfb3GrUO3pBTjVKvyLPD3ZzGCM02m4qisA_sACJqDYYiOgihk4k_tuRycGruSAdm57C_lpMUE0SPyYnk86r84VT0kQu1m/s1600/MKHBC-8-R1-UART.bmp" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="482" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjC5q7dHjYYCZ35_H8xd1TjwQIu__ucYJGrHirtE0XLKYuvWPAhfb3GrUO3pBTjVKvyLPD3ZzGCM02m4qisA_sACJqDYYiOgihk4k_tuRycGruSAdm57C_lpMUE0SPyYnk86r84VT0kQu1m/s640/MKHBC-8-R1-UART.bmp" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Circuit.</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiEUPslkd2e8LLd_pp-CqDb5mNSb3AelG7xjkOg50MxMSLj8XwKkeTRqfr4YJtUp6Tvr56Z1pMWKIgjz-Ng9exhyoX3RWRBPNiSc26QnFDbjmDIR-xBOuo24dp9mHT8MrO2r1eKlka-Cv7w/s1600/mkhbc-8-r1-uart-pcblayout.bmp" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="524" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiEUPslkd2e8LLd_pp-CqDb5mNSb3AelG7xjkOg50MxMSLj8XwKkeTRqfr4YJtUp6Tvr56Z1pMWKIgjz-Ng9exhyoX3RWRBPNiSc26QnFDbjmDIR-xBOuo24dp9mHT8MrO2r1eKlka-Cv7w/s640/mkhbc-8-r1-uart-pcblayout.bmp" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Layout.</td></tr>
</tbody></table>
<span style="font-family: Verdana, sans-serif;"> <table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhN8vNGmzUbJCGyKqGUAIT08HiqLHPgfGJDeNwAgVamiH-WoalZuK87iZbLGgsXuX8npHETiKIXXda9d6jLROcxL1JTVczBZFWQQF6-mibtiB0JCMd-ZGwkQxKyLS88ysN6v4ZLIlzbseSY/s1600/DSCN6411.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhN8vNGmzUbJCGyKqGUAIT08HiqLHPgfGJDeNwAgVamiH-WoalZuK87iZbLGgsXuX8npHETiKIXXda9d6jLROcxL1JTVczBZFWQQF6-mibtiB0JCMd-ZGwkQxKyLS88ysN6v4ZLIlzbseSY/s640/DSCN6411.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Testing CPU card in the mother-board. The "mobo" still lacks power supply, interrupt controller and I/O port - just passive CPU bus and buffered I/O bus (black slots in the back).</td></tr>
</tbody></table>
</span><br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKTkN187TQ3n4hrwBaesby2jjExkqcW9DE0mh5AfPujHqHwZEPgS7hEcPVZTefU43VuFfLYZ0vCSiaAXo6O0IA-_e8FD3AignGFHEt23VTV6gLfBuHxQI4IvN4vfplWO2uqmSN_RNvvK9I/s1600/DSCN6412.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKTkN187TQ3n4hrwBaesby2jjExkqcW9DE0mh5AfPujHqHwZEPgS7hEcPVZTefU43VuFfLYZ0vCSiaAXo6O0IA-_e8FD3AignGFHEt23VTV6gLfBuHxQI4IvN4vfplWO2uqmSN_RNvvK9I/s640/DSCN6412.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">In front, the prototyping board which will host UART circuit.</td></tr>
</tbody></table>
<br />
11/12/2015<br />
<br />
MKMarek Karczhttp://www.blogger.com/profile/03281397436610614441noreply@blogger.com0tag:blogger.com,1999:blog-4155387638169532413.post-14732694251308572242015-11-01T20:49:00.002-08:002015-11-01T20:49:37.787-08:00Update on MKHBC-R1, 6502 based home-brew computer.It took me awfully long time to get back to this project, but I finally did.<br />
I finished assembly and verification of the CPU card. After checking all connections with a multi-meter, I populated the board with IC-s and assembled simple power supply (5V stabilizer) and testing circuit (just 3 LED-s with resistors and a reset switch) on the bread-board. Then I burned test program on EPROM that just selects 3 of the I/O selection outputs in a loop and I put the EPROM chip in the board. The other 32K EPROM chip for now is not in the board. The test worked. See it <a href="https://youtu.be/UGRYlCjyWfI" target="_blank">here</a>.<br />
This test verified following basic CPU board functionality:<br />
* clock circuit<br />
* reset circuit<br />
* I/O address selection circuit<br />
Next step is to assemble the serial communication circuit on the bread-board and test the CPU and serial communication with a bit more advanced but still rudimentary operating system (Monitor program). After that, serial communication card assembly on a permanent board (I/O card).<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxf9tu5QuvNqLrnGpx9Pl-SwNkqY6l79Faf3CZCMWcCWYofyYF_b8lt8_D7JKiHyV7u1QsMqT01h5I9oB7jgJFSGZXUkl1jQS4pLaNcRlMKXOhAA05azfi5l6nJWDP0H_eU1znc7GFT4G9/s1600/DSCN6401.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxf9tu5QuvNqLrnGpx9Pl-SwNkqY6l79Faf3CZCMWcCWYofyYF_b8lt8_D7JKiHyV7u1QsMqT01h5I9oB7jgJFSGZXUkl1jQS4pLaNcRlMKXOhAA05azfi5l6nJWDP0H_eU1znc7GFT4G9/s640/DSCN6401.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">MKHBC-R1, back in business.</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjixBbKQi_LRLMcT5IA75Wk5giB6ylbYFZrsueMvp9go7Q4hMNUOOggLUCEHC8qEh-Y1hQlsgp0vurVO6nb_GnpPvsZQQUHKu2tycesN9leWRjZFluFNAp5LpnDE_CSuSViO-F9770FOfLD/s1600/DSCN6402.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjixBbKQi_LRLMcT5IA75Wk5giB6ylbYFZrsueMvp9go7Q4hMNUOOggLUCEHC8qEh-Y1hQlsgp0vurVO6nb_GnpPvsZQQUHKu2tycesN9leWRjZFluFNAp5LpnDE_CSuSViO-F9770FOfLD/s640/DSCN6402.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Chips populated, only EPROM to burn and face the truth.</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrOeQh-WRVAaZ6n97UN9mkpMEn9Ogr5AA6kavBLfTd0ira_ykXD9VOz0Zewt5tIBnzOKVJ83qI3_4ByBLMgvRvidOpwywNUW7mPTRsTtW6YYI369aXtogowcy0exJMEdhy0kw2jkquQqLN/s1600/DSCN6408.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgrOeQh-WRVAaZ6n97UN9mkpMEn9Ogr5AA6kavBLfTd0ira_ykXD9VOz0Zewt5tIBnzOKVJ83qI3_4ByBLMgvRvidOpwywNUW7mPTRsTtW6YYI369aXtogowcy0exJMEdhy0kw2jkquQqLN/s640/DSCN6408.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">It worked!</td></tr>
</tbody></table>
Thanks for looking.<br />
<br />
Marek Karcz<br />
11/1/2015Marek Karczhttp://www.blogger.com/profile/03281397436610614441noreply@blogger.com0tag:blogger.com,1999:blog-4155387638169532413.post-2531699266522232252014-11-08T15:43:00.000-08:002014-11-08T15:43:26.619-08:00Fish Tank Automation - finished.<span style="font-family: Verdana, sans-serif;">Time for celebration has come as I finished my Fish Tank Automation project and the system is up and running now for almost a week with no problems so far. I updated the source code and documentation and all is available for download from my <a href="http://1drv.ms/1ErE2JC" target="_blank">skydrive</a> folder. Look for file <i>fishtankautom_doc.zip</i>, which contains documentation, pictures and source code. The Arduino sketch alone is also available under the same folder in archive <i>fishtankautom6.zip</i>, however the documentation archive contains all additional libraries needed to compile the code.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">Pictures of the installed and running system:</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgx9Ok0sJP8kCRXDFPzi66Th7KsDvR_pG6FBsr6D3gYB3FYSZ97vqLUQZpaS3Nty9eXI2XBWIpMj0Y2SK3VW12sGgYm6dw34kAFYnVZNY8THQ4LdWSiEJ6NYYWE5sl64aCFBOEWt33QZRyV/s1600/IMG_2120.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgx9Ok0sJP8kCRXDFPzi66Th7KsDvR_pG6FBsr6D3gYB3FYSZ97vqLUQZpaS3Nty9eXI2XBWIpMj0Y2SK3VW12sGgYm6dw34kAFYnVZNY8THQ4LdWSiEJ6NYYWE5sl64aCFBOEWt33QZRyV/s1600/IMG_2120.JPG" height="480" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-size: small;">Dry test run before installing the system on the fish tank.</span></td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhflaaOeBXRoJZ3k4Rv9P5LavPA-fgSKQD-KrxK6lhMYOSwyrGq58DdJrOPkhU1qj835cUAdydZnckdu_priV1fxT3SUqxxrvqTkcUdWYOGAdrqbnVLj2JL3NLDFf5GNKXjqsj2TxN6ak77/s1600/IMG_2121.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhflaaOeBXRoJZ3k4Rv9P5LavPA-fgSKQD-KrxK6lhMYOSwyrGq58DdJrOPkhU1qj835cUAdydZnckdu_priV1fxT3SUqxxrvqTkcUdWYOGAdrqbnVLj2JL3NLDFf5GNKXjqsj2TxN6ak77/s1600/IMG_2121.JPG" height="480" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-size: small;">Installed and running.</span></td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgryuo81HCFy1ZQp6kTreZ9tj4OZb7UIjo28mM5s_eh56bYNU8S3qb10085-hoIoNu3IoAE_Rlf5Yrm21t1i0WYIL6x2Uw-sdpvjZafI4OXkRX8LdW0fd9Wxb4IYH1gw7ANTaCgeh1DB1n1/s1600/IMG_2122.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgryuo81HCFy1ZQp6kTreZ9tj4OZb7UIjo28mM5s_eh56bYNU8S3qb10085-hoIoNu3IoAE_Rlf5Yrm21t1i0WYIL6x2Uw-sdpvjZafI4OXkRX8LdW0fd9Wxb4IYH1gw7ANTaCgeh1DB1n1/s1600/IMG_2122.JPG" height="480" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-size: small;">Food dispensing unit.</span></td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYWAreNhOCrXaLegBJ2wSov3YhvvEx4j9qXOkBCJBnmsGOkoNwMcQar3Kd9p1XIhqZXilJSggNYXXOWNgHNk5agKzImBoQ8z3kEASd7oN02bqLo-O4XsTIs0hwpXZmg9410VwnduMNWorh/s1600/IMG_2123.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYWAreNhOCrXaLegBJ2wSov3YhvvEx4j9qXOkBCJBnmsGOkoNwMcQar3Kd9p1XIhqZXilJSggNYXXOWNgHNk5agKzImBoQ8z3kEASd7oN02bqLo-O4XsTIs0hwpXZmg9410VwnduMNWorh/s1600/IMG_2123.JPG" height="480" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-size: small;">Control unit, temperature warning LED-s and Sel/Set buttons.</span></td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhunivfmdMFnekqxQG5u5-O-QwPOyZOgG0uTdxuc-FbJfp8vxDZskz0TrqneFekBsy-Hdf0tiZ-5Bb5Slbczcrn40Z4ArpiM1Q1V44sTS6RFk4SMbo44DYmVnD9W4V-QBWLQTvfu9Y9stqK/s1600/IMG_2124.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhunivfmdMFnekqxQG5u5-O-QwPOyZOgG0uTdxuc-FbJfp8vxDZskz0TrqneFekBsy-Hdf0tiZ-5Bb5Slbczcrn40Z4ArpiM1Q1V44sTS6RFk4SMbo44DYmVnD9W4V-QBWLQTvfu9Y9stqK/s1600/IMG_2124.JPG" height="480" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-size: small;">Temperature sensor is visible here just below the control unit - it is of course inside the fish tank.</span></td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEguPwpGKNYDjgxLpQsUvFORQdo2n7NAPsoEMqQyzcbMHxz5kYjl7OhQXhkjweYWYOhmRUXcmeS4xgcS-j5Uk_DFJK5VNFwzpp_WKu2vF6HmBDce4VjTDpt934_xJix688W1Nr7n4p4gqdn9/s1600/IMG_2125.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEguPwpGKNYDjgxLpQsUvFORQdo2n7NAPsoEMqQyzcbMHxz5kYjl7OhQXhkjweYWYOhmRUXcmeS4xgcS-j5Uk_DFJK5VNFwzpp_WKu2vF6HmBDce4VjTDpt934_xJix688W1Nr7n4p4gqdn9/s1600/IMG_2125.JPG" height="480" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-size: small;">My fish likes it :-)</span></td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgz4q-BQegF1cyS_lBIkAADkYEPe_gyShrbar4-oV6STbe_7cB4m9dGbDKaoLs2s0i4O2fUV6YiFXrcT6XFwvaJtaDTSzSE-9U4Kx5AHYNfOYDyIr3OToH6TQvZ1jQpIZsdO8JbENLSNuuv/s1600/IMG_2126.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgz4q-BQegF1cyS_lBIkAADkYEPe_gyShrbar4-oV6STbe_7cB4m9dGbDKaoLs2s0i4O2fUV6YiFXrcT6XFwvaJtaDTSzSE-9U4Kx5AHYNfOYDyIr3OToH6TQvZ1jQpIZsdO8JbENLSNuuv/s1600/IMG_2126.JPG" height="480" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-size: small;">The power housing unit is visible here to the left of the fish tank.</span></td></tr>
</tbody></table>
<span style="font-family: Verdana, sans-serif;">It is always good to see the project all the way through to the practical application. So many of my projects end up forgotten and unfinished. </span><br />
<span style="font-family: Verdana, sans-serif;">I used this one to teach myself some discipline.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">Thank you for visiting my blog.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">Marek Karcz 11/8/2014</span>Marek Karczhttp://www.blogger.com/profile/03281397436610614441noreply@blogger.com0tag:blogger.com,1999:blog-4155387638169532413.post-53903903166758319962014-09-17T21:37:00.000-07:002014-09-17T21:37:34.584-07:00Fish Tank Automation - casing.<span style="font-family: Verdana, sans-serif; font-size: x-small;">I am done with prototyping and programming (am I? :-)), so it is time to move the circuit from prototype board to some housing such that it will have a practical application.</span><div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">I decided to keep Arduino board with the supporting circuitry, LCD module, stepper motor control module, buttons, LED-s etc. in a separate case (which I call 'controller housing') from the 110V relay for obvious reasons - safety.</span></div>
<div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">The other identical case will house the receptacle/110V socket for the aquarium's light and the relay (power housing). The power cord with the plug will go out of the case to the 110V socket and the receptacle mounted on the case will provide relay controlled/scheduled from Arduino power source for the fish tank light (see the pictures at the end of this article).</span></div>
<div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">From the controller housing, two wires will go to the power housing that will provide current for the relay's coil. This way the electronics part will be completely isolated from the high-voltage part (unless I screw up insulation inside the power housing, hopefully not). Another 4-wire connector will go from the controller housing to the feeding drum (stepper motor). I still need to drill some more holes for Arduino's power/USB sockets, LED-s, perhaps I will add a reset button to the controller housing.</span></div>
<div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">Considering the (poor) level of my manual skills, this looks quite OK, judge for yourself.</span></div>
<div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1ngq3H-bmBMAdwkInphyphenhyphen2GZ2P3IzPCKd82WI-IgpGBQQ6ohzntAQC5uEAIvXU8kaofzTTII03j84_oAvMe3w3J3Ye19d6ifmbssvhUZUULTh1mFagkYdESIVjS9LJcQeR8AAKulXSvhs1/s1600/IMG_2022.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg1ngq3H-bmBMAdwkInphyphenhyphen2GZ2P3IzPCKd82WI-IgpGBQQ6ohzntAQC5uEAIvXU8kaofzTTII03j84_oAvMe3w3J3Ye19d6ifmbssvhUZUULTh1mFagkYdESIVjS9LJcQeR8AAKulXSvhs1/s1600/IMG_2022.JPG" height="480" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgo9wxr8uAgafcOHG4lAayb4OtHPsOQA3hWdalAVbsL2YyCi2za6ALPWz-tQn-DJoXjlDAJUvFiIak51GsebGMYdp_wCtu0KplnjKclISwlftgzHbG_reTImPN49fPsZwnlqy0-O90o7VvQ/s1600/SANY0005.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgo9wxr8uAgafcOHG4lAayb4OtHPsOQA3hWdalAVbsL2YyCi2za6ALPWz-tQn-DJoXjlDAJUvFiIak51GsebGMYdp_wCtu0KplnjKclISwlftgzHbG_reTImPN49fPsZwnlqy0-O90o7VvQ/s1600/SANY0005.JPG" height="360" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjA-mpiPMJFAxglypdKm8xwfk34-7kemiiGfCo9YRLdaGd3Rr0aceUrSv6lTpyouaTnlhou2d4Uj0qHQzyjkJrk-QNjoroQW2MntSrKLH_MjSHMVzcNq9FaI6XJKoi9NwfuVF4pSI6jh61X/s1600/IMG_2026.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjA-mpiPMJFAxglypdKm8xwfk34-7kemiiGfCo9YRLdaGd3Rr0aceUrSv6lTpyouaTnlhou2d4Uj0qHQzyjkJrk-QNjoroQW2MntSrKLH_MjSHMVzcNq9FaI6XJKoi9NwfuVF4pSI6jh61X/s1600/IMG_2026.JPG" height="480" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2zL9hmzVDeRVt50du-B1V0hSGj61DzN5C-ZovQqcKWyZ17T_MLxhSz6aRP0Ta6rqd8OCzireMIgnDo26fwgA6NTTQngJJSl1_Fmh8wcaOdkDLrfEzUK37SrQ5mQGNph78mWDePsQFPE0i/s1600/IMG_2025.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2zL9hmzVDeRVt50du-B1V0hSGj61DzN5C-ZovQqcKWyZ17T_MLxhSz6aRP0Ta6rqd8OCzireMIgnDo26fwgA6NTTQngJJSl1_Fmh8wcaOdkDLrfEzUK37SrQ5mQGNph78mWDePsQFPE0i/s1600/IMG_2025.JPG" height="480" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCMuVw0amzbrGFYCk81i1KP3phBenqfSS_orbmZJOJschYNl1UXvvGvNWIC5IgiYL-vne2tUZR6TSvepZIisQESlXDHS2iGxEb77rrDNHclTHrpmUfThHPf5tDwnID_h_VVVs-EtdtV4j3/s1600/IMG_2027.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCMuVw0amzbrGFYCk81i1KP3phBenqfSS_orbmZJOJschYNl1UXvvGvNWIC5IgiYL-vne2tUZR6TSvepZIisQESlXDHS2iGxEb77rrDNHclTHrpmUfThHPf5tDwnID_h_VVVs-EtdtV4j3/s1600/IMG_2027.JPG" height="480" width="640" /></a></div>
<div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></div>
<div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></div>
<div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">Thank you for your time.</span></div>
<div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><br /></span></div>
<div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">Marek Karcz</span></div>
<div>
<span style="font-family: Verdana, sans-serif; font-size: x-small;">9/18/2014</span></div>
Marek Karczhttp://www.blogger.com/profile/03281397436610614441noreply@blogger.com0tag:blogger.com,1999:blog-4155387638169532413.post-77847057623114724292014-09-07T20:45:00.000-07:002014-09-08T21:45:01.657-07:00Fish Tank Automation - upgrades.<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">Since
my original article about Fish Tank Automation project, I did not
proceed to the practical execution of it (remained a prototype). I
recently reviewed that project and found it inadequate. I decided
that the command line interface to program and operate the module is
not good enough for a micro-controller and added LCD module and
buttons. I also added low/high temperature warning LED-s. This can be
easily expanded to automatically control the water heater, however I
have no use for it since the water heater module has a thermostat of
its own. I was able to keep the original command line interface code,
however I used up almost the entire available program storage in Arduino (less than 1kB left).
Therefore if anybody would like to expand this project, I suggest to
remove either command line interface code or the buttons/LCD UI part.</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<br />
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">Here
is the modified circuit diagram:</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtTl5-qM4vf4FkPDkWxBtalWUhyn8VBZQOaZKdu9tYGAA8q_wJCrE7WyPjPk_6zIKaI2dvPE8bxw4RP7sSI-2Yy4RXrlycsi97YVNuC0QgqP89Qlpzm4MmkwHCF52lCD9QcGB4_NP67wJi/s1600/FishTankAutomSch2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhtTl5-qM4vf4FkPDkWxBtalWUhyn8VBZQOaZKdu9tYGAA8q_wJCrE7WyPjPk_6zIKaI2dvPE8bxw4RP7sSI-2Yy4RXrlycsi97YVNuC0QgqP89Qlpzm4MmkwHCF52lCD9QcGB4_NP67wJi/s1600/FishTankAutomSch2.jpg" height="459" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">Perhaps
one day I will draw it using some more professional software than Paint and scan hybrid, but it must suffice for now.</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">There
were many additions to the sketch code as well as a nasty bug was
corrected in the aquarium light switching code.</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">The sketch (updated 9/9/2014):</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div style="margin-bottom: 0in;">
<span style="background-color: white; font-family: Courier New, Courier, monospace; font-size: x-small;">/*</span><br />
<span style="background-color: white; font-family: Courier New, Courier, monospace; font-size: x-small;"> * Fish tank automation.</span><br />
<span style="background-color: white; font-family: Courier New, Courier, monospace; font-size: x-small;"> * Version 3.0</span><br />
<span style="background-color: white; font-family: Courier New, Courier, monospace; font-size: x-small;"> *</span><br />
<span style="background-color: white; font-family: Courier New, Courier, monospace; font-size: x-small;"> * Changes (from 2.0):</span><br />
<span style="background-color: white; font-family: Courier New, Courier, monospace; font-size: x-small;"> *</span><br />
<span style="background-color: white; font-family: Courier New, Courier, monospace; font-size: x-small;"> * - Bug fixes (light scheduler).</span><br />
<span style="background-color: white; font-family: Courier New, Courier, monospace; font-size: x-small;"> * - Temperature log discontinued (useless).</span><br />
<span style="background-color: white; font-family: Courier New, Courier, monospace; font-size: x-small;"> * - Temperature is measured every 5 minutes (was 20).</span><br />
<span style="background-color: #eeeeee; font-family: Courier New, Courier, monospace; font-size: x-small;"> *</span><br />
<span style="background-color: #eeeeee; font-family: Courier New, Courier, monospace; font-size: x-small;"> * Created by Marek Karcz 2013,2014. All rights reserved.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> * Free to copy for personal use.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> * </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> * Hardware:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> *</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> * 1) Arduino Uno</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> * 2) ULN2003 stepper motor driver module.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> * 3) 28BYJ-48 stepper motor (propelling food distribution mechanism).</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> * 4) Food distributing drum.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> * Taken from cheap Walmart fish automated feeder propelled by battery</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> * operated clock.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> * 5) Radio Shack's SPDT Micromini 5VDC Relay (275-0240) - light control.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> * 6) DS18B20 one-wire temperature sensor in water proof casing or coating.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> * Currently the temperature read is only for informational/logging</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> * purpose since my fish tank water heater has its own thermostate.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> * 7) Tiny RTC, I2C module (DS1307 AT24C32).</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> * 8) I2C LCD 20x4 display from SainSmart.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> * 9) Green LED, red LED and 2 buttons (SET and SEL).</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> * NOTE: Button pins must be connected to pull-up resistors.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> * Per Arduino's reference:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> * "If the pin isn't connected to anything, digitalRead() can </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> * return either HIGH or LOW (and this can change randomly)."</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> *</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> * Theory of operation:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> *</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> * The RTC clock will synchronize the scheduled tasks.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> * Scheduler will program the feeding and light on-off times.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> * The feeding drum will be spinned by a stepper motor.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> * The setup will be stored in EEPROM of the RTC clock module or Arduino's EEPROM.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> * Device will be programmed with 3-buttons and LCD UI as well as via serial port</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> * (command line interface).</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> * Green and Red LED-s will show the temperature status (too low or too high).</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> *</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> * Credits/copyright acknowledgements/references:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> *</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> * - The stepper motor code inspired by: </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> * http://arduino-info.wikispaces.com/SmallSteppers</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> * - The Dallas temperature sensor code ripped from: </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> * http://www.pjrc.com/teensy/td_libs_OneWire.html</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> * and refactored.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> * - The I2c bit-banged library:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> * 2010-12 Tod E. Kurt, http://todbot.com/blog/</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> *</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> */</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#include <avr/pgmspace.h></span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#include <EEPROM.h> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#include <Stepper.h></span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#include <OneWire.h></span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#include <Wire.h></span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#include <RTClib.h></span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#include <SoftI2CMaster.h></span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#include <LCD_I2C_BB.h></span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#define MAXCOL 20 // columns on LCD disp.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#define MAXROW 4 // rows on LCD disp.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#define LCDUPD 200 // loop iterations between LCD updates</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#define SHOWFSOUT 50 // loop iter. before show food schedule disp. tout</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#define SHOWLSOUT 100 // loop iter. before show light schedule disp. tout</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#define BACKLTOUT 150 // loop iter. before lcd backlight timeout</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#define MENUOUT 200 // loop iter. before menu timeout</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">//#define MYDEBUG0</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">//#define MYDEBUG1</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">//#define MYDEBUG2</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">//#define MYDEBUG3</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Pin definitions.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#define REDLEDPIN 4</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#define GREENLEDPIN 13</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#define BTNSEL 2</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#define BTNSET 3</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#define DTROW 0</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#define TEMPROW 1</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#define FSROW 2</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#define LSROW 0</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#define STPMIN1PIN 8</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#define STPMIN2PIN 9</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#define STPMIN3PIN 10</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#define STPMIN4PIN 11</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#define LIGHTPIN 12</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#define DS1820PIN 7 // did not work on pin 13 (because of the LED connected) </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // and on pin 7 works every other time</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// (Number of steps per revolution of INTERNAL motor in 4-step mode)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#define STEPS_PER_MOTOR_REVOLUTION 32 </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// (Steps per OUTPUT SHAFT of gear reduction)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#define STEPS_PER_OUTPUT_REVOLUTION 32 * 64 //2048 </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Calendar definitions.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">prog_char Sun[] PROGMEM = "Sun";</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">prog_char Mon[] PROGMEM = "Mon";</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">prog_char Tue[] PROGMEM = "Tue";</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">prog_char Wed[] PROGMEM = "Wed";</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">prog_char Thu[] PROGMEM = "Thu";</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">prog_char Fri[] PROGMEM = "Fri";</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">prog_char Sat[] PROGMEM = "Sat";</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">PROGMEM const char *daysOfWeek[] = {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Sun, Mon, Tue, Wed, Thu, Fri, Sat</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">};</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Error codes</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">enum eErrors {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ERR_OK = 0,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ERR_ARGTOOLONG, // 1 : argument too long</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ERR_TOOMANYARGS, // 2 : too many arguments</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ERR_TOOMANYLS, // 3 : too many entries in light on/off schedule</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ERR_LSEEPROMOOR, // 4 : light on/off schedule setup exceeds EEPROM range</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ERR_LSENTINVFMT, // 5 : invalid entry format (light on/off schedule)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ERR_TOOMANYFS, // 6 : too many entries in feeding schedule</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ERR_FSEEPROMOOR, // 7 : feeding schedule setup exceeds EEPROM range</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ERR_FSENTINVFMT, // 8 : invalid entry format (feeding schedule)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ERR_UNKNCMD, // 9 : unknown command</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ERR_TEMPRD, // 10 : temperature sensor read failed</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ERR_NIL</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">};</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// recognized commands</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">enum eCommands {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> CMD_DATE = 0,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> CMD_TEMP,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> CMD_ADDFT,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> CMD_SHOWFS,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> CMD_DELFT,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> CMD_ADDLS,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> CMD_SHOWLS,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> CMD_DELLS,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> CMD_SETDT,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> CMD_HELP,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> CMD_DEFFS,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> CMD_DEFLS,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> CMD_NIL</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">};</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// states of the LCD display/UI input</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">enum eLcdDispStates {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> LCD_START = 0,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> LCD_SHOWSTATUS,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> LCD_SHOWFS,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> LCD_SHOWLS,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> LCD_MAINMENU,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> LCD_SETDTMENU,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> LCD_SETFSMENU,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> LCD_SETFSADD,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> LCD_SETFSDEL,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> LCD_SETFSDFLT,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> LCD_SETLSMENU,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> LCD_SETLSADD,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> LCD_SETLSDEL,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> LCD_SETLSDFLT,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> LCD_END</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">};</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">enum eButtons {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> BTN_NONE = 0,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> BTN_SEL,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> BTN_SET</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">};</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#define CMDL 5</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">PROGMEM prog_char Date[CMDL] = "date";</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">PROGMEM prog_char Temp[CMDL] = "temp";</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">PROGMEM prog_char Addft[CMDL] = "addf";</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">PROGMEM prog_char Showfs[CMDL] = "shfs";</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">PROGMEM prog_char Delft[CMDL] = "delf";</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">PROGMEM prog_char Addls[CMDL] = "addl";</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">PROGMEM prog_char Showls[CMDL] = "shls";</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">PROGMEM prog_char Dells[CMDL] = "dell";</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">PROGMEM prog_char Setdt[CMDL] = "setd";</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">PROGMEM prog_char Help[CMDL] = "help";</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">PROGMEM prog_char Deffs[CMDL] = "deff";</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">PROGMEM prog_char Defls[CMDL] = "defl";</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">PROGMEM const char *cmdTable[] = {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Date, // display date/time</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Temp, // display last temperature read</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Addft, // add feeding times to feeding schedule</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Showfs, // show feeding schedule</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Delft, // delete feeding schedule</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Addls, // add times to the light on/off schedule</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Showls, // show light on/off schedule</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Dells, // delete light on/off schedule</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Setdt, // set date/time</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Help, // show help</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Deffs, // reset feeding schedule to default (9 AM, 9 PM).</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Defls // reset light on/off schedule to default (8:30 AM on, 9:30 PM off)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">};</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Help for commands.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// PROGMEM directive forces these variables into program memory</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// instead of SRAM. Supported types must be used and special API</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// functions to use these variables.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">prog_char hlpstr_0[] PROGMEM = "- view D/T";</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">prog_char hlpstr_1[] PROGMEM = "- view temp.";</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">prog_char hlpstr_3[] PROGMEM = "hh:mm [hh:mm ...] - add feed times";</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">prog_char hlpstr_4[] PROGMEM = "- view feed sched.";</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">prog_char hlpstr_5[] PROGMEM = "- del. feed sched.";</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">prog_char hlpstr_6[] PROGMEM = "hh:mm [hh:mm ...] - add light times";</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">prog_char hlpstr_7[] PROGMEM = "- view light sched.";</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">prog_char hlpstr_8[] PROGMEM = "- del. light sched.";</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">prog_char hlpstr_9[] PROGMEM = "Yr Mon Day Hr Min - set D/T";</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">prog_char hlpstr_10[] PROGMEM = "- help";</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">prog_char hlpstr_12[] PROGMEM = "- set deflt feed sch.";</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">prog_char hlpstr_13[] PROGMEM = "- set deflt light sch.";</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">PROGMEM const char *cmdHelp[] = {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> hlpstr_0,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> hlpstr_1,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> hlpstr_3,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> hlpstr_4,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> hlpstr_5,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> hlpstr_6,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> hlpstr_7,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> hlpstr_8,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> hlpstr_9,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> hlpstr_10,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> hlpstr_12,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> hlpstr_13,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">};</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// this buffer must accomodate the longest string of hlpstr_N plus</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// terminating NULL.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">char progmembuf[36];</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Stepper motor</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// The pin connections need to be 4 pins connected</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// to Motor Driver In1, In2, In3, In4 and then the pins entered</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// here in the sequence 1-3-2-4 for proper sequencing</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">Stepper small_stepper(STEPS_PER_MOTOR_REVOLUTION, STPMIN1PIN, STPMIN3PIN, STPMIN2PIN, STPMIN4PIN);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Real time clock</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">RTC_DS1307 RTC;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Temperature sensor</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">OneWire ds(DS1820PIN);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// set the LCD i2c address and display dimensions</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">LCD_I2C_BB lcd(0x3f,MAXCOL,MAXROW);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// global variables</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">int Steps2Take; // stepper motor</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">char textbuf[10]; // text buffer for temp. conversions</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">boolean cmdReady; // a flag - command is entered</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">String cmdTmp = ""; // temporary string buffer for command</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">String cmd = ""; // command string buffer</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">int cmdCode = -1; // command code</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">long lastTempRead = 0; // the unixtime second of last temperature read</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">boolean bTempRead = false; // if the temp. read was successfull</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// temp. sensor read protocol flags and variables</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">byte present = 0;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">byte type_s;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">byte data[12];</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">byte addr[8];</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">float celsius, fahrenheit;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">DateTime timeNow;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// UI control variables</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">byte lcdupdate; // lcd update counter</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">byte lcdstate; // current state of UI</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">byte lcdbacklt; // lcd backlight on counter (If > 0, backlight is on)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">byte lcdmenuct; // counter for selected menu on lcd timeout</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// scheduler flags and variables</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Schedule structure</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">struct SchedTbl {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int hour;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int minute;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">};</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#define LS_LEN 6 // lenght of the light schedule entry (HH:MM)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#define LS_MAX 8 // maximum number of light on/off schedule entries</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">int lsLen = -1; // the length of light on/off schedule (# of entries)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">String lsTable[LS_MAX]; // the String form of light on/off scheduler, as saved in EEPROM</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">SchedTbl lsSched[LS_MAX]; // numeric table of light on/off scheduler</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">boolean lightswitch = false; // current status of the light switch</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Other definitions</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#define TEMP_RD_EVERY 5 // how often to read temperature (minutes)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#define FS_LEN 6 // length of the feeding schedule entry (HH:MM)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#define FS_MAX 6 // maximum number of feeding schedule entries</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">int fsLen = -1; // the length of food dispensing schedule (# of entries)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">String fsTable[FS_MAX]; // the String form of food disp. scheduler, as saved in EEPROM</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">SchedTbl fsSched[FS_MAX]; // numeric table of food disp scheduler</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">long foodDispTime = 0; // time (seconds) when food last dispensed</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// constants</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">const float lowtemp = 70.0;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">const float hitemp = 80.0;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">const char *PROMPT = "CMD> ";</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">const char *LCDHELP = " Press SET for Menu";</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">const char *VERSION = "Fish Tank Ctrl. v3.0";</span></span><br />
<br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Initialization sequence.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">void setup()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.init();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // Print a message to the LCD.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.backlight();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,0);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print(VERSION); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,1);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print("(C) Marek Karcz 2014");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,2);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print("Init...");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdstate = LCD_START;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> pinMode(GREENLEDPIN, OUTPUT);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> pinMode(REDLEDPIN, OUTPUT);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> digitalWrite(GREENLEDPIN, LOW);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> digitalWrite(REDLEDPIN, LOW); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdupdate = LCDUPD; </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdmenuct = MENUOUT;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> cmdReady = false;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.begin(9600); // serial port will be the main mode of communication</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // with the device and programming the light and feeding</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // scheduler</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> pinMode(LIGHTPIN, OUTPUT);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lightOn();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // power to i2c_ds1307_at24c32 module provided via A2, A3 pins</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // for Uno: A4 = SDA, A5 = SCL</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> pinMode(A3, OUTPUT); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> digitalWrite(A3, HIGH);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> pinMode(A2, OUTPUT);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> digitalWrite(A2, LOW);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // start communication, I2C and RTC</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Wire.begin();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> RTC.begin();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ds.reset();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // NOTE: Stepper Library sets pins as outputs</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // Rotate CW 1/8 turn forward and backwards to show the system is working</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Steps2Take = STEPS_PER_OUTPUT_REVOLUTION / 8;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> small_stepper.setSpeed(600); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> small_stepper.step(Steps2Take);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Steps2Take = - Steps2Take;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> small_stepper.setSpeed(600); // 700 a good max speed??</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> small_stepper.step(Steps2Take);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lightOff();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> initLsTable();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lsLen = loadSavedLS2Table(); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> for (int i = 0; i < lsLen && i < LS_MAX; i++)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lsSched[i].hour = getHourFromTimeEntry(lsTable[i]);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lsSched[i].minute = getMinuteFromTimeEntry(lsTable[i]);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> } </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> initFsTable();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> fsLen = loadSavedFS2Table(); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> for (int i = 0; i < fsLen && i < FS_MAX; i++)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> fsSched[i].hour = getHourFromTimeEntry(fsTable[i]);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> fsSched[i].minute = getMinuteFromTimeEntry(fsTable[i]);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> } </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> pinMode(BTNSET, INPUT);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> pinMode(BTNSEL, INPUT);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> digitalWrite(GREENLEDPIN, HIGH);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> digitalWrite(REDLEDPIN, HIGH); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.println(VERSION);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.println("Ready.");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print(PROMPT);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,3);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print("Done.");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> delay(500);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdDispMainScrFrame();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdstate = LCD_SHOWSTATUS;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdbacklt = BACKLTOUT;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Main control loop.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">void loop()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // Read time.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> timeNow = RTC.now();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // control light via scheduler</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> controlLight();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // control food dispenser</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> controlFoodDisp();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // Read temperature.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> readTemp();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // refresh LCD, read user input</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (lcdstate >= LCD_MAINMENU)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> switch (lcdstate)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case LCD_MAINMENU:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdstate = execMainMenu();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case LCD_SETDTMENU:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdstate = execSetDtMenu();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case LCD_SETFSMENU:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdstate = execSetFsMenu();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (lcdstate == LCD_SHOWFS)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdShowFeedingSchedule();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case LCD_SETFSDFLT:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> serialDefaultFS();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdShowFeedingSchedule(); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case LCD_SETFSDEL:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> serialDeleteFeedingSchedule();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdShowFeedingSchedule();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case LCD_SETFSADD:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> execAddFeedingTimeMenu();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdShowFeedingSchedule();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case LCD_SETLSMENU:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdstate = execSetLsMenu();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (lcdstate == LCD_SHOWLS)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdShowLightSchedule();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case LCD_SETLSDFLT:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> serialDefaultLS();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdShowLightSchedule();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case LCD_SETLSDEL:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> serialDeleteLightSchedule();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdShowLightSchedule();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case LCD_SETLSADD:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> execAddLightTimeMenu();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdShowLightSchedule();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break; </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> default:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdstate = LCD_SHOWSTATUS;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (lcdstate != LCD_SHOWFS && lcdstate != LCD_SHOWLS) </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdDispMainScrFrame();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (lcdupdate == LCDUPD && lcdstate == LCD_SHOWSTATUS)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdWriteDTNow();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdConvWriteTemp();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> String ft = getNextFeedingTime();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> String lt = getNextLightSwitchTime();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdClearRow(2);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print("Nxt F<");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print(ft);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print(">L<");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print(lt);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print('>');</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // command interpreter (via serial)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> interpretCommand();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdupdate--;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if ((lcdstate == LCD_SHOWFS || lcdstate == LCD_SHOWLS) </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> && lcdupdate == 0</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> )</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdstate = LCD_SHOWSTATUS;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdDispMainScrFrame();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> } </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (lcdupdate == 0)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdupdate = LCDUPD;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (lcdbacklt > 0)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdbacklt--;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (lcdbacklt == 0) // time-out LCD backlight</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.noBacklight();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (lcdstate >= LCD_MAINMENU && lcdmenuct > 0)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdmenuct--;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (lcdmenuct == 0) // time-out any opened menu</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdmenuct = MENUOUT;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdstate = LCD_SHOWSTATUS;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int selbtn = BTN_NONE;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // check buttons input</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if ((selbtn = readButtons()) != BTN_NONE)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdbacklt = BACKLTOUT;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.backlight();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> switch (selbtn)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case BTN_SET:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (lcdstate < LCD_MAINMENU)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdstate = LCD_MAINMENU;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case BTN_SEL:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> default:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> delay(100);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Basic screen re-draw with static data.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">void lcdDispMainScrFrame()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.clear();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,0);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print(VERSION);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,3);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print(LCDHELP); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Simple up/down set number UI with buttons and LCD.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">int setNumberMenu(int start, </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int low, </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int high, </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int row, </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> unsigned int iter)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> boolean loopmenu = true;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int setNumber = start;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int tout = iter;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> while (loopmenu)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int btnsel = readButtons();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> switch (btnsel)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case BTN_SET:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (setNumber > low)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> setNumber--;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdClearRow(row);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print(setNumber);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> tout = iter;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case BTN_SEL:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (setNumber < high)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> setNumber++;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdClearRow(row);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print(setNumber);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> tout = iter;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> default:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> tout--;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (tout == 0)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> loopmenu = false;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> delay(100);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> } </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> return setNumber;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Execute UI/Menu - add feeding time.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">void execAddFeedingTimeMenu()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int setHour = 0;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int setMinute = 0;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int n = 0;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> initFsTable(); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> fsLen = loadSavedFS2Table(); // load feeding schedule from EEPROM to lsTable</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> for (int i = 0; i < fsLen && i < FS_MAX; i++, n++)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> fsSched[i].hour = getHourFromTimeEntry(fsTable[i]);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> fsSched[i].minute = getMinuteFromTimeEntry(fsTable[i]);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (n < FS_MAX) </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> setHour = timeNow.hour();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> setMinute = timeNow.minute(); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.clear(); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,0);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print("Feeding Hour:");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,1);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print(setHour);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> setHour = setNumberMenu(setHour, 0, 23, 1, 30);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> //lcd.clear(); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,2);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print("Feeding Minute:");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,3);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print(setMinute);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> setMinute = setNumberMenu(setMinute, 0, 59, 3, 30);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> fsSched[n].hour = setHour;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> fsSched[n].minute = setMinute;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> fsLen = n + 1;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> sortFsTables(); // sort feeding schedule numeric tables</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> convFsTblToStringTbl(); // convert fsHoursTbl and fsMinutesTbl to fsTable</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int err = saveFsTable(); // save feeding schedule table to EEPROM</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (err != ERR_OK)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.clear();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,0);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print("Err# ");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print(err);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> delay(2000);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> else</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.clear(); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,0);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print("ERR: Schedule full.");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> delay(2000);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Execute UI/Menu - add light switch time.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Note - number of entries should be even to match every ON with OFF.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Therefore it is normal to see a warning about missing OFF switch</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// after adding the entry. This is a remainder, not an error.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Just add another switch time later.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">void execAddLightTimeMenu()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int setHour = 0;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int setMinute = 0;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int n = 0;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> initLsTable(); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> fsLen = loadSavedLS2Table(); // load light schedule from EEPROM to lsTable</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> for (int i = 0; i < lsLen && i < LS_MAX; i++, n++)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lsSched[i].hour = getHourFromTimeEntry(lsTable[i]);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lsSched[i].minute = getMinuteFromTimeEntry(lsTable[i]);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (n < LS_MAX)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> setHour = timeNow.hour();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> setMinute = timeNow.minute(); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.clear(); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,0);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print("Light Switch Hour:");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,1);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print(setHour);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> setHour = setNumberMenu(setHour, 0, 23, 1, 30);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> //lcd.clear(); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,2);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print("Ligth Switch Minute:");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,3);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print(setMinute);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> setMinute = setNumberMenu(setMinute, 0, 59, 3, 30);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lsSched[n].hour = setHour;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lsSched[n].minute = setMinute;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lsLen = n + 1;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> sortLsTables(); // sort light schedule numeric tables</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> convLsTblToStringTbl(); // convert lsHoursTbl and lsMinutesTbl to lsTable</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int err = saveLsTable(); // save light schedule table to EEPROM</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (err != ERR_OK)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.clear();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,0);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print("Err# ");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print(err);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> delay(2000);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> else</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.clear(); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,0);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print("ERR: Schedule full.");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> delay(2000);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Execute UI/Menu - select feeding schedule setup option.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">int execSetFsMenu()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int sel = 0;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> boolean loopmenu = true;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int tout = MENUOUT;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int ret = LCD_SHOWSTATUS;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.clear(); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,0);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print("Show Feeding Sched.");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,1);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print("Add Feeding Time");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,2);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print("Del. Feeding Sched."); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,3);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print("Set Default");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(MAXCOL-1,sel);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print('<');</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> while (loopmenu)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int selbtn = BTN_NONE;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if ((selbtn = readButtons()) != BTN_NONE)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> switch (selbtn)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case BTN_SEL:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> tout = MENUOUT;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> sel++;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (sel > 3)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> sel = 0;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case BTN_SET:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> loopmenu = false;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> switch (sel)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case 0:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ret = LCD_SHOWFS;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case 1:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ret = LCD_SETFSADD;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case 2:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ret = LCD_SETFSDEL;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case 3:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ret = LCD_SETFSDFLT;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> default:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> default:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> tout--;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (tout == 0)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> loopmenu = false;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> delay(100);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdDispMenuSel(sel);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> return ret;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Execute UI/Menu - select light switch schedule setup option.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">int execSetLsMenu()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int sel = 0;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> boolean loopmenu = true;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int tout = MENUOUT;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int ret = LCD_SHOWSTATUS;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.clear(); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,0);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print("Show Light Schedule");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,1);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print("Add Lite OnOff Time");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,2);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print("Del. Light Schedule"); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,3);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print("Set Default");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(MAXCOL-1,sel);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print('<');</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> while (loopmenu)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int selbtn = BTN_NONE;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if ((selbtn = readButtons()) != BTN_NONE)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> switch (selbtn)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case BTN_SEL:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> tout = MENUOUT;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> sel++;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (sel > 3)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> sel = 0;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case BTN_SET:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> loopmenu = false;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> switch (sel)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case 0:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ret = LCD_SHOWLS;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case 1:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ret = LCD_SETLSADD;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case 2:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ret = LCD_SETLSDEL;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case 3:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ret = LCD_SETLSDFLT;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> default:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> default:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> tout--;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (tout == 0)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> loopmenu = false;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> delay(100);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdDispMenuSel(sel);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> return ret;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Execute UI/Menu - select setup option.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">int execMainMenu()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int sel = 1;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> boolean loopmenu = true;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int tout = MENUOUT;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int ret = LCD_SHOWSTATUS;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.clear(); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,0);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print("Setup:");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,1);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print("Date/Time");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,2);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print("Feeding Schedule");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,3);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print("Light Schedule");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(MAXCOL-1,sel);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print('<');</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> while (loopmenu)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int selbtn = BTN_NONE;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if ((selbtn = readButtons()) != BTN_NONE)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> switch (selbtn)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case BTN_SEL:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> tout = MENUOUT;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> sel++;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (sel > 3)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> sel = 1;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case BTN_SET:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> loopmenu = false;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> switch (sel)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case 1:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ret = LCD_SETDTMENU;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case 2:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ret = LCD_SETFSMENU;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case 3:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ret = LCD_SETLSMENU;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> default:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> default:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> tout--;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (tout == 0)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> loopmenu = false;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> delay(100);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdDispMenuSel(sel);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> return ret;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Execute UI/Menu - set the date/time (Real Time Clock).</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">int execSetDtMenu()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int ret = LCD_SHOWSTATUS;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int setYear = 2013;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int setMonth = 12;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int setDay = 7;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int setHour = 0;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int setMinute = 0;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> timeNow = RTC.now();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> setYear = timeNow.year(); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> setMonth = timeNow.month();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> setDay = timeNow.day();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> setHour = timeNow.hour();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> setMinute = timeNow.minute();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.clear(); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,0);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print("Year:");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,1);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print(setYear);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> setYear = setNumberMenu(setYear, 2014, 2100, 1, 20);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.clear(); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,0);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print("Month:");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,1);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print(setMonth);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> setMonth = setNumberMenu(setMonth, 1, 12, 1, 20);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> //lcd.clear(); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,2);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print("Day:");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,3);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print(setDay);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> setDay = setNumberMenu(setDay, 1, 31, 3, 20);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.clear(); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,0);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print("Hour:");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,1);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print(setHour);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> setHour = setNumberMenu(setHour, 0, 23, 1, 20);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> //lcd.clear(); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,2);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print("Minute:");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,3);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print(setMinute);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> setMinute = setNumberMenu(setMinute, 0, 59, 3, 20);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> RTC.adjust(DateTime(setYear, setMonth, setDay, setHour, setMinute, 0)); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> return ret;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// LCD - display marker '<' next to the currently selected menu item.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">void lcdDispMenuSel(int sel)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> for (int i=0; i<MAXROW; i++)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(MAXCOL-1, i);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (i == sel)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print('<');</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> else</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print(' ');</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Determine if/which button is pressed (and released).</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// NOTE: Button must be released after it is pressed in order to proceed.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">int readButtons()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int ret = BTN_NONE;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (digitalRead(BTNSEL) == LOW)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> while(digitalRead(BTNSEL) == LOW);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ret = BTN_SEL;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> else if (digitalRead(BTNSET) == LOW)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> while(digitalRead(BTNSET) == LOW);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ret = BTN_SET;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> return ret;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Clear row on the lcd display and position the cursor at the start of the row.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">void lcdClearRow(unsigned int row)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> String clr = String(" ");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> clr.substring(0,MAXCOL);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,row);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print(clr);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> /* this loop seems a bit slower than above code</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> for(int i=0; i<MAXCOL; i++)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print(' ');</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> */</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,row);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Interpret command - serial port interface, this is a separate means of</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// communicating with device, apart from buttons/LCD.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">void interpretCommand()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (cmdReady)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int err = 0;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> String memCmd;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#ifdef MYDEBUG0</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print("DBG: command=\"");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print(cmd);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.println("\"");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#endif </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> cmdCode = getCmdCode();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> cmdReady = false;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> memCmd = cmd;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> cmd = "";</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> switch (cmdCode) {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case CMD_DATE:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> serialWriteDTNow();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case CMD_TEMP:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (bTempRead) </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> serialConvWriteTemp();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> else </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> err = ERR_TEMPRD;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case CMD_ADDFT:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> err = serialAddFeedingSchedule(memCmd);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case CMD_SHOWFS:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> serialShowFeedingSchedule();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdShowFeedingSchedule(); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case CMD_DELFT:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> serialDeleteFeedingSchedule();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case CMD_ADDLS:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> err = serialAddLightSchedule(memCmd);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case CMD_SHOWLS:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> serialShowLightSchedule();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdShowLightSchedule();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case CMD_DELLS:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> serialDeleteLightSchedule();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case CMD_SETDT:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> err = serialSetDateTime(memCmd);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case CMD_HELP:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> serialHelp();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break; </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case CMD_DEFFS:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> err = serialDefaultFS();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case CMD_DEFLS:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> err = serialDefaultLS();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> default:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> err = ERR_UNKNCMD;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (0 != err)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print("ERR: #");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.println(err);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print(PROMPT); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Remove current light on/off schedule and replace it with a default one.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">int serialDefaultLS()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int err = ERR_OK;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> String deflscmd;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> strcpy_P(progmembuf, (char*)pgm_read_word(&(cmdTable[CMD_ADDLS])));</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> deflscmd = String(progmembuf) + " 08:30 21:30";</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> serialDeleteLightSchedule();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> err = serialAddLightSchedule(deflscmd);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> return err;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Remove current feeding schedule and replace it with a default one.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">int serialDefaultFS()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int err = ERR_OK;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> String deffscmd;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> strcpy_P(progmembuf, (char*)pgm_read_word(&(cmdTable[CMD_ADDFT]))); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> deffscmd = String(progmembuf) + " 09:00 21:00";</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> serialDeleteFeedingSchedule();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> err = serialAddFeedingSchedule(deffscmd);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> return err; </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Display the list of commands.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">void serialHelp()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> for (int i = 0; i < CMD_NIL; i++)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> strcpy_P(progmembuf, (char*)pgm_read_word(&(cmdTable[i])));</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print(progmembuf);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print(' ');</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> strcpy_P(progmembuf, (char*)pgm_read_word(&(cmdHelp[i])));</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.println(progmembuf);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Process addft command. Add feeding times to food dispenser scheduler.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// addft hh:mm [hh:mm ...]</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">int serialAddFeedingSchedule(String command)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int err = ERR_OK;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int n = 0;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> boolean token = false;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> String argBuf;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> initFsTable(); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> fsLen = loadSavedFS2Table(); // load feeding schedule from EEPROM to lsTable</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> for (int i = 0; i < fsLen && i < FS_MAX; i++, n++)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> fsSched[i].hour = getHourFromTimeEntry(fsTable[i]);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> fsSched[i].minute = getMinuteFromTimeEntry(fsTable[i]);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#ifdef MYDEBUG3</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print("DBG: Loaded ");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print(n);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.println(" entries.");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#endif</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> strcpy_P(progmembuf, (char*)pgm_read_word(&(cmdTable[CMD_ADDFT])));</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> for (int i = strlen(progmembuf); i <= command.length() && ERR_OK == err; i++)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (token && (command.charAt(i) == ' ' || i == command.length()))</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> { </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#ifdef MYDEBUG3</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print("DBG: Adding item #");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print(n);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.println(".");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print("DBG: val=\"");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print(argBuf);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.println("\"");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#endif </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (n < FS_MAX)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (5 == argBuf.length())</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> fsTable[n] = argBuf;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> fsSched[n].hour = getHourFromTimeEntry(argBuf);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> fsSched[n].minute = getMinuteFromTimeEntry(argBuf);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> else</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> err = ERR_FSENTINVFMT;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#ifdef MYDEBUG3</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.println("DBG: Wrong argument format.");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print("DBG: val=\"");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print(argBuf);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.println("\"");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#endif</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> } </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> else</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> err = ERR_TOOMANYFS;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#ifdef MYDEBUG3</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.println("DBG: Too many arguments.");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print("DBG: FS_MAX=");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print(FS_MAX);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.println(".");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#endif </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> token = false;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> argBuf = "";</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> n++;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> else if (command.charAt(i) != ' ')</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (false == token)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> token = true;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (5 > argBuf.length())</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> argBuf = argBuf + command.charAt(i);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> else</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> err = ERR_ARGTOOLONG;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#ifdef MYDEBUG3 </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.println("DBG: Argument too long (>5).");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#endif </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (ERR_OK == err)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> fsLen = n;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> sortFsTables(); // sort feeding schedule numeric tables</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> convFsTblToStringTbl(); // convert fsHoursTbl and fsMinutesTbl to fsTable</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> err = saveFsTable(); // save feeding schedule table to EEPROM </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> return err; </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Read temperature sensor. Turn the temp. warning LED-s on/off.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">void readTemp()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> byte i;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (0 == lastTempRead || timeNow.unixtime() - lastTempRead > TEMP_RD_EVERY * 60)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> bTempRead = false;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // try 2 times</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if ( !ds.search(addr)) {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ds.reset_search();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> delay(250); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if ( !ds.search(addr)) {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ds.reset_search();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> delay(250);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> return;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> } </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> } </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (OneWire::crc8(addr, 7) != addr[7]) {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // Invalid CRC</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> return;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> type_s = determineDSChip();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (2 == type_s) {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // Device is not a DS18x20 family device.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> return; </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> } </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ds.reset();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ds.select(addr);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ds.write(0x44, 1); // start conversion, with parasite power on at the end</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> delay(1000); // maybe 750ms is enough, maybe not</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // we might do a ds.depower() here, but the reset will take care of it.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> present = ds.reset();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ds.select(addr); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ds.write(0xBE); // Read Scratchpad</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> for ( i = 0; i < 9; i++) { // we need 9 bytes</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> data[i] = ds.read();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> bTempRead = true;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lastTempRead = timeNow.unixtime();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // Convert the data to actual temperature</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // because the result is a 16 bit signed integer, it should</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // be stored to an "int16_t" type, which is always 16 bits</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // even when compiled on a 32 bit processor.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int16_t raw = (data[1] << 8) | data[0];</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (type_s) {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> raw = raw << 3; // 9 bit resolution default</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (data[7] == 0x10) {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // "count remain" gives full 12 bit resolution</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> raw = (raw & 0xFFF0) + 12 - data[6];</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> } else {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> byte cfg = (data[4] & 0x60);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // at lower res, the low bits are undefined, so let's zero them</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> //// default is 12 bit resolution, 750 ms conversion time</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> celsius = (float)raw / 16.0;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> fahrenheit = celsius * 1.8 + 32.0;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (fahrenheit < lowtemp)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> digitalWrite(GREENLEDPIN, LOW);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> digitalWrite(REDLEDPIN, HIGH);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> else if (fahrenheit > hitemp)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> digitalWrite(REDLEDPIN, LOW);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> digitalWrite(GREENLEDPIN, HIGH);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> else</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> digitalWrite(REDLEDPIN, HIGH);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> digitalWrite(GREENLEDPIN, HIGH); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> } </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Control light per light on/off scheduler setup.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Scheduler table contains accelerated ON/OFF times.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">void controlLight()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> boolean turnon = true;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (lsLen <= 0)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> flipLightSwitch(false); // there is no light on/off schedule, keep the light off</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> else</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // check the light on/off schedule entries against current time</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> for (int i = 0; i < lsLen; i++)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // check if the current time falls between current and next scheduled times</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if ((lsSched[i].hour == timeNow.hour() && lsSched[i].minute <= timeNow.minute())</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ||</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lsSched[i].hour < timeNow.hour()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ) </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // we are past the currently checked scheduled time, </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // check if we are before the next scheduled time</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (i+1 < lsLen)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // the next schedule exists, check if current time falls before it</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if ((lsSched[i+1].hour == timeNow.hour() && lsSched[i+1].minute > timeNow.minute())</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ||</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lsSched[i+1].hour > timeNow.hour()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ) </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // yes, the current time falls within currently checked period</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> flipLightSwitch(turnon);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> else</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // there is no next schedule, so turn the light ON or OFF accordingly</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> flipLightSwitch(turnon);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> turnon = ((turnon) ? false : true);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Turn the light ON or OFF depending on the argument and current status of</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// the light switch flag.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">void flipLightSwitch(boolean turnon)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (turnon)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (false == lightswitch)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // if the light is OFF, turn it ON, flip the flag</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lightOn();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lightswitch = true;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdbacklt = BACKLTOUT;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.backlight();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> else</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (lightswitch)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // if the light is ON, turn it OFF, flip the flag</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lightOff();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lightswitch = false;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdbacklt = BACKLTOUT;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.backlight(); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> } </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Control food dispenser per feeding schedule setup.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">void controlFoodDisp()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> for (int i = 0; i < fsLen; i++)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (fsSched[i].hour == timeNow.hour() && fsSched[i].minute == timeNow.minute())</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (foodDispTime == 0 || timeNow.unixtime() - foodDispTime > 60)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdbacklt = BACKLTOUT;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.backlight(); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> dispenseFood();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> foodDispTime = timeNow.unixtime();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Get string representation of the next feeding time.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">String getNextFeedingTime()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> String ret = "??:??";</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> boolean found = false;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> for (int i = 0; i < fsLen; i++)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if ((fsSched[i].hour == timeNow.hour() && fsSched[i].minute >= timeNow.minute())</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ||</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> (fsSched[i].hour > timeNow.hour())</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> )</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ret = fsTable[i];</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> found = true;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> } </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // not found, perhaps there is one the next day?</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (false == found)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> for (int i = 0; i < fsLen; i++)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if ((fsSched[i].hour == 0 && fsSched[i].minute >= timeNow.minute())</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ||</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> (fsSched[i].hour > 0)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> )</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ret = fsTable[i];</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> } </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> return ret;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Get string representation of the next light switch time.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">String getNextLightSwitchTime()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> String ret = "??:??";</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> boolean found = false;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> for (int i = 0; i < lsLen; i++)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if ((lsSched[i].hour == timeNow.hour() && lsSched[i].minute >= timeNow.minute())</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ||</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> (lsSched[i].hour > timeNow.hour())</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> )</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ret = lsTable[i];</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> found = true;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> } </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // not found, perhaps there is one the next day?</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (false == found)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> for (int i = 0; i < lsLen; i++)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if ((lsSched[i].hour == 0 && lsSched[i].minute >= timeNow.minute())</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ||</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> (lsSched[i].hour > 0)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> )</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ret = lsTable[i];</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> } </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> return ret;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Send light on/off schedule to serial line.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">void serialShowLightSchedule()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> boolean turnon = true;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> initLsTable();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lsLen = loadSavedLS2Table();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> for (int i = 0; i < lsLen && i < LS_MAX; i++)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lsSched[i].hour = getHourFromTimeEntry(lsTable[i]);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lsSched[i].minute = getMinuteFromTimeEntry(lsTable[i]);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print(lsTable[i]);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print(" ");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.println(((turnon) ? "ON" : "OFF"));</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> turnon = ((turnon) ? false : true);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (false == turnon)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.println("! Missing OFF time.");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Show light on/off schedule on LCD.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">void lcdShowLightSchedule()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> boolean turnon = true;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int row = 1;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> initLsTable();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lsLen = loadSavedLS2Table();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.clear();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,0);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> //lcd.print("Light schedule:");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> //lcd.setCursor(0,1);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> for (int i = 0; i < lsLen && i < LS_MAX; i++)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lsSched[i].hour = getHourFromTimeEntry(lsTable[i]);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lsSched[i].minute = getMinuteFromTimeEntry(lsTable[i]);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print(lsTable[i]);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print(' ');</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print(((turnon) ? "ON" : "OFF"));</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print(' ');</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> turnon = ((turnon) ? false : true);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (i < lsLen-1 && (i+1)%2 == 0)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,row++);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (false == turnon)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // this is just a remainder to enter matching OFF time</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // nothing to worry about</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,3);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print("! Missing OFF time.");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdstate = LCD_SHOWLS;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdupdate = SHOWLSOUT;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Send feeding schedule to serial line.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">void serialShowFeedingSchedule()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> initFsTable();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> fsLen = loadSavedFS2Table();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> for (int i = 0; i < fsLen && i < FS_MAX; i++)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> fsSched[i].hour = getHourFromTimeEntry(fsTable[i]);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> fsSched[i].minute = getMinuteFromTimeEntry(fsTable[i]);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.println(fsTable[i]);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Send feeding schedule to lcd.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">void lcdShowFeedingSchedule()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int row = 2;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> initFsTable();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> fsLen = loadSavedFS2Table();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.clear();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,0);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print("Feeding schedule:");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,1);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> for (int i = 0; i < fsLen && i < FS_MAX; i++)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> fsSched[i].hour = getHourFromTimeEntry(fsTable[i]);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> fsSched[i].minute = getMinuteFromTimeEntry(fsTable[i]);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print(fsTable[i]);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print(' ');</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if ((i+1)%3 == 0)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.setCursor(0,row++);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdstate = LCD_SHOWFS;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdupdate = SHOWFSOUT;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Initialize light on/off schedule tables.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">void initLsTable()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> for (int i = 0; i < LS_MAX; i++)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lsTable[i] = "";</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lsSched[i].hour = 0;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lsSched[i].minute = 0;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Initialize feeding schedule tables.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">void initFsTable()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> for (int i = 0; i < FS_MAX; i++)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> fsTable[i] = "";</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> fsSched[i].hour = 0;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> fsSched[i].minute = 0;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Delete entire light on/off schedule.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">void serialDeleteLightSchedule()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int addr = 0;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> while (addr < LS_LEN * LS_MAX)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> EEPROM.write(addr++, 0);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lsLen = -1;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Delete entire feeding schedule.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">void serialDeleteFeedingSchedule()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int addr = LS_LEN * LS_MAX;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> while (addr < LS_LEN * LS_MAX + FS_LEN * FS_MAX)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> EEPROM.write(addr++, 0);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> fsLen = -1;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Parse/interpret addls command, add times to light on/off schedule.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// addls hh:mm [hh:mm ...]</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">int serialAddLightSchedule(String command)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int err = ERR_OK;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int n = 0;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> boolean token = false;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> String argBuf;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> initLsTable(); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lsLen = loadSavedLS2Table(); // load light on/off schedule from EEPROM to lsTable</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> for (int i = 0; i < lsLen && i < LS_MAX; i++, n++)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lsSched[i].hour = getHourFromTimeEntry(lsTable[i]);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lsSched[i].minute = getMinuteFromTimeEntry(lsTable[i]);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#ifdef MYDEBUG2</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print("DBG: Loaded ");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print(n);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.println(" entries.");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#endif</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> strcpy_P(progmembuf, (char*)pgm_read_word(&(cmdTable[CMD_ADDLS])));</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> for (int i = strlen(progmembuf); i <= command.length() && ERR_OK == err; i++)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (token && (command.charAt(i) == ' ' || i == command.length()))</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> { </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#ifdef MYDEBUG2</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print("DBG: Adding item #");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print(n);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.println(".");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print("DBG: val=\"");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print(argBuf);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.println("\"");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#endif </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (n < LS_MAX)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (5 == argBuf.length())</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lsTable[n] = argBuf;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lsSched[n].hour = getHourFromTimeEntry(argBuf);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lsSched[n].minute = getMinuteFromTimeEntry(argBuf);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> else</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> err = ERR_LSENTINVFMT;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#ifdef MYDEBUG2</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.println("DBG: Wrong argument format.");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print("DBG: val=\"");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print(argBuf);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.println("\"");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#endif</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> } </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> else</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> err = ERR_TOOMANYLS;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#ifdef MYDEBUG2</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.println("DBG: Too many arguments.");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print("DBG: LS_MAX=");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print(LS_MAX);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.println(".");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#endif </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> token = false;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> argBuf = "";</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> n++;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> else if (command.charAt(i) != ' ')</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (false == token)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> token = true;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (5 > argBuf.length())</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> argBuf = argBuf + command.charAt(i);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> else</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> err = ERR_ARGTOOLONG;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#ifdef MYDEBUG2 </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.println("DBG: Argument too long (>5).");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#endif </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (ERR_OK == err)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lsLen = n;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> sortLsTables(); // sort light on/off schedule numeric tables</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> convLsTblToStringTbl(); // convert lsHoursTbl and LsMinutesTbl to lsTable</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> err = saveLsTable(); // save light on/off schedule table to EEPROM </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> return err;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Save schedule to EEPROM.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">int saveSchedule(String tbl[], </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int startaddr, </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int endaddr,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int numofentries,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int arglen,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int rangeerr, </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int fmterr)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int err = ERR_OK;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int addr = 0;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> addr = startaddr;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> for (int i = 0; i < numofentries && ERR_OK == err; i++)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (arglen == tbl[i].length())</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> for (int j = 0; j < tbl[i].length(); j++)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (addr < endaddr)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> EEPROM.write(addr++, tbl[i].charAt(j));</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> else</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> err = rangeerr; // too many entries, exceeds alloted EEPROM space</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#ifdef MYDEBUG1</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print("DBG: Saving table, address out of range: ");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print(addr);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.println(".");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#endif</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> EEPROM.write(addr++, 0);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> else</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> err = fmterr; // invalid entry format</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#ifdef MYDEBUG1</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print("DBG: Saving table, invalid format, value=\"");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print(tbl[i]);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.println("\"");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#endif</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break; </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> } </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> return err; </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Save light on/off schedule table to EEPROM.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">int saveLsTable()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int err = ERR_OK;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // light on/off schedule is saved after temperature log. </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> err = saveSchedule(lsTable, </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> 0, </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> LS_LEN*LS_MAX,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lsLen,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> 5,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ERR_LSEEPROMOOR, </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ERR_LSENTINVFMT); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> return err;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Save feeding schedule table to EEPROM.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">int saveFsTable()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int err = ERR_OK;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int addr = 0;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // Feeding schedule is saved after temperature log and light on/off schedule. </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> err = saveSchedule(fsTable, </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> LS_LEN*LS_MAX, </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> LS_LEN*LS_MAX+FS_LEN*FS_MAX,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> fsLen,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> 5,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ERR_FSEEPROMOOR, </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ERR_FSENTINVFMT); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> return err;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Convert lsHoursTbl and LsMinutesTbl to lsTable.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">void convLsTblToStringTbl()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> char txtbuf[6];</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> for (int i = 0; i < lsLen; i++)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> sprintf(txtbuf, "%02d:%02d\0", lsSched[i].hour, lsSched[i].minute);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lsTable[i] = String(txtbuf);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#ifdef MYDEBUG0</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print("DBG: lsSched[");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print(i);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print("].hour=");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.println(lsSched[i].hour);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print("DBG: lsSched[");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print(i);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print("].minute=");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.println(lsSched[i].minute);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print("DBG: txtbuf=\"");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print(txtbuf);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.println("\"");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print("DBG: lsTable[");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print(i);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print("]=\"");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print(lsTable[i]);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.println("\"");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#endif </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Convert fsHoursTbl and fsMinutesTbl to fsTable.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">void convFsTblToStringTbl()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> char txtbuf[6];</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> for (int i = 0; i < fsLen; i++)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> sprintf(txtbuf, "%02d:%02d\0", fsSched[i].hour, fsSched[i].minute);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> fsTable[i] = String(txtbuf);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#ifdef MYDEBUG3</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print("DBG: fsSched[");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print(i);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print("].hour=");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.println(fsSched[i].hour);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print("DBG: fsSched[");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print(i);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print("].minute=");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.println(fsSched[i].minute);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print("DBG: txtbuf=\"");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print(txtbuf);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.println("\"");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print("DBG: fsTable[");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print(i);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print("]=\"");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print(fsTable[i]);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.println("\"");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">#endif </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Sort numeric light on/off schedule tables.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">void sortLsTables()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int tmp;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int v1, v2;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> for (int i = 0; i < lsLen - 1; i++)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> for (int j = i + 1; j < lsLen; j++)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> v1 = lsSched[j].hour*100 + lsSched[j].minute;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> v2 = lsSched[i].hour*100 + lsSched[i].minute;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (v1 < v2)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> tmp = lsSched[i].hour;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lsSched[i].hour = lsSched[j].hour;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lsSched[j].hour = tmp;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> tmp = lsSched[i].minute;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lsSched[i].minute = lsSched[j].minute;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lsSched[j].minute = tmp;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Sort numeric feeding schedule tables.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">void sortFsTables()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int tmp;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int v1, v2;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> for (int i = 0; i < fsLen - 1; i++)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> for (int j = i + 1; j < fsLen; j++)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> v1 = fsSched[j].hour*100 + fsSched[j].minute;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> v2 = fsSched[i].hour*100 + fsSched[i].minute;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (v1 < v2)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> tmp = fsSched[i].hour;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> fsSched[i].hour = fsSched[j].hour;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> fsSched[j].hour = tmp;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> tmp = fsSched[i].minute;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> fsSched[i].minute = fsSched[j].minute;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> fsSched[j].minute = tmp;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Convert hour part of light on/off schedule entry in String format to integer.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">int getHourFromTimeEntry(String timestr)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> String hr;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> hr = timestr.substring(0, timestr.indexOf(':'));</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> return hr.toInt();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Convert minute part of light on/off schedule entry in String format to </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// integer.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">int getMinuteFromTimeEntry(String timestr)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> String mn;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> mn = timestr.substring(timestr.indexOf(':')+1);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> return mn.toInt();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Load saved schedule from EEPROM to lsTable or fsTable as pointed by lsfs</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// argument.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">int loadSavedSchedule(int startaddr,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int endaddr,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int arglen,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int maxitems,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> boolean lsfs // true - ls, false - fs</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> )</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int n = 0, l = 0, addr = 0;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> char val, prev = 0;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int ret = -1;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> boolean noerr = true;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> addr = startaddr;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> while (addr < endaddr && n < maxitems)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> val = EEPROM.read(addr++);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (0 != val)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (arglen > l)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (lsfs)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lsTable[n] += val;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> else</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> fsTable[n] += val;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> l++;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> else</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // error, each entry should be only <arglen> characters long</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> noerr = false;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> else</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (prev == 0)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break; // two zeroes in a row - the end of setup in EEPROM</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> n++;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> l = 0;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> prev = val;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (noerr)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ret = n;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> return ret; </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">} </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Load light on/off schedule from EEPROM to lsTable.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">int loadSavedLS2Table()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int ret = -1;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // light on/off schedule is saved after temperature log </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ret = loadSavedSchedule(0,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> LS_LEN*LS_MAX,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> 5,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> LS_MAX,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> true); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> return ret;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Load feeding schedule from EEPROM to lsTable.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">int loadSavedFS2Table()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int ret = -1;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // feeding schedule is saved after temperature log and light on/off schedule. </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ret = loadSavedSchedule(LS_LEN*LS_MAX,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> LS_LEN*LS_MAX+FS_LEN*FS_MAX,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> 5,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> FS_MAX,</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> false); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> return ret;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Parse/interpret setdt command, set RTC date/time.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// setdt YYYY MM DD hh mm</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">int serialSetDateTime(String command)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int err = ERR_OK;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> char numBuf[5];</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int setYear = 2013;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int setMonth = 12;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int setDay = 7;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int setHour = 0;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int setMinute = 0;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> boolean token = false;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int argnum = 0, n = 0;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> timeNow = RTC.now();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> setYear = timeNow.year(); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> setMonth = timeNow.month();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> setDay = timeNow.day();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> setHour = timeNow.hour();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> setMinute = timeNow.minute();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> for (n = 0; n < 5; n++) </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> numBuf[n] = 0;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> strcpy_P(progmembuf, (char*)pgm_read_word(&(cmdTable[CMD_SETDT])));</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> for (int i = strlen(progmembuf), n = 0; i <= command.length() && ERR_OK == err; i++)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (token && (command.charAt(i) == ' ' || i == command.length()))</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> argnum++;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (n < 5)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> numBuf[n] = 0;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> else</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> err = ERR_ARGTOOLONG;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> switch (argnum)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case 1:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> setYear = atoi(numBuf);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case 2:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> setMonth = atoi(numBuf);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case 3:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> setDay = atoi(numBuf);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case 4:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> setHour = atoi(numBuf);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case 5:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> setMinute = atoi(numBuf);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> default:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> err = ERR_TOOMANYARGS;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> token = false;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> for (n = 0; n < 5; n++)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> numBuf[n] = 0;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> n = 0;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> else if (command.charAt(i) != ' ')</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (false == token)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> token = true;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (n < 4)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> numBuf[n++] = command.charAt(i);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> else</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> err = ERR_ARGTOOLONG;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (ERR_OK == err)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> RTC.adjust(DateTime(setYear, setMonth, setDay, setHour, setMinute, 0));</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> return err;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Interpret command string, return command code.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Works best if all commands are CMDL-characters long.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">int getCmdCode()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> int ret = -1;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> char buf[6] = {0,0,0,0,0,0};</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> cmd.toCharArray(buf, 5);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> for (byte i = 0; i < CMD_NIL; i++)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> memset(progmembuf,'\0',sizeof(progmembuf));</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> strcpy_P(progmembuf, (char*)pgm_read_word(&(cmdTable[i])));</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (0 == strncmp(progmembuf, buf, CMDL))</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ret = i;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> return ret;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Send date/time to serial line.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">void serialWriteDTNow()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> strcpy_P(progmembuf, (char*)pgm_read_word(&(daysOfWeek[timeNow.dayOfWeek()])));</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print(progmembuf);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print(' '); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print(timeNow.year());</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print('/');</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (timeNow.month() < 10)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print('0');</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print(timeNow.month());</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print('/');</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (timeNow.day() < 10)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print('0'); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print(timeNow.day());</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print(' ');</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (timeNow.hour() < 10)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print('0'); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print(timeNow.hour());</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print(':');</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (timeNow.minute() < 10)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print('0'); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print(timeNow.minute());</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.println(); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Send date/time to lcd.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">void lcdWriteDTNow()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdClearRow(DTROW);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> strcpy_P(progmembuf, (char*)pgm_read_word(&(daysOfWeek[timeNow.dayOfWeek()])));</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print(progmembuf);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print(' '); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print(timeNow.year());</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print('/');</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (timeNow.month() < 10)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print('0');</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print(timeNow.month());</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print('/');</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (timeNow.day() < 10)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print('0'); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print(timeNow.day());</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print(' ');</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (timeNow.hour() < 10)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print('0'); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print(timeNow.hour());</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print(':');</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (timeNow.minute() < 10)</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print('0'); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print(timeNow.minute());</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Send temperature readings in human readable form to serial line.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">void serialConvWriteTemp()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print("T = ");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> dtostrf(celsius, 8, 2, textbuf);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print(textbuf);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print(" C, ");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> dtostrf(fahrenheit, 8, 2, textbuf);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.print(textbuf);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.println(" F"); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Display temperature readings in human readable form on a LCD.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">void lcdConvWriteTemp()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcdClearRow(TEMPROW);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> dtostrf(celsius, 8, 2, textbuf);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print('T');</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print(textbuf);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print("C ");</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> dtostrf(fahrenheit, 8, 2, textbuf);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print(textbuf);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> lcd.print("F"); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// DS temperature sensor chip type determination.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">byte determineDSChip()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> byte ret = 2;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // the first ROM byte indicates which chip</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> switch (addr[0]) {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case 0x10:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // Chip = DS18S20 or old DS1820</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ret = 1;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case 0x28:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // Chip = DS18B20</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ret = 0;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> case 0x22:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // Chip = DS1822</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> ret = 0;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> default:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // Device is not a DS18x20 family device.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> break;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> } </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> return ret;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Turn the light on.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">void lightOn()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> digitalWrite(LIGHTPIN, HIGH);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Turn the light off.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">void lightOff()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> digitalWrite(LIGHTPIN, LOW);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// Run food dispenser. Perform fool 360 deg. revolution and some (1/8) </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// of the stepper motor.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// During this time, the serial console to the controller will be unresponsive.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">void dispenseFood()</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Steps2Take = STEPS_PER_OUTPUT_REVOLUTION + STEPS_PER_OUTPUT_REVOLUTION/8;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> small_stepper.setSpeed(250);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> small_stepper.step(Steps2Take);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// -----------------------------------------------------------------------------</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">/*</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> * SerialEvent occurs whenever a new data comes in the</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> * hardware serial RX. This routine is run between each</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> * time loop() runs, so using delay inside loop can delay</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> * response. Multiple bytes of data may be available.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> * Here it is used to read user input via serial port/USB.</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> */</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">// ----------------------------------------------------------------------------- </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">void serialEvent() </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">{</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> while (Serial.available()) {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // get the new byte:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> char inChar = (char)Serial.read(); </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // send echo</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.write(inChar);</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // add it to the command string</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> if (inChar != '\r')</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> cmdTmp += inChar;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // if the incoming character is a newline, set a flag</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // so the main loop can do something about it:</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> // if (inChar == '\r') {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> else {</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> cmd = cmdTmp;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> cmdTmp = "";</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> Serial.println();</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> cmdReady = true;</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> } </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"> }</span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;">}</span></span></div>
<div style="margin-bottom: 0in;">
<span style="background-color: white; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="background-color: white;">Note that I used software I2C for the LCD panel to avoid any potential issues/conflicts between RTC and LCD modules if ran on the same I2C bus. The bit-banged i2c works quite well, however it is a little slower than the one provided by Arduino. It can however be used with long wires, which may allow some flexibility in mounting LCD module away from the main unit, if needed. The software controlled bus does not require pull-up resistors with the short connection, but I did not test it with the long wires.</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="background-color: white;">Because I used the sotware i2c, I had to make a copy of original LiquidCrystal_I2C library, renamed LCD_I2C_BB, which uses SoftI2CMaster library code for i2c communication.</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="background-color: white;"><br /></span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="background-color: white;">The archive of the entire project with updated code and documentation can be downloaded here: <a href="https://onedrive.live.com/redir?resid=1134B9F29C36FE0B%21106" target="_blank">Fish Tank Automation 2</a></span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif; font-size: x-small;"><i>NOTE 9/9/2014: File fishtankautom2.zip contains original documentation and source code of version #2. I recommend downloading fishtankautom3.zip for updated code version #3 (quoted in this article), with bug fixes and temperature log (eeprom) code removed. The documentation is only in fishtankautom2.zip archive for now, but it is mostly accurate. Pictures below were made while running version #2 of the firmware, however there are only cosmetic differences between versions #2 and #3 as far as UI is concerned.</i></span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">Pictures of the prototype:</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYb3YzEiyKJZtvgoC2ks4w_1VLDRZadLud9kNv8xjVWkOkPinBMisv2TPn3nP1W7VEBtp03xvO9r6vCYJtmRV2xIPeDgzPFHu9xPdU4LHQJ28rowE4yeZ9SM6gHgI1-I5aCwRbUtLphbrf/s1600/IMG_2003.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhYb3YzEiyKJZtvgoC2ks4w_1VLDRZadLud9kNv8xjVWkOkPinBMisv2TPn3nP1W7VEBtp03xvO9r6vCYJtmRV2xIPeDgzPFHu9xPdU4LHQJ28rowE4yeZ9SM6gHgI1-I5aCwRbUtLphbrf/s1600/IMG_2003.JPG" height="480" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8hzL2Z2x9qyqtxDzeRbtpp8E2QSIoUSGDUlpS4Zd2t7PV-XCmMfxTKWRkwxbJFl5w4j_JO1Bh-IbsWfZAYks_o094gwnVwZ0hOv8-YVcPZQc9zdh7ufxMCeOpuDHcklInG2UWG78wOgwN/s1600/IMG_2007.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8hzL2Z2x9qyqtxDzeRbtpp8E2QSIoUSGDUlpS4Zd2t7PV-XCmMfxTKWRkwxbJFl5w4j_JO1Bh-IbsWfZAYks_o094gwnVwZ0hOv8-YVcPZQc9zdh7ufxMCeOpuDHcklInG2UWG78wOgwN/s1600/IMG_2007.JPG" height="480" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnEv1q-JvYRTcWuZ2-NyYzK-z9SAEIG_f7TJngGwv403HxS0El6Euz-00oXGeaKTWdWBvdLB7IhLig15bcovkPhWVNOEHgC83HDLCpX-EL_APZiZUTtQyuqRH-zjk5xsN1w7RX_vLhQDKC/s1600/IMG_2008.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgnEv1q-JvYRTcWuZ2-NyYzK-z9SAEIG_f7TJngGwv403HxS0El6Euz-00oXGeaKTWdWBvdLB7IhLig15bcovkPhWVNOEHgC83HDLCpX-EL_APZiZUTtQyuqRH-zjk5xsN1w7RX_vLhQDKC/s1600/IMG_2008.JPG" height="480" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg229jdAdWOBySaGFQC5lDfJofDhZ5AzFkHmC2mQrw0y6BKkAkgie5KtnaLJ1vCbKLpeUe47uOyarMmLCdVGMpKaLLwSanyikp0NL3a4hL2-6UCpd-K_2dfwV6wzgRZNR01iqQqlLIdOUGt/s1600/IMG_2009.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg229jdAdWOBySaGFQC5lDfJofDhZ5AzFkHmC2mQrw0y6BKkAkgie5KtnaLJ1vCbKLpeUe47uOyarMmLCdVGMpKaLLwSanyikp0NL3a4hL2-6UCpd-K_2dfwV6wzgRZNR01iqQqlLIdOUGt/s1600/IMG_2009.JPG" height="480" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_mJDU_we5KGm7sKlHbd2DXbzqObuQWMV-Zl0BXFanMSsc9sP5OtTDhnmkqXC3G3BEJG6lcC2z5hIkp34YTQc9SVwQV5c24wT4fy0hL8kKrPbGc16bmM1wi5XsJhpzpdY7i3FCGnnyO21-/s1600/IMG_2011.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_mJDU_we5KGm7sKlHbd2DXbzqObuQWMV-Zl0BXFanMSsc9sP5OtTDhnmkqXC3G3BEJG6lcC2z5hIkp34YTQc9SVwQV5c24wT4fy0hL8kKrPbGc16bmM1wi5XsJhpzpdY7i3FCGnnyO21-/s1600/IMG_2011.JPG" height="480" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZjDf2ShWwVarOOVqktPGyCjZFsuZhv5gU65f_nzHvw0T9qm8S8Po-IzeGrXlsUfzOV6Vu_bPWePNUPrT2hFJL0F4jIxHZExZnZs60_JWR-bHCZCjlP3Ujb7t5EtSytOUAr7BMYC_kb3N9/s1600/IMG_2012.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZjDf2ShWwVarOOVqktPGyCjZFsuZhv5gU65f_nzHvw0T9qm8S8Po-IzeGrXlsUfzOV6Vu_bPWePNUPrT2hFJL0F4jIxHZExZnZs60_JWR-bHCZCjlP3Ujb7t5EtSytOUAr7BMYC_kb3N9/s1600/IMG_2012.JPG" height="640" width="480" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5Kgt9r6_yWQ-qKj8E_y0M-Ys2TmqiK4smRmhcpsQ1DSRFVnCLBx9KWJYqQkb9GQV5TiP28yUI6nYxwqjVnBaKWGL8Qo6GS-5V0z8AV7bzWkXbfQSxO_BYtLqndtUg_qmnn06N4-p9TCHR/s1600/IMG_2015.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh5Kgt9r6_yWQ-qKj8E_y0M-Ys2TmqiK4smRmhcpsQ1DSRFVnCLBx9KWJYqQkb9GQV5TiP28yUI6nYxwqjVnBaKWGL8Qo6GS-5V0z8AV7bzWkXbfQSxO_BYtLqndtUg_qmnn06N4-p9TCHR/s1600/IMG_2015.JPG" height="480" width="640" /></a></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">Thank you for your interest.</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">Marek Karcz</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">9/7/2014</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
Marek Karczhttp://www.blogger.com/profile/03281397436610614441noreply@blogger.com0tag:blogger.com,1999:blog-4155387638169532413.post-88571908837155287302014-05-11T16:57:00.002-07:002015-10-11T22:06:05.072-07:00Update on MKHBC-8-R1.<span style="font-family: Verdana, sans-serif;">I am pleased to say, that I finished soldering of the CPU card. The work is not done yet though. I need to check all the connections with a multimeter (just by the visual inspection I found one mistake, who knows how many may there be), populate the board's IC sockets with the chips, create a small test circuit (some LED-s I guess, perhaps I'll breadbin the UART again and connect to the MKHBC via serial port), power switch etc., write a test program and test if it works. By looking at the mess of wires on the bottom side of the board, I'd say it will be a miracle if it does work at the 1st try, but I am in my optimistic mood, so I hope it will go just fine.</span><span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">I added the memory configuration jumper (K1) to the board that wasn't there before (it was on the circuit diagram, I just totally forgot about it when designing layout of the PCB, so there we go):</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3uA4YrDxsqhUnh7uJuv3D_K7ZKIk1Fs8U71L1pmZ5xj-Bv5VEaSTptzIvswQSOVb7NVgd28jw4WVX0N1xDpbLfZI_svYraSPWyJ1xrTdq7_L0Ov2SlZsVq0s5RytaCjSRLdNsVBTS_nCi/s1600/mkhbc-8-r1-cpu_complayout.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="498" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3uA4YrDxsqhUnh7uJuv3D_K7ZKIk1Fs8U71L1pmZ5xj-Bv5VEaSTptzIvswQSOVb7NVgd28jw4WVX0N1xDpbLfZI_svYraSPWyJ1xrTdq7_L0Ov2SlZsVq0s5RytaCjSRLdNsVBTS_nCi/s1600/mkhbc-8-r1-cpu_complayout.jpg" width="640" /></a></div>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">J5 is a clock speed selector (1 or 2 MHz) and K1 is a memory configuration selector for a future video card.</span><br />
<span style="font-family: Verdana, sans-serif;">It took me quite some time today to solder the remaining connections and I am tired and my back hurts, so I am postponing the work on the project to some later time (hopefully much shorter that 6 months like I did the last time, more like in the next few weeks or so at most).</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">Thank you for visiting my blog.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">5/11/2014</span><br />
<span style="font-family: Verdana, sans-serif;">Marek Karcz</span>Marek Karczhttp://www.blogger.com/profile/03281397436610614441noreply@blogger.com0tag:blogger.com,1999:blog-4155387638169532413.post-49024232386005224762014-01-01T18:33:00.000-08:002014-01-02T19:34:02.306-08:00Fish Tank Automation with Arduino Uno.<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="color: #20124d;">I have
a 10 gallon fish tank. I always face the same dillema when I travel
for longer than 2 days - who will feed my fish? Who will turn the
light on and off? I had a mechanical light timer lying around and I
bought battery powered Automatic Fish Feeder by Aqua Culture in
Walmart. It was simple and relatively reliable. But something was
missing. I thought about it for a while (few seconds) and I knew -
this was an ideal micro controller project!</span></span></div>
<div style="margin-bottom: 0in;">
<span style="color: #20124d;"><br />
</span></div>
<div style="margin-bottom: 0in;">
<span style="color: #20124d; font-family: Verdana, sans-serif;">OK, so
I already had an Arduino Uno in my parts stash. To control light, I
needed a relay, which I also already had - a Radio Shack's SPDT
Micromini 5VDC Relay, rated 1A at 120AC/24VDC. However to control the
feeding drum, I needed a precise electric motor or a servo. After
some consideration I decided on a stepper motor. Quick research on
the internet and then on e-bay resulted in me buying a cheap stepper
motor with a controller (actually it was a 2-pack) with specs that
fit the requirements for my project - <span style="font-size: small;">2pcs
DC 5V Stepper Motor + ULN2003 Driver Test Module Board from a seller
called "goldpart".</span></span></div>
<div style="margin-bottom: 0in;">
<span style="color: #20124d; font-family: Verdana, sans-serif;">Next
thing I needed was a proper time keeping facility so I would be able
to create a precise schedule of feeding and tank's light on/off
switching.</span></div>
<div style="margin-bottom: 0in;">
<span style="color: #20124d; font-family: Verdana, sans-serif;">I
already had a DS1307 based real-time clock I2C module, which I used
previously with my Arduino Clock project, ideal for this purpose.</span></div>
<div style="margin-bottom: 0in;">
<span style="color: #20124d; font-family: Verdana, sans-serif;">Since
I have some one-wire temperature sensors lying around as well
(DS18B20), as a bonus I decided to add water temperature logging to
my project.</span></div>
<div style="margin-bottom: 0in;">
<span style="color: #20124d;"><br />
</span></div>
<div style="margin-bottom: 0in;">
<span style="color: #20124d; font-family: Verdana, sans-serif;">There
is enough information on the internet regarding stepper motor and
ULN2003 driver for anyone who wants to research the stepper motor
control in detail. For the stepper motor control I used library
written by someone else. The library and how to code to control the
particular stepper motor I bought can be found here:
</span><span style="font-family: Verdana, sans-serif;"><span style="color: blue; font-size: small;"><u><a href="http://arduino-info.wikispaces.com/SmallSteppers">http://arduino-info.wikispaces.com/SmallSteppers</a></u></span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="color: #20124d; font-size: small;">How
to use the one-wire temp. sensor is also well documented:
</span><span style="color: blue; font-size: small;"><u><a href="http://www.pjrc.com/teensy/td_libs_OneWire.html">http://www.pjrc.com/teensy/td_libs_OneWire.html</a></u></span></span></div>
<div style="margin-bottom: 0in;">
<span style="color: #20124d;"><br />
</span></div>
<br />
<div style="margin-bottom: 0in;">
<span style="color: #20124d; font-family: Verdana, sans-serif;">Here
is the hand-drawn schematic of my circuit:</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiMV_TVKh97VRFlT85zsjjR1omNhXVlDgyy8pKabGo5-8tIZxue5MksnK70jusZO1EfFqIBkYGsHgqrNYK2eAZ14SxoZ9fl6FRww5EJLxh4z7IVoiL-udyywaQBpe-SuElgGcedQRip1iYR/s1600/FishTankAutomSch.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiMV_TVKh97VRFlT85zsjjR1omNhXVlDgyy8pKabGo5-8tIZxue5MksnK70jusZO1EfFqIBkYGsHgqrNYK2eAZ14SxoZ9fl6FRww5EJLxh4z7IVoiL-udyywaQBpe-SuElgGcedQRip1iYR/s1600/FishTankAutomSch.jpg" height="460" width="640" /></a></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div style="margin-bottom: 0in;">
<span style="color: #20124d; font-family: Verdana, sans-serif;">I
started with the prototype of an electric circuit so I could write
and test the code. The electric circuit was an easy part since it
just required a small breadboard, some wires, power supply and LED to
emulate the fish tank's light. Incorporating the stepper motor into
the Automatic Fish Feeder was a bit more challenging. I achieved it
by removing the battery powered clock mechanism from it, cutting a
square portion of the case on the back away so the motor would be
fitted inside, putting the stepper motor inside (and fitting its axle
into the socket/hole in the center of the feeding drum) and then
reinforcing the case with a few pieces of plastic and metal and
screws (due to the part that was cut away, the case would not hold
together). The result is presented on the pictures at the end of the
article. It is not pretty, but it works. I am kind of proud of it
since I am not very talented as far as handcrafting of anything is
involved.</span></div>
<div style="margin-bottom: 0in;">
<span style="color: #20124d;"><br />
</span></div>
<div style="margin-bottom: 0in;">
<span style="color: #20124d; font-family: Verdana, sans-serif;">The
sketch.</span></div>
<div style="margin-bottom: 0in;">
<span style="color: #20124d;"><br />
</span></div>
<div style="margin-bottom: 0in;">
</div>
<div style="margin-bottom: 0in;">
<span style="color: #20124d; font-family: Verdana, sans-serif;">It
would be cool to be able to control this contraption via internet,
but then it would require some more hardware and code. Therefore I
decided to keep it simple as far as user interface goes. I assumed
the device should be controlled via USB/serial port with command line
interface. All the feeding and light on/off scheduling can be setup
by opening a terminal connection to the arduino and issuing commands
with proper arguments. There are commands for setting up and
retrieving time, setting up and displaying feeding and light on/off
schedules etc. Here is the code:</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">/*</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> * Fish tank automation.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> * Created by Marek Karcz 2013. All rights reserved.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> * Free to copy for personal use.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> * </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> * Hardware:</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> *</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> * 1) Arduino Uno</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> * 2) ULN2003 stepper motor driver module.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> * 3) 28BYJ-48 stepper motor (propelling food distribution mechanism).</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> * 4) Food distributing drum.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> * Taken from cheap Walmart fish automated feeder propelled by battery</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> * operated clock.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> * 5) Radio Shack's SPDT Micromini 5VDC Relay (275-0240) - light control.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> * 6) DS18B20 one-wire temperature sensor in water proof casing or coating.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> * Currently the temperature read is only for informational/logging</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> * purpose since my fish tank water heater has its own thermostate.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> * 7) Tiny RTC, I2C module (DS1307 AT24C32).</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> *</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> * Theory of operation:</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> *</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> * The RTC clock will synchronize the scheduled tasks.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> * Scheduler will program the feeding and light on-off times.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> * The feeding drum will be spinned by a stepper motor.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> * The setup will be stored in EEPROM of the RTC clock module or Arduino's EEPROM.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> * The temperature will be logged in Arduino's EEPROM.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> * Device will be programmed via USB/serial port using command line interface.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> *</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> * Credits/copyright acknowledgements/references:</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> *</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> * - The stepper motor code inspired by: </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> * http://arduino-info.wikispaces.com/SmallSteppers</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> * - The Dallas temperature sensor code ripped from: </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> * http://www.pjrc.com/teensy/td_libs_OneWire.html</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> * and refactored.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> */</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#include <avr/pgmspace.h></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#include <EEPROM.h> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#include <Stepper.h></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#include <OneWire.h></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#include <Wire.h></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#include <RTClib.h></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">//#define MYDEBUG0</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">//#define MYDEBUG1</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">//#define MYDEBUG2</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">//#define MYDEBUG3</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">const char *VERSION = "Fish Tank Automation v.1.0.";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Pin definitions.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#define STPMIN1PIN 8</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#define STPMIN2PIN 9</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#define STPMIN3PIN 10</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#define STPMIN4PIN 11</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#define LIGHTPIN 12</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#define DS1820PIN 7 // did not work on pin 13 (because of the LED connected) </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // and on pin 7 works every other time</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// (Number of steps per revolution of INTERNAL motor in 4-step mode)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#define STEPS_PER_MOTOR_REVOLUTION 32 </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// (Steps per OUTPUT SHAFT of gear reduction)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#define STEPS_PER_OUTPUT_REVOLUTION 32 * 64 //2048 </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Calendar definitions.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">prog_char Sun[] PROGMEM = "Sun";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">prog_char Mon[] PROGMEM = "Mon";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">prog_char Tue[] PROGMEM = "Tue";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">prog_char Wed[] PROGMEM = "Wed";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">prog_char Thu[] PROGMEM = "Thu";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">prog_char Fri[] PROGMEM = "Fri";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">prog_char Sat[] PROGMEM = "Sat";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">PROGMEM const char *daysOfWeek[] = {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Sun, Mon, Tue, Wed, Thu, Fri, Sat</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">};</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Error codes</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">enum eErrors {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> ERR_OK = 0,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> ERR_ARGTOOLONG, // 1 : argument too long</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> ERR_TOOMANYARGS, // 2 : too many arguments</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> ERR_TOOMANYLS, // 3 : too many entries in light on/off schedule</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> ERR_LSEEPROMOOR, // 4 : light on/off schedule setup exceeds EEPROM range</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> ERR_LSENTINVFMT, // 5 : invalid entry format (light on/off schedule)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> ERR_TOOMANYFS, // 6 : too many entries in feeding schedule</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> ERR_FSEEPROMOOR, // 7 : feeding schedule setup exceeds EEPROM range</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> ERR_FSENTINVFMT, // 8 : invalid entry format (feeding schedule)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> ERR_UNKNCMD, // 9 : unknown command</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> ERR_TEMPRD, // 10 : temperature sensor read failed</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> ERR_NIL</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">};</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// recognized commands</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">enum eCommands {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> CMD_DATE = 0,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> CMD_TEMP,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> CMD_LTEMP,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> CMD_ADDFT,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> CMD_SHOWFS,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> CMD_DELFT,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> CMD_ADDLS,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> CMD_SHOWLS,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> CMD_DELLS,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> CMD_SETDT,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> CMD_HELP,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> CMD_VER,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> CMD_DEFFS,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> CMD_DEFLS,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> CMD_NIL</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">};</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">PROGMEM prog_char Date[] = "date";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">PROGMEM prog_char Temp[] = "temp";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">PROGMEM prog_char Ltemp[] = "ltemp";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">PROGMEM prog_char Addft[] = "addft";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">PROGMEM prog_char Showfs[] = "showfs";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">PROGMEM prog_char Delft[] = "delft";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">PROGMEM prog_char Addls[] = "addls";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">PROGMEM prog_char Showls[] = "showls";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">PROGMEM prog_char Dells[] = "dells";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">PROGMEM prog_char Setdt[] = "setdt";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">PROGMEM prog_char Help[] = "help";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">PROGMEM prog_char Ver[] = "ver";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">PROGMEM prog_char Deffs[] = "deffs";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">PROGMEM prog_char Defls[] = "defls";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">PROGMEM prog_char Nil[] = "nil";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">PROGMEM const char *cmdTable[] = {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Date, // display date/time</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Temp, // display last temperature read</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Ltemp, // display saved temperature log</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Addft, // add feeding times to feeding schedule</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Showfs, // show feeding schedule</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Delft, // delete feeding schedule</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Addls, // add times to the light on/off schedule</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Showls, // show light on/off schedule</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Dells, // delete light on/off schedule</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Setdt, // set date/time</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Help, // show help</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Ver, // show firmware version</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Deffs, // reset feeding schedule to default (9 AM, 9 PM).</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Defls, // reset light on/off schedule to default (8:30 AM on, 9:30 PM off)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Nil // do not remove, must be at the end</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">};</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Help for commands.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// PROGMEM directive forces these variables into program memory</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// instead of SRAM. Supported types must be used and special API</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// functions to use these variables.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">prog_char hlpstr_0[] PROGMEM = "- disp. D/T";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">prog_char hlpstr_1[] PROGMEM = "- disp. temp.";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">prog_char hlpstr_2[] PROGMEM = "- show temp. log";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">prog_char hlpstr_3[] PROGMEM = "hh:mm [hh:mm ...] - add feed times";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">prog_char hlpstr_4[] PROGMEM = "- show feed sched.";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">prog_char hlpstr_5[] PROGMEM = "- del. feed sched.";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">prog_char hlpstr_6[] PROGMEM = "hh:mm [hh:mm ...] - add light times";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">prog_char hlpstr_7[] PROGMEM = "- show light sched.";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">prog_char hlpstr_8[] PROGMEM = "- del. light sched.";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">prog_char hlpstr_9[] PROGMEM = "Yr Mon Day Hr Min - set D/T";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">prog_char hlpstr_10[] PROGMEM = "- this help screen";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">prog_char hlpstr_11[] PROGMEM = "- show firmware version";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">prog_char hlpstr_12[] PROGMEM = "- set deflt feed sch.";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">prog_char hlpstr_13[] PROGMEM = "- set deflt light sch.";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">prog_char hlpstr_14[] PROGMEM = "nil";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">PROGMEM const char *cmdHelp[] = {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> hlpstr_0,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> hlpstr_1,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> hlpstr_2,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> hlpstr_3,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> hlpstr_4,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> hlpstr_5,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> hlpstr_6,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> hlpstr_7,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> hlpstr_8,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> hlpstr_9,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> hlpstr_10,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> hlpstr_11,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> hlpstr_12,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> hlpstr_13,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> hlpstr_14 </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">};</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// this buffer must accomodate the longest string of hlpstr_N plus</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// terminating NULL.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">char progmembuf[36];</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">const char *PROMPT = "CMD> ";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Stepper motor</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// The pin connections need to be 4 pins connected</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// to Motor Driver In1, In2, In3, In4 and then the pins entered</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// here in the sequence 1-3-2-4 for proper sequencing</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">Stepper small_stepper(STEPS_PER_MOTOR_REVOLUTION, STPMIN1PIN, STPMIN3PIN, STPMIN2PIN, STPMIN4PIN);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Real time clock</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">RTC_DS1307 RTC;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Temperature sensor</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">OneWire ds(DS1820PIN);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// global variables</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">int Steps2Take; // stepper motor</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">char textbuf[10]; // text buffer for temp. conversions</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">boolean cmdReady; // a flag - command is entered</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">String cmdTmp = ""; // temporary string buffer for command</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">String cmd = ""; // command string buffer</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">int cmdCode = -1; // command code</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">long lastTempRead = 0; // the unixtime second of last temperature read</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">boolean bTempRead = false; // if the temp. read was successfull</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// temp. sensor read protocol flags and variables</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">byte present = 0;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">byte type_s;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">byte data[12];</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">byte addr[8];</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">float celsius, fahrenheit;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">DateTime timeNow;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// temperature log</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// note: temp. will be logged to EEPROM in 40 character long entries</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// last 10 readings will be kept in log in following format:</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// HH:MM SCCCCCC.CC SFFFFFF.FF</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// where:</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// HH - hour</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// MM - minute</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// S - sign (- or none)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// C - digits of Celsius temperature value</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// F - digits of Fahrenheit temperature value</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// char templogbuf[40]; // temperature log buffer</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">int logAddr = 0; // current temperature log address</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">int logEntries = 0; // total number of log entries in temp. log</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">int logEntry = 0; // recent log position # in temp. log (round-robin)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// scheduler flags and variables</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Schedule structure</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">struct SchedTbl {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> int hour;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> int minute;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">};</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#define LS_LEN 6 // lenght of the light schedule entry (HH:MM)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#define LS_MAX 8 // maximum number of light on/off schedule entries</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">int lsLen = -1; // the length of light on/off schedule (# of entries)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">String lsTable[LS_MAX]; // the String form of light on/off scheduler, as saved in EEPROM</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">SchedTbl lsSched[LS_MAX]; // numeric table of light on/off scheduler</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">boolean lightswitch = false; // current status of the light switch</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Other definitions</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#define TEMP_RD_EVERY 20 // how often to read temperature (minutes)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#define TEMP_LOG_LEN 25 // how long one temp. log entry</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#define TEMP_LOG_MAX 12 // how many temperature log entries</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#define FS_LEN 6 // length of the feeding schedule entry (HH:MM)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#define FS_MAX 6 // maximum number of feeding schedule entries</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">int fsLen = -1; // the length of food dispensing schedule (# of entries)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">String fsTable[FS_MAX]; // the String form of food disp. scheduler, as saved in EEPROM</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">SchedTbl fsSched[FS_MAX]; // numeric table of food disp scheduler</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">long foodDispTime = 0; // time (seconds) when food last dispensed</span></div>
<div>
</div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Initialization sequence.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">void setup()</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">{</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> cmdReady = false;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.begin(9600); // serial port will be the main mode of communication</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // with the device and programming the light and feeding</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // scheduler</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> pinMode(LIGHTPIN, OUTPUT);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> lightOn();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // power to i2c_ds1307_at24c32 module provided via A2, A3 pins</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // for Uno: A4 = SDA, A5 = SCL</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> pinMode(A3, OUTPUT); </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> digitalWrite(A3, HIGH);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> pinMode(A2, OUTPUT);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> digitalWrite(A2, LOW);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // start communication, I2C and RTC</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Wire.begin();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> RTC.begin();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> ds.reset();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // NOTE: Stepper Library sets pins as outputs</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // Rotate CW 1/8 turn forward and backwards to show the system is working</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Steps2Take = STEPS_PER_OUTPUT_REVOLUTION / 8;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> small_stepper.setSpeed(600); </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> small_stepper.step(Steps2Take);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Steps2Take = - Steps2Take;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> small_stepper.setSpeed(600); // 700 a good max speed??</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> small_stepper.step(Steps2Take);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> lightOff();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> initTempLog();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> initLsTable();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> lsLen = loadSavedLS2Table(); </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> for (int i = 0; i < lsLen && i < LS_MAX; i++)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> lsSched[i].hour = getHourFromTimeEntry(lsTable[i]);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> lsSched[i].minute = getMinuteFromTimeEntry(lsTable[i]);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> } </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> initFsTable();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> fsLen = loadSavedFS2Table(); </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> for (int i = 0; i < fsLen && i < FS_MAX; i++)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> fsSched[i].hour = getHourFromTimeEntry(fsTable[i]);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> fsSched[i].minute = getMinuteFromTimeEntry(fsTable[i]);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> } </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.println(VERSION);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.println("System online.");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(PROMPT);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">}</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Main control loop.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">void loop()</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">{</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // Read time.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> timeNow = RTC.now();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // control light via scheduler</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> controlLight();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // control food dispenser</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> controlFoodDisp();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // Read temperature.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> readTemp();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // command interpreter</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> interpretCommand();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> delay(100);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">}</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Interpret command.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">void interpretCommand()</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">{</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (cmdReady)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> int err = 0;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> String memCmd;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#ifdef MYDEBUG0</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print("DBG: command=\"");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(cmd);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.println("\"");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#endif </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> cmdCode = getCmdCode();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> cmdReady = false;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> memCmd = cmd;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> cmd = "";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> switch (cmdCode) {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> case CMD_DATE:</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> serialWriteDTNow();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> case CMD_TEMP:</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (bTempRead) </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> serialConvWriteTemp();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> else </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> err = ERR_TEMPRD;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> case CMD_LTEMP:</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> serialTempLog();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> case CMD_ADDFT:</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> err = serialAddFeedingSchedule(memCmd);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> case CMD_SHOWFS:</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> serialShowFeedingSchedule();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> case CMD_DELFT:</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> serialDeleteFeedingSchedule();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> case CMD_ADDLS:</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> err = serialAddLightSchedule(memCmd);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> case CMD_SHOWLS:</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> serialShowLightSchedule();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> case CMD_DELLS:</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> serialDeleteLightSchedule();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> case CMD_SETDT:</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> err = serialSetDateTime(memCmd);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> case CMD_HELP:</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> serialHelp();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> break; </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> case CMD_VER:</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.println(VERSION);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> case CMD_DEFFS:</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> err = serialDefaultFS();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> case CMD_DEFLS:</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> err = serialDefaultLS();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> default:</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> err = ERR_UNKNCMD;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (0 != err)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print("ERR: #");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.println(err);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(PROMPT); </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">}</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Remove current light on/off schedule and replace it with a default one.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">int serialDefaultLS()</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">{</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> int err = ERR_OK;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> String deflscmd;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> strcpy_P(progmembuf, (char*)pgm_read_word(&(cmdTable[CMD_ADDLS])));</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> deflscmd = String(progmembuf) + " 08:30 21:30";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> serialDeleteLightSchedule();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> err = serialAddLightSchedule(deflscmd);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> return err;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">}</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Remove current feeding schedule and replace it with a default one.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">int serialDefaultFS()</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">{</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> int err = ERR_OK;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> String deffscmd;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> strcpy_P(progmembuf, (char*)pgm_read_word(&(cmdTable[CMD_ADDFT]))); </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> deffscmd = String(progmembuf) + " 09:00 21:00";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> serialDeleteFeedingSchedule();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> err = serialAddFeedingSchedule(deffscmd);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> return err; </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">}</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Display the list of commands.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">void serialHelp()</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">{</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> boolean doloop = true;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> for (int i = 0; doloop; i++)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> strcpy_P(progmembuf, (char*)pgm_read_word(&(cmdTable[i])));</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (strcmp(progmembuf, "nil"))</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(progmembuf);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(' ');</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> strcpy_P(progmembuf, (char*)pgm_read_word(&(cmdHelp[i])));</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.println(progmembuf);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> else</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> doloop = false;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">}</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Process addft command. Add feeding times to food dispenser scheduler.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// addft hh:mm [hh:mm ...]</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">int serialAddFeedingSchedule(String command)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">{</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> int err = ERR_OK;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> int n = 0;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> boolean token = false;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> String argBuf;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> initFsTable(); </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> fsLen = loadSavedFS2Table(); // load feeding schedule from EEPROM to lsTable</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> for (int i = 0; i < fsLen && i < FS_MAX; i++, n++)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> fsSched[i].hour = getHourFromTimeEntry(fsTable[i]);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> fsSched[i].minute = getMinuteFromTimeEntry(fsTable[i]);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#ifdef MYDEBUG3</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print("DBG: Loaded ");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(n);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.println(" entries.");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#endif</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> strcpy_P(progmembuf, (char*)pgm_read_word(&(cmdTable[CMD_ADDFT])));</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> for (int i = strlen(progmembuf); i <= command.length() && ERR_OK == err; i++)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (token && (command.charAt(i) == ' ' || i == command.length()))</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> { </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#ifdef MYDEBUG3</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print("DBG: Adding item #");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(n);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.println(".");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print("DBG: val=\"");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(argBuf);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.println("\"");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#endif </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (n < FS_MAX)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (5 == argBuf.length())</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> fsTable[n] = argBuf;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> fsSched[n].hour = getHourFromTimeEntry(argBuf);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> fsSched[n].minute = getMinuteFromTimeEntry(argBuf);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> else</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> err = ERR_FSENTINVFMT;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#ifdef MYDEBUG3</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.println("DBG: Wrong argument format.");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print("DBG: val=\"");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(argBuf);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.println("\"");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#endif</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> } </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> else</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> err = ERR_TOOMANYFS;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#ifdef MYDEBUG3</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.println("DBG: Too many arguments.");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print("DBG: FS_MAX=");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(FS_MAX);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.println(".");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#endif </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> token = false;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> argBuf = "";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> n++;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> else if (command.charAt(i) != ' ')</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (false == token)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> token = true;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (5 > argBuf.length())</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> argBuf = argBuf + command.charAt(i);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> else</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> err = ERR_ARGTOOLONG;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#ifdef MYDEBUG3 </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.println("DBG: Argument too long (>5).");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#endif </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (ERR_OK == err)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> fsLen = n;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> sortFsTables(); // sort feeding schedule numeric tables</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> convFsTblToStringTbl(); // convert fsHoursTbl and fsMinutesTbl to fsTable</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> err = saveFsTable(); // save feeding schedule table to EEPROM </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> return err; </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">}</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Read temperature sensor. Save log.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">void readTemp()</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">{</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> byte i;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (0 == lastTempRead || timeNow.unixtime() - lastTempRead > TEMP_RD_EVERY * 60)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> bTempRead = false;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // try 2 times</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if ( !ds.search(addr)) {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> ds.reset_search();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> delay(250); </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if ( !ds.search(addr)) {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> ds.reset_search();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> delay(250);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> return;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> } </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> } </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (OneWire::crc8(addr, 7) != addr[7]) {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // Invalid CRC</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> return;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> type_s = determineDSChip();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (2 == type_s) {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // Device is not a DS18x20 family device.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> return; </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> } </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> ds.reset();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> ds.select(addr);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> ds.write(0x44, 1); // start conversion, with parasite power on at the end</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> delay(1000); // maybe 750ms is enough, maybe not</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // we might do a ds.depower() here, but the reset will take care of it.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> present = ds.reset();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> ds.select(addr); </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> ds.write(0xBE); // Read Scratchpad</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> for ( i = 0; i < 9; i++) { // we need 9 bytes</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> data[i] = ds.read();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> bTempRead = true;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> lastTempRead = timeNow.unixtime();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // Convert the data to actual temperature</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // because the result is a 16 bit signed integer, it should</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // be stored to an "int16_t" type, which is always 16 bits</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // even when compiled on a 32 bit processor.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> int16_t raw = (data[1] << 8) | data[0];</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (type_s) {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> raw = raw << 3; // 9 bit resolution default</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (data[7] == 0x10) {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // "count remain" gives full 12 bit resolution</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> raw = (raw & 0xFFF0) + 12 - data[6];</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> } else {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> byte cfg = (data[4] & 0x60);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // at lower res, the low bits are undefined, so let's zero them</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (cfg == 0x00) raw = raw & ~7; // 9 bit resolution, 93.75 ms</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> else if (cfg == 0x20) raw = raw & ~3; // 10 bit res, 187.5 ms</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> else if (cfg == 0x40) raw = raw & ~1; // 11 bit res, 375 ms</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> //// default is 12 bit resolution, 750 ms conversion time</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> celsius = (float)raw / 16.0;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> fahrenheit = celsius * 1.8 + 32.0;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> logTemp();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> } </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">}</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Control light per light on/off scheduler setup.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Scheduler table contains accelerated ON/OFF times.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">void controlLight()</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">{</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> boolean turnon = true;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (lsLen <= 0)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> lightOff(); // there is no light on/off schedule, keep the light off</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> else</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // check the light on/off schedule entries against current time</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> for (int i = 0; i < lsLen; i++)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // check if the current time falls between current and next scheduled times</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if ((lsSched[i].hour == timeNow.hour() && lsSched[i].minute <= timeNow.minute())</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> ||</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> lsSched[i].hour < timeNow.hour()</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> ) </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // we are past the currently checked scheduled time, </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // check if we are before the next scheduled time</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (i+1 < lsLen)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // the next schedule exists, check if current time falls before it</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if ((lsSched[i+1].hour == timeNow.hour() && lsSched[i+1].minute >= timeNow.minute())</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> ||</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> lsSched[i+1].minute > timeNow.hour()</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> ) </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // yes, the current time falls within currently checked period</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> flipLightSwitch(turnon);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> else</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // there is no next schedule, so turn the light ON or OFF accordingly</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> flipLightSwitch(turnon);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> turnon = ((turnon) ? false : true);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">}</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Turn the light ON or OFF depending on the argument and current status of</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// the light switch flag.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">void flipLightSwitch(boolean turnon)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">{</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (turnon)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (false == lightswitch)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // if the light is OFF, tuen it ON, flip the flag</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> lightOn();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> lightswitch = true;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> else</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (lightswitch)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // if the light is ON, turn it OFF, flip the flag</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> lightOff();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> lightswitch = false;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> } </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">}</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Control food dispenser per feeding schedule setup.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">void controlFoodDisp()</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">{</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> for (int i = 0; i < fsLen; i++)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (fsSched[i].hour == timeNow.hour() && fsSched[i].minute == timeNow.minute())</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (foodDispTime == 0 || timeNow.unixtime() - foodDispTime > 60)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> dispenseFood();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> foodDispTime = timeNow.unixtime();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">}</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Send light on/off schedule to serial line.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">void serialShowLightSchedule()</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">{</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> boolean turnon = true;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> initLsTable();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> lsLen = loadSavedLS2Table();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> for (int i = 0; i < lsLen && i < LS_MAX; i++)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> lsSched[i].hour = getHourFromTimeEntry(lsTable[i]);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> lsSched[i].minute = getMinuteFromTimeEntry(lsTable[i]);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(lsTable[i]);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(" ");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.println(((turnon) ? "ON" : "OFF"));</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> turnon = ((turnon) ? false : true);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (false == turnon)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.println("WARN: Missing OFF time.");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">}</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Send feeding schedule to serial line.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">void serialShowFeedingSchedule()</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">{</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> initFsTable();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> fsLen = loadSavedFS2Table();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> for (int i = 0; i < fsLen && i < FS_MAX; i++)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> fsSched[i].hour = getHourFromTimeEntry(fsTable[i]);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> fsSched[i].minute = getMinuteFromTimeEntry(fsTable[i]);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.println(fsTable[i]);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">}</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Initialize light on/off schedule tables.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">void initLsTable()</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">{</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> for (int i = 0; i < LS_MAX; i++)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> lsTable[i] = "";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> lsSched[i].hour = 0;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> lsSched[i].minute = 0;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">}</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Initialize feeding schedule tables.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">void initFsTable()</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">{</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> for (int i = 0; i < FS_MAX; i++)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> fsTable[i] = "";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> fsSched[i].hour = 0;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> fsSched[i].minute = 0;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">}</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Delete entire light on/off schedule.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">void serialDeleteLightSchedule()</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">{</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> int addr = TEMP_LOG_LEN * TEMP_LOG_MAX;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> while (addr < TEMP_LOG_LEN * TEMP_LOG_MAX + LS_LEN * LS_MAX)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> EEPROM.write(addr++, 0);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> lsLen = -1;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.println("OK");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">}</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Delete entire feeding schedule.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">void serialDeleteFeedingSchedule()</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">{</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> int addr = TEMP_LOG_LEN * TEMP_LOG_MAX + LS_LEN * LS_MAX;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> while (addr < TEMP_LOG_LEN * TEMP_LOG_MAX + LS_LEN * LS_MAX + FS_LEN * FS_MAX)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> EEPROM.write(addr++, 0);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> fsLen = -1;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.println("OK");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">}</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Parse/interpret addls command, add times to light on/off schedule.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// addls hh:mm [hh:mm ...]</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">int serialAddLightSchedule(String command)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">{</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> int err = ERR_OK;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> int n = 0;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> boolean token = false;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> String argBuf;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> initLsTable(); </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> lsLen = loadSavedLS2Table(); // load light on/off schedule from EEPROM to lsTable</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> for (int i = 0; i < lsLen && i < LS_MAX; i++, n++)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> lsSched[i].hour = getHourFromTimeEntry(lsTable[i]);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> lsSched[i].minute = getMinuteFromTimeEntry(lsTable[i]);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#ifdef MYDEBUG2</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print("DBG: Loaded ");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(n);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.println(" entries.");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#endif</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> strcpy_P(progmembuf, (char*)pgm_read_word(&(cmdTable[CMD_ADDLS])));</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> for (int i = strlen(progmembuf); i <= command.length() && ERR_OK == err; i++)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (token && (command.charAt(i) == ' ' || i == command.length()))</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> { </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#ifdef MYDEBUG2</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print("DBG: Adding item #");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(n);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.println(".");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print("DBG: val=\"");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(argBuf);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.println("\"");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#endif </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (n < LS_MAX)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (5 == argBuf.length())</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> lsTable[n] = argBuf;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> lsSched[n].hour = getHourFromTimeEntry(argBuf);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> lsSched[n].minute = getMinuteFromTimeEntry(argBuf);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> else</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> err = ERR_LSENTINVFMT;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#ifdef MYDEBUG2</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.println("DBG: Wrong argument format.");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print("DBG: val=\"");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(argBuf);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.println("\"");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#endif</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> } </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> else</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> err = ERR_TOOMANYLS;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#ifdef MYDEBUG2</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.println("DBG: Too many arguments.");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print("DBG: LS_MAX=");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(LS_MAX);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.println(".");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#endif </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> token = false;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> argBuf = "";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> n++;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> else if (command.charAt(i) != ' ')</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (false == token)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> token = true;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (5 > argBuf.length())</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> argBuf = argBuf + command.charAt(i);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> else</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> err = ERR_ARGTOOLONG;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#ifdef MYDEBUG2 </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.println("DBG: Argument too long (>5).");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#endif </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (ERR_OK == err)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> lsLen = n;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> sortLsTables(); // sort light on/off schedule numeric tables</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> convLsTblToStringTbl(); // convert lsHoursTbl and LsMinutesTbl to lsTable</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> err = saveLsTable(); // save light on/off schedule table to EEPROM </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> return err;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">}</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Save schedule to EEPROM.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">int saveSchedule(String tbl[], </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> int startaddr, </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> int endaddr,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> int numofentries,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> int arglen,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> int rangeerr, </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> int fmterr)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">{</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> int err = ERR_OK;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> int addr = 0;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> addr = startaddr;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> for (int i = 0; i < numofentries && ERR_OK == err; i++)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (arglen == tbl[i].length())</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> for (int j = 0; j < tbl[i].length(); j++)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (addr < endaddr)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> EEPROM.write(addr++, tbl[i].charAt(j));</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> else</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> err = rangeerr; // too many entries, exceeds alloted EEPROM space</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#ifdef MYDEBUG1</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print("DBG: Saving table, address out of range: ");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(addr);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.println(".");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#endif</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> EEPROM.write(addr++, 0);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> else</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> err = fmterr; // invalid entry format</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#ifdef MYDEBUG1</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print("DBG: Saving table, invalid format, value=\"");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(tbl[i]);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.println("\"");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#endif</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> break; </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> } </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> return err; </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">}</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Save light on/off schedule table to EEPROM.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">int saveLsTable()</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">{</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> int err = ERR_OK;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // light on/off schedule is saved after temperature log. </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> err = saveSchedule(lsTable, </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> TEMP_LOG_LEN*TEMP_LOG_MAX, </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> TEMP_LOG_LEN*TEMP_LOG_MAX+LS_LEN*LS_MAX,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> lsLen,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> 5,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> ERR_LSEEPROMOOR, </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> ERR_LSENTINVFMT); </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> return err;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">}</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Save feeding schedule table to EEPROM.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">int saveFsTable()</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">{</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> int err = ERR_OK;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> int addr = 0;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // Feeding schedule is saved after temperature log and light on/off schedule. </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> err = saveSchedule(fsTable, </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> TEMP_LOG_LEN*TEMP_LOG_MAX+LS_LEN*LS_MAX, </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> TEMP_LOG_LEN*TEMP_LOG_MAX+LS_LEN*LS_MAX+FS_LEN*FS_MAX,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> fsLen,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> 5,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> ERR_FSEEPROMOOR, </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> ERR_FSENTINVFMT); </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> return err;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">}</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Convert lsHoursTbl and LsMinutesTbl to lsTable.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">void convLsTblToStringTbl()</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">{</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> char txtbuf[6];</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> for (int i = 0; i < lsLen; i++)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> sprintf(txtbuf, "%02d:%02d\0", lsSched[i].hour, lsSched[i].minute);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> lsTable[i] = String(txtbuf);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#ifdef MYDEBUG0</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print("DBG: lsSched[");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(i);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print("].hour=");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.println(lsSched[i].hour);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print("DBG: lsSched[");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(i);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print("].minute=");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.println(lsSched[i].minute);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print("DBG: txtbuf=\"");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(txtbuf);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.println("\"");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print("DBG: lsTable[");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(i);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print("]=\"");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(lsTable[i]);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.println("\"");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#endif </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">}</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Convert fsHoursTbl and fsMinutesTbl to fsTable.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">void convFsTblToStringTbl()</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">{</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> char txtbuf[6];</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> for (int i = 0; i < fsLen; i++)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> sprintf(txtbuf, "%02d:%02d\0", fsSched[i].hour, fsSched[i].minute);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> fsTable[i] = String(txtbuf);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#ifdef MYDEBUG3</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print("DBG: fsSched[");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(i);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print("].hour=");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.println(fsSched[i].hour);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print("DBG: fsSched[");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(i);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print("].minute=");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.println(fsSched[i].minute);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print("DBG: txtbuf=\"");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(txtbuf);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.println("\"");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print("DBG: fsTable[");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(i);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print("]=\"");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(fsTable[i]);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.println("\"");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">#endif </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">}</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Sort numeric light on/off schedule tables.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">void sortLsTables()</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">{</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> int tmp;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> int v1, v2;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> for (int i = 0; i < lsLen - 1; i++)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> for (int j = i + 1; j < lsLen; j++)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> v1 = lsSched[j].hour*100 + lsSched[j].minute;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> v2 = lsSched[i].hour*100 + lsSched[i].minute;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (v1 < v2)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> tmp = lsSched[i].hour;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> lsSched[i].hour = lsSched[j].hour;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> lsSched[j].hour = tmp;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> tmp = lsSched[i].minute;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> lsSched[i].minute = lsSched[j].minute;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> lsSched[j].minute = tmp;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">}</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Sort numeric feeding schedule tables.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">void sortFsTables()</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">{</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> int tmp;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> int v1, v2;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> for (int i = 0; i < fsLen - 1; i++)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> for (int j = i + 1; j < fsLen; j++)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> v1 = fsSched[j].hour*100 + fsSched[j].minute;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> v2 = fsSched[i].hour*100 + fsSched[i].minute;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (v1 < v2)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> tmp = fsSched[i].hour;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> fsSched[i].hour = fsSched[j].hour;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> fsSched[j].hour = tmp;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> tmp = fsSched[i].minute;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> fsSched[i].minute = fsSched[j].minute;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> fsSched[j].minute = tmp;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">}</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Convert hour part of light on/off schedule entry in String format to integer.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">int getHourFromTimeEntry(String timestr)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">{</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> String hr;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> hr = timestr.substring(0, timestr.indexOf(':'));</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> return hr.toInt();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">}</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Convert minute part of light on/off schedule entry in String format to </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// integer.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">int getMinuteFromTimeEntry(String timestr)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">{</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> String mn;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> mn = timestr.substring(timestr.indexOf(':')+1);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> return mn.toInt();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">}</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Load saved schedule from EEPROM to lsTable or fsTable as pointed by lsfs</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// argument.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">int loadSavedSchedule(int startaddr,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> int endaddr,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> int arglen,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> int maxitems,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> boolean lsfs // true - ls, false - fs</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> )</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">{</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> int n = 0, l = 0, addr = 0;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> char val, prev = 0;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> int ret = -1;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> boolean noerr = true;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> addr = startaddr;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> while (addr < endaddr && n < maxitems)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> val = EEPROM.read(addr++);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (0 != val)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (arglen > l)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (lsfs)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> lsTable[n] += val;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> else</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> fsTable[n] += val;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> l++;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> else</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // error, each entry should be only <arglen> characters long</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> noerr = false;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> else</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (prev == 0)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> break; // two zeroes in a row - the end of setup in EEPROM</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> n++;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> l = 0;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> prev = val;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (noerr)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> ret = n;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> return ret; </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">} </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Load light on/off schedule from EEPROM to lsTable.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">int loadSavedLS2Table()</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">{</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> int ret = -1;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // light on/off schedule is saved after temperature log </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> ret = loadSavedSchedule(TEMP_LOG_LEN*TEMP_LOG_MAX,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> TEMP_LOG_LEN*TEMP_LOG_MAX+LS_LEN*LS_MAX,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> 5,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> LS_MAX,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> true); </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> return ret;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">}</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Load feeding schedule from EEPROM to lsTable.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">int loadSavedFS2Table()</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">{</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> int ret = -1;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // feeding schedule is saved after temperature log and light on/off schedule. </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> ret = loadSavedSchedule(TEMP_LOG_LEN*TEMP_LOG_MAX+LS_LEN*LS_MAX,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> TEMP_LOG_LEN*TEMP_LOG_MAX+LS_LEN*LS_MAX+FS_LEN*FS_MAX,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> 5,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> FS_MAX,</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> false); </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> return ret;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">}</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Parse/interpret setdt command, set RTC date/time.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// setdt YYYY MM DD hh mm</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">int serialSetDateTime(String command)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">{</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> int err = ERR_OK;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> char numBuf[5];</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> int setYear = 2013;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> int setMonth = 12;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> int setDay = 7;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> int setHour = 0;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> int setMinute = 0;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> boolean token = false;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> int argnum = 0, n = 0;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> timeNow = RTC.now();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> setYear = timeNow.year(); </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> setMonth = timeNow.month();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> setDay = timeNow.day();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> setHour = timeNow.hour();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> setMinute = timeNow.minute();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> for (n = 0; n < 5; n++) </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> numBuf[n] = 0;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> strcpy_P(progmembuf, (char*)pgm_read_word(&(cmdTable[CMD_SETDT])));</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> for (int i = strlen(progmembuf), n = 0; i <= command.length() && ERR_OK == err; i++)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (token && (command.charAt(i) == ' ' || i == command.length()))</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> argnum++;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (n < 5)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> numBuf[n] = 0;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> else</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> err = ERR_ARGTOOLONG;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> switch (argnum)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> case 1:</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> setYear = atoi(numBuf);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> case 2:</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> setMonth = atoi(numBuf);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> case 3:</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> setDay = atoi(numBuf);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> case 4:</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> setHour = atoi(numBuf);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> case 5:</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> setMinute = atoi(numBuf);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> default:</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> err = ERR_TOOMANYARGS;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> token = false;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> for (n = 0; n < 5; n++)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> numBuf[n] = 0;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> n = 0;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> else if (command.charAt(i) != ' ')</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (false == token)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> token = true;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (n < 4)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> numBuf[n++] = command.charAt(i);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> else</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> err = ERR_ARGTOOLONG;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (ERR_OK == err)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> RTC.adjust(DateTime(setYear, setMonth, setDay, setHour, setMinute, 0));</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.println("Set D/T to:");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(setYear); Serial.print('/');</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(setMonth); Serial.print('/');</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(setDay); Serial.print(' ');</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(setHour); Serial.print(':');</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if(setMinute < 10)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print('0');</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.println(setMinute); </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> return err;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">}</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Interpret command string, return command code.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">int getCmdCode()</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">{</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> int ret = -1;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> boolean doloop = true;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> char buf[8] = {0,0,0,0,0,0,0,0};</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> cmd.toCharArray(buf, 8);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> for (int i = 0; doloop; i++)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> strcpy_P(progmembuf, (char*)pgm_read_word(&(cmdTable[i])));</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (strcmp(progmembuf, "nil"))</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (0 == strcmp(progmembuf, buf) || 0 == strncmp(progmembuf, buf, strlen(progmembuf)))</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> ret = i;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> else</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> doloop = false;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> return ret;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">}</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Send date/time to serial line.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">void serialWriteDTNow()</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">{</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print("DT:");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> strcpy_P(progmembuf, (char*)pgm_read_word(&(daysOfWeek[timeNow.dayOfWeek()])));</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(progmembuf);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(' '); </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(timeNow.year());</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print('/');</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (timeNow.month() < 10)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print('0');</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(timeNow.month());</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print('/');</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (timeNow.day() < 10)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print('0'); </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(timeNow.day());</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(' ');</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (timeNow.hour() < 10)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print('0'); </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(timeNow.hour());</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(':');</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (timeNow.minute() < 10)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print('0'); </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(timeNow.minute());</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.println(); </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">}</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Send temperature readings in human readable form to serial line.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">void serialConvWriteTemp()</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">{</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print("T = ");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> dtostrf(celsius, 8, 2, textbuf);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(textbuf);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(" C, ");</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> dtostrf(fahrenheit, 8, 2, textbuf);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(textbuf);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.println(" F"); </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">}</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// DS temperature sensor chip type determination.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">byte determineDSChip()</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">{</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> byte ret = 2;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // the first ROM byte indicates which chip</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> switch (addr[0]) {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> case 0x10:</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // Chip = DS18S20 or old DS1820</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> ret = 1;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> case 0x28:</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // Chip = DS18B20</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> ret = 0;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> case 0x22:</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // Chip = DS1822</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> ret = 0;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> default:</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // Device is not a DS18x20 family device.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> break;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> } </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> return ret;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">}</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Initialize EEPROM for temperature log.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">void initTempLog()</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">{</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> for (int i = 0; i < TEMP_LOG_LEN * TEMP_LOG_MAX; i++)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> EEPROM.write(i, 0);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">}</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Log current time and temperature read in EEPROM.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">void logTemp()</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">{</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> int i = 0;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> progmembuf[i++] = (char) ((int)(timeNow.hour() / 10) + 48);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> progmembuf[i++] = (char) ((int)timeNow.hour() - (int)(timeNow.hour() / 10)*10 + 48);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> progmembuf[i++] = ':';</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> progmembuf[i++] = (char) ((int)(timeNow.minute() / 10) + 48);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> progmembuf[i++] = (char) ((int)timeNow.minute() - (int)(timeNow.minute() / 10)*10 + 48); </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> progmembuf[i++] = ' ';</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> dtostrf(celsius, 8, 2, textbuf);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> for (int n = 0; n < strlen(textbuf) && i < TEMP_LOG_LEN-1; i++, n++)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> progmembuf[i] = textbuf[n];</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> progmembuf[i++] = ' '; </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> dtostrf(fahrenheit, 8, 2, textbuf);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> for (int n = 0; n < strlen(textbuf) && i < TEMP_LOG_LEN-1; i++, n++)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> progmembuf[i] = textbuf[n];</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> for (; i < TEMP_LOG_LEN-1; i++)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> progmembuf[i] = ' ';</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> progmembuf[TEMP_LOG_LEN-1] = 0;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (logEntry == TEMP_LOG_MAX)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // reset the log address and entries (start on top again)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> logAddr = 0;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> logEntry = 0;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> for (i = 0; i < TEMP_LOG_LEN; i++)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> EEPROM.write(logAddr++, progmembuf[i]);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (logEntries < TEMP_LOG_MAX)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> logEntries++;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> logEntry++;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">}</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Send the contents of temperature log to serial line.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">void serialTempLog()</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">{</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> int addr = 0;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> for (int i = 0; i < logEntries && addr < 512; i++)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> char val = EEPROM.read(addr++);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> while (0 != val)</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.print(val);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> val = EEPROM.read(addr++);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.println();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">}</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Turn the light on.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">void lightOn()</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">{</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> digitalWrite(LIGHTPIN, HIGH);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">}</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Turn the light off.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">void lightOff()</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">{</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> digitalWrite(LIGHTPIN, LOW);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">}</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// Run food dispenser. Perform fool 360 deg. revolution and some (1/8) </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// of the stepper motor.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// During this time, the serial console to the controller will be unresponsive.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">void dispenseFood()</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">{</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Steps2Take = STEPS_PER_OUTPUT_REVOLUTION + STEPS_PER_OUTPUT_REVOLUTION/8;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> small_stepper.setSpeed(250);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> small_stepper.step(Steps2Take);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">}</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// -----------------------------------------------------------------------------</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">/*</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> * SerialEvent occurs whenever a new data comes in the</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> * hardware serial RX. This routine is run between each</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> * time loop() runs, so using delay inside loop can delay</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> * response. Multiple bytes of data may be available.</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> */</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">// ----------------------------------------------------------------------------- </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">void serialEvent() </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">{</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> while (Serial.available()) {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // get the new byte:</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> char inChar = (char)Serial.read(); </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // send echo</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.write(inChar);</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // add it to the command string</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> if (inChar != '\r')</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> cmdTmp += inChar;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // if the incoming character is a newline, set a flag</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // so the main loop can do something about it:</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> // if (inChar == '\r') {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> else {</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> cmd = cmdTmp;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> cmdTmp = "";</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> Serial.println();</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> cmdReady = true;</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> } </span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;"> }</span></div>
<div>
<span style="background-color: white; color: #20124d; font-family: Courier New, Courier, monospace; font-size: x-small;">}</span></div>
<div>
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><span style="background-color: white;"><br /></span></span></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div>
<div style="background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="color: #20124d; font-family: Verdana, sans-serif;">I
consider the code to be finished, so now awaits the most difficult
and boring part for me - mounting this in an aesthetic and safe way
in my fish tank. I also think that the device should be powered via a
battery backup unit (the Arduino Uno and food dispensing unit) so
there are no surprises due to prolonged power outages. I also do not
have any ideas yet how to make the temperature sensor waterproof.</span></div>
<div style="background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="color: #20124d;"><br /></span></div>
<div style="background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="color: #20124d; font-family: Verdana, sans-serif;">And
now the pictures:</span></div>
<div style="background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheeWzrs3847JUfpuktAZt05o9weTF0ZClDkYnCutsigsvUNKl9dhWAa5jtWvQAz7lvnvCiT50u_h27izyvmEqmSjcbFKoqQOMBwQBfOPBZEqgiXbTGo5jiKEK78ABACkz3WxN6yyEjuahyphenhyphen/s1600/IMG_1924.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEheeWzrs3847JUfpuktAZt05o9weTF0ZClDkYnCutsigsvUNKl9dhWAa5jtWvQAz7lvnvCiT50u_h27izyvmEqmSjcbFKoqQOMBwQBfOPBZEqgiXbTGo5jiKEK78ABACkz3WxN6yyEjuahyphenhyphen/s1600/IMG_1924.JPG" height="640" width="480" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: Verdana, sans-serif; font-size: x-small;">Image 1 - The food dispensing unit with the stepper motor that replaced the factory clock mechanism.<br /></span></td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjr6-VMrkUgV4od_DP4YJnGqTXCS-egDTD4KLiNjP6aZcdp4kdIMbApiwEdkgTlJfHfvQ8J8ri85lpaMld2K2UYX6-ZHXEtSL1Iyn_tOCl2clfLHc8ms7ERhL9SlzFQcBRiodqsJl30h9_m/s1600/IMG_1926.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjr6-VMrkUgV4od_DP4YJnGqTXCS-egDTD4KLiNjP6aZcdp4kdIMbApiwEdkgTlJfHfvQ8J8ri85lpaMld2K2UYX6-ZHXEtSL1Iyn_tOCl2clfLHc8ms7ERhL9SlzFQcBRiodqsJl30h9_m/s1600/IMG_1926.JPG" height="480" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: Verdana, sans-serif; font-size: x-small;">Image 2 - The food dispensing unit, front view.<br /></span></td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div style="background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcW3L9ecOUzlFFXA5eeIOd_lbjjWCqKmXS5jVxJe07-T-cXvYxS42oFXDoq8WBeSEElNgrBsSMMmYwHsqE21uAnnrBqQkcp4WM3BoV3FR1I79cta3nr7FzKUBCnPDhPWz0Z1w0kf22mNNC/s1600/IMG_0012_e2.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcW3L9ecOUzlFFXA5eeIOd_lbjjWCqKmXS5jVxJe07-T-cXvYxS42oFXDoq8WBeSEElNgrBsSMMmYwHsqE21uAnnrBqQkcp4WM3BoV3FR1I79cta3nr7FzKUBCnPDhPWz0Z1w0kf22mNNC/s1600/IMG_0012_e2.jpg" height="480" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: Verdana, sans-serif;">Image 3 - The circuit prototype.</span></td></tr>
</tbody></table>
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5KMYdMID3fNmOy_p3iNGci1Aq8Odcnr648dqi4INpVMgF4_QgAUbrgMWAcEBP8jGkT28LlW5HJVGdgbed9IcwWkT9_ujEzGUsw6nZZRe5QAL9bljgc-WMn72g7ZGs5JD4pnbzlLdpPR3Y/s1600/IMG_1930.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj5KMYdMID3fNmOy_p3iNGci1Aq8Odcnr648dqi4INpVMgF4_QgAUbrgMWAcEBP8jGkT28LlW5HJVGdgbed9IcwWkT9_ujEzGUsw6nZZRe5QAL9bljgc-WMn72g7ZGs5JD4pnbzlLdpPR3Y/s1600/IMG_1930.JPG" height="480" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: Verdana, sans-serif;">Image 4 - Working prototype.</span></td></tr>
</tbody></table>
<div style="background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzDybH4VS7CCziHFLIYV1mIKisqv7NKXJYuZndESFSbqF-ZA4VN-1_0gx9S6YNY-64-GGx5ZkxFTkTNurGGTNugjOXjHennVrFehhD_cbFL5iIN31FxSaAK6NJ4LGJlN4KQUcUjNjIodje/s1600/scrshot001.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzDybH4VS7CCziHFLIYV1mIKisqv7NKXJYuZndESFSbqF-ZA4VN-1_0gx9S6YNY-64-GGx5ZkxFTkTNurGGTNugjOXjHennVrFehhD_cbFL5iIN31FxSaAK6NJ4LGJlN4KQUcUjNjIodje/s1600/scrshot001.jpg" height="640" width="580" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: Verdana, sans-serif;">Image 5 - Command line/terminal session to the device.</span></td></tr>
</tbody></table>
<div style="background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div style="background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="color: #20124d; font-family: Verdana, sans-serif;">This is it. Thank you for reading my blog.</span></div>
<div style="background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="color: #20124d; font-family: Verdana, sans-serif;"><br /></span></div>
<div style="background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="color: #20124d; font-family: Verdana, sans-serif;">Marek Karcz</span></div>
<div style="background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="color: #20124d; font-family: Verdana, sans-serif;">1/1/2014</span></div>
</div>
Marek Karczhttp://www.blogger.com/profile/03281397436610614441noreply@blogger.com2tag:blogger.com,1999:blog-4155387638169532413.post-61707848649219816682013-11-17T21:52:00.000-08:002013-11-18T05:59:12.071-08:00Update on MKHBC-8-R1.<span style="font-family: Verdana, sans-serif;">If I only knew this would be so much work... ;-)</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">OK, the point-to-point soldering isn't really fun. At least not when you have to do so many soldering points. Well, I guess nothing builds itself. If I want to see some results then I have to go through it. No way around it, I can not afford outsourcing.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">Therefore over the past several, aaaah..., months, I did most of the soldering on my CPU card. So, don't loose the hope yet, we just might see the end of this part of the project before the end of the year. My goal is to have CPU card and serial port card ready this year, as I outlined in my last update.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">Just take a look at the pictures, as the computer takes a shape...</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8zAmig-G_-hAaai341OGoNU86oWA4IFmsOfhHZM-9zc8Ry2FSSPKYlYl3_lSlPZmsT3RASYnx4CbSWj-MxNu6ZlsyPc36QBDv-zKwzeGCwl7syXn_XOmFi8MgWSsFO6KaaefcNKsEFzMN/s1600/IMG_1919.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh8zAmig-G_-hAaai341OGoNU86oWA4IFmsOfhHZM-9zc8Ry2FSSPKYlYl3_lSlPZmsT3RASYnx4CbSWj-MxNu6ZlsyPc36QBDv-zKwzeGCwl7syXn_XOmFi8MgWSsFO6KaaefcNKsEFzMN/s640/IMG_1919.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: Verdana, sans-serif;">Image 1 : CPU card (to the left) and mother board (to the right). I record my soldering progress the old fashioned way by checking out the connections on the list.</span></td></tr>
</tbody></table>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGzfwDD7qbG4b7AkGb6ojhNXfmvrePFX8n909Rc0LzELrFP5QWl7TutInxY8yvOyJ_Q0Ig_XEy3IeYl8HpM0FUuPMv0U-s7xN_rNsw6Ao_5Htl8a4noS8eDZvkd5qQRpnWtkfb9Ahih6sK/s1600/IMG_1921.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="640" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiGzfwDD7qbG4b7AkGb6ojhNXfmvrePFX8n909Rc0LzELrFP5QWl7TutInxY8yvOyJ_Q0Ig_XEy3IeYl8HpM0FUuPMv0U-s7xN_rNsw6Ao_5Htl8a4noS8eDZvkd5qQRpnWtkfb9Ahih6sK/s640/IMG_1921.JPG" width="480" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: Verdana, sans-serif;">Image 2 : Closer look at the CPU card.</span></td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgsZwWe8wtnK2BWe4RbsXp32qdByRBn0Lg4sV9GeznxDD252PdpCZfGx_1TWAyQLPb7VSpCn7qi7HuDY_3yRYMhR6hgE52P1WXYEOQErk-3uzybw7t4NUON8dYSR8m-lgFsZ_GYdPBsgM_t/s1600/IMG_1920.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgsZwWe8wtnK2BWe4RbsXp32qdByRBn0Lg4sV9GeznxDD252PdpCZfGx_1TWAyQLPb7VSpCn7qi7HuDY_3yRYMhR6hgE52P1WXYEOQErk-3uzybw7t4NUON8dYSR8m-lgFsZ_GYdPBsgM_t/s640/IMG_1920.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: Verdana, sans-serif;">Image 3 : CPU card, the connections side. It looks like a big mess of wires, but believe me, each connection is very carefully laid out, done and checked with the multi-meter. I hope this will work :-)</span></td></tr>
</tbody></table>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDqZ2HJ0KaQHlPuUHmrexK3QU8eYsEkopFOPXKG88tigRamYPa_F0HcpgnA_sblCzU7FAAFrK3PsVuWYbd6-U0HxP7WqzrKx2BRwrSDzrmdQm1yygBFfDEJaw7vWbt_WHFUp9YwpAGwtJ1/s1600/IMG_1829.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiDqZ2HJ0KaQHlPuUHmrexK3QU8eYsEkopFOPXKG88tigRamYPa_F0HcpgnA_sblCzU7FAAFrK3PsVuWYbd6-U0HxP7WqzrKx2BRwrSDzrmdQm1yygBFfDEJaw7vWbt_WHFUp9YwpAGwtJ1/s640/IMG_1829.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-family: Verdana, sans-serif;">Image 4 : This is how it looked like nearly 2 months ago, when I connected the Vcc and Ground points.</span></td></tr>
</tbody></table>
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">This article does not look like much, but it actually describes about 8-10 hours of my work (on the CPU card alone). And this brings us to the beginning of this article. ;-)</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">Thank you for visiting.</span><br />
<span style="font-family: Verdana, sans-serif;"><br /></span>
<span style="font-family: Verdana, sans-serif;">Marek Karcz, 11/18/2013</span>Marek Karczhttp://www.blogger.com/profile/03281397436610614441noreply@blogger.com0tag:blogger.com,1999:blog-4155387638169532413.post-63889646487021611422013-11-16T10:39:00.000-08:002013-11-16T11:14:36.296-08:00Raspberry Pi, I2C LCD screen and Safe Power Down button.<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><b>The
Raspberry Pi, just sitting there, asking to be played with...</b></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">As I
looked over my existing projects I noticed this sad little lone R-Pi
sitting on my desk. Some time ago I bought it. Played with it a bit,
installed NOOB image on the SD card, connected I2C LCD text display
to it and a shutdown switch and played a bit with GPIO programming in
Python. I want to make a car trip computer out of this R-Pi. You
know, a computer that will read car's ECU via OBD2 port and display
information in real time, like the average and current gas usage,
trip time and length, how many miles left on the remaining fuel and
such. In the future perhaps I could add a camera and trip log. This
may be a cool project. I commute to work 15 miles, so there will be
plenty opportunity to test the toy.</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">I
remembered that this LCD screen, connected to GPIO pins via some
prototyping wire (female connectors at both ends) gave me a lot of
trouble related to poor contact, so I decided to upgrade it and make
a dedicated connector with wires soldered to it. I also need a keypad
for the project, but since I did not buy or make one yet, I just
connected a LCD and a shutdown switch at this time.</span></div>
<br />
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">The
LCD takes just 4 wires – <b>5V</b>, <b>GND</b>, <b>SDA</b> and <b>SCL</b>
(I2C and power, Pi's GPIO pins #2, 6, 3, 5 respectively). The
unfortunate thing is that the R-Pi's logic is 3.3V, however this
display's power voltage requirement and logic is 5V. I tried to power
it from Pi's 3.3V pin hoping that it has some built in tolerance,
however the display would not work then. Therefore I powered the
screen from Pi's 5V pin with a bit of scare that I might damage the
Pi's GPIO port, however this seems to work fine. It looks like the
device accepts 3.3V logic, just needs to be powered by 5V to operate.
I guess it should be OK as long as I am not sending the input to R-Pi
in the 5V level. Since LCD is an output device, this is not the case.
The temporary connection I made previously suffered from poor contact
and I often had voltage drops that caused information loss on the
display, even with the 5V power connected to the device. With the new
connector things look much better and the display is finally
reliable.</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><b>Connections
diagram.</b></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><b><br /></b></span>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBUNzp_38gvhh4l31r57p995YL5pDeNs9M-pJhDKefG_5a5WDBgVyWW8wQEHOHCifK35xEYh2u25FNtlwP09_3BwLG8rmu4p5TxzSGdXtyzl_N7bpx3rJPr4e9bm60MFlVXj8kKwh-42ZO/s1600/i2clcd_pwdsw.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="530" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBUNzp_38gvhh4l31r57p995YL5pDeNs9M-pJhDKefG_5a5WDBgVyWW8wQEHOHCifK35xEYh2u25FNtlwP09_3BwLG8rmu4p5TxzSGdXtyzl_N7bpx3rJPr4e9bm60MFlVXj8kKwh-42ZO/s640/i2clcd_pwdsw.jpg" width="640" /></a></div>
<span style="font-family: Verdana, sans-serif;"><b><br /></b></span></div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><b><br /></b></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><b>The
code.</b></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">I
found very useful information <a href="http://www.rpiblog.com/2012/07/interfacing-16x2-lcd-with-raspberry-pi.html" target="_blank">here.</a></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">It presents the driver in Python for LCD display that is in turn driven by
PCF8574 expander chip, which is basically an I2C hardware driver for
the LCD display.</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">It is
easy to implement and start programming your LCD screen in Python
right away (assuming you already installed and configured your GPIO
libraries).</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">The
actual driver code listed below, <i>lcddriver.py was</i> taken from above web site at the time I made the project:</span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">import smbus</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">from time import *</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<br /></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"># General i2c device
class so that other devices can be added easily</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">class i2c_device:</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">def __init__(self,
addr, port):</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.addr = addr</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.bus =
smbus.SMBus(port)</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<br /></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">def write(self,
byte):</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.bus.write_byte(self.addr,
byte)</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<br /></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">def read(self):</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> return
self.bus.read_byte(self.addr)</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<br /></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">def
read_nbytes_data(self, data, n): # For sequential reads > 1 byte</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> return
self.bus.read_i2c_block_data(self.addr, data, n)</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<br /></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<br /></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">class lcd:</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> #initializes
objects and lcd</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> '''</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> Reverse Codes:</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> 0: lower 4 bits of
expander are commands bits</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> 1: top 4 bits of
expander are commands bits AND P0-4 P1-5 P2-6</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> 2: top 4 bits of
expander are commands bits AND P0-6 P1-5 P2-4</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> '''</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> def __init__(self,
addr, port, reverse=0):</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.reverse =
reverse</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_device =
i2c_device(addr, port)</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> if self.reverse:</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_device.write(0x30)</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_strobe()</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> sleep(0.0005)</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_strobe()</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> sleep(0.0005)</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_strobe()</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> sleep(0.0005)</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_device.write(0x20)</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_strobe()</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> sleep(0.0005)</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> else:</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_device.write(0x03)</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_strobe()</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> sleep(0.0005)</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_strobe()</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> sleep(0.0005)</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_strobe()</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> sleep(0.0005)</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_device.write(0x02)</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_strobe()</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> sleep(0.0005)</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<br /></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_write(0x28)</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_write(0x08)</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_write(0x01)</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_write(0x06)</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_write(0x0C)</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_write(0x0F)</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<br /></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> # clocks EN to
latch command</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> def
lcd_strobe(self):</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> if self.reverse ==
1:</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_device.write((self.lcd_device.read()
| 0x04))</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_device.write((self.lcd_device.read()
& 0xFB))</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> if self.reverse ==
2:</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_device.write((self.lcd_device.read()
| 0x01))</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_device.write((self.lcd_device.read()
& 0xFE))</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> else:</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_device.write((self.lcd_device.read()
| 0x10))</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_device.write((self.lcd_device.read()
& 0xEF))</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<br /></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> # write a command
to lcd</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> def lcd_write(self,
cmd):</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> if self.reverse:</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_device.write((cmd
>> 4)<<4)</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_strobe()</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_device.write((cmd
& 0x0F)<<4)</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_strobe()</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_device.write(0x0)</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> else:</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_device.write((cmd
>> 4))</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_strobe()</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_device.write((cmd
& 0x0F))</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_strobe()</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_device.write(0x0)</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<br /></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> # write a character
to lcd (or character rom)</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> def
lcd_write_char(self, charvalue):</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> if self.reverse ==
1:</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_device.write((0x01
| (charvalue >> 4)<<4))</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_strobe()</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_device.write((0x01
| (charvalue & 0x0F)<<4))</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_strobe()</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_device.write(0x0)</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> if self.reverse ==
2:</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_device.write((0x04
| (charvalue >> 4)<<4))</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_strobe()</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_device.write((0x04
| (charvalue & 0x0F)<<4))</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_strobe()</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_device.write(0x0)</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> else:</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_device.write((0x40
| (charvalue >> 4)))</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_strobe()</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_device.write((0x40
| (charvalue & 0x0F)))</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_strobe()</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_device.write(0x0)</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<br /></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> # put char function</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> def lcd_putc(self,
char):</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_write_char(ord(char))</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<br /></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> # put string
function</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> def lcd_puts(self,
string, line):</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> if line == 1:</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_write(0x80)</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> if line == 2:</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_write(0xC0)</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> if line == 3:</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_write(0x94)</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> if line == 4:</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_write(0xD4)</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<br /></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> for char in
string:</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_putc(char)</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<br /></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> # clear lcd and set
to home</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> def
lcd_clear(self):</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_write(0x1)</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_write(0x2)</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<br /></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> # add custom
characters (0 - 7)</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> def
lcd_load_custon_chars(self, fontdata):</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_device.bus.write(0x40);</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> for char in
fontdata:</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> for line in char:</span></span></div>
<div style="margin-bottom: 0in;">
</div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> self.lcd_write_char(line)</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"><br /></span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"><br /></span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">Example
of use, the script that displays welcome banner, <i>hello.py</i>:</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div align="JUSTIFY" style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">import
lcddriver</span></span></div>
<div align="JUSTIFY" style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">from
time import *</span></span></div>
<div align="JUSTIFY" style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<br /></div>
<div align="JUSTIFY" style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">lcd
= lcddriver.lcd()</span></span></div>
<div align="JUSTIFY" style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<br /></div>
<div align="JUSTIFY" style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">lcd.lcd_clear()</span></span></div>
<div align="JUSTIFY" style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">lcd.lcd_display_string("*------------------*",1);</span></span></div>
<div align="JUSTIFY" style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">lcd.lcd_display_string("|System
is running.|",2)</span></span></div>
<div align="JUSTIFY" style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">lcd.lcd_display_string("*------------------*",3);</span></span></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
<br /></div>
<div style="background-color: #e6e6e6; background-position: initial initial; background-repeat: initial initial; margin-bottom: 0in;">
</div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">I
modified few start-up and shutdown handling scripts to run the
scripts that display information on the LCD screen. This way I have
neat messages that you can see on the pictures when the system is
booted up and ready to use and also when I press the shutdown button,
I get the information displayed about the shutdown progress. Since
there is only one display and there are multiple scripts or programs
that would like to write data to it, the proper way to do it would be
to create some sort of a server that would take the requests from
clients and relay them to the LCD screen. For now however I write
them directly to the LCD screen since this was meant as a demo and
proof of operation.</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">E.g:
the script displaying welcome banner, <i>hello.py</i>, was added in
script <i>/etc/rc.local</i> at the end:</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">cd
~pi/src/py/i2c/lcd/hello</span></span></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">python
hello.py &</span></span></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">cd
-</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">The
script that polls GPIO pin #18 for low state, then shuts down the
R-Pi and displays adequate messages to LCD screen, <i>safeoff.py</i>:</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">import
lcddriver</span></span></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">from
time import *</span></span></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">import
RPi.GPIO as GPIO</span></span></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">import
os</span></span></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">import
time</span></span></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<br /></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">GPIO.setmode(GPIO.BCM)</span></span></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">GPIO.setup(18,
GPIO.IN,pull_up_down=GPIO.PUD_UP)</span></span></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<br /></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">lcd
= lcddriver.lcd()</span></span></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">while
True:</span></span></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> if(GPIO.input(18) ==
0):</span></span></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> lcd.lcd_clear()</span></span></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> lcd.lcd_display_string("Shutting
down...",1)</span></span></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> os.system("sudo
shutdown -h now")</span></span></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> break</span></span></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> time.sleep(2)</span></span></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<br /></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">progress
= "/"</span></span></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">while
True:</span></span></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> lcd.lcd_display_string(progress,2)</span></span></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> progress=progress+"/"</span></span></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> time.sleep(1);</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">was
added to <i>/etc/rc.local</i> script as well:</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">cd
~pi/src/py/i2c/lcd/safeoff</span></span></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">python
safeoff.py &</span></span></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">cd
-</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">The
script that displays the final message, <i>systemoffmsg.py</i>:</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">import
lcddriver</span></span></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<br /></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">lcd
= lcddriver.lcd()</span></span></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">lcd.lcd_clear()</span></span></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">lcd.lcd_display_string("System
is halted.",1)</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">And
the script that displays the system restart message, <i>sysrestmsg.py</i>:</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">import
lcddriver</span></span></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<br /></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">lcd
= lcddriver.lcd()</span></span></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">lcd.lcd_clear()</span></span></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">lcd.lcd_display_string("System
will restart.",1)</span></span></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">lcd.lcd_display_string("Wait
for welcome",2)</span></span></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">lcd.lcd_display_string("screen...",3)</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">were
added to <i>/etc/init.d/halt</i> and <i>/etc/init.d/reboot</i>
respectively:</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> log_action_msg
"Will now halt"</span></span></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> python
~pi/src/py/i2c/lcd/safeoff/sysoffmsg.py >/dev/null 2>&1</span></span></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> halt -d -f
$netdown $poweroff $hddown</span></span></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">}</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;">and</span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">do_stop
() {</span></span></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="background-position: initial initial; background-repeat: initial initial;"><span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> # Message
should end with a newline since kFreeBSD may</span></span></span></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="background-position: initial initial; background-repeat: initial initial;"><span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> # print more
stuff (see #323749)</span></span></span></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="background-position: initial initial; background-repeat: initial initial;"><span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> log_action_msg
"Will now restart"</span></span></span></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="background-position: initial initial; background-repeat: initial initial;"><span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> python
~pi/src/py/i2c/lcd/safeoff/sysrestmsg.py</span></span></span></div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="background-position: initial initial; background-repeat: initial initial;"><span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> reboot -d -f
-i</span></span></span></div>
<div style="margin-bottom: 0in;">
</div>
<div align="JUSTIFY" style="background: #e6e6e6; margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"><span style="background-position: initial initial; background-repeat: initial initial;">}</span></span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><b>Pictures.</b></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><b><br /></b></span></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-Na2_DGvGTc5o1YBJrlz7fDARMWvyeF9w3AwB2N0_WxgYDSuhi0BzmY21EP51Y6BY_bQ1I6bakyyLM9CPG5V1l7hxblBa-HH0S9O_U8tvzmZJvpBWvnG84SVQeWcIj8U_PV1oqjZguaaX/s1600/IMG_1899.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg-Na2_DGvGTc5o1YBJrlz7fDARMWvyeF9w3AwB2N0_WxgYDSuhi0BzmY21EP51Y6BY_bQ1I6bakyyLM9CPG5V1l7hxblBa-HH0S9O_U8tvzmZJvpBWvnG84SVQeWcIj8U_PV1oqjZguaaX/s640/IMG_1899.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><div align="CENTER" style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: x-small;"><b>Image
1: R-Pi with I2C LCD and shutdown switch connected before it was put
in the case.</b></span></span></div>
</td></tr>
</tbody></table>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><b><br /></b></span></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggL0GcxbUCpi8moErwhCqgXcnhLKdQnk4gdy7cr2YzPvxE-qsxcISU4hrf9L0CyPnjGtDuokN-cQNQy0jhvRIdS8VWHjmr4yRUtcWKWVlZRbWARAsfyuVNR33gvi7c-xxwOVcMd10-DxOR/s1600/IMG_1900.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggL0GcxbUCpi8moErwhCqgXcnhLKdQnk4gdy7cr2YzPvxE-qsxcISU4hrf9L0CyPnjGtDuokN-cQNQy0jhvRIdS8VWHjmr4yRUtcWKWVlZRbWARAsfyuVNR33gvi7c-xxwOVcMd10-DxOR/s640/IMG_1900.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><div align="CENTER" style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: x-small;"><b>Image
2: Detailed view of GPIO connector.</b></span></span></div>
</td></tr>
</tbody></table>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><b><br /></b></span></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijIbjdALN-B_424iB9HE2P2SoPgYp4uQPHwmlBkeCOPltvTrfY_coJmHLF7AYKNnwU25TfSfV4e4CrPJMpe5uoFyMGszpBGwZ1dJOxGBBZUTRDSnl08mRsDOId7lH1t9M0YWwR_qTN5mtv/s1600/IMG_1901.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijIbjdALN-B_424iB9HE2P2SoPgYp4uQPHwmlBkeCOPltvTrfY_coJmHLF7AYKNnwU25TfSfV4e4CrPJMpe5uoFyMGszpBGwZ1dJOxGBBZUTRDSnl08mRsDOId7lH1t9M0YWwR_qTN5mtv/s640/IMG_1901.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><div align="CENTER" style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: x-small;"><b>Image
3: Detailed view of I2C LCD connector.</b></span></span></div>
</td></tr>
</tbody></table>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><b><br /></b></span></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSi7xzplo3HsLmXJPqIz2N6R95NOTPUZBs4N9XmrF9wZAOBJ4WCm-CMtdJjFd8GVX5PjMxToqynnfvhRmitldqdO0to8VUbeDas1_WVVD6bdxk96IUdSyQFrZf0-aOnadSoLwJc4LkMQs2/s1600/IMG_1906.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSi7xzplo3HsLmXJPqIz2N6R95NOTPUZBs4N9XmrF9wZAOBJ4WCm-CMtdJjFd8GVX5PjMxToqynnfvhRmitldqdO0to8VUbeDas1_WVVD6bdxk96IUdSyQFrZf0-aOnadSoLwJc4LkMQs2/s640/IMG_1906.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><div align="CENTER" style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: x-small;"><b>Image
4: R-Pi in case with LCD attached on top with the rubber bands.</b></span></span></div>
</td></tr>
</tbody></table>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><b><br /></b></span></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRgURuImEX_MoS-2nb3yoBsugMFs-ozPxLwqkz5Orxovdwv93EIDk2LGxHBz219Wj4p29ntRJIX1CRppElCqGWqABupckoTyQPGv8EXWvH1woLWAp24sNTWq-z72oeqp0hPEMiu2nuoDnp/s1600/IMG_1907.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjRgURuImEX_MoS-2nb3yoBsugMFs-ozPxLwqkz5Orxovdwv93EIDk2LGxHBz219Wj4p29ntRJIX1CRppElCqGWqABupckoTyQPGv8EXWvH1woLWAp24sNTWq-z72oeqp0hPEMiu2nuoDnp/s640/IMG_1907.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><div align="CENTER" style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: x-small;"><b>Image
5: R-Pi, side view.</b></span></span></div>
</td></tr>
</tbody></table>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><b><br /></b></span></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxpml5PsqD9eKtnBpWoCar1aw882TNuBw6Vj9eZSF6WUtD_WYu9QrX9jPKuX1dMBBFdkRCFnViMcwjpqX-45h9E4sZP2UoDFEkq-gLnPHkR21eH-gPb3rDlzi0rXDzhfw6E8qXO_-QC2nJ/s1600/IMG_1908.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjxpml5PsqD9eKtnBpWoCar1aw882TNuBw6Vj9eZSF6WUtD_WYu9QrX9jPKuX1dMBBFdkRCFnViMcwjpqX-45h9E4sZP2UoDFEkq-gLnPHkR21eH-gPb3rDlzi0rXDzhfw6E8qXO_-QC2nJ/s640/IMG_1908.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><div align="CENTER" style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: x-small;"><b>Image
6: R-Pi, back side view, a bit of creativity with a Lego (C) block
supporting the LCD screen.</b></span></span></div>
</td></tr>
</tbody></table>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><b><br /></b></span></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjyHq8l5yD-1jLYf0j9R3H7uKcGQmbSd3KgKKceWqqWRtZIHWT0AGqM_f_qHUVzBk29624TvsFF1L-omGT3fkTcifGjXGTpnovbaRGnxTLv33Umfr2F0JuN4Tk01yNW-WeVa3uJwdiABEjX/s1600/IMG_1909.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjyHq8l5yD-1jLYf0j9R3H7uKcGQmbSd3KgKKceWqqWRtZIHWT0AGqM_f_qHUVzBk29624TvsFF1L-omGT3fkTcifGjXGTpnovbaRGnxTLv33Umfr2F0JuN4Tk01yNW-WeVa3uJwdiABEjX/s640/IMG_1909.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><div align="CENTER" style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: x-small;"><b>Image
7: ...and the SD card side view.</b></span></span></div>
</td></tr>
</tbody></table>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><b><br /></b></span></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmw0tz8DKmI_ulnycqw8w8NBpkWUoCkqLKjKAzvwFLO_SDMKGdGTYPo03SQuhVBir7ha6Egnbop0zpI8sI6Et4MHQd-vdWhKH4Jldemnu9lb6EMLk8M0N34Ww0F6Jw97c1rLXDdt-xtZIZ/s1600/IMG_1910.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjmw0tz8DKmI_ulnycqw8w8NBpkWUoCkqLKjKAzvwFLO_SDMKGdGTYPo03SQuhVBir7ha6Egnbop0zpI8sI6Et4MHQd-vdWhKH4Jldemnu9lb6EMLk8M0N34Ww0F6Jw97c1rLXDdt-xtZIZ/s640/IMG_1910.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><div align="CENTER" style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: x-small;"><b>Image
8: Welcome banner displayed on LCD after R-Pi boot-up.</b></span></span></div>
</td></tr>
</tbody></table>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><b><br /></b></span></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicbM4jwVgjKiEyCuXePGYHmzP92DpQu9N44rrI3QDh-AuDZE4gjh38AJyhuOStRRVdoZwvcVIIG6A3wlu55mbiWIMoqtdWXoh8cpvd0SjLHYynXVN-1TuytKUwgizGfZpZpd-93AANij1M/s1600/IMG_1913.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEicbM4jwVgjKiEyCuXePGYHmzP92DpQu9N44rrI3QDh-AuDZE4gjh38AJyhuOStRRVdoZwvcVIIG6A3wlu55mbiWIMoqtdWXoh8cpvd0SjLHYynXVN-1TuytKUwgizGfZpZpd-93AANij1M/s640/IMG_1913.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><div align="CENTER" style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: x-small;"><b>Image
9: Testing shutdown button.</b></span></span></div>
</td></tr>
</tbody></table>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><b><br /></b></span></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhW5G8aTnrjol9OZrNIqQ8SS4-B4X6SUVNwVMpbg5hBLNmzSqe3-nv3kFGprv2nDiiQBzFeTcvUsuzy-K2iwuQliU-RAf1OzmQ2QpOv8hEIhwP1rg2l2J8ZcVq69S2mJR5D887gBazkLRrK/s1600/IMG_1914.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhW5G8aTnrjol9OZrNIqQ8SS4-B4X6SUVNwVMpbg5hBLNmzSqe3-nv3kFGprv2nDiiQBzFeTcvUsuzy-K2iwuQliU-RAf1OzmQ2QpOv8hEIhwP1rg2l2J8ZcVq69S2mJR5D887gBazkLRrK/s640/IMG_1914.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><div align="CENTER" style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: x-small;"><b>Image
10: Shutdown progress displayed.</b></span></span></div>
</td></tr>
</tbody></table>
<div style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><b><br /></b></span></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4QyncRupZU5uJ5hQx4nbUbAE5gIrJ48-UFjXrfxQBvHp4rBbJzle-JukghKXWBtP5TcnNLWJ1FlfsCZ3Lytifn3NRVgbK0YHuS2-8HZ_qpSLfflsOYcPEXkYxW5C3Hgz5FeiFlLZLmE_L/s1600/IMG_1916.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4QyncRupZU5uJ5hQx4nbUbAE5gIrJ48-UFjXrfxQBvHp4rBbJzle-JukghKXWBtP5TcnNLWJ1FlfsCZ3Lytifn3NRVgbK0YHuS2-8HZ_qpSLfflsOYcPEXkYxW5C3Hgz5FeiFlLZLmE_L/s640/IMG_1916.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><div align="CENTER" style="margin-bottom: 0in;">
<span style="font-family: Verdana, sans-serif;"><span style="font-size: x-small;"><b>Image
11: It is now safe to power off your R-Pi.</b></span></span></div>
</td></tr>
</tbody></table>
<br />
<div>
<span style="font-family: Verdana, sans-serif;">Well, this is it. Nothing much, but perhaps this article will help somebody doing first steps in R-Pi exploration or looking for the information related to the topic of connecting LCD or making a safe power-off switch for R-Pi's embedded use (with no keyboard and HDMI display).</span></div>
<div>
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Verdana, sans-serif;">Thanks for reading.</span></div>
<div>
<span style="font-family: Verdana, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Verdana, sans-serif;">Marek Karcz, 11/16/2013</span></div>
Marek Karczhttp://www.blogger.com/profile/03281397436610614441noreply@blogger.com0tag:blogger.com,1999:blog-4155387638169532413.post-7886127949075355562013-08-05T19:59:00.002-07:002013-08-05T22:08:37.281-07:00Getting acquainted with Raspberry Pi<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">The whole Raspberry Pi craze lasted long enough for me to go and buy one of these boards to try it on. Got one on e-bay, model B, just a board. I purchased SD card separately, an 8GB SDHC SanDisk Ultra. Few days later, just 2 days ago I received my order in mail.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">I must say the setup was a breeze. With the NOOB image, all you need to do is format your SD card, copy files from ZIP archive to your card and stick the SD card in the RPi's slot. Connect keyboard, mouse and display and power it up.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">In 2 days that I have been playing with this board I managed to:</span><br />
<ul>
<li><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">Setup US keyboard layout (default is British). </span></li>
<li><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">Configure WiFi network (SMC WiFi dongle, based on ZD1211 chip).</span></li>
<li><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">Install and configure VNC server so I can access GUI desktop of my RPi from Windows or Linux based computer with TightVNC client.</span></li>
<li><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">Check USB to RS-232 converter that works with RPi (based on PL2302 chip). </span></li>
<li><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">Install and configure Samba for server file sharing.</span></li>
<li><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">Install GPIO and I2C Python libraries.</span></li>
<li><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">Connect and successfully program (with the help of wonderfully rich internet resources already available for RPi) I2C LCD screen that I originally purchased for my Arduino.</span></li>
<li><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">Make a safe shutdown switch connected to GPIO pin #18 which is polled by a simple Python script that shuts down RPi when the switch is pressed for more than 1 second while displaying shutdown progress on LCD screen.</span></li>
</ul>
<span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">I was going to publish some of the URL-s and instructions/code that I used while achieving above goals, h</span><span style="font-family: 'Helvetica Neue', Arial, Helvetica, sans-serif;">owever anybody that can Google stuff can find out quick enough how to do these things. No need to create more noise I guess. Perhaps when I do something original with the touch of my own original thought, I will publish detailed documentation of the process.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;"><br /></span>
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">These are wonderful times for electronics/computer hobbyists. Sometimes I think this stuff is just too easy!</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">My plan is to make a trip/car computer out of this RPi with the aid of OBD2 to USB codes scanner/converter I got on eBay, which is based on ELM 327 chip and with aforementioned I2C LCD display as a data presentation device. There is a piece of free software that works with that ODB2 scanner device on RPi and it can be integrated into Python's code.</span><br />
<span style="font-family: Helvetica Neue, Arial, Helvetica, sans-serif;">Considering that this board is almost a full blown PC computer, and considering its low price and the amount of software/code base already available on the internet for tinkering and numerous examples of use, this is a great deal. The device that is ready for standard PC compatible peripherals (via USB) and with its GPIO expansion slot, it is the best of 2 worlds - a standard PC platform running familiar Linux OS with more than sufficient processing power for hobby projects and beyond and with the means to interface with outside world it is a great board to be added to any computer/electronics hobbyist's toolbox.</span><br />
<div>
<br /></div>
Marek Karczhttp://www.blogger.com/profile/03281397436610614441noreply@blogger.com0tag:blogger.com,1999:blog-4155387638169532413.post-69108225356165364162013-06-07T21:09:00.000-07:002015-11-19T19:59:42.904-08:00MKHBC-8-R1 homebrew 6502 computer - assembling CPU card.<span style="font-family: "verdana" , sans-serif;">Very slowly however consequently I move forward with the project. I finished (well, almost) my back plane and now I am ready to assemble my first two cards - CPU card (which is really a combination of CPU, address and I/O decoders, ROM and RAM) and the serial port/uart card.</span><br />
<span style="font-family: "verdana" , sans-serif;">Every engineering project should be well documented. I created circuit diagrams in Express SCH and component layout for CPU card in Express PCB.</span><br />
<span style="font-family: "verdana" , sans-serif;">I also created a <a href="https://skydrive.live.com/redir?resid=1134B9F29C36FE0B!35445" target="_blank">design and specifications document</a> which I update regularly.</span><br />
<span style="font-family: "verdana" , sans-serif;"><br /></span>
<span style="font-family: "verdana" , sans-serif;">(NOTE: You may want to download this document to your computer and view it locally with Open Office instead of the Word viewer provided by SkyDrive - for some reason it can not display pictures embedded in the document when viewed in the web viewer. Probably Open Office/Word format incompatibility issue.)</span><br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipEhM3E6Gsmy7_peRDofwoDKC27c9GfpxSZ4giyXhd5nu25f4uBJg5tTe2nrljUH7UXVDv-XqZm-dWRQS8OSnAJ1UCj6uDxSdV9dt7YCzvK4ssI2Wmm6x96lbUXemgtJ1Ppezd-eqAvvCE/s1600/MKHBC-8-R1-CPU1.bmp" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="442" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEipEhM3E6Gsmy7_peRDofwoDKC27c9GfpxSZ4giyXhd5nu25f4uBJg5tTe2nrljUH7UXVDv-XqZm-dWRQS8OSnAJ1UCj6uDxSdV9dt7YCzvK4ssI2Wmm6x96lbUXemgtJ1Ppezd-eqAvvCE/s1600/MKHBC-8-R1-CPU1.bmp" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">CPU card circuit diagram.</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFTn9IpKKe_5IJCBqGiLuTSHSQtDJ9VQlSWujN-fFDfIg5q4CaYwktWYzu6dc3YDHS60EV5WzetK7KdIz0-OOpM6q_FXJM8qMU8zcOX_h0dkVGibNVKLBB5VTSqfCX0wjatqgzbtvwblhe/s1600/MKHBC-8-R1-EPROM.bmp" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="442" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiFTn9IpKKe_5IJCBqGiLuTSHSQtDJ9VQlSWujN-fFDfIg5q4CaYwktWYzu6dc3YDHS60EV5WzetK7KdIz0-OOpM6q_FXJM8qMU8zcOX_h0dkVGibNVKLBB5VTSqfCX0wjatqgzbtvwblhe/s1600/MKHBC-8-R1-EPROM.bmp" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">CPU card - EPROM.</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjbAyp0gVuutWoXrPM2IyGzddZZ_M7iVMeVXdQkPFg2IiiJp9sx1fPxdpHMkC57I5iWTLFX-6ZVpPnWxAE9FVASmqW9Pu3L0Uj0tlM8ybSPgbyXhOv3N3do3fFOkBAqSunRebHMqV-e3w_k/s1600/MKHBC-8-R1-BaseRAM.bmp" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="482" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjbAyp0gVuutWoXrPM2IyGzddZZ_M7iVMeVXdQkPFg2IiiJp9sx1fPxdpHMkC57I5iWTLFX-6ZVpPnWxAE9FVASmqW9Pu3L0Uj0tlM8ybSPgbyXhOv3N3do3fFOkBAqSunRebHMqV-e3w_k/s1600/MKHBC-8-R1-BaseRAM.bmp" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">CPU card - base RAM.</td></tr>
</tbody></table>
<span style="font-family: "verdana" , sans-serif;"><br /></span>
<span style="font-family: "verdana" , sans-serif;">Some of the circuit elements are missing on the board, I will update the blog shortly as the work progresses.</span><br />
<span style="font-family: "verdana" , sans-serif;">It is worth the note that despite the fact that I use a multiple board back plane design, I decided to make the CPU card able to function in a single board mode (sort of). Additionally to the euro 64-pin male connector that goes into the back plane's slot, the CPU card will also have the IDE type 40-pin male connector on the opposite side (or on the top) from euro connector (J4 on the diagram). This 40-pin connector, or rather slot will be identical that I used for the I/O expansion bus slots. The connector's pins will be connected to the same signals on CPU card that go into the I/O expansion bus (will be compatible with I/O expansion bus pin-out and IOSEL signal will go directly to one of the /IO0../IO7 pins on CPU card, perhaps via some jumper selector to allow configuration choices) thus creating ability to connect the I/O card (e.g: serial port card, general purpose I/O card etc.) directly to the CPU board. The euro connector will be used in the SBC mode to attach the CPU card to the control panel board with power supply, control buttons, LCD, generic I/O etc. - we can call it a simplified back plane, with one 64-pin slot only (luckily I have one spare). The details are included in the </span><a href="https://skydrive.live.com/redir?resid=1134B9F29C36FE0B!35445" style="font-family: Verdana, sans-serif;" target="_blank">design and specifications document</a><span style="font-family: "verdana" , sans-serif;"> mentioned earlier. When inserted to back plane, the J4 slot on the CPU card will not be used. This design may require some creative programming so the firmware would not require to be updated if I move between back plane and SBC modes (auto detection of some sort).</span><br />
<span style="font-family: "verdana" , sans-serif;">I made some layout work already on the CPU card and soldered the IC sockets and J4 connector into the board.</span><br />
<span style="font-family: "verdana" , sans-serif;"><br /></span>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj06TEXtY85Fucxb3t4cQ1bCD-QMYZWGVPaJIaCx7ngWM0841bAhL5VpV8snzjxX6GoffYO5MLB9yAZ6baeHUp0W8A38vyRvX5EeM8V6khyphenhyphenghcHf7D5ysBFxqjSKBBT96m8REBZ1Qa5dN38/s1600/MKHBC-8-R1-CPUCardCompLayout.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="458" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj06TEXtY85Fucxb3t4cQ1bCD-QMYZWGVPaJIaCx7ngWM0841bAhL5VpV8snzjxX6GoffYO5MLB9yAZ6baeHUp0W8A38vyRvX5EeM8V6khyphenhyphenghcHf7D5ysBFxqjSKBBT96m8REBZ1Qa5dN38/s1600/MKHBC-8-R1-CPUCardCompLayout.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">CPU card - PCB layout.</td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: center;">
</div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgVh7oGuwyrcVp4rKqyv2iHvpo2gLP2JAtR7R78ggfeGGns1F5N_owMB_DO0oTAmoBHef1B8z1suAm0OWfvYz135dnt-0vXvd5F9vI_fcXhDD_LaRnYWrTAPdmf0khqgLP_qB3YXogQUy4/s1600/IMG_1266.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjgVh7oGuwyrcVp4rKqyv2iHvpo2gLP2JAtR7R78ggfeGGns1F5N_owMB_DO0oTAmoBHef1B8z1suAm0OWfvYz135dnt-0vXvd5F9vI_fcXhDD_LaRnYWrTAPdmf0khqgLP_qB3YXogQUy4/s1600/IMG_1266.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">The actual CPU card board in its current building phase.</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5nXWjMXCEHU5ThJhBQJnw4YVhgbOLDdjGu6EPeR6ev82_JTO5aww3cDXgVhmj94rWwcAU5P_L4h6b69t0hzGnpJCINRojDm1WlHjwdzAaeM91XEVkCDzJnEyt6BIWvn2omx_D7R0Fof39/s1600/IMG_1267.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi5nXWjMXCEHU5ThJhBQJnw4YVhgbOLDdjGu6EPeR6ev82_JTO5aww3cDXgVhmj94rWwcAU5P_L4h6b69t0hzGnpJCINRojDm1WlHjwdzAaeM91XEVkCDzJnEyt6BIWvn2omx_D7R0Fof39/s1600/IMG_1267.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">The back of the CPU card - there will be a lot more soldered points and wires here soon.</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi7Vu9lZ06GZR_HZXFOPx_zG4-ukAjUts-go82CRdnynNEDY9dMQb9zFj3EUwVRgXcXTvlk83i-SqlqKPg9XI6dzHrXSOENJWWC6mNI4bEbrG1sL5YMbkO1HPRCaNViuCmhNT6EX6Ejom9z/s1600/IMG_1268.JPG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="480" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi7Vu9lZ06GZR_HZXFOPx_zG4-ukAjUts-go82CRdnynNEDY9dMQb9zFj3EUwVRgXcXTvlk83i-SqlqKPg9XI6dzHrXSOENJWWC6mNI4bEbrG1sL5YMbkO1HPRCaNViuCmhNT6EX6Ejom9z/s1600/IMG_1268.JPG" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">CPU card sitting in the back plane's CPU bus slot.</td></tr>
</tbody></table>
<span style="font-family: "verdana" , sans-serif;">Since the back-plane is almost finished, I include the circuit diagram of CPU and I/O expansion buses below as well.</span><br />
<span style="font-family: "verdana" , sans-serif;"><br /></span>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzYah3kpXzPO-U6OwEs5YeE4RbqplURYrJURJdTVG3B1oyPHFlmXy8KVt5iGUjuZFIACjNQQQG6_SU5JQJZ2qoQnoWnMNOXxeIwFAGPERWzSnSJb39HdkwU2RqaG4Wjv-wMvt-MPMPz9NP/s1600/MKHBC-8-R1-CPUBus.bmp" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="442" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzYah3kpXzPO-U6OwEs5YeE4RbqplURYrJURJdTVG3B1oyPHFlmXy8KVt5iGUjuZFIACjNQQQG6_SU5JQJZ2qoQnoWnMNOXxeIwFAGPERWzSnSJb39HdkwU2RqaG4Wjv-wMvt-MPMPz9NP/s1600/MKHBC-8-R1-CPUBus.bmp" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Back plane - CPU bus.</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMmzBSqxdOC5LP6Tp5TPBtGYpgX129MUMMIBznk90w5katEdstej0FdtdwRXIIoN0xm6BQms1ebeV-zc_roRq-xIBzdcbjxpRKFKjucrkpQwhTj3yrCSbTIUGXm28KnH4qm2dyp0vRMJV3/s1600/MKHBC-8-R1-IOBUS.bmp" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="442" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhMmzBSqxdOC5LP6Tp5TPBtGYpgX129MUMMIBznk90w5katEdstej0FdtdwRXIIoN0xm6BQms1ebeV-zc_roRq-xIBzdcbjxpRKFKjucrkpQwhTj3yrCSbTIUGXm28KnH4qm2dyp0vRMJV3/s1600/MKHBC-8-R1-IOBUS.bmp" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Back plane - I/O expansion bus.</td></tr>
</tbody></table>
<span style="font-family: "verdana" , sans-serif;">Thank you for visiting my blog.</span><br />
<span style="font-family: "verdana" , sans-serif;"><br /></span>
<span style="font-family: "verdana" , sans-serif;">Marek</span><br />
<span style="font-family: "verdana" , sans-serif;"><br /></span>
<span style="font-family: "verdana" , sans-serif;">6/8/2013.</span><br />
<span style="font-family: "verdana" , sans-serif;"><br /></span>Marek Karczhttp://www.blogger.com/profile/03281397436610614441noreply@blogger.com0tag:blogger.com,1999:blog-4155387638169532413.post-23191993784215310722013-05-27T10:45:00.000-07:002013-05-27T10:59:28.751-07:00I2C keyboard controller - update.<div style="margin-bottom: 0in;">
Months of testing with various Arduino
projects has proven that the I2C keyboard prototype is working therefore I
decided to assemble it on the permanent board. I used a RadioShack's
pre-drilled stripboard number 276-168B and point to point soldering
technique with 30-gauge solderable magnet wire (insulation coating
dissolves under heat from soldering iron). I have made modifications
to the original circuit diagram. I added programming connector so the
firmware can be updated without taking out the AT89S52 chip out of
the board. All you need is an ISP programmer with 10 pin connector
and you need to open the J4 jumper pins 1, 2 for programming mode. A
fact worth noting is that I connected AT89S52's pin #31 (/EA) to VCC
- a must for an internal program execution mode. It took me an extra
hour to figure this out when my board wasn't working. I apparently
had this connection done on the breadboard but I forgot to update it
on the diagram. Months passed since and I forgot. I also replaced
ugly keyboard and LCD symbols on the diagram with connector symbols.
The board is built in such a way that it can also serve as a basic
development board for AT89S52. It has standard 16x2 16-pin LCD
connector for HDD44780 compatible display which can be used as multi
purpose I/O connector in case LCD display is not used and 15-pin
connector for the matrix keyboard (TI-99/4A) can be used as a multi
purpose I/O ports connector as well. I may need to add some more I/O
connectors and a serial port in case I use this board for any other
purpose than I2C keyboard driver, but this is not likely. I will
rather build another one, but I digress.</div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
I did changes to the firmware since last update:<br />
<br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">/*</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * Project: TI99-4A I2C keyboard.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * Module: ti994a</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * Author: Marek Karcz</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * Updated: 2012/12/30</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * Purpose: TI99-4A keyboard and LCD disp. with micro connected to I2C.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * I2C input device. Works in MASTER mode.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * I2C output device (LCD). Works in MASTER mode.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * Hardware:</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * Atmel 8051 compatible microcontroller AT89S52.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * 1602 LCD display</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * TI99-4A matrix keyboard (ports P2, P3).</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * I2C line drivers (NPN transistors, base and pull-up resistors, NAND gates 74LS00).</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * NAND gates - incoming SDA, SCK from I2C bus to data/clock in pins.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * NPN transistors - outgoing SDA, SCL signals from 8051 data/clock out pins to I2C bus.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> *</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * Keyboard to port pin connections:</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> *</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * TI99-4a pin# Pn.b</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * --------------------------</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * 11 P3.7</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * 10 P3.6</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * 3 P3.5</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * 7 P3.4</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * 2 P3.3</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * 1 P3.2</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * 4 P3.1</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * 5 P3.0</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> *</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * 6 P2.6</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * 8 P2.5</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * 9 P2.4</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * 15 P2.3</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * 14 P2.2</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * 13 P2.1</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * 12 P2.0</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> *</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * =================================</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> *</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * I2C bus interface:</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> *</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * P1.3 - sda (data) out inverted</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * P1.4 - sda (data) in inverted</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * P1.5 - scl (clock) out inverted</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * P1.6 - scl (clock) in inverted</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> *</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * ================================</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> *</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * TO DO:</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> *</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * 1) Auto-repeat. - DONE</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * 1a) Keyboard scan must run in interrupt and queue the keys in a buffer. - DONE</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * 2) Cover all CTRL ANSI codes.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * 3) Receive characters from I2C bus and display on LCD.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * In progress...</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * Current protocol: </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * * Device sends a single key code to I2C bus.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * * Device requests single key code from I2C bus (echo).</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * Planned expansion to protocol:</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * * Device sends a single key code to I2C bus.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * * Device requests number of available bytes for LCD display from I2C bus.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * * Device reads all available bytes from I2C bus.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * 4) Fully implement arbitration and clock stretching. - DONE</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * 5) Figure out why Arduino does not ACK when addressed as slave-receiver. - DONE</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * (NOTE: implementation of #4 and polling data until ACK returns OK)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * 6) Use extra port line to generate interrupt for external receiver/CPU.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> */</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#include <at89x52.h></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#include <stdlib.h></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#include <string.h></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">// keil -> sdcc</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define sbit __sbit</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define code __code</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define using __using</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define interrupt __interrupt</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define _nop_() __asm NOP __endasm</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">//#define _nop4_() __asm NOP NOP NOP NOP NOP NOP __endasm</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define _nop4_() __asm NOP NOP NOP NOP __endasm</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">typedef unsigned char BYTE;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">typedef unsigned int WORD;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">typedef sbit BOOL ;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define rs P1_0 </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define rw P1_1</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define ep P1_2</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define KBP1 P3</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define KBP2 P2</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">// NOTE: I2C pins are inverted</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">// </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define SDA_OUT P1_3</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define SDA_IN P1_4</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define SCL_OUT P1_5</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define SCL_IN P1_6</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define I2C_HIGH 0</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define I2C_LOW 1</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define ACK FALSE</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define NACK TRUE</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define TRUE 1</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define FALSE 0</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define WAIT4ACK 100</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define KEYBUFLEN 16</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define INTDIVCT 0</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">#define KBRPTDEL 18 // keyboard repeat delay</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">BYTE code g_ucaDispMsgPrdNameVer[] = {"I2C kbrd 2.4 "};</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">BYTE code g_ucaDispMsg2[] = {"(C) Marek Karcz "};</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">BYTE code g_ucaDispMsgLineBusy[] = {"I2C line busy..."};</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">BYTE g_ucaDispBuf[17];</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">BYTE g_ucKeyCode=0;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">BYTE g_ucPrevKey=0;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">BYTE g_ucRow=0;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">BYTE g_ucColumn=0;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">BYTE code g_ucaKbMatrix[8][7] =</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{11, 43, 42, 41, 40, 22, 0},</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{47, 31, 30, 29, 28, 32, 0},</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{33, 20, 19, 18, 17, 21, 0},</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{ 0, 9, 8, 7, 6, 10, 0},</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{48, 2, 3, 4, 5, 1, 45},</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{44, 24, 25, 26, 27, 23, 0},</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{46, 13, 14, 15, 16, 12, 0},</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{ 0, 36, 37, 38, 39, 35, 0}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">};</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">BOOL g_bShiftOn = FALSE;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">BOOL g_bCtrl = FALSE;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">BOOL g_bFunc = FALSE;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">BOOL g_bLock = FALSE;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">BOOL g_bStarted = FALSE;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">BYTE g_ucaKeyBuf[KEYBUFLEN];</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">BYTE g_ucKeyBufStartIndex = 0;// at the beginning buffer is empty</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">BYTE g_ucKeyBufEndIndex = 0; // StartIndex == EndIndex -> buffer empty</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">BYTE g_ucDivIntCt = INTDIVCT; // kb scan interrupt divider/counter</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">BYTE g_ucKbRptDel = KBRPTDEL; // kb repeat delay counter</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">void init_SFR(void)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> TMOD |= 0x01; // timer 0, mode 1, 16 bit</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>TH0 = 0x70; // for 40 ms timer (on XTAL=11.0592 MHz)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>TL0 = 0x00; // keyboard scan frequency is 25/INTDIVCT/s</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>IE = 0xA2; // 0x82; // enable IE.1 (timer 0) and global interrupt. (IE.7)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> TR0 = 1; // timer 0 runs</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">void init_ports(void)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>KBP1 = 0x00;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>KBP2 = 0xFF;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>P1 = 0xFF;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>SDA_IN = 1;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>SCL_IN = 1;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>SDA_OUT = 0;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>SCL_OUT = 0;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">void init_g_ucaDispBuf(void)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>BYTE i = 0;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>for(i=0; i<16; i++)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>g_ucaDispBuf[i]=32;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>g_ucaDispBuf[i]=0;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">void init_vars(void)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>BYTE i = 0;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>init_g_ucaDispBuf();</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>g_ucKeyCode=0xFF;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>g_ucPrevKey=0;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>g_ucRow=0;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>g_ucColumn=0;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>g_ucKeyBufStartIndex = g_ucKeyBufEndIndex = 0;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>for (i=0; i<KEYBUFLEN; i++)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>g_ucaKeyBuf[i] = 0;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>g_ucDivIntCt = INTDIVCT;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>g_ucKbRptDel = KBRPTDEL;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">void delay(BYTE ms)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">{ </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> BYTE i;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> while(ms--)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> {</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> for(i = 0; i< 250; i++)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> {</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> _nop4_();</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> }</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> }</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">/*</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * LCD 16x2 driver functions.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> */</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">BOOL lcd_bz()</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">{ </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> BOOL result;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> rs = 0;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> rw = 1;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> ep = 1;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> _nop4_();</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> result = (BOOL)(P0 & 0x80);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> ep = 0;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> return result; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">void lcd_wcmd(BYTE cmd)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">{ </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> while(lcd_bz());</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> rs = 0;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> rw = 0;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> ep = 0;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> _nop_();</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> _nop_(); </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> P0 = cmd;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> _nop4_();</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> ep = 1;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> _nop4_();</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> ep = 0; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">void lcd_pos(BYTE pos)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> lcd_wcmd(pos | 0x80);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">void lcd_wdat(BYTE dat) </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">{ </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> while(lcd_bz());</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> rs = 1;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> rw = 0;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> ep = 0;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> P0 = dat;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> _nop4_();</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> ep = 1;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> _nop4_();</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> ep = 0; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">void lcd_init()</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> lcd_wcmd(0x38); </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> delay(1);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> lcd_wcmd(0x0c); </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> delay(1);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> lcd_wcmd(0x06);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> delay(1);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> lcd_wcmd(0x01);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> delay(1);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">void lcd_clear(BYTE pos)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> BYTE i=0;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> lcd_pos(pos);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> for(i=0; i<16; i++)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> {</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> lcd_wdat(32);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> }</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">void lcd_text(BYTE pos, BYTE txt[])</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> BYTE i=0;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> lcd_clear(pos);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> lcd_pos(pos);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> i=0;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> while((int)txt[i] != (int)'\0')</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> {</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> lcd_wdat(txt[i]); </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> i++;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> }</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">void lcdmsg(BYTE msg[], BYTE iter, BYTE dl)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>BYTE n;</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>lcd_text(0, msg);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>for(n=0; n<iter; n++)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> delay(dl);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> lcd_text(0, g_ucaDispMsgPrdNameVer);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">/*</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * TI99-4A keyboard driver functions.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> */</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">/* Scans keyboard.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * Returns 0 if no key pressed.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * Returns row# (1-8) if key pressed.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * Sets global flags indicating special/control key pressed.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * Column is calculated from the read key code.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> */</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">BYTE read_kb(void)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>BYTE i=0;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>BYTE j=0;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>BYTE ret=0;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>BYTE keyscan=0;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>BYTE pattern=0x01;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>BYTE col=0;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>g_ucKeyCode = 0;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>for (i=0,pattern=0x01; pattern!=0; pattern<<=1,i++)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> KBP2 = 0xFF;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> KBP1 = ~pattern;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> keyscan = KBP2;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> if(keyscan!=0xFF)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> {</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> init_g_ucaDispBuf();</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> for(j=1,col=0; j!=0; j<<=1,col++)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> {</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> if (~keyscan & j)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> {</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if (g_ucaKbMatrix[i][col] == 44) g_bShiftOn = TRUE;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>else if (g_ucaKbMatrix[i][col] == 45) { g_bShiftOn = TRUE; g_bLock = TRUE; }</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>else if (g_ucaKbMatrix[i][col] == 46) g_bCtrl = TRUE;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>else if (g_ucaKbMatrix[i][col] == 48) g_bFunc = TRUE;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>else { g_ucRow = i; ret = i+1; g_ucColumn = col; g_ucKeyCode = g_ucaKbMatrix[g_ucRow][g_ucColumn]; }</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> }</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> }</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> }</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>// key released, reset flags</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if (ret == 0)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> g_bShiftOn = g_bLock = g_bCtrl = g_bFunc = FALSE;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>return ret;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">/*</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * Keyboard buffer is a ring/round-about FIFO register.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> */</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">static void add2KeyBuf(BYTE kc) using 1</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> g_ucaKeyBuf[g_ucKeyBufEndIndex++] = kc;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if (g_ucKeyBufEndIndex >= KEYBUFLEN)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>g_ucKeyBufEndIndex = 0;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">static BYTE getKeyFromBuf(void) using 1</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> BYTE kbk = 0;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if (g_ucKeyBufStartIndex != g_ucKeyBufEndIndex)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> kbk = g_ucaKeyBuf[g_ucKeyBufStartIndex++];</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if (g_ucKeyBufStartIndex >= KEYBUFLEN)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>g_ucKeyBufStartIndex = 0;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>return kbk;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">/*</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * Interrupt routine - timer 0.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * Scan keyboard, queue pressed keys in the buffer;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> */</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">void tim0(void) interrupt 1 using 1</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>TH0=0x70;<span class="Apple-tab-span" style="white-space: pre;"> </span> // reload counter</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>TL0=0x00;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if (g_ucDivIntCt) g_ucDivIntCt--;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> if (g_ucDivIntCt == 0)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if (read_kb())</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> if (g_ucKeyCode != g_ucPrevKey)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> add2KeyBuf(g_ucKeyCode);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>g_ucKbRptDel = KBRPTDEL;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>else</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if (g_ucKbRptDel) g_ucKbRptDel--;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if (g_ucKbRptDel == 0)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> add2KeyBuf(g_ucKeyCode);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>g_ucKbRptDel = KBRPTDEL/4;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>g_ucPrevKey = g_ucKeyCode;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>g_ucDivIntCt = INTDIVCT;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">/* </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * I2C bus communication driver functions.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> *</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * NOTE: in/out data and clk signals inverted</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> */</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">BOOL I2C_SclBusy(void)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>return (SCL_IN == I2C_LOW);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">BOOL I2C_SdaBusy(void)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>return (SDA_IN == I2C_LOW);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">BOOL I2C_LineBusy(void)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>return (I2C_SclBusy() || I2C_SdaBusy());</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">/*</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * Arbitration of the I2C line.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * Returns TRUE if won, FALSE if lost.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> */</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">BOOL I2C_Arbitration(void)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>return ((I2C_SdaBusy()) ? FALSE : TRUE);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">void I2C_StretchScl(void)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> int nTimeOut = 2000;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>while (I2C_SclBusy() && nTimeOut > 0) // clock stretching</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> nTimeOut--; // prevent hang up</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">/* Send start condition with clock stretching</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * and arbitration of I2C line.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> *</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> */</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">void I2C_Start(void)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> SDA_OUT = I2C_HIGH;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> SCL_OUT = I2C_HIGH;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> if (g_bStarted) // already started - do restart</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> {</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> _nop4_();</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>I2C_StretchScl();</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> _nop4_();</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> }</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> if (I2C_Arbitration())</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> {</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> _nop4_();</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> SDA_OUT = I2C_LOW;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> _nop4_();</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> SCL_OUT = I2C_LOW;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> g_bStarted = TRUE;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">void I2C_Stop(void) /*Stop condition*/</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>I2C_StretchScl();</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> if (I2C_Arbitration())</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> {</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> SDA_OUT = I2C_LOW;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> SCL_OUT = I2C_LOW;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> _nop4_();</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> SCL_OUT = I2C_HIGH;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> _nop4_();</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> SDA_OUT = I2C_HIGH;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> _nop4_();</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> g_bStarted = FALSE;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">void I2C_WriteBit(BOOL bitval)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> SDA_OUT = ((bitval) ? I2C_HIGH : I2C_LOW);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> _nop4_();</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>SCL_OUT = I2C_HIGH;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>I2C_StretchScl();</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if (!bitval || I2C_Arbitration())</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> _nop4_();</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>SCL_OUT = I2C_LOW;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">BOOL I2C_ReadBit(void)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> BOOL br = FALSE;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>SCL_OUT = I2C_HIGH;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>_nop4_();</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>I2C_StretchScl();</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>br = ((SDA_IN == I2C_HIGH) ? TRUE : FALSE);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> _nop4_();</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>SCL_OUT = I2C_LOW;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>return br;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">BOOL I2C_WriteByte(BOOL sendstart,</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> BOOL sendstop,</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> BYTE byteval)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> BYTE bitc = 0;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>BOOL nack = FALSE;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if (sendstart)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> I2C_Start();</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>for (bitc=0; bitc<8; bitc++)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> I2C_WriteBit((byteval & 0x80) != 0);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>byteval <<= 1;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>nack = I2C_ReadBit();</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if (sendstop)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> I2C_Stop();</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>return nack;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">BYTE I2C_ReadByte(BOOL nack,</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> BOOL sendstop)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> BYTE rbyte = 0;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>BYTE bitc = 0;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>for (bitc=0; bitc<8; bitc++)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> rbyte = (rbyte << 1) | I2C_ReadBit();</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>I2C_WriteBit(nack);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>if (sendstop)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> I2C_Stop();</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>return rbyte;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">void I2C_SendKey(BYTE kc)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>BOOL nack = TRUE;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>int nTimeOut = WAIT4ACK;</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> lcd_pos(0x4b); lcd_wdat('S');</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>SDA_OUT = I2C_HIGH;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>SCL_OUT = I2C_HIGH;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> _nop4_();</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>// slave receiver address = 4 </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>// shift left for 7 bit addr. and set LSB (R/W bit)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>// LSB = 0 - WRITE</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>while (nack && nTimeOut > 0)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> nack = I2C_WriteByte(TRUE,FALSE,(4<<1)&0xfe); </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> lcd_pos(0x4f); lcd_wdat((nack) ? 'N' : 'A');</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> nTimeOut--;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>delay(5);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>nTimeOut = WAIT4ACK;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>nack = TRUE;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>while (nack && nTimeOut > 0)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> nack = I2C_WriteByte(FALSE,TRUE,kc);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> lcd_pos(0x4a); lcd_wdat((nack) ? 'N' : 'A');</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>nTimeOut--;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>delay(5);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">BYTE I2C_GetKey(void)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> BYTE brd = 0;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>BOOL nack = TRUE;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>int nTimeOut = WAIT4ACK;</span><br />
<span class="Apple-tab-span" style="white-space: pre;"><span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> </span></span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> lcd_pos(0x4b); lcd_wdat('G');</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>SDA_OUT = I2C_HIGH;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>SCL_OUT = I2C_HIGH;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> _nop4_();</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>// slave transmitter address = 4</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>// shift left for 7 bit addr. and set LSB (R/W bit)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>// LSB = 1 - READ</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>while (nack && nTimeOut > 0)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> nack = I2C_WriteByte(TRUE,FALSE,(4<<1)|0x01); </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> lcd_pos(0x4e); lcd_wdat((nack) ? 'N' : 'A');</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>nTimeOut--;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>delay(5);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> brd = I2C_ReadByte(NACK, TRUE);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>return brd;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">/*</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * Convert keyboard scan code to ANSI ASCII code.</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * (more or less :-) )</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> */</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">BYTE convKeyCode2Char(BYTE kc)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> BYTE ch = 0;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> switch (kc)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> {</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> case 1: ch = ((g_bShiftOn) ? '!' : '1'); break; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> case 2: ch = ((g_bShiftOn) ? '@' : '2'); break; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> case 3: ch = ((g_bShiftOn) ? '#' : '3'); break; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> case 4: ch = ((g_bShiftOn) ? '$' : '4'); break; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> case 5: ch = ((g_bShiftOn) ? '%' : '5'); break; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> case 6: ch = ((g_bShiftOn) ? '^' : '6'); break; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> case 7: ch = ((g_bShiftOn) ? '&' : '7'); break; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> case 8: ch = ((g_bShiftOn) ? '*' : '8'); break; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> case 9: ch = ((g_bShiftOn) ? '(' : '9'); break; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> case 10: ch = ((g_bShiftOn) ? ')' : '0'); break; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> case 11: ch = ((g_bShiftOn) ? '+' : '='); break; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> case 12: if (g_bCtrl) ch = 17; /* CTRL-Q */ else ch = ((g_bShiftOn) ? 'Q' : 'q'); break; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> case 13: if (g_bFunc) ch = '~'; else ch = ((g_bShiftOn) ? 'W' : 'w'); break; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> case 14: if (g_bFunc) ch = 128; /* up arrow */ else ch = ((g_bShiftOn) ? 'E' : 'e'); break; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> case 15: if (g_bFunc) ch = '['; else ch = ((g_bShiftOn) ? 'R' : 'r'); break; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> case 16: if (g_bFunc) ch = ']'; else ch = ((g_bShiftOn) ? 'T' : 't'); break; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> case 17: ch = ((g_bShiftOn) ? 'Y' : 'y'); break; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> case 18: if (g_bFunc) ch = '_'; else ch = ((g_bShiftOn) ? 'U' : 'u'); break; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> case 19: if (g_bFunc) ch = '?'; else ch = ((g_bShiftOn) ? 'I' : 'i'); break; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> case 20: if (g_bFunc) ch = '\''; else ch = ((g_bShiftOn) ? 'O' : 'o'); break; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> case 21: if (g_bFunc) ch = '"'; else ch = ((g_bShiftOn) ? 'P' : 'p'); break; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> case 22: ch = ((g_bShiftOn) ? '-' : '/'); break; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> case 23: if (g_bFunc) ch = '|'; else ch = ((g_bShiftOn) ? 'A' : 'a'); break; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> case 24: if (g_bCtrl) ch = 19; /* CTRL-S */</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> else {if (g_bFunc) ch = 129; /* left arrow */ else ch = ((g_bShiftOn) ? 'S' : 's');}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> break; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> case 25: if (g_bFunc) ch = 130; /* right arrow */ else ch = ((g_bShiftOn) ? 'D' : 'd'); break; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> case 26: if (g_bFunc) ch = '{'; else ch = ((g_bShiftOn) ? 'F' : 'f'); break; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> case 27: if (g_bFunc) ch = '}'; else ch = ((g_bShiftOn) ? 'G' : 'g'); break; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> case 28: if (g_bCtrl) ch = 8; /* CTRL-H or BACKSPACE */ else ch = ((g_bShiftOn) ? 'H' : 'h'); break; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> case 29: ch = ((g_bShiftOn) ? 'J' : 'j'); break; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> case 30: ch = ((g_bShiftOn) ? 'K' : 'k'); break; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> case 31: ch = ((g_bShiftOn) ? 'L' : 'l'); break; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> case 32: ch = ((g_bShiftOn) ? ':' : ';'); break; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> case 33: ch = '\n'; break;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> case 35: if (g_bCtrl) ch = 26; /* CTRL-Z */</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> else {if (g_bFunc) ch = '\\'; else ch = ((g_bShiftOn) ? 'Z' : 'z');}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> break; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> case 36: if (g_bFunc) ch = 131; /* down arrow */ else ch = ((g_bShiftOn) ? 'X' : 'x'); break; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> case 37: if (g_bCtrl) ch = 3; /* CTRL-C */</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> else { if (g_bFunc) ch = '`'; else ch = ((g_bShiftOn) ? 'C' : 'c');} </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> break; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> case 38: ch = ((g_bShiftOn) ? 'V' : 'v'); break; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> case 39: ch = ((g_bShiftOn) ? 'B' : 'b'); break; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> case 40: ch = ((g_bShiftOn) ? 'N' : 'n'); break; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> case 41: ch = ((g_bShiftOn) ? 'M' : 'm'); break; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> case 42: ch = ((g_bShiftOn) ? '<' : ','); break; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> case 43: ch = ((g_bShiftOn) ? '>' : '.'); break; </span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> case 44: ch = 0; break;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> case 45: ch = 0; break;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> case 46: ch = 0; break;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> case 47: ch = ' '; break;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> case 48: ch = 0; break;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> default: ch = 0; break;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> }</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> g_bShiftOn = g_bLock = g_bFunc = g_bCtrl = FALSE;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> return ch;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">}</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">/*</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> * -------------- MAIN LOOP ---------------------</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> */</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">main()</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">{</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> BYTE kcodehex[5];</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> BYTE kcodedec[10];</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> BYTE rowbuf[3];</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> BYTE ch = 0;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>BYTE key = 0;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><br /></span>
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> init_vars();</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> init_ports();</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> lcd_init();</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span>init_SFR();</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> delay(10);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> // wait for I2C bus to become available</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> while (I2C_LineBusy())</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> {</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> lcdmsg(g_ucaDispMsgLineBusy, 4, 255); // Line busy message to LCD</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> }</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> lcd_text(0,g_ucaDispMsgPrdNameVer);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> lcd_text(0x40,g_ucaDispMsg2);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> delay(255);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> delay(255);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> while(1)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> {</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> if ((key = getKeyFromBuf()) != 0)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> {</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> _uitoa(g_ucKeyCode,kcodehex,16);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> _uitoa(g_ucKeyCode,kcodedec,10);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> strcpy(g_ucaDispBuf,kcodehex);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> strcat(g_ucaDispBuf,":");</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> strcat(g_ucaDispBuf,kcodedec);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> lcd_text(0x40,g_ucaDispBuf);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> ch = convKeyCode2Char(key);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> if (ch != 0)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> {</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> I2C_SendKey(ch);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> delay(1);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> ch = I2C_GetKey();</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> if (ch != 0)</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> {</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> rowbuf[0] = ch;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> rowbuf[1] = 0;</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> lcd_text(0x0f, rowbuf);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> }</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> }</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> }</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> else</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> {</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> lcd_clear(0x40);</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"><span class="Apple-tab-span" style="white-space: pre;"> </span> }</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;"> }</span><br />
<span style="font-family: Courier New, Courier, monospace; font-size: xx-small;">}</span><br />
<br />
LCD
display is not really needed. I used it for debugging purposes. It
can be safely taken out without any changes to the firmware, the
controller will still work.<br />
<br /></div>
<div style="margin-bottom: 0in;">
Arduino
test sketch code:</div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">//
Wire Slave Receiver/Sender</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">//
by Marek Karcz 2012</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">//
based on examples</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">//
by Nicholas Zambetti <http://www.zambetti.com></span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">//
Demonstrates use of the Wire library</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">//
Receives data as an I2C/TWI slave device</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">//
Sends data as an I2C/TWI slave device</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">//
Refer to the "Wire Master Writer" example for use with this</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">//
Created 29 March 2006</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">//
This example code is in the public domain.</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">#include
<Wire.h></span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">unsigned
char nLastRcvCh = 0;</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">void
setup()</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">{</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> Wire.begin(4);
// join i2c bus with address #4</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> Wire.onReceive(receiveEvent);
// register receive event</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> Wire.onRequest(requestEvent);
// register request event</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> Serial.begin(9600);
// start serial for output</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> Serial.println("I2C
Slave Receiver/Sender");</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">}</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">void
loop()</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">{</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> delay(100);</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">}</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">unsigned
char getCharFromKeyCode(unsigned char c)</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">{</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> unsigned
char ch = 0;</span></span></div>
<div style="margin-bottom: 0in;">
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> switch
(c)</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> {</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> case
128: break;</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> case
129: break;</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> case
130: break;</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> case
131: break;</span></span></div>
<div style="margin-bottom: 0in;">
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> default:
ch = c; break;</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> }</span></span></div>
<div style="margin-bottom: 0in;">
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> return
ch;</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">}</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">//
function that executes whenever data is received from master</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">//
this function is registered as an event, see setup()</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">void
receiveEvent(int howMany)</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">{</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> char
ch;</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> unsigned
char c;</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> //Serial.print("receiveEvent:");</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> while(Wire.available())
// loop through all</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> {</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> c
= Wire.read(); // receive byte as an integer</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> ch
= getCharFromKeyCode(c);</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> if
(ch)</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> Serial.print(ch);
// print the character</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> }</span></span></div>
<div style="margin-bottom: 0in;">
</div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> nLastRcvCh
= c;</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">}</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">//
function that executes whenever data is requested by master</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">//
this function is registered as an event, see setup()</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">void
requestEvent()</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">{</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> //Serial.println(":requestEvent");</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> Wire.write(nLastRcvCh);</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;"> nLastRcvCh
= 0;</span></span></div>
<div style="margin-bottom: 0in;">
<span style="font-family: Courier New, monospace;"><span style="font-size: x-small;">}</span></span></div>
<div style="margin-bottom: 0in;">
<br /></div>
<br />
<div style="margin-bottom: 0in;">
For the practical applications, I recommend to create 2 separate character buffers (one for I2C keyboard protocol and one for application use) for received via I2C bus characters and add them to the buffers as they come in receiveEvent method. Do not perform any more actions in the receiveEvent/requestEvent methods other than adding the characters to the buffer and sending back an echo in requestEvent as required by the keyboard driver protocol. In the main application loop, retrieve characters from the buffer designed for the application use. This will ensure lag free operation of the keyboard and will prevent locking up.<br />
<br /></div>
<div style="margin-bottom: 0in;">
Here is an updated circuit diagram and
some pictures of the populated board and pictures of the board with
LCD display and keyboard attached and connected to the Arduino board
for testing. To date it is the cleanest point to point soldering
board I have ever made. I guess I am getting better at this, which is
good. I need all the training I can get before I start assembling my
MKHBC-8-R1 computer boards.</div>
<div style="margin-bottom: 0in;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigS_8dN7qHrYpKvwEa44SKHvas9ubvvotwlPlQTrPgA6NgDRTGchRaXaR_OIlExJ5bzUgdjoff772ciYVJ5fYxka_IeX9Nl7oXGvJeresKQXRZZN9t12cJixnyHBkLnU91BuMD6R1V3ehv/s1600/i2c-kb-lcd.bmp" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigS_8dN7qHrYpKvwEa44SKHvas9ubvvotwlPlQTrPgA6NgDRTGchRaXaR_OIlExJ5bzUgdjoff772ciYVJ5fYxka_IeX9Nl7oXGvJeresKQXRZZN9t12cJixnyHBkLnU91BuMD6R1V3ehv/s1600/i2c-kb-lcd.bmp" height="481" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFyiuYUoPmnkAZhO7XndzpmvzE1lelya6UYyd2UpOhyphenhyphennqW658ti1GhVByDA-2uRcI2h5fezwx8_Di836M6L3wv4UuhuLPq3tJylmu_92nwOlil6fRYem37jDM-vPaOm2qNxdZkhPn_R0Yv/s1600/IMG_1244.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFyiuYUoPmnkAZhO7XndzpmvzE1lelya6UYyd2UpOhyphenhyphennqW658ti1GhVByDA-2uRcI2h5fezwx8_Di836M6L3wv4UuhuLPq3tJylmu_92nwOlil6fRYem37jDM-vPaOm2qNxdZkhPn_R0Yv/s1600/IMG_1244.JPG" height="480" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9L4VkfKriD42chyphenhyphenQzAj5AlDsikaZbZPVo4trsc1dRcNA1EMZINkB7lxGw0l7BZoO99a7T_XGG5_y5bsoNg-wZd86tAUIY12GnApmozVcF-7CTfUL95_dMqgTmHZm2_TBiYqY-JPaz3zxm/s1600/IMG_1245.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9L4VkfKriD42chyphenhyphenQzAj5AlDsikaZbZPVo4trsc1dRcNA1EMZINkB7lxGw0l7BZoO99a7T_XGG5_y5bsoNg-wZd86tAUIY12GnApmozVcF-7CTfUL95_dMqgTmHZm2_TBiYqY-JPaz3zxm/s1600/IMG_1245.JPG" height="480" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8tn89V1FZjC9tpOBAyE0Kg-KxzsFEEDcQf8jDQXyCMSqTPqtw6oHU48mcZP36tB2OsdZg6GRZXjw1jhyphenhyphenDLo3vO-sijzpjPrbT13rtfABaFjnXli8FVuaIo-tBvK1nnz2T9SmUi4Fs4rpn/s1600/IMG_1246.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi8tn89V1FZjC9tpOBAyE0Kg-KxzsFEEDcQf8jDQXyCMSqTPqtw6oHU48mcZP36tB2OsdZg6GRZXjw1jhyphenhyphenDLo3vO-sijzpjPrbT13rtfABaFjnXli8FVuaIo-tBvK1nnz2T9SmUi4Fs4rpn/s1600/IMG_1246.JPG" height="480" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-J0daxRnsNClw1j1fMblqgf14VKZWaEenEx3DtlM0mfxTDtZyK33V3Bj0tMHhEuzVqXsiRTFJxH6KjufOKZaTKts2V69_8lZo8bvNRkpnKC1EvsR1uV-GV95H6Q5BF6BIO9i9w2DAGNhX/s1600/IMG_1247.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-J0daxRnsNClw1j1fMblqgf14VKZWaEenEx3DtlM0mfxTDtZyK33V3Bj0tMHhEuzVqXsiRTFJxH6KjufOKZaTKts2V69_8lZo8bvNRkpnKC1EvsR1uV-GV95H6Q5BF6BIO9i9w2DAGNhX/s1600/IMG_1247.JPG" height="480" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqqy-rj_zleQlebDnRTWTiMPsmNYCskoTRHJqh3Pi52PgvaBP5JHtajeWZsnqR325ewRkFpkTu8jWdK4B9rBTkWvgsVFdb4Ga8SMXD56Lh39A_GlbsP13MRT7PfeZ7JWbMmL0i-57AAMvo/s1600/IMG_1248.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiqqy-rj_zleQlebDnRTWTiMPsmNYCskoTRHJqh3Pi52PgvaBP5JHtajeWZsnqR325ewRkFpkTu8jWdK4B9rBTkWvgsVFdb4Ga8SMXD56Lh39A_GlbsP13MRT7PfeZ7JWbMmL0i-57AAMvo/s1600/IMG_1248.JPG" height="480" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgw4cRBkluaG1vBz6qMMb83W6WrA0LkYQIc55X7krJ9AfF0NubE9w36tMBwh3P2yrKGaCSbmLBzTtP8C761MDAGXf2W5PhHjJwlVskw-a_29cF7gZRfbaEJu2E6XkkcOYXpoldSSJsP4qhq/s1600/IMG_1249.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgw4cRBkluaG1vBz6qMMb83W6WrA0LkYQIc55X7krJ9AfF0NubE9w36tMBwh3P2yrKGaCSbmLBzTtP8C761MDAGXf2W5PhHjJwlVskw-a_29cF7gZRfbaEJu2E6XkkcOYXpoldSSJsP4qhq/s1600/IMG_1249.JPG" height="480" width="640" /></a></div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
Thanks for looking at my blog. I hope you find it helpful.</div>
<div style="margin-bottom: 0in;">
<br /></div>
<div style="margin-bottom: 0in;">
Marek Karcz</div>
<div style="margin-bottom: 0in;">
05/27/2013</div>
<div style="margin-bottom: 0in;">
<br /></div>
Marek Karczhttp://www.blogger.com/profile/03281397436610614441noreply@blogger.com0