
%\newpage
\chapter{Special Software Parts}

Several modifications are done to save flash memory.
The LCD-Output of probe-pin numbers was done in the form ``lcd\_data('1'+pin)''.
To save the add operation for every call, the entry ``lcd\_testpin(uint8\_t pin)''
was added to the lcd\_routines.c.


The pseudo calls in the form ``\_delay\_ms(200)'' are not implemented as library calls,
but wait loops are implemented for every call. This will consume much memory, if you
have many calls at different location in your program.
All of this pseudo calls are replaced with calls to my special assembly written library,
which uses only 74~bytes of flash memory (@8MHz), but enables calls from wait1us() to wait5s()
in steps of 1,2,3,4,5,10,20\dots . The routines  include the Watch Dog Reset for all calls
above \(50ms\). Every wait call usually only need one instruction (2~Byte). Wait calls
with interim value such as \(8ms\) need two calls (\(5ms\) and \(3ms\) or two times a \(4ms\) call).
I don't know any implementation, which is more economical if you use many wait calls in your program.
The calls uses no registers, only the Stack Pointers for the return adresses
in the RAM (at most 28 Byte stack space in current release) is used.
The total list of functions is:\\
wait1us(), wait2us(), wait3us(), wait4us(), wait5us(), wait10us(), \\
wait20us(), wait30us(), wait30us(), wait40us(), wait50us(), wait100us(), \\
wait200us(), wait300us(), wait400us(), wait500us(), wait1ms(),\\
wait2ms(), wait3ms(), wait4ms(), wait5ms(), wait10ms(),\\
wait20ms(), wait30ms(), wait40ms(), wait50ms(), wait100ms(),\\
wait200ms(),wait300ms(), wait400ms, wait500ms(), wait1s(),\\
wait2s(), wait3s(), wait4s() and wait5s();\\
That are 36~functions with only 37~instructions inclusive Watch Dog Reset!
There is really no way to shorten this library.
Last not least matches the wait calls the exactly delay time, if the lowest wait call does.
Only the wait calls above \(50ms\) are one cycle per \(100ms\) to long because of the additionally integrated watch dog reset.


Additionally the often used calling sequence ``wait5ms(); ReadADC\dots();'' is replaced by the call
``W5msReadADC(\dots);''.
The same is done for the sequence ``wait20ms(); ReadADC(\dots);'' which is replaced by one 
``W20msReadADC(\dots);'' call.
The function ReadADC is additionally written in assembly language, so that this add-on could be
implemented very effective. The functional identical C-version of the ReadADC function is
also avaiable as source.
