'Wasserflußüberwachung nur 1x pro einschalten->Test ok!
'Anzeige Relais 7 entspricht nicht Ausgang->Test
'Level-Pump wird immer wieder eingeschaltet ->Test
'Abfrage Pumpenanzahl bei Messung?->Test
'Ausgänge anders ansteuern!->Test
'Temperatur-Steuerung Test->
'Wassertemp ->Test
'Überwachung Pumpe Test ok
'Telefonnummer anrufen->Test
'Wahlschalter jetzt andere Widerst
'Doku: einfache Art der Bewässerung mit Tank + zwei Auslässen
'Meldungen Fernsteuerkompatibel!
'Test ok Kanäle
'Test ok Tel-Nr
'Test ok Time
'Test ok U out
'Test ok Manual
'Test ok Daten->Flash
'Test: Wassertemp, Überwachung Pumpe
'Ä wenn drei Pumpen: vierte Kanal ist Temp-Steuerung mit Hysterese!
'Test wieviel Tage ohne Bewässerung->Test
'Doku Spannung und Zeit zusammen; (ev.Tag noch dazu: wenn Protokoll wann Pumpe ein)
'Test Telefon-Modul
'Doku Test ok Protokoll für Bewässerungszeiten
'Doku ok, Test ok Simu-Mode zum Testen
'Test ok Tel-Nr eingabe + wählen ok
'Doku: wenn Wasser kalt->Sauerstoffaufnahme
'Battery Alarm von Laderegler!
'Test Schaltuhr Kanal 1-4: zeit, all,
'Doku ok bei Time ev.Monat/Tag dazu
'Test Sensor-Überwachung->macht bei Start gleich Sensor-Fehler!
'Meldungen Fernsteuerbar
'Analog-Anzeige wackelt!
'Mini-System mit Helligkeits-Sensor, Programmschalter (Tröpfchen oder Dauer), Regler für Wassermenge
'Doku ok: Messungen: geschirmtes Kabel, ev. verdrillt, Gehäuse auch an Masse; Bei Strommessung Shunt verwenden ca. 166 Ohm (bis 30 mA) oder 250 Ohm (bis 20mA) max. 200 m, geschirmt
'Doku: Simulation
'Test: Temp-Anzeige
'I Automtische Einstellung Bewässerungslevel: Min/Max /2; (ab und zu Min/Max löschen); Meßwert nur akzeptieren wenn fast wie Wert vorher
'Ä nur Feuchtigkeits-getriggert Bewässern
'Doku besser nur alle paar Tage bewässern als jeden Tag
'Ä Test Telefon-funktion
'Test Grenzwert bei Kanal-Eingabe mit write_nein!
' Doku Drehstrom über Relais R3/R5/R7
'Test 3 = Days without water/month:00
'Test Auto Feuchte-Sollwert
'Test + Doku Auto-Start über LDR->nur wenn häufig Stromausfall!
'Ä ev.Programmschalter für weitere Funktionen
'Test neue Schalter: Auto-Setpoint; Autostart LDR
'Test wieso sagt er Sensor 4 Fault und ruft gleich an?
'Test manchmal springt er plötzlich zurück ins Grundmenü
'Test Statt Sens ->Sensor
'Ä Meldungen PC-Kompatibel
'Doku: nicht zu kleine Schaltintervalle: Verbrennen der Kontakte
'Ä Macht gleich Telefonanruf
'Test Handebene PC völlig falsch!
'Doku Drehstrom-Pumpen: Anzahl Pumpen = 1
'Ä mehr Bew-Kanäle
'Test Sensor 1 paßt nicht: Sens1:000; Auto mit tel_nr = 1
'Doku Automatische Trockenlauf-Erkennung
'Test Protokoll
'Doku: Wenn Stunde+Min = 0 dann Wenn Sollwert unterschritten Pumpe ein für die Programmierte Zeit
'Doku: Temperatur-Korrektur: Sensor-Anzahl < 4 und Sensor 4 = Temperatur
'oder Sensor 5 = Temperatur
'Doku Mittelwert aktivieren: 1 Feuchtesensor angeben, 4 oder 3 anschließen
'alt Sensor: wenn 4 Sensoren, jeder Kanal eigene Sensor; Mittelwertbildung aktivieren
'nein ev.Temperatur-Korrektur/Temperatur-Steuerung/Temperatur-Freigabe für Bewässerung extra einschalten
'Test FKT2=Mittelwert-Bildung 2-4
'Doku; Test ok bei Pulsbew. nur 1* am Tag
'I immer Temp-Kompensation mit ext_Temperature
'Doku: Preset-Values; only Input of Time
'Doku ok Anti-Frost-Irrigation; Surpress Irrigation when Temperature to cold/hot
'Test ok: Anzeige Minus Grad + Vorbelegung
'I alle Minute wird AT+CMGL gesendet (Receive SMS)
'Test ok bei Sensor-Anzahl 1,2,3 keine Anzeige Grad, mS;kein 4.Wert!
'Doku; Test ok;  nur 1* am Tag Impulsbewässerung
'Doku; Test ok  Frostbew.
'Doku ok Test ok keine Bewässerung bei Temp
'Test ok Frostbewässerung nur 1* am Tag
'Test ok Schaltuhr mit Analog
'Test ok Schaltuhr ohne Analog
'Test ok on .. all
'Test Beep bei Testanruf
'Doku ok If number of Pumps = 1 then all Setpoints of other channels must be set to "0"; Otherwise you have four Time-programms for one Pump
'Doku ok If you have a three-Phase-Pump set Number of Pumps = 1; then three Relais will be activated;
'Test ok über Zeit + 2* Schalter Niveau-Pump
'Test ok Sensor_monitoring
'Test ok Alarm Tank empty
'Test: Receive SMS
'Fusion: Wahrscheinlich die umfangreichste Bewässerungssteuerung der Welt! Vergleichen Sie doch mal!
'Test ok Hat bei Niveau-Pumpe ein /aus?
'Test ok bei Fkt6 geht Reset nicht mehr
'Test ok Auto no flow
'Test am Anfang springt er gleich ins Grundmenü zurück -> bei welcher Fkt?
'Test falsches Blinken bei Telefon über PC
'Test Temp-Steuerung
'Test Time/Date wie bei Alarm
'Ä Switch Receive SMS EEPROM 90
'Ä bei Receive SMS ev. auf Hand schalten; Bis Meta99;
'ok löschen SMS nur wenn SMS verwendet
'Test Sensor abfragen
'Ä+Doku: Check Inputs all minute! if Simu then immediately!
'Test Auto Start Pumps with LDR; one after the other
'Ä V10 mit mehr Kanälen

'Test auch in Submenüs Meldungen anzeigen
'Doku: auf Wunsch präparierte 220V dazu
'Test besserer Solar-Laderegler
'Test Auto-Detect Humidity-Setpoint
'ok Anzeige Istwert Submenü
'ok Test Auto-Setpoint
'Test Bei Simu gleich Tank empty für lange Zeit
'ok trotz Auto kein neuer Sollwert generiert
'ok trotz alles 0 ist Pumpe ein????
'Test ev. kurz vor bewässern Mittelwertbildung-> nur einmal nachts 3 Uhr abfragen
'ok auch bei Uhr Auto: Dann versuchen mit LDR Uhrzeit + Bewässerungszeitpunkt auf 4 Uhr nachts; Zählen Stunden hell (Zeit = Std + SA 5 Uhr); Zählen Stunden dunkel (Zeit = Std + SU 9 Uhr);
'Test Schalter Auto Time
'Test bei Fkt7 Spg. mit V:
'Test Wenn Auto dann Zeit eintragen!
'Test + Doku: Temp/Spg noch über Wahlschalter ins Grundmenü
'Ä mehr Texte in neuer Form
'Doku: Quick Start: Auto-Setpoint, Auto-Time, und los!
'Test Anzeige: Aus!
'Test ok Stunde immer speichern
'Ä Infozeilen nach unten
'Test PC Menü 7 Fragezeichen falsch
'Test wenn Auto Stunden dann keine Meldung Sensor 4 ausgefallen
'Ä Fkt8 viele Parameter! z.B. Solar-spannungen
'Test wenn Sensoren = 3 gewählt macht er Sensor 4 Alarm
'Test erst nach e. bestimmten Zeit Anzeige PC
'Test Echo off neu
'Test ev. Auto Setpoint
'Test autodetect Time
'ok Überwachung des Vorratsbehälters durch Anschluss eines Niveau-Sensors und Steuerung einer zusätzlichen Pumpe zum befüllen des Tanks
'Ä Handsteuerung aller angeschlossenen Pumpen, optional mit Eingabe einer gewünschten Bewässerungsdauer
'Ä ev. Info-Texte kurz einblenden
'Test für weitere Kanäle + Sensoren (V11) vorbereiten
'Test learning mode, min/max, calculate SP
'Test: Autodetect_time
'TEst am Anfang nach gewisser Zeit wird in Grundmenü geschaltet
'Auto Sollw.Feuchte: Humid Max-Min = Delta; Pro digit: 100 / Delta; %=(max-aktuell)*pro Digit; % * Max-Dauer = Bew-Dauer
'               650-600 = 100;      100 / 50 = 2;     625-600=25;25*2=50%; 0,5 * 60 min = 30 min
'Doku: Auto-Setpoint Formel und Bew.Dauer bezieht sich auf Max-Dauer (sec/min/hr)
'Doku: Einmalig Pumpe ein: Zeit + Dauer eingeben; Aus: Zeit auf "0"
'Doku: Handsteuerung
'Test ok Ausgänge schalten in Abh. von Pumpenanzahl->ok 1,2,3
'Doku: Eingabe Zeit Fill-Pump
'Doku optional mit Eingabe einer gewünschten Bewässerungsdauer: über Start-Zeit + Dauer
'SMS senden bei Wasser-Alarm->Test
'Doku beliebige Sensoren
'ok Menü 8 Auswahl 0/1/2 + weiter Einstellungen (Sprache etc)
'Test wenn alle "0" Tage eingegeben dann nur 1*malig bewässern
'ok zwei-sprachig + genauere Bezeichnungen
'Test ev.bei Anzeige Zeit wenn größer 100 1.10 mit
'Test mit Dialer
'ok bei Menü do Irrigate mehr Info dazu!
'Test Anwahl Analog-Eingang 4,7 oder 10K NTC; 10K=2,5V; 4,7K = 3,57V; 3,57/x = 2,5; x = 1,428; also Rohwert 0-1024 / 1,428 / 4
'test Messwerte aufzeichnen
'Test Anzeige Solar/Bewässerung wechseln blinken oder mit "#"
'Test Menüs mit 1.20 min
'ok Einheit Auto SP falsch
'Test wenn Wert > 100 fkt1 dann kein Leerraum zwischendrin
'ok weitere Messwerte anzeigen
'Test + Doku: Alarm 4*
'Doku: Additional device on
'Test + Doku ok Verzögerung Alarm aktive
'Doku ok: nur anrufen bei Alarm-Schalter
'Ä ev. auch verzögerung Alarm beim zurückkommen
'Test alarm Eingang 6 ok
'Ä + Doku: wie wenn nur 1* Bewässerung gewünscht?
'Zeichnen Alarm-Input, Bewegungsmelder, Solar etc oder einfach Solar-Charger übernehmen?
'Test + Doku Lastkanäle über zusätzliche Sensoren steuern
'Doku ok integrierter Solar-Laderegler
'ok wieso wird Akku-Typ überschrieben??--> weil dann Standard_laden angewählt!!
'Doku ok: wird der Akku-Typ geändert (Gel/Blei), dann wird erst mal die Standard-Einstellung für den neuen Typ geladen
'Test ev. bei Wiederanwahl Fkt9 Text anzeigen
'Ä ev. mit Kühlung Funktion von Solar übernehmen
'Ä Eingabe neue Fkt irgendwie falsch
'Ä wie ist die Relais-Zuordnung neue Funktionen (Bewegungs-Melder)?
'Ä Kühlen welcher Sensor
'Ä wieso eingabe U_batt falsch??
'Test Ausgänge Solar Load liessen sich nicht schalten
'Doku: Load 3 Type : 0=Batt, 1=Act>Set/2=Act<Set
'Internet neue Funktionen
'Doku: auch als Wetterstation.., SD-Card
'Doku ev. auch freie Relais-Zuordnung, aber mit Zuordnung 1-3 Relais pro Kanal
'Ä Parameter 5 kein Wert; 11 falsche Anzeige; 12 falsch: Nicht ja/nein; 13 falsch wert; 23 Kommastelle
'Ä Abbruch bei Telefon
'Test + Doku Daten->SD-Chip wie bei Laderegler
'Ä mehr Kanäle für alles Relais + MOSFET; In Schleife machen
'Ä über Funk schalten
'ok PWM-Ausgang ok?
'ok Port für neue Ausgänge definiert?
'Doku wie angabe drei Relais gleichztg?
'Test Alarm Door nach Relais
'ev.Ä Typ anrufen für Ausgang; z.B. 108 = anrufen + Beeper
'Ä Corel: Relais ins Bild
'Doku: Rangierung Ausgänge + Telefon..., 'Ä Output 303 etc = 3 Relais
'Test: Output 303 etc = 3 Relais
'Test Bei Alarm Anzeige blinken
'Test Fkt5 Daten nach FKT 8;
'ev. Ä Sollwerte Spg.Last nicht mehr über FKT8 nötig, aber andere Daten-Nr.verw.
'Test Anzeige Spannung
'Test U-Batt anders
'ok Tank leer Alarm kommt immer wieder
'Test kein blinken bei Meldugen! Manchmal dann ganz aus!
'I Display blinken &B00001100 oder &B00001000
'Doku+ Einlegestr: wenn Grundmenü # or + then switch to Menu Solar Charge Controller
'Test wieso Solar Werte für 24V
'Test Parameter 11 Grundeinstellg '282 = 11 Blei-Gel/Blei
'Test Data direct to PC
'Test anrufen wie bei Laderegler
'Test Feuchte mit Funksensor!
'ev. Ä Werte fkt8 zusammenfassen und gosub
'Test auch für Solar Relais!!
'Test kein Laden Solar
'Test keine manuelle Anwahl Solar möglich
'Test bei Rückschalten auf Grundmenü keine Anzeige 2.Zeile mehr; auch 1.wird nicht aktualisiert; wenn vorher in Menü 9
'Test ok neue Simu mit Poti
'Test Message ev. Zeile 2 quit with #
'Doku Simu-wert
'Test am Anfang Alarm Tank leer; muß mit vielen drücken quuittiert werden
'Test Bewässerung mit mehr Kanälen; ev. anderes Frontbild;
'Doku SD-Card
'I: Datum Uhrzeit wird im Eprom gesp

'Test drehstrom-Ansteuerung dazu
'Test Wenn ein Sensor-Draht bricht, erkenne ich das an der Leitfähigkeit (< Min-Wert) und rechne dann mit entsprechend weniger
'TEst ev. Send SMS in Data
'Ä Doku neue Parameter
'Ä telefonnumer 16 Zeichen?
 'Ä Datum/Uhrzeit verändern wie bei Generator?
'ev. Daten-Eingabe sichern mit Password
'Doku:: Im Winter Leitungen entleeren
' ok Sensor (Analog oder Digital), Analog-Eingang: 1-15 = %; 21-35=Temp; 41-55 = bar; 101-108 = Digital (erst ein dann aus-Eingang); 201.. Funk
'Doku Dosier-Kreis-Steuerung dazu (Messung, Puls/Pause...)
'Test + doku mit Simu anders lösen
'ok auch bei Parameter optimieren
'Doku: Display-Text auch rein
'Doku Hinweise
'Doku: Bei Load gibt es auch die Möglichkeit Typ 2/3.. für Soll <> ISt!
'Doku an Eing u.ausgang Klemmen hinschr.
'Test Temp-Korrection nur wenn Feuchte!
'Test Humidity_average
'Doku Eingänge und Analog alle Min lesen; zum Testen * oder # drücken!
'Bild: Sensoren mit Digitalen Ausgang freischalten; Aber Spannung sinkt wenn alle LED ein!
'Test Standard laden richtige WErte + bereinigen
'Test Temp-Kompenastion ok?
'ok Eingabe Analog = % oder Temp->Type
'Doku: individuelle Konfiguration; entweder 2 Temp-steuerungen, Niveau..., Bewässerung, Dosieren
'Test Days without watering
'Doku Bewegungsmelder-Funktion! Alarm?? Auf Analog 10; auch Doku + bild
'Doku Humidity 6 kann keine Humidity sein
'Test pro Kanal definieren: Bewässerung, Level-Control; Temp-Steuerung, Dosiersteuerung;
'Doku: 3-phase Pump
'Ä Corel + Excel
'Test PRg-Selector? darüber Umschaltung Anzeige
'Doku: auch bis zu 6 Kanäle auf eine Pumpe
'Test wieso am Anfang so lange Boot?
'test Eingabe Input/Output falsch
'Test Anzeige über Wahlschlter
'Doku für jeden Kanal noch anderer Ausgang dazu verriegeln: aus wenn Ein/Ausg xy..1-200; ein wenn Ein/Ausg xy..;
'Ä Umrechnung Radio-Sensors (siehe Solar-Regler)
'Doku Stunde+Minute = 0 dann einmaliger Puls-betrieb
'Test + Doku bei Input 1+2 auch Ausgänge mit dazu: ein mit: mit anderen Ausgang ein; aus: verriegeln
'Test Digital-Eingänge: geht es auch mit 4,7 K?
'Test + Doku Level 2 can also be a Interlock by a Input
'Test Temp do Irrigate etc. nur auf Knäle die Bew.
'Doku Typ 1 ist Bew. 2 = Temp; 3 = Niveau etc.
'Test: channel Analog <> + Hyst ok; Timer ok, Interlock Input/Output
'Test + Doku PE4 ist Sensor active!;  extra Ausgang für Analog-Werte lesen
'Doku wenn on all dann ist hr start-Stunden und min Stop-Zeit (Std)->Anzeigen
'Test schaltet nicht bei Digital Ist < Soll
'Test + Doku Sensor-Typ nach Parameter
'Test Überwachungszeiten für alle Ausgänge! eingebbar; wenn Fehler (Pump on for long and no change Humidity) then Alarm (Telefon or SMS)
'Internet: 12V, 24V oder 48V Systemspannung u.anderes
'Doku: Relais Ausgänge nicht kurzschluss-Geschützt!!
'Test If you want to have the device being switched depending from a analog input only for a specific time
'Doku; Test ok Handsteuerung mit Eingabe einer gewünschten Bewässerungsdauer
'Doku: Typ 0 = Bew. Typ 1 = Temp; Typ 2 = Level+Dosg; Typ 3 = Level mit Alarm
'Test bei Sensor Alarm Tel + SMS etc
'Test Prg-Schalter Position 8? + einlesen
'ok Level-Alarm nur in eine Richtung
'Test Anzeige Kanal 789 Grundmenü; Display....
'Doku: Wenn Eingabe Kanal kein STart der Bewässerung
'Ä ev. einstellbarer Delay für Sollwert? oder Zeitscheibe?
'Test Autodetect Time
'mehr in 10 sec Timer
'Test Send / Receive SMS wie Laderegler
'Test + Doku  max-Time als raus
'Test + Doku wie geht das mit Level Start Zeit für 1 Sensor; dann Parameter raus
'I fkt5: Füllezeit ist entfallen
'doku + Fusion: neue Überwachungen
'Test Antifrost_irrigation;
'Ä fkt 6 Tooltip besser
'Doku auch bei Bewegungsmelder Eingang wählen; Ev. Funktion mit verzögert ein, verzögert aus damit machen (z.B. wenn Sensor best.Zeit ein)
'Doku Bewegungmelder mit Nr; Ein/Aus,  Dely on; Delay off; Eingang/Ausgang
'Ä von Solar übernehmen Delay_add_device_on?
'Ä ev. mehrere Zeitversezte Zeitscheiben
'Doku Tabelle E/A; Tabelle versch. Kanäle (Alarm + Bew)
'ok bei Data direkt -> PC auch Status Pumpen für Anzeige
'ok VB Prozess-Bild mit Daten
'Ä alles durchsehen
'Doku bei Bewegungsmelder: Typ: 0=nur Aktion; 1=Alarm-Text + Beep; 2=Telephone; (just Call or SMS)
'ok wenn Daten direkt nach PC kein Timeout Kopplung
'Ä SMS als Text und Kanal-Nummer dazu!
'I jetzt wenn Tel-Nr eingegeben Alarm anrufen; wenn Send SMS
'Doku das Relais nicht kurzschlussgeschützt
'Test Irrigate by Temp
'Ä ev. Delay bei Sensor
'Ä wenn mit anrufen dann mit abbrechen
'Test abfrage analog 9-15
'ok PWM- Out Solar??
'Doku: der Wassermanaager; the water Management System; Intro über Wasser; eines der....
'Test: Max-Time, Auto no flow
'Doku auch Ausgang auf Beeper versch
'Ä Channel_temperature kann noch in Schleife
'Ä neuer Solar algorhytmus nach Bewässerung! Solar U_batt smooth etc.
'ok 3 Modi: Data->Flash; Data direct->PC; View-Data: mit Dialer dann nur values, sonst mobile_aktive.... = 1
'Ä Prg. neu laden: alles auf 0 wenn ungültige Daten! und andere auf sinnvolle Werte
'Ä wen Past ein Daten erst mal richtig rein
'ok Bedienung über Remote: auch Tasten Esc und Return
'Doku Select com: Output "S" (seriell);  End Programm: Output "R" (Reset); Prozeßvisualierung: "O" nach unten schicken; End Processvisualisation "E"; Keyboard: ok = CR; back = ESC;  Fully Remote Control: "F" nach unten schicken
'ok  bei anderen bei Fernbedienung Wahlschalter über Dialer (Wert 21-32); WErte 1-12 = ASCII A, B, C, D, G, H I J K L M N
'Doku mAh gilt für alle Zellen! (was ist wenn zwei parallel etc): Standard: 2 Batt; Wenn 4 dann in mAh doppelt so viel
'Ä Switch_input_block auch bei anderen
'Ä zweizeilige Meldung möglich (nicht quit...)
'ok immer mit Anlagen-View!
'Ä no sun etc. übernehmen
'Ä bei SMS send ev. welche Alarm-Kanal Nr
'Ä ev. Digital auch mit Delay on/off
'Test + doku ok Analog noch Delay off (mindesteinschaltzeit)
'Test + Doku bei Analog Verzögert ein und verzögert aus! bei Digi 2 auch; ev. = 1 / = 0 dann nach Laderegler!!
'I feuchtemessung_mit_einer_Spg möglich
'ok bei Kanälen Ein/aus
'Ä ev. 2.Sensor so wie bei Laderegler (Output 1-15)
'Ä U_batt smooth auch dazu!
'Test ev. Input 2 wie LAderegler mit =1, = 0
'Doku bei Level mit sPeichern
'Doku: Funksensorem
'Doku mit * nur ein schritt zurück!
'Ä channel auf 7!?
'Test ok nch best. Zeit zurück ins Grundmenü
'Doku: wenn zwei Sensoren Input 1 für ein; Input 2 für aus
'Ä channel on/off dann wieder on geht nicht
'Test anrufen Alarm Channel-nr
'Ä Alarm channel wie bei Laderegler;
'Ä Alarm bei digital anders
'ev. Ä ein freier Typ Analog-Eingang über Parameter versorgen
'Ä test write_eeporom...
'ok eingabe data fkt8 wie ladereg
'Ä ev. Temp-Kompensation extra Type; z.Zt. wenn Channel Typ = 0 dann Kompensation
'Test ok Analog Typ Parameter xy ok!
'Ä ev Alarm on-Schalter
'Ä Parameter Dynamischer LAstabwurf?
'Test bei Standard-WEre erst alle 0!
'Test bei Timer Temp_b4!! wie Solar
'ok CDR Sensor-Nummer rein
'Test Korrektur weitere Ausgänge!
'Test Korrektur-Faktoren
'ev.Ä Eingabe anzahl kanäle
'Test Sensor-Type richtig
'Test Zeit-Modul Kanäle war nicht ganz reset
'Test Am Anfang gleich anrufen
'ok alles für LDR getauscht? (von Aus.15->9)
'I 1= Leer Alarm,
'I 2= Leer Pumpe ein,
'I 3= Behälter voll
'Referenz Ladergler ->Bewässerung
'94/17->346  '346 = 43 / Stop Boost-Charge manually
'72->272
'74->274
'76->276
'60->260
'188->  no  //188 = 69 Network: 0=0ff/1=Master/2=Slave
'84->284 'Solar Relay active
'78->278
'144-> no'Triggered by Time?
'100-> no! I2C
'ok Kanal 7-9 auch Anzeige Istwerte Grundmenü?
'oder über Bewegungs-Melder ein Licht einschalten (Zeit programmieren und Sollwert; als Eingang Analog Bewegungsmelder;
'Test Anzeige Input2 actual!
'Test channels mit Alarm dabei (schleife....
'Test bei 0 und Temp-Korrection macht er -5
'Doku unten aufs Bild Gehäuse Parameter!
'Doku in die Preisliste auch kleine Bilder und mittleres und großes Gehäuse!!
'Doku Dialer ins Internet (Bild + exe)

'ev. Ä Parameter Batt Spannung Lastabwurf kann raus
'Test Typ Sensor
'Test Korrektur Spannungsabfall!
'Doku Excel-Liste ins Internet
'Doku: Anzeige IStwert Input 2
'Doku: Ausgänge mit automatischer Sicherung, max 10A
'Doku mit virtueller  Ausgang
'Doku Sensoren anschliessen mit Ausgang
'doku corel: geschirmte Kabel
'Doku: Korrektur Spannungsabfall
'Doku: Humidity-Sensors auch Radio! + Preisblatt
'Doku: ELV Light-Sensor
'Doku: Kanäle Als Anwesenheits-Simulator: verschiedenen Gerät (Lampen, Radio) zu bestimmten Zeiten einschalten (nur Zeiten programmieren)
'Doku: Tricks: auch mit Prg-Schalter
'Doku neue Parameter Solar...
'Doku weitere Funktionen von
'Doku: Tips: Dialer Source-Code, selbst ändern
'Doku: how to configuer the Channels? (4 Uhr etc.)
'Doku ev. Pumpe 6 nach cdr

'Test manual an/aus Boost-charge
'Test nach boost charge lädt er nicht mehr weiter
'Doku Wird die Funktionen der automatische Zeit-Einstellung verwendet, so wird über einen Licht- empfindlichen Sensor die Uhr-Zeit bestimmt. Dieser muss im Freien montiert werden.
'Doku Beim Aktivieren der Funktionen wird die Startzeit für das Bewässern auf 4:00 Uhr nachts gestellt und ihn Bewässerungszeit auf 30 Minuten voreingestellt (Kanal 1 bis 5).
'Test ev. delay on beenden wenn abgelaufen
'Doku: Parameter-Liste in Excel

'Test Solarstrom erst negativ?
'Test Emergency-swtich off
'Test + Doku Auto-Irrigation-Time !
'Test Timer Lastabwurf schrecklich!
'Test Reverse-Connect
'Ä in Schleife alle Flash-Daten nach PC und zurück->ist schon bei Flash-Read dabei!
'Doku Bilder vom Gerät etc in d.Anleitung (PNG?)
'Doku Auto-SEtpoint: if min/max is too small, then preset 30 min;
'Test auto-Setpoint!
'Test Alarm Batt. leer
'Test wieso Anzahl wieder auf 10?
'ok wenn bei Autobewässerung kein vernünftiger min/max dann trotz Soll/ist keine Bew!
'ok Values for minimum and maximum humidity -> Flash
'Dim channel_typ As byte
'Dim more_then As Byte
'Doku: Telefon-Anruf: wenn als Ausgang 16 bei Kanal oder als Typ 3 oder 4
'Test + Doku Pasteuer
'Ä Auto-Setpoint: Prg. versucht Sollwert zu erreichen; nahe dran x Dosen, sonst große; Sollwert = max-min; bei Min = 90% bei max 0%
'Ä Bew-Dauer: Sollwert vorgegeben: wie weit ist Actual von Sollwert weg, Relation zu min/max-Feuchte(ev. testen); %-Satz von Max-Time
'Ä min_max auch über Paramtrierung; Max-Min: Sollwert - MAX = Relation % von max-Min; Soll 300; Ist 300; Min: 100
'Eckdaten: Min Feuchte = max-Bew-Dauer; max-feuchte = 0 Bew-Dauer; akt. Bewässerg-Zeit = % von Feuchte ->% von Bew-Zeit;
'Max-Bew-Zeit über Sollwert?
'Doku: Pasteur in die Features + Internet
'Test + Doku Pasteur-Funktion mit dazu; Sollwert ist Past-Einheit; Max = Sp_time_pump_on_max_past = 10   in Seconds Delta_t_past_off
'Test + Doku ev. auch Pasteur Delta aus über Parameter
'I 300W Tauchpumpe: 11m Förderhöhe = 1,1 bar; mit 1 ' Schlauch: 4600 l/h; mit 16 mm Regenrohr: 1750 l/h bei  www.isc-gmbh.info gardenline GLRP 300
'Ä Auto Setpoint: delta; Puls-T; Ergebniss: Korrektur +/- Impuls
'Test alle relevanten Solardaten + KWH -> Dialer + Anzeige im Bild;
'I ansteuerung alle 10 min
'I ein Trockenlauf wird erkannt, die Pumpe für 15 Min. ausgeschaltet und dann neu gestartet.
'Doku Effizientes Wassermanagement durch e.Durchflussmengensensors
'Doku mehrere Programme pro Tag  über versch. Kanäle
'I Überspannungsschutz: MOV (Metal Oxide Varistor)
'Doku Geschützte Klemmleiste im Gehäuse
'Doku Manueller Start einer Station oder eines Zyklus
'I kann mit Digitalem Eingang gemacht werden; RAIN-CHECK schauen ob's gerechnet hat; Der Regensensor RSD ist ein Gerät zum Messen des Niederschlags
'ok kein Schalten wenn Delay on/off Channels = 0!!!
'ok Doku Anschluss Impulssteuer-Ventil:Pulsausgang: Nummer anwählen dann wenn Flanke ein Impuls; anderer Parameter Ausgang Flanke aus Impuös?
'ev mehr mit Pulszähler
'Test aber Doku ok! Anti-Blockiersystem: Start der Pumpe alle 24 Std. für 1 Sek., um zu verhindern, dass das Förderrad bei langer Pause blockiert (nur Position AUTO). Extra Paramter: Ausgang-Nr; ->check ob Pumpe bewässert hat; wenn nicht dann 3 sec ein
'Test Alarm-SMS möglich?
'Doku: Dialer: 'for Dialer: 1-10 = channels, 11=U_batt_smooth, 12=I_solar, 13 = ext.Temp
'Doku: wenn log ELV Rain etc.dann in Kanäle rein
'Ä www.tensio.de und Info ins Internet
'Test fkt7: Auto time erst bei zweiter Zeile
'Test nachdem SMS gesendet kommt viel über die Serielle SS!!
'Test bein Einschalten aus dann kein Impuls!
'test + Doku mit anrufen: Ausgang 16!!
'Doku Send SMS /anr verzögert
'Beim Einschalten wird auf die Impulsventile ein Impuls gegeben. Soll das Ventil aber nicht eingeschaltet werden, so ist die Metamorphose noch mal aus und wieder ein zu schalten.
'Doku per SMS schalten
'K Output 16 initiates a Telephone-call. The Telephone-number defined in Menu 4 is called
'Doku: überall im Internet: Zuverlässigeit, einfache Bedienung, Flexibilität
'Test + Doku: 2ter Ausgang; wozu?
'Doku auf 20 Kanäle?
'Doku: 3phase-Pump goes on channel 1 with Relais_2 = 1 : Relais_3 = 1 : Relais_5 = 1
'Doku: 6 Relais; 6 Transistor; 8 weitere freie Kanäle; über Gardena Verteiler nutzbar oder
'Doku: 25.7.08: Jetzt sind 20 (statt 10) Universal-Kanäle möglich. Damit können auch komplexere Verknüpfungen gelöst werden. 6 Relais-Ausgänge, 6 Transistor-Ausgänge, die weiteren Kanäle können z.B. für Alarm-Meldungen über Telefon etc. genutzt werden.
'354 = 47 Load 1 Select Output 1 abschalten!
'356 = 48 Load 2 Select Output 9
'358 = 49 Load 3 Select Output 10
'360 = 50 Load 4 Select Output 11
'362 = 51 Load 5 Select Output 12
'Doku: beim ausschalten gehen die Daten verloren
'Feuchte-Sensor klein: Sensor: trocken: 35K, feucht 10-20K; nur Wasser: 1900K
'Doku Features deu + engl neu!!
'Solaranlagen werden zunehmend komplexer mit einer größer werdenden Diversität. Um dieser Anforderung Rechnung zu tragen gerade im Bezug auf intelligentes Energie-Management wurde dieser sehr flexible Laderegler entwickelt.
'Test sensor 4 Fehler?
'Test sPannung unruhig wegen Spgsregler (C21 must be at least 22 µF to maintain stability.) C21? Fusebits? 10K Array auf gute Masse
'XPORT Sleep-Mode?
'Ä ev. bei Solarbetrieb: Battery_voltage_ok = 0 beeper aus
'Ä VB-daten zuweilen falsch; ev. wie bei Bier blocken
'Doku wenn Probleme kontakieren in die Anleitung
'Ä wie bei Auto-Alarm nur autorisierte schalten
'test wenn Laderegler geladen und dann Bewässerung so geht bleibt er beim start hängen
'Test LCD zuweilen keine Anzeige!
'ev. 4 = Alarm extern; zentral scharf schalten über Menü 3, ansonsten wie Alarm Typ 3
'Test ev. bei Parameter xx zweite Zeile Minus = *
'Ä Delta wasssertemp / Pflanze Bewässerung darf nicht zu groß sein; nicht unter 5 °C giessen
'Ä mehr Doku Solar charge controller
'Ä reset Min/Max-Feuchte
'Ä Wasserbudget: Veränderung der Beregnungsdauer von 0 bis 200 % in Schritten von 10 %
'Doku: Sicherung der Flash-daten
'Test Alarm-Typ wie bei Laderegler: Delay off ein wenn delay on abgelaufen; Ausgang nur von Delay off steuerun; dann Pausenzeit von 10 min
'Ä Min/Max-Temp Fühler 1+2: Die Max./Min.-Werte werden im Automatik-Betrieb alle 3 Stunden gespeichert.;  2 -3 Parameter mit Eing-Nr analog -> Anzeige wenn was eingetragen; send to PC
'Ä ev. Name für Analog/Digital->download-> EEPROM + Anzeigen
'Ä ev. einstellbar welche Messungen im Grundmenü
'Ä Min/Max, Laufzeit übernehmen von Beer.bas
'Doku Minimalwert für die Solarpanel-Temperatur und der Maximalwert für die Speichertemperatur
'Ä ev. auch mit Parameter Einschaltzeit Anzeige Istwert
'Test min/max, Laufzeit und gosub output ist neu!
'I 128K = 131072: - 2048 = 129024 Bytes max!
'Doku auch für Umwälzpumpen-Steuerung: spart Heiz und Stromkosten: Temp Vorlauf/Rücklauf
'ok map analog Min/Max, Laufzeit
'Test Zähler mit dazu
'Doku Internet neue Funktionen: Counter, Min, Max, Laufzeit
'Doku: Anzeige Grundmenü entsprechend der Universal-Kanäle
'Test Reset Min/Max Einschaltzeiten
'Test Kablebruch
'Ä Kalkulations-Liste ins Internet
'Ä Universal-Kanäle Möglichkeiten beschr
'Ä Data to PC wie bei Laderegler
'Doku neue Funktion Impuls
'Ä Auch Anzeige PC Freuchte, Wind etc bei Send nach PC eintragen
'I 1,6 Millionen sterben an verschmutzen Trinkwasser, 900 Mio haben kein sauberes Trinkwasser
'Mikro-Filtration, 50 Euro, Nano-Filtration
'Test Data direct to PC in OpenFormat
'Ä wie ist das mit start/Stop-Stunde? wird das benötigt?
'Test was macht der Sensor Alarm? Auch ausgang aus?
'Ä ev. auch gespeicherte Daten im Open-Format senden
'Ä keine Anzeige Grundmenü 1,2,3??
'Ä In the Ground-Menu when a message is displayed, you can acknowledge this message by pressing any key
'Ä Rücksetzen maximale Spannung und minimale Spannung
'K Einschaltzeit Pumpe = maximal-Zeit-Pumpe / (Minimaler Wert Feuchte + Maximaler Wert Feuchte) / 2 + Faktor)
'K welcher Eingang für Lastabwurf Not-aus
'Test Anzeige fkt8! Pu etc-
'Ä Solarer Regler schneller
'Ä Homepage Dialer neu
'Ä zweimal Humid-Sensor??
'Ä was ist wenn zwei Sensoren? bei alt und neu!
'Ä habe ich als Messelektroden die kohlestifte der AA Alkalibaterien verwendet.

'Ä mehrere Freuchtesensor
'36'49'59'49'59'0'50'51'44'54'59'0'59'51'56'59'0'59'0'48'13'10'0
'Test ev. Verzögerung ein auch sec/Min/Std
'Ä weitere Zeitstufen
'Ä channels: von Laderegler
'Doku: Daten direkt an PC + auswerten
'Ä einmaliger Impuls geht nicht
'Ä sek-Anzeige
'Ä Channels Alarm wie bei Alarm: 10-15 = Alarm
'Ä In dieser Zeit kann der Alarm über die zentrale Alarmaktivierung (Menü 3) ausgeschaltet werden.
'Test Alarm channels
'Ä keine Anzeige minus bei Param 16
'Ä wenn Analog und alarm dann nicht speichern!!
'Ä Flash ->Dialer
'Test + Doku ist Verriegelung drin?
'Test + Doku Alarm: Water should not be to cold or too hot, about 25 °C, minimal 15°C, at most 35'C!
'Ä ev. Temp Wasser + Temp Umgebung wenn Delta zu groß Alarm; kann zweiter Eingang auch Analog?
'ok Reset LCD
'Ä Kanal-Eingang nach oben; In VB Textliste für Überschrift und Tooltip für Anzeige
'Ä mit Case 1 ....
'ev. Ä LAstabwuf über Universal-Kanal! jetzt über extra Teil
'ok Einheit A?
'Test Korrektur Uhr
'Ä Doku: Kabel-Anschluss
'Test Korrektur Uhr + Doku
'Test ELV-Sensor neu $1;1;;;
'Ä für zwei Sensoren Temp_sensor_detect
'Ä ev. Anzeige zweiter Sensor Temp etc
'Doku: Wind-Sensor wieder dazu!
'Ä was ist wenn ELV Temp < 10 etc; wird es mit 0 en aufgefüllt?
'Doku auch Solarthermische kühlen um den Material-Stress zu reduzieren + zum reinigen
'Doki Kühlung für Solarkollektoren
'Die Aufgabe von Flachkollektoren besteht darin, Wärme bei einer Betriebstemperatur von ca. 60 °C bereit zu stellen. Dies erfordert eine gute Wärmedämmung des Kollektors, die wiederum im Stillstand, wenn der Kollektor nicht durch das Arbeitsmedium gekühlt wird, zu Stillstandstemperaturen um 200 °C führt. Im Stillstand liegen im Kollektor wesentlich höhere Drücke und Temperaturen vor, als im Betrieb. Kollektoren werden so ausgelegt, dass sie diesen Anforderungen Stand halten können. Dies setzt dem Einsatz von kostengünstigen Werkstoffen, insbesondere von Kunststoffen, enge Grenzen und führt daher zu hohen Kosten.
'Die technischen Anforderungen an die Kollektoren lassen sich deutlich reduzieren wenn der Kollektor gekühlt wird, sobald die Temperatur im Innern oberhalb der tatsächlich im Betrieb benötigten Temperaturen liegt.
'Die Vorteile einer derartigen, leicht realisierbaren Kühlung (siehe Skizze) bestehen insbesondere darin, dass sämtliche Leitungen für deutlich geringere Betriebsdrücke ausgelegt werden können sowie darin, dass kostengünstige Kunststoffe in wesentlich grösserem Umfang eingesetzt werden können, so z.B. beim Bau der Absorber.
'Doku: einmaliger Impuls beschreiben!
'ev. Check_min_max_runtime direkt in Param anzeigen wie bei Laderegler
'doku: Die Kabel zum LCD-Display und zu den Schaltern dürfen nicht in der Nähe der 220V Schaltgeräte oder deren Kabel geführt werden. Da wird sonst Hochspannung induziert.
'Doku: nach Laderegler Bewässerung geladen, wirre anzeigen
'Ä sec-Anzeige Fkt 7
'Ä wenn Solar Laderegler und U max dann alles aus?
'Doku: Prg. max 129 groß!
'Prg. kürzen!!
'Ä statt send 0,0 einfach nur 0
'Ä anzeige Kanal 2 Soll etc
'Ä Patameter 74 nicht so leicht auf "0" zu schalten?
'Ä englische Parameter-Liste senden geht nicht!
'Software-Revision und kürzen!
'Ä correctur +/- mit 2 Kommastellen wie bei Laderegler
'Ä Korrektur Zeit!

'Test ok
'=======
'Solar Laderegler
'ok wenn daten senden und es klappt nicht dann timeout keine daten empfangen!!!
'Logview: Parameter
'Logview: Flash
'Upload Parameter deu
'Download Parameter deu
'neuer Timer
'Kanal Menü 1: ein/aus mit Sollwert + Verzögerung; Anzeige Einheit; Transfer Analog-eingang, Timer, alle....;
'Test ok mit virtueller  Ausgang
'ok Daten senden an Dialer??

'Menü 3: Test ok Typ 0 und 2
'Menü 6 Lastabwurf: Spannung verzögert ein/aus ok, timer
'Uhr ok
'Alarm Kanal Typ 3 ok
'Alarm Menü 3 ok!
'do Irrigate anti-frost irrigation
'Solar laden, Boost laden, abschalten
'Channels max-Time, no change analog
'Test Auto Alarm no Water coming
'Test wenn aus dann auch Verzögerung Reset
'Test Writeeeprom ok
'Test nur Auto-Zeit setzen bei Kanälen wo auch Typ bewässerung
'Auto Detect Min/Max
'Test Send SMS über Fkt4 oder Kanal
'Test Reset Channels was kommt!
'Test 20 Kanäle ok
'Test 2.ter Ausgang ok
'ok bei Alarm Eingang speichern -> Delay_on Zähler > nicht reset; 15.10.08
'ok kein Transfer Temp ach Kanal 1!
'Test ok Impulssteuer-Ventile; auch nach dem einschalten


'Solar-Thermisch
'==================
'Hat das Differenz-Temperatur einen Wert von x Grad überschritten, schaltet die Zirkulations-Pumpe ein
'Hat das Speicherwasser eine Höchsttemperatur von 95 Grad erreicht, schaltet die Pumpe ab, um eine Überhitzung des Speichers zu verhindern
'Hat das Wasser des Solar-Panels eine Minimale Temperatur von x Grad unterschritten, schaltet die Pumpe ab
'Ä Um Rückschlüsse auf die Wirtschaftlichkeit der Anlage zu erhalten werden die Einschaltzeiten der Relais (Laufzeiten der Pumpen) sowie die an Fühler 1 und Fühler 2 gemessene Minimal- und Maximaltemperatur gespeichert.
'Alle Betriebsparameter, wie die Temperaturdifferenz bei der das Gerät schalten soll, die Schalthysterese, der Minimalwert für die Solarpanel-Temperatur und der Maximalwert für die Speichertemperatur, sind über Tasten leicht programmierbar. Alle programmierten Werte bleiben auch bei einem Stromausfall erhalten, d. h. nach einem Stromausfall arbeitet die Anlage sofort wieder weiter. Selbst die ermittelten Einschaltzeiten der Relais und die gespeicherten min./max. Fühlertemperaturen bleiben erhalten.
'Hinweis: Die Betriebsparameter werden beim Umschalten von Manuell-Betrieb(Programmiermodus) zum Automatik-Betrieb gespeichert. Die Max./Min.-Werte werden im Automatik-Betrieb alle 3 Stunden gespeichert.
'Alle Messwerte (Solarpanel -Temperatur, Speichertemperatur, Temperaturdifferenz), sowie alle programmierten Betriebsparameter (Differenz, Hysterese, Min-/Maxwert, Relais-Einschaltzeiten) können auf einem 2 x 16 stelligen Display abgefragt werden.
'Um ein Verkalken des Wärmespeichers zu verhindern kann eine maximale Speichertemperatur programmiert werden. Bei Erreichen dieser Temperatur schaltet ein zweites Relais, mit dem z. B. ein Bypass-Ventil oder eine zweite Umwälzpumpe angesteuert werden.
'Für einen evtl. Notbetrieb sind beide Relais manuell per Tastendruck schaltbar. Die Schaltzustände der Relais werden über Leuchtdioden angezeigt.
'Ä Bei einem evtl. Fühlerbruch werden beide Relais eingeschaltet, um eine Überhitzung der Anlage zu vermeiden. -> Temp < x
'Durch den weiten Einstellbereich ist das Gerät auch für den Einsatz in Schwimmbad-Solarheizungen und vergleichbaren Anwendungen geeignet.
'Die Minimaltemperaturbegrenzung in der Wärmequelle kann z.B. in Verbindung mit Feststoffkesseln eingesetzt werden. Durch Einhalten einer Mindesttemperatur im Wärmeerzeuger wird die Rauchgaskondensation an den Kesselwänden vermieden.
'Ä Einschaltzeiten Pumpen: 2 -3 Parameter mit Ausg/Eing-Nr; über map_analog!!! Zähler if Output_digital_1.nr = 1 then incr Output_digital_2.nr inputs.nr -> flash Anzeige wenn was eingetragen; send to PC
'Ä detektieren ob wasser Pasteurisiert!


'256K Version
'==============
'Ä Datenaufzeichnung mit 8 K RAM SD-Chip
' ***M256 there you find M256-Features
'Ä NimH-Lader
'Ä Regler mit Analog-Ausgang
'Ä E/A-Liste runterladen
'ev. Ä aber es gibt ja schon Max-Time; Schalter Sicherheitsabschaltung ein; Ausgang Reset

'**********************************
' Bewässerungs-Steuerung
'**********************************
'Infos
'I Learning_mode: wenn auf Auto "1" dann Learning_mode = 1; dann Bew-Zeit = Max; wenn Irrigate fertig dann Supress irrigate für 5 Tage (Learning_mode=2)
'Bew-Dauer: keine Sollwertvorgabe: wie weit bin ich von Max entfernt? D=Max-Min; max-actual; in Prozent; of Max-Time Irrigate
'I es sollten die Sensoren > 0 sein, sonst wird kein Kanal geschaltet!
'I PRg-Schalter Dialer 0-11 aber 1-12
'Soll die Pumpe nie eingeschalten werden Wahlschalter auf Pos 0
'wenn Sollwert Feuchte unterschritten dann Start Pumpe ein
'Die Sensoren werden nur alle Minute oder wenn eine Funktion 1-4 angewählt ist abgefragt und abgespeichert,
'um die elektrochemische Korrision zu verhindern
'Ist die Tröpfchen-Bewässerung aktiviert, so gibt die Eingabe Stunden die Startzeit, Minute die Endezeit an
'Bei allen Optionen kann immer über die Verdrahtung entschieden werden, ob ein oder aus bei "aktiv"

'Ausgang:
'g.1= 134 = Output 9/Load 2
'g.3= 118 = Output_10/Load 3
'g.4= 119 = Output_11/Load 4
'e.7= 109 = Output_12/Load 5
'g.2= Output_13/Load 6
'd.7= Output 14/Input Counter etc
'e.5 = LED-Light
'PE.4 (CPU 106) mit 330 Ohm nach Klemme 98 für Sensor aktiv

'Analog:
'1:Getadc(0)      'Battery voltage
'2:Getadc(1)       'Output voltage
'3:Getadc(2)       'Humidity 1
'4:Getadc(3)       'Humidity 2
'5:Getadc(4)       'Humidity 3
'6:Getadc(5)       'Humidity 4
'7:Getadc(6)       'Humidity 5
'8:Getadc(7)       'Program-Selector

'PD0 = Counter 1 schnell
'PD1 = Counter 2 schnell

'9: Analog 9 =  LDR
'10= Analog_10 Sensor_temp_kompensation Temp-Kompensation Solar / Channel 1 Input
'11= Analog_11 Ext_temperature ext.Sensor Temp (for Humid-Sensors)
'12= Analog_12 I_Load_down/left_AI_12 / Channel 2 Input
'13= Analog_13 I_Load_up/right_AI_13 / Channel 3 Input
'14= I_solar_ai_14 I_Solar_AI_14 / Channel 4 Input
'15= Analog_15 Nicd / Channel 5 Input

'Analog Inputs
'1 = Battery Voltage (internal)
'2 = Output-Voltage (Plus at Terminal 43, Minus at 44)
'3 = Sensor 3 (Signal Plus 5V from Terminal 59, Signal at Terminal 61)
'4 = Sensor 4 (Plus from Terminal 62, Signal at Terminal 63)
'5 = Sensor 5 (Sensor at Terminal 62 and 64)
'6 = Sensor 6: Temperature Compensation Ambient Temperature (internal; if external then Signal at Terminal 71 and 72)
'7 = internal
'8 = Program-Switch (internal)
'9 = Light Sensitive Senor (LDR) Measuring at Terminal 74+75
'10 = external Sensor Temperature (for Humid-Sensors):  Measuring at Terminal 74+76
'11 = internal Sensor Temperature. Terminal 77 and 78
'12 = Load-Current 2 Output 1+2
'13 = Load-Current 1 Output 3-5
'14 = Solar- Current
'15 = Voltage NiCd / NimH

'Eingang
'1= Leer Alarm,
'2= Leer Pumpe ein,
'3= Behälter voll
'4=
'5=
'6:Input_6 = Diebstahl-Alarm 2 (Bewegungsmelder)
'7:Input_7 = Diebstahl-Alarm 3 (Bewegungsmelder)
'8:Input_8 = Diebstahl-Alarm 4

'201 = ELV Radio-Sensor 1 Wind Speed
'202 = ELV Radio-Sensor 3 Temperature
'203 = ELV Radio-Sensor 4 Humidity 1
'204 = ELV Radio-Sensor 5 Rain
'
'211 = ELV Radio-Sensor Humidity 2
'212 = ELV Radio-Sensor Humidity 3
'213 = ELV Radio-Sensor Humidity 4
'214 = ELV Radio-Sensor Humidity 5
'
'Data in EEPROM:
'===============
'11-39 free
'40 = hour
'41 = Auto_Detect_Time

'85: Funktion Temp-Sensor 5
'86: Temp-Wert up
'88: Temp-Wert down

'89-129 free

'130 = Pointer Phonenumber
  '131-144 = Telefonnummer 1
'145-159 = Telefonnummer 2
'160-173 = Telefonnummer 2

'Month , 201
'Day , 202
'Hour , 203
'Minute , 204

'221 = Data-Pointer Settings 16 bit

'226 = Timer channel 1 hr  for Solar Load 1
'227 = Timer channel 1 min for Solar Load 1
'228 = Timer channel 1 for for Solar Load 1
'229 = Timer channel 2 hr  for Solar Load 2
'230 = Timer channel 2 min for Solar Load 2
'231 = Timer channel 2 for for Solar Load 2
'232 = Timer channel 3 hr  for Solar Load 3
'233 = Timer channel 3 min for Solar Load 3
'234 = Timer channel 3 for for Solar Load 3
'235 = Timer channel 4 hr  for Solar Load 4
'236 = Timer channel 4 min for Solar Load 4
'237 = Timer channel 4 for for Solar Load 4
'238 = Timer channel 5 hr  for Solar Load 5
'239 = Timer channel 5 min for Solar Load 5
'240 = Timer channel 5 for for Solar Load 5

'242 = Lastabwurf_1 = 11,5 'Blei: 11,1V-10,5V; bei Gel: 10,1V;
'244 = Lastabwurf_2 = 11,3 'Blei: 11,1V-10,5V; bei Gel: 10,1V;
'246 = Lastabwurf_3 = 11,1 'Blei: 11,1V-10,5V; bei Gel: 10,1V;
'248 = Lastabwurf 4 10,9 Volt.off
'250 = Lastabwurf 5 10,7 Volt.off

'260 = 0  Umin_min Batterie 12V
'262 = 1  U Batt Corr cable length
'264 = 2  U Batt Corr cable Area
'266 = 3  Days without watering
'268 = 4  Vorwarnung =  117 '11,7 V
'270 = 5  Hysterese_Rueckschaltung = 10 ': 12,3-12,6 V
'272 = 6  Voltage_Stop_Puls = 137 ': 13,7V
'274 = 7  Zylisches_Laden = 144 '(Blei/Gel): 14,4V/14,1V für max. 1 Std 1x/Monat
'276 = 8  Ausgleichsladen = 147 '(Blei): 14,7V für max. 1 Std 1x/Monat
'278 = 9  Max_Spannung = 155 'max. 15V
'280 = 10 Sprache
'282 = 11 Blei-Gel/Blei
'284 = 12 Irrigation: Average-Calculation
'286 = 13 Channel-Numbers max.20
'288 = 14 Correction Time
'290 = 15 Sensor-Type (0=linear; 1=NTC 10K; 2=NTC 4,7K, 3=lin Type 2) ******
'292 = 16 Analog Input correction +/- ****
'294 = 17 Analog Input correction Factor
'296 = 18 Send Flash to Logview = 1; all Data to Logview = 2
'298 = 19 Werkseinstellung Standard-Values load Reset ****
'300 = 20 Res Additional Device on
'302 = 21 Res Delay_add_device_on
'304 = 22 Receive SMS on
'306 = 23 Send SMS
'308 = 24 Country_code SMS
'310 = 25 Detect Sensor fault?
'312 = 26 Learning mode 1=max.Irrigate; 2=no Irrigate
'314 = 27 ELV V2-Sensors
'316 = 28 Voltage_Nicd_charge
'318 = 29 NiCd mAh
'320 = 30 Solar-Charger aktiv
'322 = 31 Scan-Time Data-Logging
'324 = 32 reserve
'326 = 33 reserve
'328 = 34 SP_Zero_value_current ****************
'330 = 35 Temp-Correction Solar
'332 = 36 PWM-Charging
'334 = 37 Max-Time for Anti-Frost-Irrigation
'336 = 38 Res
'338 = 39 Correction KWh
'340 = 40 resere
'342 = 41 Version
'344 = 42
'346 = 43 Start/Stop Boost-charge
'348 = 44 SD_Card present
'350 = 45 Number of Scans Analog
'352 = 46 Pointer SD-Chip Block
'354 = 47 Load 1 Select Output 1
'356 = 48 Load 2 Select Output 9
'358 = 49 Load 3 Select Output 10
'360 = 50 Load 4 Select Output 11
'362 = 51 Load 5 Select Output 12
'364 = 52 Analog Range Start
'366 = 53 Analog Range End
'368 = 54 Raw Start
'370 = 55 Raw End
'372 = 56 Parameter-Nr for Simu
'374 = 57 Simu-Value
'376 = 58 Reserve Faktor for Simulation with Poti
'378 = 59 Pulsed Output on-Pulse
'380 = 60 Pulsed Output off-Pulse
'382 = 61 Pulsed Output on-Pulse
'384 = 62 Pulsed Output off-Pulse
'386 = 63 Pulsed Output on-Pulse
'388 = 64 Pulsed Output off-Pulse
'390 = 65 Pulsed Output on-Pulse
'392 = 66 Pulsed Output off-Pulse
'394 = 67 Anti-Blocking-System Output 1
'396 = 68 Anti-Blocking-System Output 2
'398 = 69 Anti-Blocking-System Output 3
'400 = 70 Anti-Blocking-System Output 4
'402 = 71 Anti-Blocking-System Output 5
'404 = 72 Min-Value Analog
'406 = 73 Max-Value Analog
'408 = 74 Run-Time hrs

'441 = Pulsed Output on-time channel 1
'442 = Pulsed Output on-time channel 2

'460 = No_Alarm_Time Channel 1
'461 = No_Alarm_Time Channel 2

'481 = Output 2 Channel 1
'482 = Output 2 Channel 2
'483 = Output 2 Channel 3
'... 500

'Channel 1:
'501 Input 1;
'502=Input 2;
'503=Type;
'504=Output 1;
'505=Auto_no_flow;
'506=max_Time_on;
'507:Analog Delay on;
'508:Analog Delay off;
'509:on/off;
'510:Input 2 = 1/0 ok

'511 Channel 2
'till 700
'
'901:Channel 1: hour;
'902:minute;
'903:time_on;
'904:all_x_min;
'905+6:Setpint (16bit);
'907=Auto_Sensor;
'908=>or<;
'909+10=Hysteresis;

'911 Channel 2
'till 1100

'Alarm-Channels
'701 = Alarm Kanal 1 Ein/Aus
'702 = Alarm Kanal 1 Delay on
'703 = Alarm Kanal 1 Delay off
'704 = Alarm Kanal 1 Input
'705 = Alarm Kanal 1 Output
'706 = Alarm Kanal 1 Type:  0=nur Aktion; 1=Alarm-Text + Beep; 2=Telephone; 3=SMS

'711 = Alarm Kanal 2 Ein/Aus
'712 = Alarm Kanal 2 Delay on
'713 = Alarm Kanal 2 Delay off
'714 = Alarm Kanal 2 Input
'715 = Alarm Kanal 2 Output
'716 = Alarm Kanal 1 Type:  0=nur Aktion; 1=Alarm-Text + Beep; 2=Telephone; 3=SMS

'till 750

'Sensor-Type
'751 = Analog_1_typ
'752 = Analog_2_typ
'753 = Analog_3_typ
'till 765 = Analog_15_typ

'771-785  Analog Input correction +/- 1-15
'791-805 Analog Input correction * 1-15
'  Typ  +   *
'1 751 771 791 (59+60) Batt 1"
'2 752 772 792  U Out"
'3 753 773 793 (59+61)
'4 754 774 794 (62+63)
'5 755 775 795 (62+64)
'6 756 776 796 (71+72)
'7 757 777 797 (71+73)
'8 758 778 798
'9 759 779 799 (74+75)
'10 760 780 800 (74+76) ext.Temp
'11 761 781 801 (77+78) int.Temp
'12 762 782 802 (77+79) Load 2
'13 763 783 803 (80+81) Load 1
'14 764 784 804 (80+82) I Solar
'15 765 785 805 (U NiCd)

'806...819 free

'820 42 = Min_humidity_1
'822 44 = Max_humidity_1
'till 898

'ab 900-1099 channels Block 2

'Ab 1100 Flash Messwerte

'Funktionen: '(old!)
'Grundmenu
'1234567890123456
'Sens 123 00:00
'99.9%99.9%99.9%
'#### Fkt 1 ##########
'P1 on for / all
'00:00 00s 00min
'####################
'1:99.9%>SP:99.9% old 'AV/SP1:99.9>99.9
'Hys:9.9% Typ:1     7+8 Typ:0=%;1=°
'####################
'Input 1:101 33+44  short:Terminals
'Output:99 44+55
'####################
'Input 2:101 33+44  short:if 2 Sensor
' Auto:1/123sec      12 Auto-Setpoint
'######## Fkt2 ########
'Temp Act:60,6° short:Input 0/1/2/#Inp
'normal  0/1/2/#
'####################
'Temp Max: 0.°0
'Temp Min: #0.°0
'######### Fkt3 ###########
'off Time: 00sec  Moving Detector
' <100=sec/>=min   Switch on Time
'######## Fkt4 ############
'Telefon
'######## Fkt5 ############
'U Batt: 12,5V
'Fill#Time:00sec
'######## Fkt6 ############
'C1:off:11,5V/off  Switch off Volt#
'Time:00:00/00sec  age Time/Timer 1#5
'######## Fkt7 ############
'Time:04.01.01:15
'Auto Time:No
'######## Fkt8 ############
'Parameter  see List
'######## Fkt9 ############
'L1P1P2P3P4P5P6
'1p2p3p4p5p6p7p

'*********************************** Pre-Settings **********************************************
Const Anzahl_tage_kein_giessen = 3                          'Wieviel Tage soll nicht gegossen werden?
Const Faktor_feuchte_start = 5                              'Mittelwert + Faktor = Start-Wert
Const Delay_check_pump_flow = 50                            'in sec
Const Sp_light = 850                                        'in hours
Const Time_sun_raise = 7
Const Time_sun_set = 19
Const Sp_no_irrigate = 3                                    'below this value, no irrigation will be started because calculated is too small

'*************************************** charge-controller *****************************
'12V-System Voreinstellung für Flüssig-Blei-Akku; bei Bleigel Korrektur um 0,5V für untere Spannung
Const Batt_leer_alles_aus = 0                               'Bei Batterie leer alles aus (=1)?
Const Sp_time_boost_charge = 120                            'Time for Boost-charging in min
Const Sp_time_full_charge = 300                             'Time for Full charging in min (5 std)
Const Sp_time_equalization_charge = 600                     'Time for equalization charging in min
Const Min_spannung = 105
Const Lastabwurf_1 = 115                                    'Blei: 11,1V-10,5V; bei Gel: 10,1V;
Const Lastabwurf_2 = 113                                    'Blei: 11,1V-10,5V; bei Gel: 10,1V;
Const Lastabwurf_3 = 111                                    'Blei: 11,1V-10,5V; bei Gel: 10,1V;
Const Lastabwurf_4 = 109                                    'Blei: 11,1V-10,5V; bei Gel: 10,1V;
Const Lastabwurf_5 = 107                                    'Blei: 11,1V-10,5V; bei Gel: 10,1V;
Const Vorwarnung = 117                                      '11,7 V
Const Hysterese_rueckschaltung = 10                         ': 12,3-12,6 V
Const Ladeendspg = 138                                      ': 13,7V
Const Zylisches_laden_blei = 144                            'bei Blei 14,4 V für max. 1-2 Std
Const Zylisches_laden_gel = 141                             'bei Gel 14,1 V für max. 1-2 Std
Const Ausgleichsladen = 147                                 'nur bei Blei 14,7 V für max 1-2 Std/Monat
Const Max_spannung = 150                                    'max. 15V
Const Sp_no_boost_charge_for = 0                            'no no_boost_charge_for 1-2 days (= 32 hours)
Const I_load_alarm_value = 220                              'Alarm-value Load-current
Const I_load_max_value = 260
Const I_solar_alarm_value = 220                             'Alarm-value Load-current
Const I_solar_max_value = 260

Const Sp_delay_low_volt = 50                                'Delay switch off load in sec
Const Sp_delay_switch_back = 50                             'Delay switch back in sec
Const Sp_time_off_u_min = 10                                'in Minutes Time Relais min off
Const Sp_time_on_u_min = 10                                 'in Minutes Time Relais min on

Const Max_temp_switch_off = 1600                            'Preset Switch off at Max-Temp
Const U_raise_alarm_weak_battery = 15                       'Differenz-voltage raise in one minute
Const Time_switch_off_overcurrent = 20                      'in Second
Const Sp_zero_value_current = 563                           'fixed Value depending on OP-Amp Resistors (386 miot V10.1)
Const Sp_i_load_high_current_1 = 80                         'Amperes High-Current for Correction
Const Correction_v_high_current_1 = 3                       'Factor for correction high current (5 = 0.5V)
Const Sp_i_load_high_current_2 = 160                        'Amperes High-Current for Correction
Const Correction_v_high_current_2 = 4                       'Factor for correction high current (5 = 0.5V)
Const Sp_i_load_high_current_3 = 240                        'Amperes High-Current for Correction
Const Correction_v_high_current_3 = 5                       'Factor for correction high current (5 = 0.5V)

'******************************** Analog-channels Settings *******************************
'U_batt Type 0
Const Mess_1_ug = 13.7                                      'Ya Meßbereich Anfang /1. Stützpunkt
Const Mess_1_og = 293.0                                     'Yb Meßbereich Ende /2. Stützpunkt
Const Mess_1_anfang = 34.0                                  'Xa 205 für 4-20mA; 0 für 0-20mA 1. Stützpunkt
Const Mess_1_ende = 762.0                                   'Xb 2. Stützpunkt
'Const Analog_1_typ = 0                                      '0=linear; 1=Tabelle für 10K NTC

'Channel Type 3 linear
Const Mess_3_ug = 0.0                                       'Meßbereich Anfang 1. Stützpunkt
Const Mess_3_og = 999.0                                     'Meßbereich Ende 2. Stützpunkt
Const Mess_3_anfang = 0.0                                   'Raw-Value 205 für 4-20mA; 0 für 0-20mA 1. Stützpunkt
Const Mess_3_ende = 1024.0                                  'Raw-Value 2. Stützpunkt

'Channel Type 4 free
Const Mess_4_ug = 0.0                                       'Meßbereich Anfang 1. Stützpunkt
Const Mess_4_og = 999.0                                     'Meßbereich Ende 2. Stützpunkt
Const Mess_4_anfang = 0.0                                   'Raw-Value 205 für 4-20mA; 0 für 0-20mA 1. Stützpunkt
Const Mess_4_ende = 1024.0                                  'Raw-Value 2. Stützpunkt

'I_load_ai_12 = Analog_12
'Const Mess_12_ug = 0.0                                       'Meßbereich Anfang 1. Stützpunkt
'Const Mess_12_og = 999.0                                     'Meßbereich Ende 2. Stützpunkt
'Const Mess_12_anfang = 0.0                                   'Raw-Value 205 für 4-20mA; 0 für 0-20mA 1. Stützpunkt
'Const Mess_12_ende = 1024.0                                  'Raw-Value 2. Stützpunkt
'Const Analog_12_typ = 0                                      '0=linear; 1=Tabelle für 10K NTC
''I_load_ai_13 = Analog_13
'Const Mess_13_ug = 0.0                                       'Meßbereich Anfang 1. Stützpunkt
'Const Mess_13_og = 999.0                                     'Meßbereich Ende 2. Stützpunkt
'Const Mess_13_anfang = 0.0                                   'Raw-Value 205 für 4-20mA; 0 für 0-20mA 1. Stützpunkt
'Const Mess_13_ende = 1024.0                                  'Raw-Value 2. Stützpunkt
'Const Analog_13_typ = 0                                      '0=linear; 1=Tabelle für 10K NTC
''I_solar_ai_14 = Analog_14 :
'Const Mess_14_ug = 0.0                                       'Meßbereich Anfang 1. Stützpunkt
'Const Mess_14_og = 999.0                                     'Meßbereich Ende 2. Stützpunkt
'Const Mess_14_anfang = 0.0                                   'Raw-Value 205 für 4-20mA; 0 für 0-20mA 1. Stützpunkt
'Const Mess_14_ende = 1024.0                                  'Raw-Value 2. Stützpunkt
'Const Analog_14_typ = 0                                      '0=linear; 1=Tabelle für 10K NTC
'U_NiCd Type 5
Const Mess_15_ug = 589.0                                    'Ya Meßbereich Anfang 1. Stützpunkt
Const Mess_15_og = 1153.0                                   'Yb Meßbereich Ende 2. Stützpunkt
Const Mess_15_anfang = 291.0                                'Raw-Value Xa 205 für 4-20mA; 0 für 0-20mA 1. Stützpunkt
Const Mess_15_ende = 556.0                                  'Raw-Value Xb 2. Stützpunkt
'Const Analog_15_typ = 0                                     '0=linear; 1=Tabelle für 10K NTC

'############################################# Pasteur #######################################
Dim Time_pa(7) As Byte
Dim Time_activated_by_sensor_on_max(7) As Byte
Dim Temp_old_past(7) As Integer
'Temp-Table
Const Grad_62 = 620                                         '10K = 212; 4,7K = 288
Const Grad_65 = 650                                         '10K = 216; 4,7K = 293
Const Grad_67 = 670                                         '10K = 218; 4,7K = 296
Const Grad_69 = 690                                         '10K = 221; 4,7K = 300
Const Grad_71 = 710                                         '10K = 223; 4,7K = 303
Const Grad_73 = 730                                         '10K = 225; 4,7K = 306
Const Grad_75 = 750                                         '10K = 227; 4,7K = 308
Const Grad_77 = 770                                         '10K = 229; 4,7K = 310
Const Grad_79 = 790                                         '10K = 231; 4,7K = 312
Const Grad_81 = 810                                         '10K = 233; 4,7K = 315

'//////////////////////////////////////////////////////////////////////////
'Dim A(1910) As Byte                                         'Array of 1800  alt 3610 alt 3410
Dim A(6010) As Byte                                         '***M256                                 'Array of 1800  alt 3610 alt 3410
'Const Pointer_end_ram = 1900
Const Pointer_end_ram = 6000                                '***M256

Dim Alarm_input(5) As Integer
Dim Alarm_input_old(5) As Integer
Dim Alarm_active_delay_on(5) As Byte
Dim Alarm_active(5) As Byte

Dim Analog_input_channel(20) As Integer
Dim Activated_by_sensor(20) As Byte
Dim Su_time(20) As Byte
Dim Pulse_antifrost(20) As Byte
'Dim Pulse_start_by_sensor(20) As Byte
Dim Output(20) As Byte
Dim Learning_mode(20) As Byte
Dim Auto_sp_irrigation_time(20) As Integer
Dim Max_humidity(20) As Integer
Dim Min_humidity(20) As Integer
Dim Humidity_yesterday(20) As Integer
Dim Analog_delay_on(20) As Byte
Dim Analog_delay_off(20) As Byte
Dim Analog_input_2_channel(20) As Byte

Dim Max_time_pump(20) As Byte
Dim Alarm_max_time_pump(20) As Byte
Dim Alarm_auto_no_flow(20) As Byte
Dim Saved_actual(20) As Integer
Dim Delay_check_actual(20) As Byte
Dim Channel_type(20) As Byte
Dim Interlock(20) As Byte
Dim Pulse(20) As Byte
Dim Pulse_input_was_active(20) As Byte
Dim Channel_typ_interlock As Bit
Dim Number_of_scans As Byte

Dim Output_digital_1 As Byte
Dim Output_digital_2 As Byte
Dim Inputs As Byte
Dim Channel_number_old As Byte

Dim Pointer_2 As Integer

' *** Port-Definition ***
Dim Lcd_port As Byte
Dim Port1 As Bit
Dim Port2 As Bit
Dim Port3 As Bit
Dim Port4 As Bit
Dim Port5 As Bit
Dim Port6 As Bit
Dim Port7 As Bit
Dim Port8 As Bit
Dim Output_1 As Bit                                         'Relais Batt ein
Dim Relais_2 As Bit                                         'Relais Batterie voll
Dim Relais_3 As Bit
Dim Relais_4 As Bit
Dim Relais_5 As Bit
Dim Relais_6 As Bit
Dim Relais_7 As Bit
Dim Lcd_rs As Bit                                           'port[9]
Dim Lcd_rw As Bit                                           'port[10]
Dim Port11 As Bit                                           'port[11]
Dim Port12 As Bit                                           'port[12]
Dim A_keyb As Bit                                           'tastatur
Dim Lcd_e As Bit
Dim Clock1 As Bit                                           'LS374 Datenübergabe
Dim Port16 As Bit
Dim Input_1 As Bit                                          '
Dim Input_2 As Bit                                          '
Dim Input_3 As Bit                                          '
Dim Input_4 As Bit                                          '
Dim Input_5 As Bit                                          '
Dim Input_6 As Bit                                          '
Dim Input_7 As Bit                                          '
Dim Input_8 As Bit                                          '

Dim U_batt As Integer                                       '12 Volt
Dim Sensor_batt As Integer                                  ' AD[1]    'Batteriespannung
Dim U_ausg As Integer                                       'Output voltage
Dim U_ausg_sensor As Integer                                'Output voltage
Dim Humidity_1_sensor As Integer
Dim Humidity_2_sensor As Integer
Dim Humidity_3_sensor As Integer
Dim Humidity_4_sensor As Integer
Dim Humidity_5_sensor As Integer
Dim Humidity_1 As Integer
Dim Humidity_2 As Integer
Dim Humidity_3 As Integer
Dim Humidity_4 As Integer
Dim Humidity_5 As Integer
'Dim Humidity_6 As Integer
'Dim Humidity_7 As Integer
Dim Wahlschalter As Byte                                    'Wahlschalter

' *** Bits-Definition ***

Dim Fkt1 As Bit                                             'Funktion Pasteuer
Dim Fkt2 As Bit                                             'Funktion Kochen
Dim Fkt3 As Bit                                             'Funktion best.Zeit Pasteuer
Dim Fkt4 As Bit                                             'Funktion Spannungsanzeige
Dim Fkt5 As Bit                                             'Funktion Statusanzeige Ausgänge
Dim Fkt6 As Bit                                             'Funktion NiCd-Anwahl, re/li ein/aus
Dim Fkt7 As Bit                                             'Funktion Uhreingabe
Dim Fkt8 As Bit                                             'Funktion Schaltuhr
Dim Fkt9 As Bit                                             'Funktion Handebene

Dim Meldung_aktiv As Bit                                    'Hupe aktiv
'Dim Alarm_no_water_flow As Bit                              '
Dim Alarm_sensor As Bit                                     'Alarm Leermeldung Behälter
'Dim Solar_pulsen As Bit                                     'Solar laden pulsen
Dim Stelle_1 As Bit
'Dim Aus As Bit
'Dim Keyb_flanke As Bit
'Dim Activated_by_sensor As Bit                              'kein Komma! + Schmierbit
'Dim Eingabe_teil_1 As Bit                                   'Dateneingabe teil 1
Dim Eingabe_teil_2 As Bit                                   'Dateneingabe teil 2
Dim Eingabe_teil_3 As Bit                                   'Dateneingabe teil 3
Dim Eingabe_teil_4 As Bit                                   'Dateneingabe teil 3
Dim Eingabe_teil_5 As Bit                                   'Anzeige Batteriespannung
Dim Eingabe_teil_6 As Bit

Dim Disp_fkt9 As Bit                                        'Nur Anzeige Handebene
Dim Input_1_old As Bit
Dim Input_2_old As Bit
Dim Input_3_old As Bit
Dim Input_4_old As Bit
Dim Input_5_old As Bit
Dim Input_6_old As Bit
Dim Input_7_old As Bit
Dim Input_8_old As Bit
Dim Kein_komma As Bit
Dim Tel_nr As Bit                                           'nur für die Diplay-Anzeige
Dim Mobile_aktiv As Bit
'Dim Senden_aktiv As Bit
Dim Nr_2_waehlen As Bit
Dim Nr_3_waehlen As Bit
Dim Send_sms As Bit
Dim Test_anruf As Bit
Dim Eeprom_full As Bit
Dim Simu As Bit
Dim English As Bit
Dim Sensor_1_present As Bit
Dim Sensor_2_present As Bit
Dim Sensor_3_present As Bit
Dim Sensor_4_present As Bit
Dim Sensor_5_present As Bit
Dim Sensor_6_present As Bit
'Dim Sensor_7_present As Bit
'Dim Puls_sensor_fault As Bit
Dim Beeper As Bit
Dim Zeiger_ram_end As Integer
'Dim Flag_call_alarm As Bit
'Dim Irrigate_ldr As Bit
'Dim Auto_start_ldr As Bit
'Dim Zahl_komma As Bit
Dim Output_1_sms As Bit
Dim Relais_2_sms As Bit
Dim Relais_3_sms As Bit
Dim Relais_4_sms As Bit
Dim Relais_5_sms As Bit
Dim Relais_6_sms As Bit
Dim Relais_7_sms As Bit
Dim Output_1_off_sms As Bit
Dim Relais_2_off_sms As Bit
Dim Relais_3_off_sms As Bit
Dim Relais_4_off_sms As Bit
Dim Relais_5_off_sms As Bit
Dim Relais_6_off_sms As Bit
Dim Relais_7_off_sms As Bit
Dim Temp_lcd As Integer
Dim Temp4 As Integer
Dim Temp5 As Integer
Dim Telephone_on As Bit
Dim Check_seriell_keyb As Bit
Dim Ten_times_channel_nr As Byte
Dim Eight_bit_value_neg As Bit
Dim M_second As Byte
Dim Second As Byte
Dim Sec_alt As Byte                                         '
Dim Minute As Byte
Dim Hour As Byte
Dim Day As Byte
Dim Month As Byte
Dim Mday As Byte
Dim Year As Byte
Dim Zaehler As Integer
Dim Delay As Byte
Dim Counter As Integer
Dim S As String * 6
Dim Freq1 As Byte
Dim Freq2 As Byte
Dim Freq1_alt As Byte
Dim Freq2_alt As Byte
Dim Programm_selector As Byte
Dim Learning_mode_old As Byte
Dim Alarm_from_input As Bit
Dim Day_learning_mode As Byte
Dim Humidity_average As Integer
Dim Max_value As Byte
Dim Make_tel_call As Bit
Dim Keyb As Byte                                            'Input keyboard
Dim Lcd_param As Byte                                       '
Dim Pointer As Integer                                      '
Dim Min_count As Byte                                       'Rückwärtszähler
Dim Value As Word                                           'Schmier-Flag
Dim Temp As Integer
Dim Temp1 As Integer
Dim Temp2 As Integer
Dim Temp3 As Integer
Dim Temp_b1 As Byte                                         'Byte-Schmier-Flag
Dim Temp_b2 As Byte                                         'Byte-Schmier-Flag
Dim Temp_b3 As Byte                                         'Byte-Schmier-Flag
Dim Temp_b4 As Byte                                         'Byte-Schmier-Flag
Dim Temp_b5 As Byte                                         'Byte-Schmier-Flag
Dim Temp_l1 As Long
Dim Temp_l2 As Long
Dim Temp_bit1 As Bit                                        'Byte-Schmier-Flag
Dim Temp_bit2 As Bit                                        'Byte-Schmier-Flag
Dim Temp_bit3 As Bit                                        'Byte-Schmier-Flag
Dim Temp_bit4 As Bit
Dim Number As Byte
Dim Zeiger_flash As Integer
Dim Pointer_eeprom As Integer
Dim Remote_key As Byte
Dim Remote_key_old As Byte
Dim Mobile_aktiv_counter As Byte
Dim Channel_number As Byte
Dim Display_zaehler As Byte
Dim Humid_input As Integer
Dim Days_without_water As Byte
Dim Pointer_eeprom_tel As Byte
'Dim Goto_ground_menu As Byte
Dim Sensor_nr_fault As Byte
Dim Beep_ein As Byte
Dim Delay_on As Byte
Dim Ext_temperature As Integer
Dim Minute_byte As Byte
Dim Setpoint As Integer
'Dim Delay_dark As Byte
'Dim Delay_light As Byte
Dim Sensor_average As Integer
Dim Zeiger_sms As Byte
Dim Time_no_seriell_pc As Byte
Dim Temp_s1 As Single
Dim Temp_s2 As Single
Dim Mess_ug As Single
Dim Mess_og As Single
Dim Mess_anfang As Single
Dim Mess_ende As Single
Dim Lcd_display_position As Byte                            'used internally by LCD_Display routine..
Dim Lcd_disp_char As String * 1                             'used internally by LCD_Display routine..
Dim Lcd_display_string As String * 16                       'string to be displayed,  set this and the 'Gosub Lcd_Display...
'Dim Display_single_digit_yn As Bit                          'used mainly for phone numbers...
Dim Lcd_display_pad_with_spaces As Bit                      '=0 no change; =1 pad 'lcd_display_string' with spaces to make it 16 characters long before displaying it to the screen, definetely overwrites anything there previously, used especially in menu 8...
Dim Hours_night As Byte
Dim Hours_day As Byte
Dim Ldr_sensor As Integer
Dim Display_time_grid As Bit
Dim Analog_input_channel_x As Integer
Dim Delay_switch_off_reverse_connect As Byte
Dim Alarm_reverse_connect As Bit
Dim Programm_selector_old As Byte
Dim Prg_switch_remote As Byte
Dim No_irrigation As Bit
Dim Do_irrigation As Bit
Dim Flag_do_irrigation As Bit
Dim Act_do_irrigation_time As Byte
Dim Pulse_alarm_empty As Bit
'Dim Channel_nr_alarm_sensor As Byte
Dim Alarm_thief As Bit
Dim No_display_basic_menu As Bit

Dim Count_data_to_pc As Byte
Dim Block_count_send As Word
Dim Sending_os_data_active As Bit

'Dim Version As Byte                                         '0 = V9; 1=V10; 2=V11
Dim Analog_block As Byte
Dim Analog_9 As Integer
Dim Analog_10 As Integer
Dim Analog_11 As Integer
Dim I_load_ai_12 As Integer
Dim I_load_ai_13 As Integer
'Dim Analog_14 As Integer
Dim Analog_15 As Integer

Dim Timer_1_sec As Byte
Dim Timer_2_sec As Byte
Dim Data_pointer As Byte
Dim U_nicd As Integer
Dim Blei_akku As Byte                                       '0= Bleigel-Akku; 1=Säure-Akku
Dim Flanke_u_max_max As Bit
Dim Blei_akku_old As Byte
Dim Pwm_charging As Bit
Dim Pwm_charging_on_by_user As Bit
Dim Stop_read_ai_extended As Bit
Dim Time_umaxmax As Byte

Dim Lcd_led As Byte
Dim Timer_nr As Byte
'Dim Timer_0_on As Bit
Dim Time_load_shedding(5) As Byte
'Dim Timer_2_on As Bit
'Dim Timer_3_on As Bit
'Dim Timer_4_on As Bit
'Dim Timer_5_on As Bit

Dim Su_time_act_1 As Byte
Dim Su_time_act_2 As Byte
Dim Su_time_act_3 As Byte
Dim Su_time_act_4 As Byte
Dim Su_time_act_5 As Byte

Dim Tiefentladen_aus_1 As Bit
Dim Tiefentladen_aus_2 As Bit
Dim Tiefentladen_aus_3 As Bit
Dim Tiefentladen_aus_4 As Bit
Dim Tiefentladen_aus_5 As Bit

'Dim I_load_sum_up As Integer
Dim Start_stop_boost_charge_old As Bit
Dim Count_day As Byte
Dim Voltage_pulse_start As Integer
Dim Fully_load_till_stop_puls As Bit
'Dim Correction_high_current As Integer
Dim Account_batterie As Integer
Dim Zero_value_current As Integer                           'fixed Value depending on OP-Amp Resistors (386 miot V10.1)
'Dim Temp_int As Integer
Dim U_batt_smooth As Integer
Dim Boost_voltage As Integer
Dim Umaxmax As Bit
Dim Boost_voltage_was_ok As Bit
Dim System_voltage_24v As Bit
'Dim System_voltage_48v As Bit
Dim Display_submenues As Byte
Dim Negative_number As Bit
Dim Display_info As Byte
'Dim Ladeendspannung As Integer
Dim Solar_loading_slow_pulses As Bit
Dim Number_of_channel_modules As Byte
Dim Pointer_u_batt As Byte
Dim I_solar_old As Integer
Dim I_solar_old_1 As Integer
Dim I_solar_old_2 As Integer

Dim Time_boost_charge As Integer
Dim I_solar As Integer
Dim I_load_1 As Integer
Dim I_load_2 As Integer
Dim I_load As Integer
Dim No_sun As Bit

Dim Boost_charge As Bit
Dim Full_charge As Bit
Dim Equalization_charge As Bit
Dim Normal_charge As Bit
Dim Charge_to_14_4v As Bit

Dim No_boost_charge_for As Byte
Dim Delay_activate_boost_charge As Byte
Dim Delay_u_min_min As Byte
Dim U_additional_dev_on As Integer
Dim Delay_add_device_on As Byte
'Dim Time_i_load_max_value As Byte
'Dim Time_i_solar_max_value As Byte
'Dim Battery_voltage_old As Integer
'Dim Old_current_solar As Integer
Dim Switch_off_alarm As Byte
Dim Batt_pwm_charge As Bit                                  'Solar laden pulsen
Dim Slow_switching_time_on As Byte
'Dim Slow_switching_10_s_timer As Byte
Dim Pwm_value As Byte
Dim Solar_loading As Bit                                    'Relais Batterie voll
Dim Sensor_2 As Integer                                     'AD[4]  'Elektronik Temp/Solarzellen kühlen
'Dim Delay_on_new_program As Byte
Dim Get_solar_value As Bit

Dim Sum_ah_solar As Word                                    'byte 19 und 20;
Dim Value_ah_solar As Word                                  'byte 21 und 22;
Dim Sum_ah_load As Word                                     'byte 19 und 20;
Dim Value_ah_load As Word                                   'byte 21 und 22;
Dim Ah_solar_day As Word
Dim Ah_load_day As Word
Dim Value_wh_solar As Single                                'byte 21 und 22;
Dim Value_wh_load As Single                                 'byte 21 und 22;
Dim Wh_solar_day As Word
Dim Wh_load_day As Word
Dim Sum_ah_load_1 As Word
Dim Sum_ah_load_2 As Word
Dim Value_ah_load_1 As Word
Dim Value_ah_load_2 As Word
Dim Ah_load_day_1 As Word
Dim Ah_load_day_2 As Word
Dim Value_wh_load_1 As Word
Dim Value_wh_load_2 As Word
Dim Wh_load_day_1 As Word
Dim Wh_load_day_2 As Word

Dim U_max_day As Integer
Dim U_min_day As Integer

'Dim I_load_1_ai_12 As Integer
'Dim I_load_2_ai_13 As Integer
Dim I_solar_ai_14 As Integer
Dim U_nicd_ai_15 As Integer

Dim Batterie_n_leer_1 As Bit
Dim Batterie_n_leer_2 As Bit
Dim Batterie_n_leer_3 As Bit

Dim Time_off_u_min_1 As Byte
Dim Time_off_u_min_2 As Byte
Dim Time_off_u_min_3 As Byte
Dim Time_off_u_min_4 As Byte
Dim Time_off_u_min_5 As Byte

Dim Delay_switch_back_1 As Byte
Dim Delay_switch_back_2 As Byte
Dim Delay_switch_back_3 As Byte
Dim Delay_switch_back_4 As Byte
Dim Delay_switch_back_5 As Byte

Dim Delay_low_volt_alarm As Byte                            'Pre-Alarm
Dim Delay_min_volt_alarm As Byte                            'Empty
'Dim Delay_max_volt_alarm As Byte                            'Empty
Dim Delay_low_volt_1 As Byte
Dim Delay_low_volt_2 As Byte
Dim Delay_low_volt_3 As Byte

Dim Average_pointer_load As Byte
Dim Array_average_load(5) As Integer                        'Array of 1800
Dim Average_pointer_solar As Byte
Dim Array_average_solar(5) As Integer                       'Array of 1800
Dim Array_smooth_u_batt(5) As Integer                       'Array of 1800

Dim Load_1 As Bit
Dim Load_2 As Bit
Dim Load_3 As Bit
Dim Load_4 As Bit
Dim Load_5 As Bit

Dim Batterie_n_leer_4 As Bit
Dim Delay_low_volt_4 As Byte
Dim Batterie_n_leer_5 As Bit
Dim Delay_low_volt_5 As Byte
Dim Sensor_temp_kompensation As Integer                     'AD[6] für Temp-Kompensation
'Dim Display_solarmenue As Bit
Dim Multiplex_display As Byte
Dim Flanke_alarm_batt As Bit                                'Flanke Batterie bald leer
Dim Flanke_u_min_batt As Bit                                'Flanke Batterie ist leer
'Dim Flanke_u_max_batt As Bit                                'Flanke Batterie ist voll
'Dim Flanke_alarm_tuer As Bit                                'Alarm Diebstahlsicherung abschalten
Dim Delay_next_key_reset As Byte
Dim Back_to_basic_menu As Byte
Dim Counter_1_puls As Bit
Dim Counter_2_puls As Bit
Dim Counter_1 As Integer
Dim Counter_2 As Integer

'Dim Alarm_aktive As Bit
'Dim Bew_melder_aktiv As Byte
'Dim Delay_alarm_aktive As Byte
Dim No_print_seriell As Bit
Dim Delay_next_key As Bit
Dim Input_new_parameter As Byte
Dim Two_comma As Bit

Dim Output_9 As Bit
Dim Output_10 As Bit
Dim Output_11 As Bit
Dim Output_12 As Bit
Dim Output_13 As Bit
Dim Output_14 As Bit
Dim Output_17 As Bit
Dim Output_18 As Bit
Dim Output_19 As Bit
Dim Output_20 As Bit
Dim Nimh_load_rel As Bit
Dim Ram_full As Bit
Dim Zeiger_ram As Integer
Dim Ram_second_time As Bit
Dim Eeprom_second_time As Bit
Dim End_pointer_flash As Integer
Dim Freq3 As Word                                           'Timer3
Dim Sum_freq3 As Word
Dim Pwm_port As Bit
Dim Channel_input_2 As Byte
Dim Write_ram As Bit
Dim Flag_call_telephone_by_output As Bit
Dim Channel_typ_load_shedding As Bit
Dim More_then As Byte
'Dim Humidity_by_radio_1 As Integer
'Dim Humidity_by_radio_2 As Integer
'Dim Humidity_by_radio_3 As Integer
'Dim Humidity_by_radio_4 As Integer
'Dim Humidity_by_radio_5 As Integer
'Dim Humidity_by_radio_6 As Integer
Dim Data_direct_to_pc As Bit

Dim Voltage_stop_puls As Integer
Dim Output_as_pulse As Bit

Dim Delay_umaxmax_off As Byte
Dim Hour_old As Byte
Dim Switch_input_block As Byte
Dim Switch_input_block_channel As Byte
Dim Display_info_line As Bit
Dim Start_by_timer As Byte

Dim Channel_alarm_auto_no_flow As Byte
Dim Channel_alarm_max_time_pump As Byte
Dim Display_all_data As Byte
Dim Show_info_channel_type As Byte
'Dim Programm_selector_old_2 As Byte

Dim Channel_nr As Byte
Dim Alarm_on_off As Byte
Dim Sp_alarm_delay_on As Byte
Dim Sp_alarm_delay_off As Byte
Dim Alarm_moving_detector As Bit
Dim Channel_nr_alarm As Byte
Dim Vb_process_display As Bit
Dim Alarm_notification_break_time As Byte
Dim Channel_typ As Byte
Dim Channel_typ_alarm As Bit
Dim Flag_alarm_channel As Bit

Dim Min_value_1 As Integer
Dim Min_value_1_old As Integer
Dim Min_value_2 As Integer
Dim Min_value_2_old As Integer
Dim Max_value_1 As Integer
Dim Max_value_1_old As Integer
Dim Max_value_2 As Integer
Dim Max_value_2_old As Integer
Dim Running_time_1_sec As Byte
Dim Running_time_2_sec As Byte
Dim Running_time_1 As Integer
Dim Running_time_2 As Integer
Dim Save_value_for_display As Byte

Dim Alarm_no_analog_nr As Byte
Dim Flag_alarm_if_no_analog As Bit
Dim Reset_alarm_if_no_analog As Byte
Dim Tick_1 As Bit

Dim Time_slice_3b As Bit
Dim Gosub_analog_extended As Bit
Dim Send_flash_to_logview As Bit
Dim Do_not_accept_keyboard_by_serial As Byte

'////////////////////////////////////////////////////////////////////////////////////////
'SD-Card
'Constants
Const Msbl = 0
'Const Msbh = 1
'Const Dly = 2
'Const Bits8 = 8
'Const Bits16 = 16
'Const Bits32 = 32

'Variables
Dim Indat(514) As Byte                                      'Memory buffer for temp storage.
Dim Dat As Byte
Dim Resp As Byte
Dim Resp2 As Word
Dim I As Word
Dim Y As Byte
Dim Addr As Long
Dim Chkres As Byte
Dim Block_nr_read As Word
Dim Adr1 As Long
Dim Read_header As Bit
Dim Write_header As Bit
Dim Number_of_scan As Byte
Dim Mmc_print As Bit
Dim Sd_card_time_out As Byte
Dim Sd_card_active As Byte

'Aliases
Cs Alias Portg.0                                            'alt:b.4
Clk Alias Portb.6                                           'alt:b.7
Miso Alias Pinb.4                                           'alt:b.6                                          'inp
Mosi Alias Portb.3                                          'alt:b.5                                         'out

'Declarations
Declare Sub Minit
Declare Sub Mstatus
Declare Sub Mwrite
Declare Sub Mread
Declare Sub Chkresp(byval Chkres As Byte)
'////////////////////////////////////////////////////////////////////////////////////////
'ELV-Sensors
Dim Temp_array(7) As Byte                                   'Array for Radio-Data
Dim Elv_v2_data(50) As Byte
Dim Elv_sensor_byte As Byte
'Dim Elv_sensor_byte_old As Byte
Dim Counter_radio_bytes As Byte
Dim Wind_speed As Integer
'Dim Wind_stability As Byte
'Dim Wind_direction As Integer
Dim Elv_temp As Integer
Dim Elv_temp_2 As Integer
Dim Elv_rain As Integer                                     '0x20 – 0x27 Regensensor
'Dim Elv_light As Integer                                    '0x20 – 0x27 Regensensor
Dim Elv_humidity As Integer
Dim Elv_humidity_2 As Integer

Dim Wind_sensor_detect As Bit
Dim Temp_sensor_detect As Bit
Dim Temp_sensor_detect_2 As Bit
Dim Rain_sensor_detect As Bit
'Dim Light_sensor_detect As Bit
Dim Humidity_sensor_detect As Bit
Dim Humidity_sensor_detect_2 As Bit

'Timer
Dim Time_value_corrected As Byte
Dim Sp_hour_timer As Byte
Dim Sp_min_timer As Byte
Dim Sp_run_time_timer As Byte
Dim Sp_on_all_timer As Byte
Dim Sp_on_time_puls As Byte
Dim Pulse_time(20) As Byte
Dim Timer_active(20) As Byte

'Programm-Selektor
Const Prg_selector_pos_1 = 4                                'Wahlschalter
Const Prg_selector_pos_2 = 28                               'Wahlschalter
Const Prg_selector_pos_3 = 34                               'Wahlschalter
Const Prg_selector_pos_4 = 46                               'Wahlschalter
Const Prg_selector_pos_5 = 61                               'Wahlschalter
Const Prg_selector_pos_6 = 103                              'Wahlschalter
Const Prg_selector_pos_7 = 130                              'Wahlschalter
Const Prg_selector_pos_8 = 166                              'Wahlschalter
Const Prg_selector_pos_9 = 194                              'Wahlschalter
Const Prg_selector_pos_10 = 224                             'Wahlschalter
Const Prg_selector_pos_11 = 246                             'Wahlschalter
Const Prg_selector_pos_12 = 255                             'Wahlschalter

'*** ASCII-Codes ***
Const A_ = &H41
Const B_ = &H42
Const C_ = &H43
Const D_ = &H44
Const E_ = &H45
Const F_ = &H46
Const G_ = &H47
Const H_ = &H48
Const I_ = &H49
Const J_ = &H4A
Const K_ = &H4B
Const L_ = &H4C
Const M_ = &H4D
Const N_ = &H4E
Const O_ = &H4F
Const P_ = &H50
Const Q_ = &H51
Const R_ = &H52
Const S_ = &H53
Const T_ = &H54
Const U_ = &H55
Const V_ = &H56
Const W_ = &H57
Const X_ = &H58
Const Y_ = &H59
Const Z_ = &H5A

Const Aa_ = &H61
Const Ae_ = &HE1
Const Bb_ = &H62
Const Cc_ = &H63
Const Dd_ = &H64
Const Ee_ = &H65
Const Ff_ = &H66
Const Gg_ = &H67
Const Hh_ = &H68
Const Ii_ = &H69
Const Jj_ = &H6A
Const Kk_ = &H6B
Const Ll_ = &H6C
Const Mm_ = &H6D
Const Nn_ = &H6E
Const Oo_ = &H6F
Const Oe_ = &HEF
Const Pp_ = &H70
Const Qq_ = &H71
Const Rr_ = &H72
Const Ss_ = &H73
Const Tt_ = &H74
Const Uu_ = &H75
Const Ue_ = &HF5
Const Vv_ = &H76
Const Ww_ = &H77
Const Xx_ = &H78
Const Yy_ = &H79
Const Zz_ = &H7A

Const Null_ = &H30
Const Eins_ = &H31
Const Zwei_ = &H32
Const Drei_ = &H33
Const Vier_ = &H34
Const Fuenf_ = &H35
Const Sechs_ = &H36
Const Sieben_ = &H37
Const Acht_ = &H38
Const Neun_ = &H39

Const Null = &H30
Const Leerz = &H20
Const Minus = &H2D
Const Gleich = &H3D
Const Punkt = &H2E
Const Hochz = &HDF
Const Doppelp = &H3A
Const Strich = &H2D
Const Ausr = &H21                                           'Ausrufungszeichen
Const Fragez = &H3F
Const Prozent = &H25
Const Schraegstrich = &H2F

Const Lcd_cursoroff = &B00001100                            'kein Cursor sichtbar
Const Lcd_cursoron = &B00001110                             'Unterstrich (nicht blinkend)
Const Lcd_cursorblock = &B00001101                          'großer Block, blinkend
Const Lcd_cursorline = &B00001110                           'Unterstrich (nicht blinkend)
Const Lcd_cursorblink = &B00001111                          'Unterstrich/Block, abwechselnd blinkend
Const Lcd_displayoff = &H08                                 'Display ausschalten
Const Lcd_displayon = &H0C                                  'Display einschalten
Const Lcd_cursorleft = &H10                                 'Cursor ein Zeichen nach links
Const Lcd_cursorright = &H14                                'Cursor ein Zeichen nach rechts
Const Lcd_displayleft = &H18                                'ges. Display ein Zeichen nach links
Const Lcd_displayright = &H1C                               'ges. Display ein Zeichen nach rechts

Const Lcd_gotoline1 = &H80                                  'Cursor in Zeile 1
Const Lcd_gotoline2 = &HC0                                  'Cursor in Zeile 2

Const Blank = &H20                                          'Zeichen ' '
Const Char_rufzeichen = &H21                                'Zeichen !
Const Char_anfzeichen = &H22                                'zeichen ""
Const Char_doppelkreuz = &H23                               'Zeichen #
Const Char_dollar = &H24                                    'Zeichen $
Const Char_prozent = &H25                                   'Zeichen %
Const Char_ampersand = &H26                                 'Zeichen &
Const Char_apostroph = &H27                                 'Zeichen '
Const Char_klammerauf = &H28                                'Zeichen (
Const Char_klammerzu = &H29                                 'Zeichen )
Const Char_stern = &H2A                                     'Zeichen *
Const Char_plus = &H2B                                      'Zeichen +
Const Char_komma = &H2C                                     'Zeichen ,
Const Char_minus = &H2D                                     'Zeichen -
Const Char_punkt = &H2E                                     'Zeichen .
Const Char_schraegstrich = &H2F                             'Zeichen /
Const Char_doppelpunkt = &H3A                               'Zeichen :
Const Char_eckklammauf = &H5B                               'Zeichen [
Const Char_eckklammzu = &H5D                                'Zeichen ]
Const Char_caret = &H5E                                     'Zeichen ^
Const Char_unterstrich = &H5F                               'Zeichen _
Const Char_geschwklammauf = &H7B                            'Zeichen {
Const Char_vertstrich = &H7C                                'Zeichen |
Const Char_geschwklammzu = &H7D                             'Zeichen }
Const Char_pfeilrechts = &H7E                               'Pfeil nach rechts
Const Char_pfeillinks = &H7F                                'Pfeil nach links
Const Char_spot = &HA5                                      'Zeichen ''
Const Char_horstrich = &HB0                                 'Zeichen '-'
Const Char_grad = &HDF                                      'Zeichen °
Const Char_mykro = &HE4                                     'Zeichen µ
Const Char_unendlich = &HF4                                 'Zeichen ý
Const Char_ohm = &HF5                                       'Zeichen Û
Const Char_block = &HFF                                     'Zeichen '¦'

' *** Initialisierungen ***
'$regfile = "m128def.dat"
$regfile = "m2561def.dat"                                   '***M256
$crystal = 4000000
$baud1 = 19200

'Porta = 0 'Reset all Relay
'Config Porta = Output
'Config Pinc.6 = Output
'Portc.6 = 1 : Waitms 20 : Portc.6 = 0                       'Übergabe an HC573

Config Pine.5 = Output                                      'LCD_LED
Porte.5 = 1 : Lcd_led = 10                                  'LCD Backlight on

Porte.2 = 0                                                 'High Current Puls Reset
Config Pine.2 = Output                                      'This must be allways like this!!!!
Porta.7 = 0
Config Pina.7 = Output                                      'This must be allways like this!!!!

Gosub Keyboard                                              'Tastatur abfragen
If Port11 = 1 Or Port3 = 1 Then Simu = 1                    'Abbruch-Taste "*" oder "#" gedrückt?

Gosub Lcd_init                                              'Initialisierungen

'Gosub Keyboard                                        'Tastatur abfragen
'If Port7 = 1 Then 'Keyb = 0 'Reset all flash!!
'Readeeprom temp_b1 , 771  'U Batt korr
'Readeeprom temp_b2 , 802  'Load 2
'Readeeprom temp_b3 , 803  'Load 1
'Readeeprom temp_b4 , 804  'I Solar
'
'Lcd_display_string = "Reset all!" :  GoSub Lcd_display
' Temp_b5 = 0
' For Pointer_eeprom = 1 To 1100 'Reset all!!
'   writeeeprom Temp_b5, Pointer_eeprom : Next
'writeeeprom temp_b1 , 771  'U Batt korr
'writeeeprom temp_b2 , 802  'Load 2
'writeeeprom temp_b3 , 803  'Load 1
'writeeeprom temp_b4 , 804  'I Solar
'End If

Portf = 0                                                   'ADC-Port
Config Adc = Single , Prescaler = Auto                      ', Reference = Avcc
Start Adc                                                   'ADC starten

'Configure for software SPI
Portb.4 = 1
Config Pinb.4 = Input                                       'Miso
Config Pinb.3 = Output                                      'MOSI
Config Pinb.6 = Output                                      'CLK
Config Ping.0 = Output                                      'CS
'                    MISO           MOSI             Cs             CLK
Config Spi = Soft , Din = Pinb.4 , Dout = Portb.3 , Ss = Portg.0 , Clock = Portb.6
Spiinit

'/////////////////////old COM-Settings/////////////////////////////////////////
'Config Com1 = Dummy , Synchrone = 0 , Parity = odd , Stopbits = 2 , Databits = 8 , Clockpol = 0
'$baud = 19200 : Open "com1:" For Binary As #2
'Config Serialin = Buffered , Size = 10
'Print #2 , "Test Com1"

'$baud1 = 19200 : Open "com2:" For Binary As #1
'Config Serialin1 = Buffered , Size = 80   '60
'Config Serialout1 = Buffered , Size = 80 '60
'Print #2 , "Test Com2"
'///////////////////////////////////////////////////////////////////////////////

'/////////////////////new COM-Settings/////////////////////////////////////////
$baud = 19200 : Open "com1:" For Binary As #1               'Communication
Config Serialin = Buffered , Size = 80                      '60
Config Serialout = Buffered , Size = 80                     '60

'Config Com2 = Dummy , Synchrone = 0 , Parity = Odd , Stopbits = 2 , Databits = 8 , Clockpol = 0       'ELV-Sensors
'$baud1 = 19200 : Open "com2:" For Binary As #2
'Config Serialin1 = Buffered , Size = 10
Config Com2 = Dummy , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
$baud1 = 19200 : Open "com2:" For Binary As #2              'Communication
Config Serialin1 = Buffered , Size = 50
Print #2 , "Com2"
'///////////////////////////////////////////////////////////////////////////////

'fast Counter
Portd.0 = 1 : Portd.1 = 1                                   'Pull-up aktivieren
Config Pind.0 = Input                                       'PD0 = Counter 1 schnell
Config Pind.1 = Input                                       'PD1 = Counter 2 schnell

Echo Off                                                    'no echo from seriell!

Print #1 , "AT^Srtc=0,4"                                    'Set the ringing tone off
Print #1 , "ate0"                                           'echo off
Waitms 50
Print #1 , "ate0"                                           'echo off

'Timer 0 RTC Clock
Config Timer0 = Timer , Prescale = 256                      '
On Ovf0 Tim0_isr                                            'Define the ISR handler
Enable Timer0

 'PWM-Timer,8 bit Timer 2
Portb.7 = 1                                                 'Pull-up aktivieren
'Tccr2 = &B01100101                                          'Config Timer2 = PWM , Prescale = 1024 , Compare Pwm = Clear Down
'TCCR1A = &B00001001 : TCCR1B = &B00000101           'M256
'Config Pinb.7 = Output

Readeeprom Month , 201
Readeeprom Day , 202
Readeeprom Hour , 203
Readeeprom Minute , 204

'Analog MUX = PB2, PD4, PD5
Config Pinb.2 = Output : Portb.2 = 0
Config Pind.4 = Output : Portd.4 = 0
Config Pind.5 = Output : Portd.5 = 0

'new Output:
Config Pinb.0 = Output                                      'NiCd
Config Pine.5 = Output
Config Pind.7 = Output
Config Pine.7 = Output
Config Pine.3 = Output
Config Pine.4 = Output                                      'read Sensor

'Timer 1 Ring-Detektor+DTMF
'Portd.6 = 1                                                 'Pull-up aktivieren

'Counter 16bit-Timer 3
Porte.6 = 1                                                 'Pull-up aktivieren
Config Pine.6 = Input
'Tccr3a = 0 : Tccr3b = 7 : Tccr3c = 0                        'Config Timer3 = Counter , Edge = Rising
Config Timer3 = Counter , Edge = Rising

Enable Interrupts

Print #1 , "ATS0=1"                                         'Modem auf antwort-Modus
Remote_key = Inkey(#1)
Remote_key_old = Remote_key

Readeeprom Temp , 280                                       'Language
Readeeprom Temp2 , 284                                      'Sensor Average Calculation
Readeeprom Temp_b1 , 221                                    'Pointer Data
Readeeprom Temp_b2 , 226                                    'Timer Load
If Temp > 10 Or Temp2 > 6 Or Temp_b1 > 100 Or Temp_b2 > 24 Then Gosub Standard_laden       'Prg neu geladen

Readeeprom Temp3 , 282                                      'Speicher Blei/Gel
If Temp3 <> 0 And Temp3 <> 1 Then Gosub Standard_laden

Gosub Load_from_flash

Gosub Read_analog_all_min                                   'Read analog Humidity

If Send_sms = 1 Then Gosub Delete_sms_memory

Readeeprom Value , 86                                       'Temp-Wert up
If Value > 450 Or Value < 0 Then
  Value = 0 : Writeeeprom Value , 86 : End If
Readeeprom Value , 88                                       'Temp-Wert down
If Value > 450 Or Value < 0 Then
  Value = 0 : Writeeeprom Value , 88 : End If

Readeeprom Temp_b1 , 41                                     'Autodetect Hour
Temp_b1 = 0 : If Temp_b1 <> 0 And Temp_b1 <> 1 Then Writeeeprom Temp_b1 , 41

Readeeprom Hour , 40 : If Hour > 24 Then Hour = 0

'Restore Min_Max_humidity
For Temp_b1 = 1 To Number_of_channel_modules                'Number_of_channel_modules
   Temp_b2 = Temp_b1 * 4 : Temp_b2 = Temp_b2 + 816
   Readeeprom Temp , Temp_b2 : Min_humidity(temp_b1) = Temp 'Min
   Incr Temp_b2 : Incr Temp_b2 : Readeeprom Temp , Temp_b2 : Max_humidity(temp_b1) = Temp       'max
Next

Blei_akku_old = Blei_akku

'If Data_direct_to_PC = 1 Then Gosub Print_header_data

Readeeprom Temp , 348                                       'SD_Card present
If Temp = 1 Then
 Sd_card_time_out = 1 : Minit : Sd_card_time_out = 0 : Sd_card_active = Temp : End If
No_sd_card:                                                 'after Time-Out
Temp = 0 : If Sd_card_time_out > 3 Then Writeeeprom Temp , 348       'no SD-Card present
Sd_card_time_out = 0


For Temp_b3 = 1 To 5
Time_load_shedding(temp_b3) = 1
Next

Batterie_n_leer_1 = 1
Batterie_n_leer_2 = 1
Batterie_n_leer_3 = 1
Batterie_n_leer_4 = 1
Batterie_n_leer_5 = 1
Fkt6 = 0

' *** Zyklisches Programm ***
Loop:
If Mobile_aktiv = 0 And Vb_process_display = 0 And Data_direct_to_pc = 0 Then
 If Time_slice_3b = 1 Then Gosub Channels
 Count_data_to_pc = 0 : Block_count_send = 0
 Stop Adc
 Idle
Else
 Gosub Data_to_pc
End If

Start Adc
Gosub Modem_call                                            'Data from seriell?
Gosub Daten_auslesen
Gosub Get_elv_sensor_data
Check_seriell_keyb = 1 : Gosub Keyboard : Check_seriell_keyb = 0
Gosub Counter_fast
If Time_slice_3b = 1 Then Gosub Channels
If Gosub_analog_extended = 1 Then Gosub Analog_extended
Gosub Sectic
Goto Loop

'Zeitscheibe Sekunde
Sectic:
If Second = Sec_alt Then Return
Sec_alt = Second
If Delay_on < 255 Then Incr Delay_on
Gosub Time_date
If Second = 58 Then Porte.4 = 1                             'activate Analog-Sensors:
If Second = 59 Then Gosub Time_min                          'Zeitscheibe Minute
Incr Count_data_to_pc

Gosub Eingaenge
Gosub Analog_werte                                          'Analog lesen
If Simu = 1 Then Gosub Read_analog_all_min
Gosub Program_switch
Gosub Simu_analog
Gosub Transfer_input_to_channels

Gosub Load_from_flash

Delay_next_key = 0
If Input_new_parameter < 255 Then Incr Input_new_parameter
If Delay_next_key_reset > 0 Then Decr Delay_next_key_reset
If Alarm_notification_break_time > 0 And Second = 10 Then Decr Alarm_notification_break_time
If Show_info_channel_type > 0 Then Decr Show_info_channel_type
If Do_not_accept_keyboard_by_serial > 0 Then Decr Do_not_accept_keyboard_by_serial

Temp_b1 = Second Mod 10
 '3 sec on/off
 Temp_b1 = Second Mod 3 : If Temp_b1 = 0 Then
 If Timer_2_sec = 0 Then Timer_2_sec = 1 Else Timer_2_sec = 0 : End If
Timer_1_sec = Second Mod 2

If Meldung_aktiv = 1 Then
 If Timer_1_sec = 0 Then Lcd_param = &B00001100 Else Lcd_param = &B00001000 : Gosub Lcd_writecmd : End If       'Display on/off

If Meldung_aktiv = 1 And Switch_off_alarm < 255 Then Incr Switch_off_alarm

If Delay_on = 20 Then                                       'Pre-Settings
 Readeeprom Temp , 260                                      'Einstellwerte U min min
 If Temp >= 100 And Temp < 200 And U_batt_smooth > 200 Then Gosub Standard_laden       'neue Werte laden wenn Spannung geändert
 If Temp >= 200 And U_batt_smooth < 200 Then Gosub Standard_laden       'neue Werte laden wenn Spannung geändert
End If

If Blei_akku_old <> Blei_akku Then
 Temp = Zylisches_laden_blei : If Blei_akku = 0 Then Temp = Zylisches_laden_gel : Gosub Correction_system_voltage : Writeeeprom Temp , 274 : End If

If Time_no_seriell_pc > 0 Then Decr Time_no_seriell_pc
If Time_no_seriell_pc = 5 Then Gosub Delete_sms_memory

If Fkt4 = 1 Then                                            'Telefonnummer-Eingabe
  If Meldung_aktiv = 0 And Mobile_aktiv = 1 Then Gosub Display_input : Return : End If       'Telefonnummer-Eingabe

If Programm_selector <> Programm_selector_old Then Prg_switch_remote = 0
Programm_selector_old = Programm_selector
If Prg_switch_remote > 0 Then Programm_selector = Prg_switch_remote - 1

Gosub Incoming_call

If Fkt9 = 1 Then Goto Hand_aktiv                            'Handebene ein oder Dateneingabe?
If Programm_selector > 0 Then                               'Off
Gosub Humidity_average
If Mobile_aktiv = 1 Or Vb_process_display = 1 Or Data_direct_to_pc = 1 Then Gosub Channels
Gosub Keyboard

Gosub Bewegungsmelder
'Gosub Auto_start_ldr
Gosub Learning_mode_start
Gosub Autodetect_time
'Gosub Sensor_monitoring
End If

'################## Solar charge-controller #########################
Readeeprom Temp , 320 : If Temp = 1 Then                    'Solar charge-controller active?
Gosub Battery_full                                          'Solar laden aus
Gosub Batterie_leer_1
Gosub Batterie_leer_2
Gosub Batterie_leer_3
Gosub Batterie_leer_4
Gosub Batterie_leer_5
Gosub Keyboard
'GoSub Dynamic_switch_off_voltage
'Gosub Setup_zero_value_solar
'Gosub Solarspg_kleiner_batterie
'Gosub Additional_device
Gosub High_currrent_pulses
Gosub Batt_pre_alarm
Gosub Alarm_batt_empty                                      'Vorwarnung Batt leer
Gosub Solar_stromwert
Gosub Correct_solar_curr
Gosub Last_stromwert
Gosub Ah_u_min_max
End If                                                      'Solar charge-controller active?

Hand_aktiv:

'################################ Display-Functions ###############################
If Meldung_aktiv = 0 And Mobile_aktiv = 1 Then
 If Fkt3 = 1 And Switch_input_block > 2 Then Gosub Display_fkt3
 If Fkt4 = 1 Then Gosub Display_input
 If Fkt6 = 1 Then Gosub Display_fkt6
End If
If Meldung_aktiv = 0 Then
 If Fkt1 = 1 Then Gosub Display_channel
 If Fkt2 = 1 Then Gosub Display_fkt2
 If Fkt3 = 1 Then Gosub Display_fkt3                        '???And Switch_input_block < 3
 If Fkt5 = 1 Then Gosub Display_fkt5                        'Spannnung
 If Fkt7 = 1 Then Gosub Display_fkt7                        'Time
 If Fkt8 = 1 Then Gosub Display_fkt8                        'Parameters
End If

If Meldung_aktiv = 1 Then                                   'short flashing
 Porte.5 = 1 : Waitms 20 : Porte.5 = 0 : End If

If Lcd_led > 0 Then
 Decr Lcd_led : Porte.5 = 1                                 'LCD_LED
Else
 Porte.5 = 0
End If

'################################## Output Transfer ########################
Gosub Reset_outputs
Gosub Output                                                'Ausgänge ansteuern
If Meldung_aktiv = 0 Then
 If Disp_fkt9 = 1 And Display_submenues = 0 Then Gosub Anzeige_handebene
 If Disp_fkt9 = 1 And Display_submenues = 1 Then Gosub Display_fkt9_2       'Anzeige Output 2
 If Disp_fkt9 = 1 And Display_submenues = 2 Then Gosub Display_fkt9a       'Analog 1
 If Disp_fkt9 = 1 And Display_submenues = 3 Then Gosub Display_fkt9a2       'Analog 2
 If Disp_fkt9 = 1 And Display_submenues = 4 Then Gosub Display_fkt9b       'Anzeige Eingänge
End If
Gosub Auto_no_flow
'Gosub Alarm_sensor
Gosub Daten_schreiben
If No_display_basic_menu = 0 Then Gosub Grundmenue : No_display_basic_menu = 0       'Anzeige Display Grundfunktionen
'Gosub Anrufen_alarm
Gosub Beep_ein
Gosub Collect_io_info
Return

'Zeitscheibe Minute
Time_min:
Incr Min_count                                              'freilaufender Minutenzähler bis 255
Freq3 = Timer3 : Sum_freq3 = Sum_freq3 + Timer3 : Timer3 = 0
Gosub Read_analog_all_min
'GoSub Alarm_batt_leer                                       'Alarmmeldung ist jetzt bei eingaenge hinten dran!
Gosub Receive_sms
Return

Humidity_average:
Temp = Analog_input_channel(1) + Analog_input_channel(2)
If Sensor_average = 2 Then Humidity_average = Temp / 2
Temp = Temp + Analog_input_channel(3)
If Sensor_average = 3 Then Humidity_average = Temp / 3
Temp = Temp + Analog_input_channel(4)
If Sensor_average = 4 Then Humidity_average = Temp / 4
Temp = Temp + Analog_input_channel(5)
If Sensor_average = 5 Then Humidity_average = Temp / 5
Temp = Temp + Analog_input_channel(6)
If Sensor_average = 6 Then Humidity_average = Temp / 6
Temp = Temp + Analog_input_channel(7)
If Sensor_average = 7 Then Humidity_average = Temp / 7
Return

Counter_fast:
'with fast counter
If Pind.0 = 0 And Counter_1_puls = 0 Then
 Incr Counter_1 : Counter_1_puls = 1 : End If
If Pind.0 = 1 Then Counter_1_puls = 0

If Pind.1 = 0 And Counter_2_puls = 0 Then
 Incr Counter_2 : Counter_2_puls = 1 : End If
If Pind.1 = 1 Then Counter_2_puls = 0
Return

Channels:
If Fkt8 = 1 And Data_pointer = 57 Then Return               'eingabe Simu
'###################### No irrigation, Do irrigation ########################################
Time_slice_3b = 0
No_irrigation = 0
Readeeprom Temp_b1 , 85                                     'Funktion Temp: no irrigate = 2
If Temp_b1 = 2 Then                                         'no Irrigation
 Readeeprom Temp , 88                                       'Temp min
    If Ext_temperature < Temp Then No_irrigation = 1
 Readeeprom Temp , 86                                       'Temp max
   If Ext_temperature > Temp And Temp <> 0 Then No_irrigation = 1
End If

Do_irrigation = 0
If Temp_b1 = 1 Then                                         'do Irrigation
  Readeeprom Temp , 88                                      'Temp min
  If Ext_temperature < Temp Then Do_irrigation = 1
 Readeeprom Temp , 86                                       'Temp max
  If Ext_temperature > Temp And Temp <> 0 Then Do_irrigation = 1
End If

If Do_irrigation = 1 And Flag_do_irrigation = 0 And Act_do_irrigation_time = 0 Then
   Readeeprom Temp , 334                                    '334 = 37 Max-Time for Anti-Frost-Irrigation
   Flag_do_irrigation = 1 : Act_do_irrigation_time = Temp
End If

If Act_do_irrigation_time > 0 And Second = 10 Then Decr Act_do_irrigation_time

If Hour = 1 And Minute = 1 And Second = 10 Then Flag_do_irrigation = 0       'Reset at midnight

'###################### Channels ########################################
For Channel_nr = 1 To Number_of_channel_modules
Ten_times_channel_nr = Channel_nr * 10
 Output(channel_nr) = 0 : Gosub Sub_channels

Temp4 = Ten_times_channel_nr + 496 : Readeeprom Temp_b2 , Temp4       'max-Time on
Gosub Auto_setpoint_humidity
Next

'######################### Min/Max Humdity save to Flash #############################
If Second <> 10 Or Minute <> 10 Or Hour <> 3 Then Return    'check every night 3 o'clock !

For Temp_b2 = 1 To Number_of_channel_modules
   Temp_b1 = Temp_b2 * 4 : Temp_b1 = Temp_b1 + 816
   Temp4 = Min_humidity(temp_b2) : Writeeeprom Temp4 , Temp_b1       'Min
   Incr Temp_b1 : Incr Temp_b1 : Temp4 = Max_humidity(temp_b2) : Writeeeprom Temp4 , Temp_b1       'max
Next
Return

'########################### Main-Prog. Channels #####################################
Sub_channels:
'off?
Temp4 = Ten_times_channel_nr + 499 : Readeeprom Temp_b1 , Temp4 :
If Temp_b1 = 0 Or Delay_on < 10 Then                        'off-Switch
   Alarm_auto_no_flow(channel_nr) = 0 : Alarm_max_time_pump(channel_nr) = 0 : Delay_check_actual(channel_nr) = 0 : Max_time_pump(channel_nr) = 0 : Su_time(channel_nr) = 0 : Pulse_time(channel_nr) = 0 : Analog_delay_on(channel_nr) = 0 : Analog_delay_off(channel_nr) = 0 : Return : End If

If Alarm_auto_no_flow(channel_nr) = 1 Or Alarm_max_time_pump(channel_nr) = 1 Then Return

'####################### Antifrost_irrigation; do Irrigate if Temp < Min ##################
If Second = 55 And Minute = 55 And Hour = 23 Then Pulse_antifrost(channel_nr) = 0       'Reset once a day
Channel_typ = Channel_type(channel_nr)                      'Typ.

Channel_typ_alarm = 0
Interlock(channel_nr) = 0
Channel_typ_interlock = 0
Output_as_pulse = 0
If Channel_typ > 9 And Channel_typ < 20 Then
  Channel_typ = Channel_typ - 10 : Channel_typ_alarm = 1 : End If
If Channel_typ > 19 And Channel_typ < 30 Then
  Channel_typ = Channel_typ - 20 : Channel_typ_interlock = 1 : End If
If Channel_typ > 29 And Channel_typ < 40 Then               'output as Pulse
  Channel_typ = Channel_typ - 30 : Output_as_pulse = 1 : End If
Channel_typ_load_shedding = 0
If Channel_typ > 39 And Channel_typ < 50 Then               'load shedding
  Channel_typ = Channel_typ - 40 : Channel_typ_load_shedding = 1 : End If

Temp4 = Ten_times_channel_nr + 898 : Readeeprom More_then , Temp4       '0 = actual < SP
Temp_b5 = 1 : If More_then <> 0 And More_then <> 1 Then Writeeeprom Temp_b5 , Temp4       'initialisieren

If Channel_typ = 0 Then                                     'Typ 0 = Irrigate
Readeeprom Temp_b1 , 85                                     '85: Funktion Temp do irrigate
If Temp_b1 = 1 Then                                         'do Irrigate if Temp < Min
    If Pulse_antifrost(channel_nr) = 0 Then
      Readeeprom Temp , 88                                  'Temp min
      If Ext_temperature < Temp Then
      Temp4 = Ten_times_channel_nr + 893 : Readeeprom Temp_b1 , Temp4 : Su_time(channel_nr) = Temp_b1 : Pulse_antifrost(channel_nr) = 1 : Return : End If
  End If
End If
End If

'get Humidity
Humid_input = Analog_input_channel(channel_nr)              'actual
If Sensor_average > 1 Then Humid_input = Humidity_average   'Mittelwert oder 4x feuchte?
Temp4 = Ten_times_channel_nr + 895 : Readeeprom Setpoint , Temp4       'Setpoint Humidity from EEprom
'#################### Setpoint from Analog in ############################
Temp4 = Ten_times_channel_nr + 492 : Readeeprom Channel_input_2 , Temp4
If Channel_input_2 > 50 And Channel_input_2 < 99 Then
  Temp_b1 = Channel_input_2 : Gosub Map_analog : Setpoint = Value : End If       'Map analog Input to Setpoint
'########################################################################
'check analog-Value

Keyb = Second Mod 3                                         'all 3 second as delay
If Keyb = 0 Then
Temp4 = Ten_times_channel_nr + 898 : Readeeprom Temp_b1 , Temp4       '< or >?
Incr Temp4 : Readeeprom Temp , Temp4                        'Hysteresis
Temp_b3 = Channel_typ                                       'Temp4 = Ten_times_channel_nr + 493 : Readeeprom Temp_b3 , Temp4       'Type

'############# > ##################################
 If Temp_b1 = 0 Then                                        'Act < SP ; Heating!
  Temp3 = Setpoint + Temp                                   'Correction Hysteresis
  If Humid_input < Setpoint Then Activated_by_sensor(channel_nr) = 1       'Actual < Set
   If Channel_input_2 = 0 Or Temp_b3 <> 2 Then              'not if Level-Function!
 If Humid_input >= Temp3 Or Humid_input = 0 Or Setpoint = 0 Then Activated_by_sensor(channel_nr) = 0 : End If       'Device on if Act < Set (Heating)or no Sensor connected or Setpoint = 0
Else                                                        'Act > SP ; Cooling!
'############# < ##################################
  Temp3 = Setpoint - Temp                                   'Correction Hysteresis
  If Humid_input > Setpoint Then Activated_by_sensor(channel_nr) = 1       '
'  If Humid_input < Setpoint Then Print #1, "Active >"
  If Channel_input_2 = 0 Or Temp_b3 <> 2 Then               'temp_b3 = Type not if Level-Function!
  If Humid_input <= Temp3 Or Humid_input = 0 Or Setpoint = 0 Then Activated_by_sensor(channel_nr) = 0 : End If       'Device on if Act > Set (Cooling) or no Sensor connected or Setpoint = 0
End If

End If                                                      'keyb = 0
 'if Setpoint = 0
If Setpoint = 0 And Channel_input_2 = 0 Then Activated_by_sensor(channel_nr) = 1

'check Input 2
Temp4 = Ten_times_channel_nr + 500 : Readeeprom Temp_b1 , Temp4       'Input =1 or =0?
'on
If Setpoint = 0 And Channel_input_2 > 0 Then                'no Setpoint but Sensor 2 defined
 If Analog_input_2_channel(channel_nr) = 1 And Temp_b1 = 1 Then Activated_by_sensor(channel_nr) = 1
 If Analog_input_2_channel(channel_nr) = 0 And Temp_b1 = 0 Then Activated_by_sensor(channel_nr) = 1
End If
'off
If Activated_by_sensor(channel_nr) = 1 And Channel_input_2 > 0 Then       'Sensor defined
 If Analog_input_2_channel(channel_nr) = 1 And Temp_b1 = 0 Then Activated_by_sensor(channel_nr) = 0
 If Analog_input_2_channel(channel_nr) = 0 And Temp_b1 = 1 Then Activated_by_sensor(channel_nr) = 0
End If

'Learning Mode
If Learning_mode(channel_nr) = 1 Then Activated_by_sensor(channel_nr) = 1

'############################################# Pasteur #######################################
Temp4 = Ten_times_channel_nr + 496 : Readeeprom Temp3 , Temp4       'max_Time_on in Seconds for Pasteurisation-Process
Temp4 = Ten_times_channel_nr + 899 : Readeeprom Temp2 , Temp4       'Hysteresis  '1 Degree less: Delta_t_past_off

If Channel_typ = 4 Then                                     'Typ Pasteuer
Activated_by_sensor(channel_nr) = 0
If Time_pa(channel_nr) >= Setpoint Then Activated_by_sensor(channel_nr) = 1       'Setpoint = Pastvalue

If Activated_by_sensor(channel_nr) = 1 And Time_activated_by_sensor_on_max(channel_nr) >= Temp3 Then Time_pa(channel_nr) = 0       'Sp_time_Activated_by_sensor_on_max_past End with max-Time

Temp = Temp_old_past(channel_nr) - Temp2                    'Delta_t_past_off
If Activated_by_sensor(channel_nr) = 1 And Humid_input <= Temp Then Time_pa(channel_nr) = 0       'Delta T less than Setpoint
'If Beep_when_past_ok = 1 And Activated_by_sensor(channel_nr) = 1 Then Beep_ein = 10
If Activated_by_sensor(channel_nr) = 0 Then
   Time_activated_by_sensor_on_max(channel_nr) = 0 : Temp_old_past(channel_nr) = Humid_input : End If
If Activated_by_sensor(channel_nr) = 1 Then
  Incr Time_activated_by_sensor_on_max(channel_nr) : Goto End_past : End If
If Humid_input < Grad_62 Then
   Time_pa(channel_nr) = 0 : Goto End_past : End If
If Humid_input < Grad_65 Then
   Temp = Second Mod 9 : Goto Temp_past : End If            '200 PE in 30 min Inkre alle 10 sec (17) 7 * 30 = 180
If Humid_input < Grad_67 Then
   Temp = Second Mod 8 : Goto Temp_past : End If            '200 PE in 30 min Inkre alle 10 sec (17) 7 * 30 = 180
If Humid_input < Grad_69 Then
   Temp = Second Mod 7 : Goto Temp_past : End If            '200 PE in 30 min Inkre alle 10 sec (17) 7 * 30 = 180
If Humid_input < Grad_71 Then
   Temp = Second Mod 6 : Goto Temp_past : End If            '200 PE in 30 min Inkre alle 10 sec (17) 7 * 30 = 180
If Humid_input < Grad_73 Then
   Temp = Second Mod 5 : Goto Temp_past : End If            '200 PE in 30 min Inkre alle 10 sec (17) 7 * 30 = 180
If Humid_input < Grad_75 Then
   Temp = Second Mod 4 : Goto Temp_past : End If            '200 PE in 30 min Inkre alle 10 sec (17) 7 * 30 = 180
If Humid_input < Grad_77 Then
   Temp = Second Mod 3 : Goto Temp_past : End If            '200 PE in 30 min Inkre alle 10 sec (17) 7 * 30 = 180
If Humid_input < Grad_79 Then
   Temp = Second Mod 2 : Goto Temp_past : End If            '200 PE in 30 min Inkre alle 10 sec (17) 7 * 30 = 180
Temp = 0                                                    'more than 79° all second incr

Temp_past:
If Temp = 0 Then Incr Time_pa(channel_nr)
End_past:
End If                                                      'Pasteuer Channel_typ = 4 Then

'#############################################################################################################################

'If Activated_by_sensor(channel_nr) = 0 Then Pulse_start_by_sensor(channel_nr) = 0

'Delay on/off
Temp4 = Ten_times_channel_nr + 498 : Readeeprom Temp_b1 , Temp4       'Setpoint Delay off in sec
Temp4 = Ten_times_channel_nr + 497 : Readeeprom Temp_b2 , Temp4       'Setpoint Delay on

Dim Correct_time_delay_off As Byte
Dim Correct_time_delay_on As Byte

Time_value_corrected = Temp_b1 : Gosub Value_range : Correct_time_delay_off = Time_value_corrected       'Delay on
Time_value_corrected = Temp_b2 : Gosub Value_range : Correct_time_delay_on = Time_value_corrected       'Delay on

'Delay_on
 If Channel_typ_alarm = 1 And Analog_delay_on(channel_nr) > 0 Or Activated_by_sensor(channel_nr) = 1 Or Pulse_input_was_active(channel_nr) = 1 Then
    Temp_b5 = Analog_delay_on(channel_nr) : Gosub Timer_count_up : Analog_delay_on(channel_nr) = Temp_b5
    If Analog_delay_on(channel_nr) >= Correct_time_delay_on And Pulse(channel_nr) = 0 Then
         Analog_delay_off(channel_nr) = Temp_b1 : Pulse(channel_nr) = 1 : End If       'changed 26.8.08
      If Channel_typ_alarm = 1 Then
        Temp4 = Channel_nr + 759 : Readeeprom Temp_b3 , Temp4       'No_Alarm_Time
          If Value = 1 Then Alarm_notification_break_time = Temp_b3       'Minutes for to turn off 31.10.08
          If Alarm_notification_break_time > 0 Then Analog_delay_on(channel_nr) = 0 : End If
End If

Time_value_corrected = Analog_delay_off(channel_nr) : Gosub Value_range
If Analog_delay_on(channel_nr) = 0 And Time_value_corrected = 0 Then Pulse(channel_nr) = 0

If Activated_by_sensor(channel_nr) = 0 Then Analog_delay_on(channel_nr) = 0

'Delay_off
Temp_b5 = Analog_delay_off(channel_nr)
If Activated_by_sensor(channel_nr) = 0 Then Gosub Timer_count
Analog_delay_off(channel_nr) = Temp_b5

'################### Output #################################
'Switch on Output Load Shedding
If Channel_typ_load_shedding = 1 And Timer_active(channel_nr) = 1 Then       'Time > 0
 If Delay_on < 30 Or Analog_delay_on(channel_nr) < Temp_b2 Then Output(channel_nr) = 1
End If

'Emergency Load_shedding_off
'If Channel_typ_load_shedding = 1 And Time_load_shedding_off > 0 Then Output(channel_nr) = 1       'Type 0 = Load shedding

If Timer_active(channel_nr) = 1 And Output_as_pulse = 0 And Channel_typ_load_shedding = 0 Then
'  If Analog_delay_on(channel_nr) > Temp_b2 And Channel_typ_Alarm = 0 Then Output(channel_nr) = 1       ' Start only by Setpoint;
  If Correct_time_delay_off > 0 And Analog_delay_on(channel_nr) >= Correct_time_delay_on Then Output(channel_nr) = 1
  If Temp_b1 = 0 And Analog_delay_on(channel_nr) > Temp_b2 Then Output(channel_nr) = 1       'Temp_b1 = Setpoint Delay off
  If Setpoint = 0 And Channel_input_2 = 0 Then Output(channel_nr) = 1       'only with Timer
  If Temp_b1 = 0 And Temp_b2 = 0 And Activated_by_sensor(channel_nr) = 1 Then Output(channel_nr) = 1       'no delay on/off
End If

'output only Pulse (Delay-on time); on only when Condition ok
If Output_as_pulse = 1 Then                                 'just for Delay on-Time
 If Activated_by_sensor(channel_nr) = 1 Then
  Pulse_input_was_active(channel_nr) = 1
  Else
  If Analog_delay_on(channel_nr) > Correct_time_delay_on Then Pulse_input_was_active(channel_nr) = 0
 End If
  Output(channel_nr) = 0
 If Analog_delay_on(channel_nr) < Correct_time_delay_on Then Output(channel_nr) = 1
End If

'output only Pulse (Delay-off time) off delayed
'If Output_as_Pulse = 1 and Analog_delay_off(channel_nr) > 0 Then Output(channel_nr) = 1

'Reset delay on
Time_value_corrected = Analog_delay_off(channel_nr) : Gosub Value_range
If Analog_delay_off(channel_nr) < 100 Or Second = 58 Then
 If Time_value_corrected = 1 Then Analog_delay_on(channel_nr) = 0 : End If

If Channel_typ_interlock = 1 And Output(channel_nr) = 1 Then Interlock(channel_nr) = 1

'########################## Timer #############################
Temp4 = Ten_times_channel_nr + 891 : Readeeprom Sp_hour_timer , Temp4       'hour aus EEprom
Incr Temp4 : Readeeprom Sp_min_timer , Temp4                'minute aus EEprom
Incr Temp4 : Readeeprom Sp_run_time_timer , Temp4           'on_time aus EEprom
Incr Temp4 : Readeeprom Sp_on_all_timer , Temp4             'all_x_min aus EEprom
Temp4 = Channel_nr + 440 : Readeeprom Sp_on_time_puls , Temp4       'on_time Pulse

'count down timer
Temp_b5 = Su_time(channel_nr) : Gosub Timer_count : Su_time(channel_nr) = Temp_b5

'Pulse-timer
Temp_b5 = Pulse_time(channel_nr) : Gosub Timer_count : Pulse_time(channel_nr) = Temp_b5

'########################## just once for x min End ########################
Time_value_corrected = Su_time(channel_nr) : Gosub Value_range
If Sp_hour_timer = 0 And Sp_min_timer = 0 And Sp_run_time_timer > 0 And Time_value_corrected = 1 Then       'End Manual Start by Pulse, no hr, minute
If Su_time(channel_nr) > 200 And Minute <> 59 And Second <> 10 Then Return
If Su_time(channel_nr) > 100 And Second <> 10 Then Return
   Temp4 = Ten_times_channel_nr + 293 : Readeeprom Temp_b5 , Temp4 : Keyb = 0 : If Temp_b5 <> 0 Then Writeeeprom Keyb , Temp4 : Return : End If

'########################## check Timer #############################
Gosub Check_timer
'########################## check on all #############################
Gosub Check_on_all_times                                    'Abfrage Zeit
'####################### Output Timer #################################
Temp_b1 = 0 : If Time_value_corrected > 0 Or Sp_run_time_timer = 0 Then Temp_b1 = 1       'Timer active

Time_value_corrected = Pulse_time(channel_nr) : Gosub Value_range
Temp_b2 = 0 : If Time_value_corrected > 0 Or Sp_on_all_timer = 0 Then Temp_b2 = 1       'Pulses active?

Timer_active(channel_nr) = 0 : If Temp_b1 = 1 And Temp_b2 = 1 Then Timer_active(channel_nr) = 1
Return

'###################### Timer ##########################
Check_timer:
If Sp_run_time_timer = 0 Then Return                        'no Timer-Function

If Sp_hour_timer = 0 And Sp_min_timer = 0 Then Goto Start_by_timer       'hr+Min then just once
If Hour <> Sp_hour_timer Or Minute <> Sp_min_timer Or Second <> 2 Then Return

Start_by_timer:
Time_value_corrected = Su_time(channel_nr) : Gosub Value_range
If Time_value_corrected = 0 Then Su_time(channel_nr) = Sp_run_time_timer
Return

'###################### on all... ##########################
Check_on_all_times:
If Sp_on_all_timer = 0 Or Second <> 2 Then Return           'deactivate function

If Sp_on_time_puls > 200 Then Goto All_x_days
If Sp_on_time_puls > 100 Then Goto All_x_hrs

'all x min
Temp_b5 = Min_count Mod Sp_on_all_timer
If Temp_b5 = 0 Then Goto Active_by_puls
Return

All_x_hrs:
Time_value_corrected = Sp_on_all_timer
Gosub Value_range                                           'Wert korrigieren wenn >100
Temp_b5 = Hour Mod Time_value_corrected
If Temp_b5 = 0 And Minute = 1 Then Goto Active_by_puls
Return

All_x_days:
Time_value_corrected = Sp_on_all_timer
Gosub Value_range                                           'Wert korrigieren wenn >100
Temp_b5 = Day Mod Time_value_corrected
If Temp_b5 <> 0 Or Hour <> Sp_hour_timer Or Minute <> 1 Then Return

Active_by_puls:
Time_value_corrected = Pulse_time(channel_nr) : Gosub Value_range
If Time_value_corrected = 0 Then Pulse_time(channel_nr) = Sp_on_time_puls
Return
'#######################################

Value_range:
If Time_value_corrected > 199 Then Time_value_corrected = Time_value_corrected - 200
If Time_value_corrected > 99 Then Time_value_corrected = Time_value_corrected - 100
Return

Timer_count:
If Temp_b5 > 0 And Temp_b5 < 100 Then Decr Temp_b5          'Delay off in sec
If Temp_b5 > 100 And Temp_b5 < 200 And Second = 10 Then Decr Temp_b5       'Delay off in min
If Temp_b5 > 200 And Second = 10 And Minute = 1 Then Decr Temp_b5       'Delay off in hr
Return

Timer_count_up:
'If Temp_b5 = 255 then return
If Temp_b2 > 0 And Temp_b2 < 100 Then Goto End_timer_count_up       'sec count
If Temp_b2 > 100 And Temp_b2 < 200 And Second = 1 Then Goto End_timer_count_up
If Temp_b2 > 200 And Second = 1 And Minute = 1 Then Goto End_timer_count_up
Return
End_timer_count_up:
If Temp_b5 < Temp_b2 Then Incr Temp_b5
Return

'Niveau -steuerung
'Level_control:
'Readeeprom Temp_b1 , 81             'Pump-Time
'If Temp_b1 <= 100 And Time_level_pump_on > 0 Then Decr Time_level_pump_on
'If Temp_b1 > 100 And Temp_b1 <= 200 And Second = 1 And Time_level_pump_on > 0 Then Decr Time_level_pump_on
'If Temp_b1 > 200 And Second = 1 And Minute = 1 And Time_level_pump_on > 0 Then Decr Time_level_pump_on
'
'Level_pump = 0
'If Time_level_pump_on > 0 Then Level_pump = 1               'nur wenn keine Pumpe Alarm
'
'If Input_2 <> Input_2_old And Level_pump = 0 Then Time_level_pump_on = Temp_b1       'Wert für Zeit Behälter füllen
'If Input_3 <> Input_3_old Then Time_level_pump_on = 0       'Behälter ist voll
'Return

Auto_setpoint_humidity:
If Second <> 10 Or Minute <> 10 Or Hour <> 3 Then Return    'check every night 3 o'clock !

If Max_humidity(channel_nr) < 50 Or Max_humidity(channel_nr) > 950 Then Max_humidity(channel_nr) = Analog_input_channel(channel_nr)       'first time
If Min_humidity(channel_nr) < 50 Or Min_humidity(channel_nr) > 950 Then Min_humidity(channel_nr) = Analog_input_channel(channel_nr)       'first time

Temp = Analog_input_channel(channel_nr) - Humidity_yesterday(channel_nr) : Temp = Abs(temp)
If Temp < 150 Then                                          'not too big changes in Humidity
      If Analog_input_channel(channel_nr) < 950 And Analog_input_channel(channel_nr) > Max_humidity(channel_nr) Then Max_humidity(channel_nr) = Analog_input_channel(channel_nr)
      If Analog_input_channel(channel_nr) > 50 And Analog_input_channel(channel_nr) < Min_humidity(channel_nr) Then Min_humidity(channel_nr) = Analog_input_channel(channel_nr) : End If
Humidity_yesterday(channel_nr) = Analog_input_channel(channel_nr)

'Sollw: wie weit bin ich von Min entfernt? D=Max-Min; max-actual in %; % of Max-Time
'Humid Max-Min = Delta; Max - Actual    in % (max-Act)/Delta SP = max-Time Irrigate * %
'      800-600 = 200;   800 - 700 = 100   100 / 200 = 0,5     100 * 0,5 = 50
'      800-600 = 200;   800 - 600 = 200   200 / 200 = 1,0     100 * 1,0 = 100
'      800-600 = 200;   800 - 800 = 0     0 / 200 = 0       100 * 0 = 0

'100 / Delta; %=(aktuell - Min-Humid)*pro Digit; % * Max-Dauer = Bew-Dauer
'100 / 50 = 2;        625-600=25; 25*2=50%; 0,5 * 60 min = 30 min

'on-time (Max-Value)
Temp4 = Ten_times_channel_nr + 893 : Readeeprom Temp_b3 , Temp4       'Max-Time Pump on
Temp_b2 = Temp_b3
If Temp_b2 > 200 Then Temp_b2 = Temp_b2 - 100
If Temp_b2 > 100 Then Temp_b2 = Temp_b2 - 100

'Max-Min = Delta
Temp = Max_humidity(channel_nr) - Min_humidity(channel_nr) : Temp_s1 = Temp
If Temp < 10 Then                                           'too small difference Min/Max
 Temp = Temp_b2 / 2                                         'Max-Time Pump on / 2
Else
'Max - Actual
Temp3 = Max_humidity(channel_nr) - Analog_input_channel(channel_nr) : Temp_s2 = Temp3       '100
'in % (max - Actual)/Delta
Temp_s1 = Temp_s2 / Temp_s1                                 '100 / 200 = 0,5
'SP = max-Time Irrigate * %
Temp_s2 = Temp_b2                                           'Max-Time on-time Pump to Real
Temp_s2 = Temp_s2 * Temp_s1 : Temp = Temp_s2                '30 * 0,5

If Temp > 0 And Temp <= Temp_b2 Then
  If Temp_b3 > 200 Then Temp_b2 = 200 + Temp
  If Temp_b3 > 100 And Temp_b3 < 200 Then Temp_b2 = 100 + Temp
  Auto_sp_irrigation_time(channel_nr) = Temp_b2
 Else
  Temp = Temp_b2 / 2                                        'max-Time / 2
  If Temp_b3 > 200 Then Temp_b2 = 200 + Temp                'Setpoint > 200
  If Temp_b3 > 100 And Temp_b3 < 200 Then Temp_b2 = 100 + Temp
  Auto_sp_irrigation_time(channel_nr) = Temp_b2
End If
End If
Return

Learning_mode_start:
Readeeprom Temp , 312                                       '312 = 26 Learning mode
'Start
If Learning_mode_old = 0 And Temp = 1 Then
 For Channel_nr = 1 To Number_of_channel_modules
  Channel_typ = Channel_type(channel_nr)
   If Channel_typ = 0 Then Learning_mode(channel_nr) = 1
 Next
 Day_learning_mode = 0                                      'count days without watering
End If

'Stop
If Learning_mode_old = 1 And Temp = 0 Then
 For Channel_nr = 1 To Number_of_channel_modules
    Channel_typ = Channel_type(channel_nr)
   If Channel_typ = 0 Then Learning_mode(channel_nr) = 0
 Next
End If

Learning_mode_old = Temp
Return

Autodetect_time:
If Second = 10 And Minute = 1 Then                          'all hour
   If Ldr_sensor <= Sp_light Then Incr Hours_night
   If Ldr_sensor > Sp_light Then Incr Hours_day

   If Hours_day >= 5 Then Hours_night = 0                   'Reset Dark counter when light again
   If Hours_night >= 5 Then Hours_day = 0
   Readeeprom Temp_b1 , 41
   If Temp_b1 = 1 Then                                      'Auto-Detect Time active?
   If Ldr_sensor <= Sp_light Then Hour = Hours_night + Time_sun_set Else Hour = Hours_day + Time_sun_raise
   If Hour >= 24 Then Hour = Hour - 24 : End If
   Readeeprom Temp_b2 , 40 : If Temp_b2 <> Hour Then Writeeeprom Hour , 40
End If
Return

'Auto_start_ldr:
'If Auto_start_ldr <> 1 Then Return
'Irrigate_ldr = 0
'If Ldr <= Sp_dark Then Incr Delay_dark                      '***T and second = 10 And minute = 10
'If Ldr > Sp_light Then Incr Delay_light                     '***T and second = 10 And minute = 10
'If Delay_dark = 20 Then Delay_light = 0                     '***T Reset Light counter when darkness
'If Delay_light = 20 Then Delay_dark = 0                     '***T Reset Dark counter when light again
'LDR defekt oder ohne?
'If Delay_dark = 19 And Delay_light = 0 Then Ldr_sensor_defekt = 1       '***T 19?
'If Delay_light = 5 Then Ldr_sensor_defekt = 0
'If Ldr_sensor_defekt = 1 And Delay_dark >= 24 Then Irrigate_ldr = 1
'Temp = Min_time_darkness
'If Delay_dark >= Temp And Delay_light < 3 Then Irrigate_ldr = 1
'Return

Auto_no_flow:
'################# Auto_no_flow Channel 1 #########################
For Channel_nr = 1 To Number_of_channel_modules
Ten_times_channel_nr = Channel_nr * 10

'no_change_analog
Temp4 = Ten_times_channel_nr + 495 : Readeeprom Temp_b1 , Temp4       '505 Auto no flow in min
Gosub No_change_analog

 'max-time
Temp4 = Ten_times_channel_nr + 496 : Readeeprom Temp_b2 , Temp4       'max-time in min
Gosub Max_time_pump
Next

'Msg_auto_no_flow:
If Channel_alarm_auto_no_flow > 0 And Meldung_aktiv = 0 Then
 Lcd_param = &B00000001 : Gosub Lcd_writecmd
 Lcd_param = 1 : Gosub Lcd_gotoline
 Value = Channel_alarm_auto_no_flow : Gosub Write_alarm_channel
 Lcd_param = 2 : Gosub Lcd_gotoline
 If English = 0 Then Lcd_display_string = "keine Istw.ändg!" Else Lcd_display_string = "no change Actual" : Gosub Lcd_display : Gosub Line_feed : Meldung_aktiv = 1 : Beep_ein = 3 : Wait 2
End If

'Msg_max-Time Pump on
If Channel_alarm_max_time_pump > 0 And Meldung_aktiv = 0 Then
 Lcd_param = &B00000001 : Gosub Lcd_writecmd
 Lcd_param = 1 : Gosub Lcd_gotoline
 Value = Channel_alarm_max_time_pump : Gosub Write_alarm_channel
 Lcd_param = 2 : Gosub Lcd_gotoline                         '1234567890123456
 If English = 0 Then Lcd_display_string = "Max-Zeit Pumpe!" Else Lcd_display_string = "Max-Time Pump on" : Gosub Lcd_display : Gosub Line_feed : Meldung_aktiv = 1 : Beep_ein = 3 : Wait 2
End If

Return

No_change_analog:
If Output(channel_nr) = 0 Or Temp_b1 = 0 Then               '505 Auto no flow in min
  Saved_actual(channel_nr) = Analog_input_channel(channel_nr) : Delay_check_actual(channel_nr) = 0 : End If       'get the actual-value

If Output(channel_nr) = 1 And Delay_check_actual(channel_nr) < 255 And Second = 10 Then Incr Delay_check_actual(channel_nr)
If Delay_check_actual(channel_nr) = Temp_b1 And Temp_b1 > 0 Then       'now check for change in Actual Value after 10 minutes
  Temp = Saved_actual(channel_nr) - Analog_input_channel(channel_nr) : Temp2 = Abs(temp)
  If Temp2 < 2 Then
      Channel_alarm_auto_no_flow = Channel_nr : Alarm_auto_no_flow(channel_nr) = 1 : End If
End If
Return

Max_time_pump:
If Output(channel_nr) = 0 Or Temp_b2 = 0 Then Max_time_pump(channel_nr) = 0       'temp_b2 = Max_time_pump

If Output(channel_nr) = 1 And Temp_b2 > 0 And Max_time_pump(channel_nr) < 100 Then       'count max 100!
   If Temp_b2 <= 100 Then Incr Max_time_pump(channel_nr)
   If Temp_b2 > 100 And Temp_b2 < 200 And Second = 10 Then Incr Max_time_pump(channel_nr)
   If Temp_b2 > 200 And Second = 10 And Minute = 10 Then Incr Max_time_pump(channel_nr) : End If

If Temp_b2 > 200 Then Temp_b2 = Temp_b2 - 100               'Setpoint
If Temp_b2 > 100 Then Temp_b2 = Temp_b2 - 100
If Max_time_pump(channel_nr) = Temp_b2 And Temp_b2 > 0 Then
   Channel_alarm_max_time_pump = Channel_nr : Alarm_max_time_pump(channel_nr) = 1 : End If       'now check for change in Actual Value
Return

Antiblocking:
Dim Output_was_active(5) As Byte
For Channel_nr = 1 To 5
 Pointer_eeprom = Channel_nr * 2 : Pointer_eeprom = Pointer_eeprom + 392       '1 Channel
 Readeeprom Temp , Pointer_eeprom : Temp_b2 = Temp          '394 = 67 Anti-Blocking-System Output 1
  Gosub Sub_antiblocking
Next
Return

Sub_antiblocking:
If Temp_b2 = 0 Then Return
Gosub Check_status_output                                   'was on?
If Temp_bit1 = 1 Then Output_was_active(channel_nr) = 1

If Hour = 0 And Minute = 1 Then                             'at midnight
If Second = 10 Or Second = 11 Then                          '2 second on
 Temp_bit3 = 1                                              'switch on
 If Output_was_active(channel_nr) = 0 Then Gosub Switch_on_output
End If

If Second = 15 Then Output_was_active(channel_nr) = 0
End If                                                      'hour = 0 and minute = 1
Return

Bewegungsmelder:
For Channel_nr = 1 To 5
Pointer_eeprom = Channel_nr * 10 : Pointer_eeprom = Pointer_eeprom + 691       '1 Channel
Readeeprom Alarm_on_off , Pointer_eeprom                    '701 =Ein/Aus; temp_b1

'active?
If Alarm_on_off = 0 Then
  Alarm_active_delay_on(channel_nr) = 0 : Alarm_active(channel_nr) = 0 : Goto End_loop_alarm : End If

Incr Pointer_eeprom : Readeeprom Sp_alarm_delay_on , Pointer_eeprom       '702 =Delay on temp_b2
Incr Pointer_eeprom : Readeeprom Sp_alarm_delay_off , Pointer_eeprom       '703 =Delay off; temp_b3
'Incr pointer_eeprom ': Readeeprom SP_Alarm_Input , pointer_eeprom    '704 =Input temp_b4
'Incr pointer_eeprom ': Readeeprom SP_Alarm_Output , pointer_eeprom    '705 =Output temp_b5
'Incr pointer_eeprom : Readeeprom temp_b2 , pointer_eeprom    '706 =1=active?

'Alarm Input
Temp = Alarm_input_old(channel_nr) - Alarm_input(channel_nr)       'change in Sensor?
Alarm_input_old(channel_nr) = Alarm_input(channel_nr)
Temp = Abs(temp)

'Start Delay on
If Temp > 15 And Alarm_active_delay_on(channel_nr) = 0 And Alarm_active(channel_nr) = 0 Then       'Alarm!
 Temp_b1 = Sp_alarm_delay_on
 If Sp_alarm_delay_on > 100 Then Temp_b1 = Temp_b1 - 100    'Wenn Eingabe Schaltdauer Bewegungsmelder in minuten
 If Sp_alarm_delay_on > 200 Then Temp_b1 = Temp_b1 - 100    'Wenn Eingabe Schaltdauer Bewegungsmelder in Std
 Alarm_active_delay_on(channel_nr) = Temp_b1 : End If       'Neuen Wert laden

'Count Delay on
If Alarm_active_delay_on(channel_nr) > 0 Then
 If Sp_alarm_delay_on <= 100 Then Decr Alarm_active_delay_on(channel_nr)
 If Sp_alarm_delay_on > 100 And Sp_alarm_delay_off <= 200 And Second = 1 Then Decr Alarm_active_delay_on(channel_nr)
 If Sp_alarm_delay_on > 200 And Second = 1 And Minute = 1 Then Decr Alarm_active_delay_on(channel_nr) : End If

'now start Delay off
If Alarm_active_delay_on(channel_nr) = 1 Then               'Delay on finished?
  Alarm_active_delay_on(channel_nr) = 0
 Pointer_eeprom = Pointer_eeprom + 3 : Readeeprom Temp_b2 , Pointer_eeprom       'Alarm-Type
 If Temp_b2 > 0 Then
   Alarm_moving_detector = 1 : Meldung_aktiv = 1 : Channel_nr_alarm = Channel_nr : If Temp_b2 > 1 Then Make_tel_call = 1 : Beep_ein = 5 : End If
 Temp_b1 = Sp_alarm_delay_off
 If Sp_alarm_delay_off > 100 Then Temp_b1 = Temp_b1 - 100   'Wenn Eingabe Schaltdauer Bewegungsmelder in minuten
 If Sp_alarm_delay_off > 200 Then Temp_b1 = Temp_b1 - 100   'Wenn Eingabe Schaltdauer Bewegungsmelder in Std
 Alarm_active(channel_nr) = Temp_b1 : End If                'Neuen Wert laden

If Sp_alarm_delay_off = 0 Then Alarm_active(channel_nr) = 0

'Count Delay off
If Alarm_active(channel_nr) > 0 Then
 If Sp_alarm_delay_off <= 100 Then Decr Alarm_active(channel_nr)
 If Sp_alarm_delay_off > 100 And Sp_alarm_delay_off <= 200 And Second = 1 Then Decr Alarm_active(channel_nr)
 If Sp_alarm_delay_off > 200 And Second = 1 And Minute = 1 Then Decr Alarm_active(channel_nr) : End If
End_loop_alarm:
Next

 If Alarm_moving_detector = 1 And Meldung_aktiv = 1 Then
  Lcd_param = 1 : Gosub Lcd_gotoline                        '1234567890123456
  Value = Channel_nr_alarm : Gosub Write_alarm_channel
  Lcd_param = 2 : Gosub Lcd_gotoline : Lcd_display_pad_with_spaces = 1
  Lcd_display_pad_with_spaces = 1 : Lcd_display_string = "Alarm-Sensor!" : Gosub Lcd_display : Gosub Line_feed
End If

If Make_tel_call = 1 Then
  Make_tel_call = 0 : Alarm_thief = 1 : Gosub Anrufen : End If
Return

'################################### ELV-Radio-Sensors #############################################################
Get_elv_sensor_data:
Dim Elv_sign As Byte
Dim Elv_sign_2 As Byte
Dim Elv_sign_3 As Byte
Dim Elv_sign_4 As Byte
Dim Elv_string As Byte
Dim Sec_changed As Byte

If Minute = 59 And Second = 10 Then                         ' reset all hour
      Wind_sensor_detect = 0 : Temp_sensor_detect = 0 : Humidity_sensor_detect = 0 : Temp_sensor_detect_2 = 0 : Humidity_sensor_detect_2 = 0 : Rain_sensor_detect = 0 : End If

Readeeprom Temp , 314                                       'new ELV-Sensor?
If Temp = 1 Then Elv_sign = Inkey(#2) Else Elv_sensor_byte = Inkey(#2)       'new ELV-Sensor?

If Temp <> 1 And Elv_sensor_byte = 0 Then Return            'old Sensor

'###################### new ELV-Sensor ######################################
'         1         2         3         4
'12345678901234567890123456789012345678901234567890
'$1;1;;;;;;21,0;;;;;;;;55;;;;20,8;50;1,6;0;0;0
'          Temp1    Feucht1 Temp2 Feucht2 Wind
'36 49 59 49 59 0 59 50 49 44 55 59 0 52 54 59 50 49 44 52 59 52 49 59 49 44 51 59 48 59 48 59 48 13 10 0
If Temp = 1 Then                                            'new ELV-Sensor
If Elv_sign = 36 Then Counter_radio_bytes = 1               'Start of string
If Elv_sign = 10 Then Counter_radio_bytes = 0               'Cr End of string

If Counter_radio_bytes > 0 And Counter_radio_bytes < 42 And Elv_sign > 0 Then       'read Data
  Elv_v2_data(counter_radio_bytes) = Elv_sign : Incr Counter_radio_bytes : Elv_sign = 0
Else
 Return
End If

'Temp-Sensor 1
Elv_sign = Elv_v2_data(11) : Elv_sign_2 = Elv_v2_data(12) : Elv_sign_3 = Elv_v2_data(13) : Elv_sign_4 = Elv_v2_data(14)
If Elv_v2_data(23) <> 59 Then                               'Wind_sensor with Temp and Humidity
 Elv_sign = Elv_v2_data(23) : Elv_sign_2 = Elv_v2_data(24) : Elv_sign_3 = Elv_v2_data(25) : Elv_sign_4 = Elv_v2_data(26) : End If
Gosub Elv_data_evaluate
Elv_temp = Temp : If Elv_temp > 0 Then Temp_sensor_detect = 1       'to Integer

'Humid-Sensor 1
Elv_sign = Elv_v2_data(23) : Elv_sign_2 = Elv_v2_data(24) : Elv_sign_3 = 59 : Elv_sign_4 = 59
If Elv_v2_data(28) <> 59 Then                               'Wind_sensor with Temp and Humidity
 Elv_sign = Elv_v2_data(28) : Elv_sign_2 = Elv_v2_data(29) : End If
Gosub Elv_data_evaluate
Elv_humidity = Temp : If Elv_humidity > 0 Then Humidity_sensor_detect = 1       'to Integer

'Temp-Sensor 2
Elv_sign = Elv_v2_data(29) : Elv_sign_2 = Elv_v2_data(30) : Elv_sign_3 = Elv_v2_data(31) : Elv_sign_4 = Elv_v2_data(32)
Gosub Elv_data_evaluate
Elv_temp_2 = Temp : If Elv_temp_2 > 0 Then Temp_sensor_detect_2 = 1       'to Integer

'Humid-Sensor 2
Elv_sign = Elv_v2_data(34) : Elv_sign_2 = Elv_v2_data(35) : Elv_sign_3 = 59 : Elv_sign_4 = 59
Gosub Elv_data_evaluate
Elv_humidity_2 = Temp : If Elv_humidity_2 > 0 Then Humidity_sensor_detect_2 = 1       'to Integer

'Wind-Sensor
Elv_sign = Elv_v2_data(31) : Elv_sign_2 = Elv_v2_data(32) : Elv_sign_3 = Elv_v2_data(33) : Elv_sign_4 = Elv_v2_data(34)
Gosub Elv_data_evaluate
Wind_speed = Temp : If Wind_speed > 0 And Wind_speed < 99 Then Wind_sensor_detect = 1       'to Integer

'Rain
'Elv_sign = Elv_v2_data(35) : Elv_sign_2 = Elv_v2_data(36) : Elv_sign_3 = Elv_v2_data(37) : Elv_sign_4 = Elv_v2_data(38)
  Return                                                    'new ELV-Sensor selected
End If                                                      'ELV V2-Sensor

'######################
If Elv_sensor_byte = 2 Then Counter_radio_bytes = 1         'STX-Sign is coming, Start Block
If Elv_sensor_byte = 3 Then Counter_radio_bytes = 0         'ETX-Sign is coming, End Block

Elv_sensor_byte = Elv_sensor_byte And &B01111111
If Counter_radio_bytes > 0 Then
 Temp_array(counter_radio_bytes) = Elv_sensor_byte : Incr Counter_radio_bytes
Else
 Return
End If

'Evaluate
Temp_b5 = Temp_array(2)

If Temp_b5 >= &H30 And Temp_b5 <= &H3F Then                 'Type Wind-Sensor
     Wind_sensor_detect = 1
     Temp_b1 = Temp_array(3) : Temp1 = Temp_b1 : Temp_b1 = Temp_array(4) : Temp2 = Temp_b1 : Shift Temp1 , Left , 7 : Wind_speed = Temp1 Or Temp2       'Wind_Speed
'     Wind_stability = Temp_array(5)                         'Wind_Stability (Schwankungsbreite)
'     Temp_b1 = Temp_array(6) : Temp1 = Temp_b1 : Temp_b1 = Temp_array(7) : Temp2 = Temp_b1 : Shift Temp1 , Left , 7 : Wind_direction = Temp1 Or Temp2       'Wind_Direction
End If                                                      'Type Wind-Sensor

If Temp_b5 > &H0 And Temp_b5 < &H1E Then Goto Elv_temp      'Außensensor Temp
If Temp_b5 = &H4F Then Goto Elv_temp                        'Innensensor Type Temp + Humidtiy Temp_b5 >= &H40 And Temp_b5 = &H4F
Goto Elv_no_temp                                            'Innensensor Type Temp-Sensor + Humitity
Elv_temp:
Temp_sensor_detect = 1
     Temp_b1 = Temp_array(3) : Temp1 = Temp_b1 : Temp_b1 = Temp_array(4) : Temp2 = Temp_b1 : Shift Temp1 , Left , 7 : Elv_temp = Temp1 Or Temp2       'Temp
'If Temp_b5 = 0 Then Humidity_by_radio_1 = Elv_temp
'If Temp_b5 = 1 Then Humidity_by_radio_2 = Elv_temp
'If Temp_b5 = 2 Then Humidity_by_radio_3 = Elv_temp
'If Temp_b5 = 3 Then Humidity_by_radio_4 = Elv_temp
'If Temp_b5 = 4 Then Humidity_by_radio_5 = Elv_temp
'If Temp_b5 = 5 Then Humidity_by_radio_6 = Elv_temp

Elv_no_temp:
If Temp_b5 = &H4F Then                                      'Innensensor Type Temp + Humidtiy  Temp_b5 >= &H40 and And Temp_b5 <= &H4F
Humidity_sensor_detect = 1
Elv_humidity = Temp_array(5) * 10 : End If

If Temp_b5 = &H1E Then                                      'Innensensor Type Temp + Humidtiy
Humidity_sensor_detect = 1
Elv_humidity_2 = Temp_array(5) * 10 : End If

If Temp_b5 >= &H20 And Temp_b5 <= &H2F Then                 'Type Rain-Sensor
Rain_sensor_detect = 1
     Temp_b1 = Temp_array(3) : Temp1 = Temp_b1 : Temp_b1 = Temp_array(4) : Temp2 = Temp_b1 : Shift Temp1 , Left , 7 : Elv_rain = Temp1 Or Temp2
End If                                                      'Type Rain-Sensor

'If Temp_b5 >= &H58 And Temp_b5 <= &H6F Then                 'Type Light-Sensor
'Light_sensor_detect = 1
'     Temp_b1 = Temp_array(3) : Temp1 = Temp_b1 : Temp_b1 = Temp_array(4) : Temp2 = Temp_b1 : Shift Temp1 , Left , 7 : Elv_light = Temp1 Or Temp2
'     Temp_b1 = Temp_array(5) : If Temp_b1 > 0 Then Elv_light = Elv_light * Temp_b1       'Mult-Factor
'End If                                                      'Type Rain-Sensor
Return

Elv_data_evaluate:
Temp = 0
 If Elv_sign = 59 Then Return                               ';
'1.Sign
  Temp = Elv_sign - 48
'2.Sign
  Temp_b1 = Elv_sign_2 - 48
 If Elv_sign_2 <> 59 And Elv_sign_2 <> 44 Then              'Sign ; and ,
 Temp = Temp * 10 : Temp = Temp + Temp_b1 : End If
'3.Sign
  Temp_b1 = Elv_sign_3 - 48
If Elv_sign_3 <> 59 And Elv_sign_3 <> 44 Then               '; and ,
   Temp = Temp * 10 : Temp = Temp + Temp_b1 : End If
'4.Sign
  Temp_b1 = Elv_sign_4 - 48
  If Elv_sign_4 <> 59 And Elv_sign_4 <> 44 Then             '; and ,
  Temp = Temp * 10 : Temp = Temp + Temp_b1 : End If
Return

Alarm_channel:
 If Channel_nr_alarm = 0 Then Flag_alarm_channel = 0
If Channel_nr_alarm > 0 And Flag_alarm_channel = 0 Then
  Beep_ein = 5 : Flag_alarm_channel = 1 : Meldung_aktiv = 1 : Gosub Alarm_channel_text : Alarm_from_input = 0 : If Temp_b1 > 1 Then Alarm_from_input = 1 : End If       ': Goto Alarm_call 27.8.08 Temp_b1 = Batt-Volt/other

If Channel_nr_alarm > 0 And Meldung_aktiv = 1 Then Gosub Alarm_channel_text
Return

Alarm_channel_text:
Lcd_param = 1 : Gosub Lcd_gotoline
 ' Lcd_display_string = "Alarm " : Gosub Lcd_display         '
  If English = 0 Then Lcd_display_string = "Kanal " Else Lcd_display_string = "Channel " : Gosub Lcd_display : Value = Channel_nr_alarm : Kein_komma = 1 : Tel_nr = 1 : Gosub Write_value : Lcd_display_string = " " : Lcd_display_pad_with_spaces = 1 : Gosub Lcd_display

  Lcd_param = 2 : Gosub Lcd_gotoline
 Ten_times_channel_nr = Channel_nr_alarm * 10               'Startwert EEprom
 Temp4 = Ten_times_channel_nr + 493 : Readeeprom Channel_typ , Temp4       'Type
Gosub Show_channel_info
Return

''################ Alarm Sensors ################################
'Alarm_sensor:
'For Channel_nr = 1 To Number_of_channel_modules
'Channel_typ = Channel_type(channel_nr)
''Ten_times_channel_nr = Channel_nr * 10
''Temp4 = Ten_times_channel_nr + 493
''Readeeprom Channel_typ , Temp4                              'Type at Adr. 503
'
' If Channel_typ > 9 Then                                    'Temp_b3 > 9  Channel Level with Alarm
'  Alarm_sensor = 0
'
'If Output(channel_nr) = 1 Then Alarm_sensor = 1
' If Alarm_sensor = 1 Then Channel_nr_alarm_sensor = Channel_nr       'which block get Alarm?
' If Channel_nr = Channel_nr_alarm_sensor And Alarm_sensor = 0 Then
'     Channel_nr_alarm_sensor = 0 : Pulse_alarm_empty = 0 : End If       'channel had Alarm?
' If Channel_nr = Channel_nr_alarm_sensor And Alarm_sensor = 1 And Pulse_alarm_empty = 0 Then
'       Pulse_alarm_empty = 1 : Alarm_from_input = 1 : Meldung_aktiv = 1 : Beep_ein = 5 : End If
'End If
'Next
'
'If Pulse_alarm_empty = 1 And Meldung_aktiv = 1 Then
' Lcd_param = 1 : Gosub Lcd_gotoline                         '1234567890123456
' Value = Channel_nr_alarm_sensor : Gosub Write_alarm_channel
' Lcd_param = 2 : Gosub Lcd_gotoline : Lcd_display_pad_with_spaces = 1
'    Lcd_display_string = "Sensor!" : Gosub Lcd_display : Gosub Line_feed
' Beep_ein = 3
' ' Gosub Send_sms_header
'' Gosub Send_sms_alarm
'End If
'Return

Alarm_no_analog:
If Reset_alarm_if_no_analog > 0 And Second = 10 Then Decr Reset_alarm_if_no_analog       'Rest after 10 minutes
If Reset_alarm_if_no_analog = 1 Then Flag_alarm_if_no_analog = 0

If Flag_alarm_if_no_analog = 0 Or Meldung_aktiv = 0 Then Return
Gosub Reset_outputs
Lcd_param = 1 : Gosub Lcd_gotoline
Lcd_display_pad_with_spaces = 1 : Lcd_display_string = "Alarm Cable" : Gosub Lcd_display
Lcd_param = 2 : Gosub Lcd_gotoline
Lcd_display_string = "Analog Input: " : Gosub Lcd_display : Value = Alarm_no_analog_nr : Kein_komma = 1 : Gosub Write_value : : Beep_ein = 10 : Gosub Line_feed : Return

'Sensor_monitoring:
'If Delay_on < 20 Then Return
'If Humidity_1 >= 5 Then Sensor_1_present = 1
'If Humidity_2 >= 5 Then Sensor_2_present = 1
'If Humidity_3 >= 5 Then Sensor_3_present = 1
'If Humidity_4 >= 5 Then Sensor_4_present = 1
'If Humidity_5 >= 5 Then Sensor_5_present = 1
'If Ldr_sensor >= 5 Then Sensor_6_present = 1
''If Humidity_7 >= 5 Then Sensor_7_present = 1
'
'Sensor_nr_fault = 0
'If Sensor_1_present = 1 And Humidity_1 < 5 Then Sensor_nr_fault = 1
'If Sensor_2_present = 1 And Humidity_2 < 5 Then Sensor_nr_fault = 2
'If Sensor_3_present = 1 And Humidity_3 < 5 Then Sensor_nr_fault = 3
'If Sensor_4_present = 1 And Humidity_4 < 5 Then Sensor_nr_fault = 4
'If Sensor_5_present = 1 And Humidity_5 < 5 Then Sensor_nr_fault = 5
'If Sensor_6_present = 1 And Ldr_sensor < 5 Then Sensor_nr_fault = 6
''If Sensor_7_present = 1 And Humidity_7 < 5 Then Sensor_nr_fault = 7
'
'If Puls_sensor_fault = 1 And Meldung_aktiv = 1 And Mobile_aktiv = 1 Then
'   Print #1 , "Sensor " ; : Value = Sensor_nr_fault : Kein_komma = 1 : Gosub Write_value
'End If
'If Sensor_nr_fault = 0 And Meldung_aktiv = 1 Then Puls_sensor_fault = 0
'If Sensor_nr_fault = 0 Or Sensor_nr_fault > 4 Or Puls_sensor_fault = 1 Or Meldung_aktiv = 1 Then Return
'Gosub Lcd_delete
'If English = 0 Then Lcd_display_string = "Sensor " : Gosub Lcd_display
'Tel_nr = 1 : Value = Sensor_nr_fault : Kein_komma = 1 : Gosub Write_value : Gosub Write_leerz : Tel_nr = 0
' If English = 0 Then Lcd_display_string = "Fehler " Else Lcd_display_string = " Fault " : Gosub Lcd_display : Gosub Line_feed : Meldung_aktiv = 1 : Puls_sensor_fault = 1 : Beep_ein = 3 : Waitms 600 : Return
'Return

'UP Batterie leer, Batt-Entnahme aus
Batterie_leer_1:
Load_1 = 0
Readeeprom Temp , 242                                       'this channel activated?
Readeeprom Temp2 , 354                                      'this channel activated?
If Time_load_shedding(1) = 0 Or Temp = 0 Or Temp2 = 0 Then
  Su_time_act_1 = 0 : Return : End If

If Tiefentladen_aus_1 = 1 Then
   Load_1 = 1 : Return : End If                             'Lastabwurf 1:

If Batterie_n_leer_1 = 1 Or Delay_on < 30 Then Load_1 = 1

If Delay_on < 30 Then Return
Analog_input_channel_x = U_batt_smooth
'Readeeprom Temp , 242                                        'siehe oben Lastabwurf_1
'Temp = Temp - Correction_high_current                       'Correction-Faktor if High Current Load (0,3; 0,4; 0,5V)
'GoSub Temp_spg_wert                                         'Temperaturatur-Korrektur
Readeeprom Temp3 , 270                                      'Rückschalten Hysterese
Temp2 = Temp + Temp3                                        ' Rückschalten = Lastabwurf-Spg + Hysterese

If Analog_input_channel_x >= Temp2 And Time_off_u_min_1 = 0 And Delay_switch_back_1 < 255 Then Incr Delay_switch_back_1       'Minimum Time for Relais on again
If Analog_input_channel_x < Temp2 Then Delay_switch_back_1 = 0       'no switch off again

If Time_off_u_min_1 = 0 And Delay_switch_back_1 > Sp_delay_switch_back Then Batterie_n_leer_1 = 1       'Last wieder zuschalten nach Lastabw + Hysterese
If Analog_input_channel_x >= Temp Then Delay_low_volt_1 = 0
If Analog_input_channel_x < Temp And Delay_low_volt_1 < 255 Then Incr Delay_low_volt_1
If Delay_low_volt_1 = Sp_delay_low_volt Then Time_off_u_min_1 = Sp_time_off_u_min       'Minimum Time for Relais off
If Time_off_u_min_1 > 0 And Second = 10 Then Decr Time_off_u_min_1       '
If Simu = 1 And Time_off_u_min_1 > 0 Then Decr Time_off_u_min_1       '
If Delay_low_volt_1 > Sp_delay_low_volt Then Batterie_n_leer_1 = 0       'delay-time u_min
Readeeprom Temp , 278                                       'U maxmax Voltage switch off to Protect Load
If Analog_input_channel_x >= Temp Then Batterie_n_leer_1 = 0

'Timer
Readeeprom Temp_b1 , 226                                    'hour Load-shedding
Readeeprom Temp_b2 , 227                                    'minute
Readeeprom Temp_b3 , 228                                    'on for

Temp_b4 = Su_time_act_1                                     'counter
Gosub Count_down_timer
Su_time_act_1 = Temp_b4                                     'counter

If Temp_b1 > 0 And Temp_b2 > 0 And Temp_b3 > 0 And Temp_b4 = 0 Then Load_1 = 0
Return

Count_down_timer:
If Temp_b4 > 0 Then
 If Temp_b3 > 200 And Minute = 1 And Second = 10 Then Decr Temp_b4       'hr-counter
 If Temp_b3 > 100 And Second = 10 Then Decr Temp_b4         'min-Counter
 If Temp_b3 < 100 Then Decr Temp_b4                         'sec-counter
End If

'start Timer
If Hour <> Temp_b1 Or Minute <> Temp_b2 Or Second <> 10 Then Return
If Temp_b3 <= 100 Then Temp_b4 = Temp_b3                    'Start Timer second
If Temp_b3 > 100 And Temp_b3 <= 200 Then Temp_b4 = Temp_b3 - 100       'Start Timer minute
If Temp_b3 > 200 Then Temp_b4 = Temp_b3 - 200               'Start Timer hr
Return

Batterie_leer_2:
Load_2 = 0                                                  'Lastabwurf 2:
Readeeprom Temp , 244                                       'this channel activated?
Readeeprom Temp2 , 356                                      'this channel activated?
If Time_load_shedding(2) = 0 Or Temp = 0 Or Temp2 = 0 Then
  Su_time_act_2 = 0 : Return : End If

If Tiefentladen_aus_2 = 1 Then
  Load_2 = 1 : Return : End If

If Batterie_n_leer_2 = 1 Or Delay_on < 30 Then Load_2 = 1

If Delay_on < 30 Then Return
Analog_input_channel_x = U_batt_smooth
Readeeprom Temp , 244                                       'Lastabwurf_2
'Temp = Temp - Correction_high_current                       'Correction-Faktor if High Current Load
'Gosub Temp_spg_wert                                         'Temperaturatur-Korrektur; nicht bei Abschaltung!
Readeeprom Temp3 , 270                                      'Rückschalten Hysterese
Temp2 = Temp + Temp3                                        ' Rückschalten = Lastabwurf-Spg + Hysterese

If Analog_input_channel_x >= Temp2 And Time_off_u_min_2 = 0 And Delay_switch_back_2 < 255 Then Incr Delay_switch_back_2       'Minimum Time for Relais on again
If Analog_input_channel_x < Temp2 Then Delay_switch_back_2 = 0       'no switch off again

If Time_off_u_min_2 = 0 And Delay_switch_back_2 > Sp_delay_switch_back Then Batterie_n_leer_2 = 1       'Last wieder zuschalten nach Lastabw + Hysterese
If Analog_input_channel_x >= Temp Then Delay_low_volt_2 = 0
If Analog_input_channel_x < Temp And Delay_low_volt_2 < 255 Then Incr Delay_low_volt_2
If Delay_low_volt_2 = Sp_delay_low_volt Then Time_off_u_min_2 = Sp_time_off_u_min       'Minimum Time for Relais off
If Time_off_u_min_2 > 0 And Second = 10 Then Decr Time_off_u_min_2
If Simu = 1 Then Time_off_u_min_2 = 0
If Delay_low_volt_2 > Sp_delay_low_volt Then Batterie_n_leer_2 = 0
Readeeprom Temp , 278                                       'maxmax Spannung
If Analog_input_channel_x >= Temp Then Batterie_n_leer_2 = 0
'Timer
Readeeprom Temp_b1 , 229                                    'hour Load-shedding
Readeeprom Temp_b2 , 230                                    'minute
Readeeprom Temp_b3 , 231                                    'on for

Temp_b4 = Su_time_act_2                                     'counter
Gosub Count_down_timer
Su_time_act_2 = Temp_b4                                     'counter

If Temp_b1 > 0 And Temp_b2 > 0 And Temp_b3 > 0 And Temp_b4 = 0 Then Load_2 = 0
Return

Batterie_leer_3:
Load_3 = 0                                                  'Lastabwurf 3:
Readeeprom Temp , 246                                       'this channel activated?
Readeeprom Temp2 , 358                                      'this channel activated?
If Time_load_shedding(3) = 0 Or Temp = 0 Or Temp2 = 0 Then
  Su_time_act_3 = 0 : Return : End If

If Tiefentladen_aus_3 = 1 Then
  Load_3 = 1 : Return : End If

If Batterie_n_leer_3 = 1 Or Delay_on < 30 Then Load_3 = 1

If Delay_on < 30 Then Return
 Analog_input_channel_x = U_batt_smooth
'Readeeprom Temp , 246      'Lastabwurf_3
'Temp = Temp - Correction_high_current                       'Correction-Faktor if High Current Load
'GoSub Temp_spg_wert                                         'Temperaturatur-Korrektur
Readeeprom Temp3 , 270                                      'Rückschalten Hysterese
Temp2 = Temp + Temp3                                        ' Rückschalten = Lastabwurf-Spg + Hysterese

If Analog_input_channel_x >= Temp2 And Time_off_u_min_3 = 0 And Delay_switch_back_3 < 255 Then Incr Delay_switch_back_3       'Minimum Time for Relais on again
If Analog_input_channel_x < Temp2 Then Delay_switch_back_3 = 0       'no switch off again

If Time_off_u_min_3 = 0 And Delay_switch_back_3 > Sp_delay_switch_back Then Batterie_n_leer_3 = 1       'Last wieder zuschalten nach Lastabw + Hysterese
If Analog_input_channel_x >= Temp Then Delay_low_volt_3 = 0
If Analog_input_channel_x < Temp And Delay_low_volt_3 < 255 Then Incr Delay_low_volt_3
If Delay_low_volt_3 = Sp_delay_low_volt Then Time_off_u_min_3 = Sp_time_off_u_min       'Minimum Time for Relais off
If Time_off_u_min_3 > 0 And Second = 10 Then Decr Time_off_u_min_3
If Simu = 1 Then Time_off_u_min_3 = 0
If Delay_low_volt_3 > Sp_delay_low_volt Then Batterie_n_leer_3 = 0
Readeeprom Temp , 278                                       'maxmax Spannung
If Analog_input_channel_x >= Temp Then Batterie_n_leer_3 = 0
'Timer
Readeeprom Temp_b1 , 232                                    'hour Load-shedding
Readeeprom Temp_b2 , 233                                    'minute
Readeeprom Temp_b3 , 234                                    'on for

Temp_b4 = Su_time_act_3                                     'counter
Gosub Count_down_timer
Su_time_act_3 = Temp_b4                                     'counter

If Temp_b1 > 0 And Temp_b2 > 0 And Temp_b3 > 0 And Temp_b4 = 0 Then Load_3 = 0
Return

Batterie_leer_4:
Load_4 = 0                                                  'Lastabwurf 3:

Readeeprom Temp , 248                                       'this channel activated?
Readeeprom Temp2 , 360                                      'this channel activated?
If Time_load_shedding(4) = 0 Or Temp = 0 Or Temp2 = 0 Then
  Su_time_act_4 = 0 : Return : End If


If Tiefentladen_aus_4 = 1 Then
  Load_4 = 1 : Return : End If

If Batterie_n_leer_4 = 1 Or Delay_on < 30 Then Load_4 = 1

If Delay_on < 30 Then Return
Analog_input_channel_x = U_batt_smooth
'Readeeprom Temp , 248                                       'Lastabwurf_4
'Temp = Temp - Correction_high_current                       'Correction-Faktor if High Current Load
'Gosub Temp_spg_wert                                         'Temperaturatur-Korrektur
Readeeprom Temp3 , 270                                      'Rückschalten Hysterese
Temp2 = Temp + Temp3                                        ' Rückschalten = Lastabwurf-Spg + Hysterese

If Analog_input_channel_x >= Temp2 And Time_off_u_min_4 = 0 And Delay_switch_back_4 < 255 Then Incr Delay_switch_back_4       'Minimum Time for Relais on again
If Analog_input_channel_x < Temp2 Then Delay_switch_back_4 = 0       'no switch off again

If Time_off_u_min_4 = 0 And Delay_switch_back_4 > Sp_delay_switch_back Then Batterie_n_leer_4 = 1       'Last wieder zuschalten nach Lastabw + Hysterese
If Analog_input_channel_x >= Temp Then Delay_low_volt_4 = 0
If Analog_input_channel_x < Temp And Delay_low_volt_4 < 255 Then Incr Delay_low_volt_4
If Delay_low_volt_4 = Sp_delay_low_volt Then Time_off_u_min_4 = Sp_time_off_u_min       'Minimum Time for Relais off
If Time_off_u_min_4 > 0 And Second = 10 Then Decr Time_off_u_min_4
If Simu = 1 Then Time_off_u_min_4 = 0
If Delay_low_volt_4 > Sp_delay_low_volt Then Batterie_n_leer_4 = 0
Readeeprom Temp , 278                                       'maxmax Spannung also switch off Load
If Analog_input_channel_x >= Temp Then Batterie_n_leer_4 = 0
'Timer
Readeeprom Temp_b1 , 235                                    'hour Load-shedding
Readeeprom Temp_b2 , 236                                    'minute
Readeeprom Temp_b3 , 237                                    'on for

Temp_b4 = Su_time_act_4                                     'counter
Gosub Count_down_timer
Su_time_act_4 = Temp_b4                                     'counter

If Temp_b1 > 0 And Temp_b2 > 0 And Temp_b3 > 0 And Temp_b4 = 0 Then Load_4 = 0
Return

Batterie_leer_5:
Load_5 = 0                                                  'Lastabwurf 3:

Readeeprom Temp , 250                                       'this channel activated?
Readeeprom Temp2 , 362                                      'this channel activated?
If Time_load_shedding(5) = 0 Or Temp = 0 Or Temp2 = 0 Then
  Su_time_act_5 = 0 : Return : End If

If Tiefentladen_aus_5 = 1 Then
 Load_5 = 1 : Return : End If

If Batterie_n_leer_5 = 1 Or Delay_on < 30 Then Load_5 = 1

If Delay_on < 30 Then Return
Analog_input_channel_x = U_batt_smooth
'Readeeprom Temp , 250                                       'Lastabwurf_5
'Temp = Temp - Correction_high_current                       'Correction-Faktor if High Current Load
'Gosub Temp_spg_wert                                         'Temperaturatur-Korrektur
Readeeprom Temp3 , 270                                      'Rückschalten Hysterese
Temp2 = Temp + Temp3                                        ' Rückschalten = Lastabwurf-Spg + Hysterese

If Analog_input_channel_x >= Temp2 And Time_off_u_min_5 = 0 And Delay_switch_back_5 < 255 Then Incr Delay_switch_back_5       'Minimum Time for Relais on again
If Analog_input_channel_x < Temp2 Then Delay_switch_back_5 = 0       'no switch off again

If Time_off_u_min_5 = 0 And Delay_switch_back_5 > Sp_delay_switch_back Then Batterie_n_leer_5 = 1       'Last wieder zuschalten nach Lastabw + Hysterese
If Analog_input_channel_x >= Temp Then Delay_low_volt_5 = 0
If Analog_input_channel_x < Temp And Delay_low_volt_5 < 255 Then Incr Delay_low_volt_5
If Delay_low_volt_5 = Sp_delay_low_volt Then Time_off_u_min_5 = Sp_time_off_u_min       'Minimum Time for Relais off
If Time_off_u_min_5 > 0 And Second = 10 Then Decr Time_off_u_min_5
If Simu = 1 Then Time_off_u_min_5 = 0
If Delay_low_volt_5 > Sp_delay_low_volt Then Batterie_n_leer_5 = 0
Readeeprom Temp , 278                                       'maxmax Spannung also switch off Load
If Analog_input_channel_x >= Temp Then Batterie_n_leer_5 = 0
'Timer
Readeeprom Temp_b1 , 238                                    'hour Load-shedding
Readeeprom Temp_b2 , 239                                    'minute
Readeeprom Temp_b3 , 240                                    'on for

Temp_b4 = Su_time_act_5                                     'counter
Gosub Count_down_timer
Su_time_act_5 = Temp_b4                                     'counter

If Temp_b1 > 0 And Temp_b2 > 0 And Temp_b3 > 0 And Temp_b4 = 0 Then Load_5 = 0
Return

Tiefentladen_aus:
'if Analog_Input_Channel_X < Umin_min then no more deep-discharge emergency
 Tiefentladen_aus_1 = 0 : Tiefentladen_aus_2 = 0 : Tiefentladen_aus_3 = 0 : Tiefentladen_aus_4 = 0 : Tiefentladen_aus_5 = 0
Readeeprom Temp_b1 , 226 : Readeeprom Temp_b2 , 227         'hour / minute Load-shedding
Readeeprom Temp_b1 , 229 : Readeeprom Temp_b2 , 230
Readeeprom Temp_b1 , 232 : Readeeprom Temp_b2 , 233
Readeeprom Temp_b1 , 235 : Readeeprom Temp_b2 , 236
Readeeprom Temp_b1 , 238 : Readeeprom Temp_b2 , 239
Readeeprom Temp , 260                                       'Umin_min Batterie
If U_batt_smooth <= Temp Then
  Su_time_act_1 = 0 : Su_time_act_2 = 0 : Su_time_act_3 = 0 : Su_time_act_4 = 0 : Su_time_act_5 = 0
  If Temp_b1 = 0 And Temp_b2 = 0 Then Time_load_shedding(1) = 0
  If Temp_b1 = 0 And Temp_b2 = 0 Then Time_load_shedding(2) = 0
  If Temp_b1 = 0 And Temp_b2 = 0 Then Time_load_shedding(3) = 0
  If Temp_b1 = 0 And Temp_b2 = 0 Then Time_load_shedding(4) = 0
  If Temp_b1 = 0 And Temp_b2 = 0 Then Time_load_shedding(5) = 0
End If
If Temp_b1 = 0 And Temp_b2 = 0 And Time_load_shedding(1) = 1 And Su_time_act_1 > 0 Then Tiefentladen_aus_1 = 1
If Temp_b1 = 0 And Temp_b2 = 0 And Time_load_shedding(2) = 1 And Su_time_act_2 > 0 Then Tiefentladen_aus_2 = 1
If Temp_b1 = 0 And Temp_b2 = 0 And Time_load_shedding(3) = 1 And Su_time_act_3 > 0 Then Tiefentladen_aus_3 = 1
If Temp_b1 = 0 And Temp_b2 = 0 And Time_load_shedding(4) = 1 And Su_time_act_4 > 0 Then Tiefentladen_aus_4 = 1
If Temp_b1 = 0 And Temp_b2 = 0 And Time_load_shedding(5) = 1 And Su_time_act_5 > 0 Then Tiefentladen_aus_5 = 1
'If Tiefentladen_aus = 1 And Second = 10 And Minute = 10 Then Incr Tiefentladen_aus_zeit
'If Tiefentladen_aus_zeit > Time_emerg_deep_dis_off Then Tiefentladen_aus = 0       '*** after xx hours switch off again
'If Tiefentladen_aus_zeit > Time_emerg_deep_dis_off Or Tiefentladen_aus = 0 Then Tiefentladen_aus_zeit = 0
Return

Battery_full:
'wenn Batt am Anfang sehr leer->Pulsladen
'Boost-Charge Bleiakkus: wenn Batterie vorher unter 40% entladen war (12,84V) oder 1x/Monat oder 1x/Woche wenn Generator->dann Ausgleichsladen (Gasungsspannung) bis max 14,7V für max. 1-2 Std
'Boost-Charge Bleigel: wenn Batterie vorher unter 70% entladen war (11,67V) oder 1x/Monat oder 1x/Woche wenn Generator ->dann Zyklische laden bis max 14,4V für max. 1-2 Std
'Boost-Charge: Spannung bis 14,4/14,7 V (aber max Umaxmax mit Hysterese); 1 Std. halten; dann Pulse-charge auf 13,8V
'Umaxmax Blei: Eingabe; Bleigel: Zykl.Laden + 0,4V
'Laden bis 13,8V (Erhaltungsladen): Spannung pendelt zwischen 12,8 und 13,8 V d.h. pulsen
Charge_to_14_4v = 0 : If Full_charge = 1 Or Boost_charge = 1 Or Equalization_charge = 1 Then Charge_to_14_4v = 1

'manual Start/Stop Boost-charge
Readeeprom Temp , 346                                       '94 = 17 Start / Stop Boost-Charge manually
If Temp = 1 And Start_stop_boost_charge_old = 0 Then
   Boost_charge = 1 : Start_stop_boost_charge_old = 1 : End If
If Temp = 0 And Start_stop_boost_charge_old = 1 Then
   Start_stop_boost_charge_old = 0 : Full_charge = 0 : Boost_charge = 0 : Equalization_charge = 0 : Fully_load_till_stop_puls = 0 : End If

Readeeprom Temp , 272 : Gosub Temp_spg_wert : Voltage_stop_puls = Temp       'Voltage_Stop_Puls;   'Temperaturatur-Korrektur->Ergebnis in Temp
Readeeprom Temp , 274 : If Equalization_charge = 1 Then Readeeprom Temp , 276 : Gosub Temp_spg_wert : Boost_voltage = Temp       'Zylisches_laden_Blei / Ausgleichsladen

'no_boost_charge_for....
If No_boost_charge_for > 0 And Second = 10 And Minute = 1 And Hour = 10 Then Decr No_boost_charge_for       'days counting
'If Time_boost_charge = Sp_time_boost_charge Then No_boost_charge_for = Sp_no_boost_charge_for       'Boost charge finished after ... min
'If U_batt_smooth >= Voltage_stop_puls And Charge_to_14_4v = 1 Then No_boost_charge_for = Sp_no_boost_charge_for

'boast-charge with battery was empty
Temp = 20 : Gosub Correction_system_voltage : Temp2 = Voltage_stop_puls - Temp       '13,8V - 2,0 = 11,8V

If U_batt_smooth < Temp2 And Delay_activate_boost_charge < 255 And Second = 10 Then Incr Delay_activate_boost_charge       'for 1 hour
If U_batt_smooth >= Temp2 Then Delay_activate_boost_charge = 0
If Delay_activate_boost_charge > 60 And No_boost_charge_for = 0 And Delay_on > 180 And Charge_to_14_4v = 0 Then       'Raise charging-level when voltage was less than ...for a special time
   Boost_charge = 1 : Temp = 1 : Readeeprom Temp4 , 346 : If Temp4 <> Temp Then Writeeeprom Temp , 346 : End If       'save to Parameters for Reset

'Full_charge all 14 Days
Temp_b1 = Day Mod 14                                        'all 14 Days
If Second = 10 And Minute = 1 And Hour = 10 And Temp_b1 = 0 And Charge_to_14_4v = 0 Then
  Temp = 2 : Readeeprom Temp4 , 346 : If Temp4 <> Temp Then Writeeeprom Temp , 346 : Full_charge = 1 : End If

'Equalization_charge 180 days
If Second = 10 And Minute = 1 And Hour = 10 And Blei_akku = 1 Then Incr Count_day
If Count_day >= 180 And Charge_to_14_4v = 0 Then
  Count_day = 0 : Equalization_charge = 1 : Temp = 3 : Readeeprom Temp4 , 346 : If Temp4 <> Temp Then Writeeeprom Temp , 346 : Full_charge = 1 : End If

'min min Spannung unterschritten->Pulsen
Readeeprom Temp , 260                                       'min min Spannung unterschritten->Pulsen
If U_batt_smooth <= Temp And Delay_u_min_min < 250 Then Incr Delay_u_min_min
If U_batt_smooth > Temp Then Delay_u_min_min = 0

'normal charging till Floating-charge
Normal_charge = 0
 If U_batt_smooth > Temp And Batt_pwm_charge = 0 And U_batt_smooth <= Voltage_stop_puls Then Normal_charge = 1       'more than Uminmin and less than Stop Pulse

'charge again to 13,8V without Pulses if Batt was less than 12,8 V
'Fully_load_till_stop_puls
 Voltage_pulse_start = Voltage_stop_puls - 10               '1 Volt Difference for Pulsation
If Charge_to_14_4v = 0 Then
If U_batt_smooth >= Voltage_stop_puls Then Fully_load_till_stop_puls = 0
If U_batt_smooth < Voltage_pulse_start Then Fully_load_till_stop_puls = 1

'Floating-charge: Pulsation-charging between 12,8V und 13,8 V
If U_batt_smooth >= Voltage_pulse_start And Fully_load_till_stop_puls = 0 Then Batt_pwm_charge = 1

''End Batt_PWM_charge
If U_batt_smooth < Voltage_pulse_start Or U_batt_smooth > Voltage_stop_puls Then Batt_pwm_charge = 0       ' 1.7.09
End If

'Cycle/Boost-Charge till 14,4 Volts
'End Full charge/Boost/Equalization_charge etc.
If Time_boost_charge >= Sp_time_boost_charge And Boost_charge = 1 Then       'Time Boost-charge End Or Boost_voltage = 0
  Batt_pwm_charge = 1 : Boost_charge = 0 : Temp = 0 : Writeeeprom Temp , 346 : Account_batterie = 0 : No_boost_charge_for = Sp_no_boost_charge_for : End If

If Time_boost_charge >= Sp_time_full_charge And Full_charge = 1 Then       'Time Boost-charge End Or Boost_voltage = 0
  Batt_pwm_charge = 1 : Full_charge = 0 : Account_batterie = 0 : No_boost_charge_for = Sp_no_boost_charge_for : End If

If Time_boost_charge >= Sp_time_equalization_charge And Equalization_charge = 1 Then       'Time Boost-charge End Or Boost_voltage = 0
  Batt_pwm_charge = 1 : Equalization_charge = 0 : Account_batterie = 0 : No_boost_charge_for = Sp_no_boost_charge_for : End If

If U_batt_smooth >= Boost_voltage And Charge_to_14_4v = 1 Then Boost_voltage_was_ok = 1
If U_batt_smooth < Voltage_stop_puls Then Boost_voltage_was_ok = 0

If Charge_to_14_4v = 0 Then
If Boost_voltage_was_ok = 0 Then Time_boost_charge = 0      'Reset Time for full charge
Else
If Boost_voltage_was_ok = 1 And U_batt_smooth >= Voltage_stop_puls And Second = 10 Then Incr Time_boost_charge       '
End If

Temp = Voltage_pulse_start                                  '12,8
'Calculate Pulses boost charge
If Charge_to_14_4v = 1 And Boost_voltage_was_ok = 1 Then
  Batt_pwm_charge = 1
  If Equalization_charge = 0 Then Readeeprom Temp3 , 274 Else Readeeprom Temp3 , 276       'Boost-Voltage : Temp3 = Temp3 + 5
  Temp = Temp3 - 10                                         '14,4-1,0 =13,4
End If

Temp = U_batt_smooth - Temp                                 'Bsp:'13,1-12,8=3 bzw. 14,2-134=8

Temp = 10 - Temp                                            'Bsp 13,1-12,8=3; bzw. 10-8=2
'If System_voltage_24v = 1 Then                              'Reverse, that means 12,8V = 10; 13,8V = 0
'   Temp = 20 - Temp : Temp = Temp / 2                       'only 0-10
'End If
'If System_voltage_48v = 1 Then                              'Reverse, that means 12,8V = 10; 13,8V = 0
'   Temp = 40 - Temp : Temp = Temp / 4                       'only 0-10
'End If

If Temp < 0 Then Temp = 0 : If Temp > 10 Then Temp = 10     '0 if 13,7V; 10 if 12,7V: 13,7-12.7=1,0V;

If Charge_to_14_4v = 1 And Boost_voltage_was_ok = 0 Then Temp = 10

'################# Network Master #########################
'I2c_output = Temp

'Print #1, "PWM-Value:"; : S = Str(Temp): Print #1, S '
'################# Network Slave #########################
'Readeeprom Temp3 , 188                                      ''188 = 69 Network: 0=0ff/1=Master/2=Slave
'If Temp3 = 2 Then                                           'Slave
'  Temp_b2 = I2c_input                                       'temp_b3 from seriell
'  Shift Temp_b2 , Right , 4                                 'left 4 bits: PWM-value; right 4 bits: 0 = no Solar_loading ; 1 = Solar_loading; 2= PWM-charge
'  Temp = Temp_b2                                            'PWM-value from Network
'End If
'##############################################################

'Slow_switching_time_on
Slow_switching_time_on = Temp * 6
Readeeprom Temp2 , 284                                      'Solar Relay active
If Temp2 > 0 Then                                           'Invers 'normally Relais off = loading; on = full
  Value = Slow_switching_time_on : Slow_switching_time_on = 60 - Value : End If

'fast PWM Pulse-loading between 12,8 und 13,8 V or when Pulse Cycle-Load
'If Temp < 4 Then Pwm_value = Temp * 8  'max 250 for PWM (255 = 0A!) but not linear!
'If Temp >= 4 and Temp <= 7 Then Pwm_value = Temp * 16
'If Temp > 7 Then Pwm_value = Temp * 25
 Pwm_value = Temp * 25

'if PWM-charging then check max. Amperes
'If Solar_loading = 1 and Batt_PWM_charge = 1 And Pwm_charging_on_by_user = 1 And Pwm_value > 0 And charge_to_14_4V  = 0 And Fkt9 = 0 Then       '
' Temp2 = temp 'save Pulses
' Stop_read_ai_extended = 1 : GoSub Disable_PWM
' Portb.2 = 0 : Portd.4 = 1 : Portd.5 = 1 : Analog_block = 5  'output to I Solar
' waitms 300 : I_solar_ai_14 = Getadc(7)
' GoSub Solar_stromwert
' Stop_read_ai_extended = 0
' I_Solar_max = I_Solar : I_Solar_calculated = I_Solar * Saved_PWM_Value : I_Solar_calculated = I_Solar_calculated / 10 'Saved_PWM_Value = 0...10 = 0-100%
' Saved_PWM_Value = Temp2 'save for next turn
'End If

'End If                                                      'if second = 30 ..

Solar_loading = 0 : Solar_loading_slow_pulses = 0

If Delay_on < 60 Then                                       'first Start loading
  Solar_loading = 1 : Solar_loading_slow_pulses = 1 : End If

'Umin min_charge
If Delay_u_min_min > 5 And Second > 40 Then
  Solar_loading = 1 : Solar_loading_slow_pulses = 1 : End If

'normal_charge
If Normal_charge = 1 Then
   Solar_loading = 1 : Solar_loading_slow_pulses = 1 : End If

'fast PWM
If Pwm_charging_on_by_user = 1 And Batt_pwm_charge = 1 And Pwm_value > 0 Then Solar_loading = 1       'dynamic Pulsation-loading Float-Charge or Cycle-Charge

'Boost-charge
If Charge_to_14_4v = 1 And U_batt_smooth < Boost_voltage Then
  Solar_loading = 1 : Solar_loading_slow_pulses = 1 : End If

'Slow Pulses
If Pwm_charging_on_by_user = 0 And Batt_pwm_charge = 1 And Second > Slow_switching_time_on Then Solar_loading_slow_pulses = 1       'Cycle-Charge
Readeeprom Temp , 284                                       'channels Solar
If Pwm_charging_on_by_user = 1 And Temp > 0 And Batt_pwm_charge = 1 And Second > Slow_switching_time_on Then Solar_loading_slow_pulses = 1       'Cycle-Charge

'Safety_interlocks:
'U_maxmax
Readeeprom Temp , 278                                       'maxmax Spannung
If U_batt_smooth >= Temp Then Umaxmax = 1                   'Blei_akku = 1

'If System_voltage_24v = 0 Then Temp = Boost_voltage + 4 Else Temp = Boost_voltage + 8       '0,4 Voltage above Boost-charge is max with Gel
'If Blei_akku = 0 And U_batt_smooth >= Temp Then Umaxmax = 1
'If Umaxmax = 1 and Delay_Umaxmax_off < 255 Then Incr Delay_Umaxmax_off : If Delay_Umaxmax_off < 30 Then Umaxmax = 0 : If Umaxmax = 0 Then Delay_Umaxmax_off = 0

If Umaxmax = 1 And Time_umaxmax < 255 Then Incr Time_umaxmax
If U_batt_smooth < Voltage_stop_puls And Time_umaxmax > 90 Then Umaxmax = 0       '***T 180 Delay 90 Sek till switch back
If Delay_on = 25 Then Umaxmax = 0

If Umaxmax = 1 Then
    Solar_loading = 0 : Solar_loading_slow_pulses = 0 : End If       'maxmax Spannung erreicht                       '

If Umaxmax = 1 And Flanke_u_max_max = 0 And Meldung_aktiv = 0 And Delay_on > 20 Then
  Meldung_aktiv = 1 : Flanke_u_max_max = 1 : Beep_ein = 3 : End If

If Flanke_u_max_max = 1 And Meldung_aktiv = 1 Then Gosub Display_umax_fault

If Solar_loading = 0 Or No_sun = 1 Then Pwm_value = 0       'PWM off

'Readeeprom Value , 296                                      'Triggered by Time?
'If Value = 0 And No_sun = 1 Then Solar_loading_slow_pulses = 0       '***14.11.07 Relais connected

'################################### Reverse connection? #############################################################

'Delay_no_sun = 0                                            'generate Delay no sun
'If No_sun = 1 And Time_delay_no_sun < 255 And Second = 10 Then Incr Time_delay_no_sun
'If No_sun = 0 Then Time_delay_no_sun = 0
'Readeeprom Temp , 222                                       '81 Delay no sun
'If Time_delay_no_sun > Temp Then Delay_no_sun = 1

If I_solar_ai_14 < 720 Or I_solar_ai_14 > 760 Then          'value if no charging
If Solar_loading = 1 Then
    Temp = I_solar_ai_14 - Zero_value_current               '570-563
    If Temp > 10 And Delay_switch_off_reverse_connect = 0 And Alarm_reverse_connect = 0 Then Delay_switch_off_reverse_connect = 20
    If Temp < 10 Then Delay_switch_off_reverse_connect = 0  '5 sec delay
 Else
   Delay_switch_off_reverse_connect = 0
 End If
End If
If Delay_switch_off_reverse_connect > 0 Then Decr Delay_switch_off_reverse_connect

'If Delay_switch_off_reverse_connect = 15 And Alarm_reverse_connect = 0 Then
' Alarm_reverse_connect = 1 : Lcd_param = 1 : Gosub Lcd_gotoline
'   Meldung_aktiv = 1 : Lcd_display_string = "Solar Reverse!!" : Gosub Lcd_display : Wait 2 : End If

'If Delay_switch_off_reverse_connect > 0 And Delay_switch_off_reverse_connect <= 15 And Delay_on > 5 Then       'Delay after reverse-Connect 5 sec
'      Solar_loading = 0 : Solar_loading_slow_pulses = 0 : End If       '***T
'################################### no sun? #############################################################
'Alle 30 Minuten Spannung vergleichen; Wenn Solarspannung < Batt-Spannung dann Laden aus
If Delay_on < 30 Or Simu = 1 Or Umaxmax = 1 Then Goto End_no_sun       'delay after switch on

Readeeprom Temp3 , 332 : If Temp3 = 0 And Temp2 > 0 Then Goto End_no_sun       'no PWM-charging; only Relay

'Readeeprom Value , 296 : If Value = 1 Then                  'Control Solar charge on/off by Timer
'  Temp_b1 = 8                                               'Readeeprom Temp_b1 , 16                                   '16 = hour sun-raise (9 o'clock)
'  Temp_b2 = 18                                              'Readeeprom Temp_b2 , 17                                   '17 = hour sun-set (18 o'clock)
'  No_sun = 0 : If Hour < Temp_b1 Or Hour > Temp_b2 Then
'    Solar_loading = 0 : Solar_loading_slow_pulses = 0 : No_sun = 1 : End If
'Goto End_no_sun : End If

If No_sun = 1 And Simu = 0 Then
   Solar_loading = 0 : Solar_loading_slow_pulses = 0 : End If       ' kein laden mehr

Temp_b1 = Minute_byte Mod 30                                'all 30 minutes
If Second <> 1 Or Temp_b1 <> 0 Then Goto End_no_sun
If Solar_loading = 1 Then                                   'there is actual no loading active
 If Batt_pwm_charge = 1 And Pwm_charging_on_by_user = 1 And Charge_to_14_4v = 0 Then       'if PWM charge then switch this off
    Gosub Disable_pwm : Wait 2 : End If
 Temp1 = I_solar_ai_14 - Zero_value_current                 'check voltage
 If Temp1 >= 0 And Temp1 < 150 Then No_sun = 1 Else No_sun = 0       '
Else
 Solar_loading = 1 : Gosub Disable_pwm : Gosub Output : Wait 3 : Solar_loading = 0       'loading on for Testing situation
 'Gosub Analog ->analog Inputs by Timer-Interrupts
 Temp1 = I_solar_ai_14 - Zero_value_current : If Temp1 > 150 Then Wait 2       'check voltage; wait longer if analog not yet finished
 Temp1 = I_solar_ai_14 - Zero_value_current
 If Temp1 >= 0 And Temp1 < 150 Then No_sun = 1 Else No_sun = 0
End If

End_no_sun:

'################# Network Master #########################
'Readeeprom Temp , 188                                       ''188 = 69 Network: 0=0ff/1=Master/2=Slave
'If Temp = 1 Then
' Temp_b1 = 0
' If Solar_loading = 1 Then Temp_b1 = 1
' If Pwm_charging_on_by_user = 1 And Solar_loading = 1 Then Temp_b1 = 2
' Temp_b2 = I2c_output : Shift Temp_b2 , Left , 4            'I2C-Output hat PWM-value from above
' Temp_b2 = Temp_b2 Or Temp_b1                               'left 4 bits: PWM-value; right 4 bits: 0 = no Solar_loading ; 1 = Solar_loading; 2= PWM-charge
'
'Temp_b3 = Second Mod 10                                     'all 10 sec
'If Temp_b3 = 0 Then
' I2csend Slave , Temp_b2 , 1                                'send the value , 1 Byte
'' waitms 250 : S=Str(I2C_Output) : Print #1, "I2C send:" ; S
'End If
'End If
'################# Network Slave #########################
'Readeeprom Temp , 188                                       ''188 = 69 Network: 0=0ff/1=Master/2=Slave
'If Temp = 2 Then                                            'Slave
''Slave = &H70                                                'slave address of a PCF 8574 I/O IC
''I2creceive Slave , I2C_Input , 1                                        'get the value see label below
'
' Temp_b1 = &B00001111 : Temp_b2 = I2c_input And Temp_b1     'right 4 bits: 0 = no Solar_loading ; 1 = Solar_loading; 2= PWM-charge
'
'Batt_PWM_charge = 0 : Solar_loading = 0
' If Temp_b2 = 1 Then Solar_loading = 1
' If Temp_b2 = 2 Then
'    Batt_PWM_charge = 1 : Solar_loading = 1 : End If
'
'If I2c_input_flag = 1 Then                                  'Supervising Coupling Time out
' I2c_input_flag = 0 : I2c_input_time = 0
'Else
' If I2c_input_time < 255 Then Incr I2c_input_time
'End If
'
'If I2c_input_time = 250 Then Writeeeprom Temp , 188         'Supervising Coupling Time out Reset Slave-Mode 188 = 69 Network: 0=0ff/1=Master/2=Slave
'
'End If
'##############################################################

'max_Temp
'Readeeprom Temp , 194                                        'Temp-max.
'Temp2 = Temp - 100                                          'Hysteresis 10.0 degrees
'If Sensor_2 < Temp2 Then Temp_alarm_trans = 0
'If Sensor_2 >= Temp Then Temp_alarm_trans = 1
'If Temp_alarm_trans = 1 And Temp <> 0 And Simu = 0 Then
' Solar_loading = 0 : Solar_loading_Slow_Pulses = 0 : End If     'max Temp erreicht (Alarmmeldung)

'temp_b1 = Second Mod 30
'If Simu = 1 And temp_b1 = 0 Then
' If Normal_charge = 1 Then Print #1 , "normal_charge "
' If Batt_PWM_charge = 1 Then Print #1 , "Batt_PWM_charge "
' If charge_to_14_4V  = 1 Then Print #1 , "Full_charge=1"
' If Equalization_charge = 1 Then Print #1 , "Equalization_charge=1"
' If No_sun = 1 Then Print #1 , "No_sun=1"
' If Umaxmax = 1 Then Print #1 , "Umaxmax=1"
' If Boost_voltage_was_ok = 1 Then Print #1 , "Boost_voltage_was_ok = 1"
' S = Str(pwm_value) : Print #1 "PWM-Value:" , S
' S = Str(slow_switching_time_on) : Print #1 "Slow Puls:" , S
' S = Str(time_boost_charge) : If Full_charge = 1 Then Print #1 "time_boost_charge" , S
'End If
Return

Display_umax_fault:
 Lcd_param = 1 : Gosub Lcd_gotoline : Lcd_display_string = "Batt-Voltage Max" : Gosub Lcd_display
 Gosub Line_feed
Return

Correct_solar_curr:
'If Delay_on_new_program < 255 Then Incr Delay_on_new_program : If Delay_on_new_program = 10 Then GoTo get_solar_value 'when new Programm loaded
If Fkt8 = 1 And Data_pointer = 34 And Eingabe_teil_2 = 1 Then Goto Get_solar_value       'Input of Solar OP-Amp-Value
'If get_solar_value = 0 And Hour = 20 And Minute = 1 And Second = 10 Then  '14.2.2007
'  get_solar_value = 1 : GoTo get_solar_value : End If 'Get_Value by Time after switch on
Return

Get_solar_value:
Gosub Disable_pwm : Stop_read_ai_extended = 1 : Portb.7 = 0 : Portb.2 = 0 : Portd.4 = 1 : Portd.5 = 1 : Analog_block = 5 : Waitms 700 : I_solar_ai_14 = Getadc(7)
Stop_read_ai_extended = 0
If I_solar_ai_14 < 500 Or I_solar_ai_14 > 650 Then Return   'reasonable value?
Readeeprom Value , 328 : If I_solar_ai_14 <> Value Then Writeeeprom I_solar_ai_14 , 328
Return

'additional_device_on if battery is full
'Additional_device:
'Readeeprom U_additional_dev_on , 300
'If U_additional_dev_on = 0 Then Return
'If U_batt_smooth > U_additional_dev_on And Delay_add_device_on < 255 Then Incr Delay_add_device_on
'Temp = U_additional_dev_on - 10                             'minus 1.0 Volt
'If U_batt_smooth <= Temp Then Delay_add_device_on = 0
''If Delay_add_device_on > 60 Then Relais_3 = 1               '
'Return

'Over_current_load:
'If Delay_on < 30 Or Fkt9 = 1 Then Return
'If I_load > I_load_max_value Then Time_i_load_max_value = Time_switch_off_overcurrent       'second time_switch_off_overcurrent
'If Time_i_load_max_value = 0 Then Return
'Output_1 = 0 : Load_2 = 0 : Load_3 = 0 : : Load_4 = 0 : : Load_5 = 0
'Return

'Over_current_solar:
'If Delay_on < 30 Or Fkt9 = 1 Then Return
'If I_solar > I_solar_max_value Then Time_i_solar_max_value = Time_switch_off_overcurrent       'second switch off by overcurrent
'If Time_i_solar_max_value <> 0 Then Solar_loading = 0
'Return

Ah_u_min_max:
If Second = 10 Then
If Solar_loading = 1 And I_solar > 0 And I_solar <= 700 Then Sum_ah_solar = Sum_ah_solar + I_solar       'aufsummieren des Solar-Stroms alle sec
If I_load <= 500 Then Sum_ah_load = Sum_ah_load + I_load    'aufsummieren des Solar-Stroms alle sec
'If I_load_1 <= 500 Then Sum_ah_load_1 = Sum_ah_load_1 + I_load_1       'aufsummieren des Solar-Stroms alle sec
'If I_load_2 <= 500 Then Sum_ah_load_2 = Sum_ah_load_2 + I_load_2       'aufsummieren des Solar-Stroms alle sec

If Minute = 10 Then
Sum_ah_solar = Sum_ah_solar / 60 : Value_ah_solar = Value_ah_solar + Sum_ah_solar : Ah_solar_day = Ah_solar_day + Sum_ah_solar : Sum_ah_solar = 0
Value_wh_solar = Value_ah_solar * U_batt_smooth : Value_wh_solar = Value_wh_solar / 10 : Wh_solar_day = Ah_solar_day * U_batt_smooth : Wh_solar_day = Wh_solar_day / 10

Sum_ah_load = Sum_ah_load / 60 : Value_ah_load = Value_ah_load + Sum_ah_load : Ah_load_day = Ah_load_day + Sum_ah_load : Sum_ah_load = 0
Value_wh_load = Value_ah_load * U_batt_smooth : Value_wh_load = Value_wh_load / 10 : Wh_load_day = Ah_load_day * U_batt_smooth : Wh_load_day = Wh_load_day / 10

'Sum_ah_load_1 = Sum_ah_load_1 / 60 : Value_ah_load_1 = Value_ah_load_1 + Sum_ah_load_1 : Ah_load_day_1 = Ah_load_day_1 + Sum_ah_load_1 : Sum_ah_load_1 = 0
'Value_wh_load_1 = Value_ah_load_1 * U_batt_smooth : Value_wh_load_1 = Value_wh_load_1 / 10 : Wh_load_day_1 = Ah_load_day_1 * U_batt_smooth : Wh_load_day_1 = Wh_load_day_1 / 10

'Sum_ah_load_2 = Sum_ah_load_2 / 60 : Value_ah_load_2 = Value_ah_load_2 + Sum_ah_load_2 : Ah_load_day_2 = Ah_load_day_2 + Sum_ah_load_2 : Sum_ah_load_2 = 0
'Value_wh_load_2 = Value_ah_load_2 * U_batt_smooth : Value_wh_load_2 = Value_wh_load_2 / 10 : Wh_load_day_2 = Ah_load_day_2 * U_batt_smooth : Wh_load_day_2 = Wh_load_day_2 / 10

Account_batterie = Account_batterie + Value_wh_solar : Account_batterie = Account_batterie - Value_wh_load
End If
End If

If U_batt_smooth > U_max_day Then U_max_day = U_batt_smooth
If Delay_on <= 30 Then U_min_day = U_batt_smooth
If U_batt_smooth < U_min_day And U_batt_smooth > 0 Then U_min_day = U_batt_smooth

If Second = 10 And Minute = 59 And Hour = 23 Then
 Ah_solar_day = 0 : Ah_load_day = 0 : Ah_load_day_1 = 0 : Ah_load_day_2 = 0 : U_max_day = U_batt_smooth : U_min_day = U_batt_smooth : Wh_solar_day = 0 : Wh_load_day = 0 : Wh_load_day_1 = 0 : Wh_load_day_1 = 0 : End If
Return

'Call by Handy
Mobile:
Lcd_param = &B00000001 : Gosub Lcd_writecmd
If English = 0 Then Lcd_display_string = "Anrufen!" Else Lcd_display_string = "Call Mobile" : No_print_seriell = 1 : Gosub Lcd_display : Waitms 500
Print #1 , "ATDT";                                          'write to SMS to memory
Gosub Get_pointer_to_tel_number
Temp_b2 = Pointer_eeprom : Temp_b3 = Pointer_eeprom + 14
For Pointer_eeprom = Temp_b2 To Temp_b3
Readeeprom Temp_b1 , Pointer_eeprom
If Temp_b1 = 11 Then Goto End_mobile
 Print #1 , Temp_b1;
Next
End_mobile:
Print #1 , ";"
If Test_anruf = 1 Then Wait 1
Return

Modem_call:
Remote_key = Inkey(#1)
'If Remote_key = 123 Then Goto &HFC00                        'Upload new Programm
If Remote_key = 123 Then Goto &H1FC00                       '***M256
If Time_no_seriell_pc > 0 Or Delay_on < 5 Then Mobile_aktiv = 0
If Time_no_seriell_pc > 0 Then Return
If Remote_key_old <> Remote_key And Mobile_aktiv = 0 And Vb_process_display = 0 And Delay = 0 Then Delay = 20

If Remote_key = "S" Then
  Mobile_aktiv = 1 : Data_direct_to_pc = 0 : End If         '83 if there is just seriell connection 83="S" send

'If Programm_selector <> Programm_selector_old_2 Then Display_all_data = 0
'Programm_selector_old_2 = Programm_selector

'If Mobile_aktiv = 0 Then Display_all_data = 0
'If Display_all_data > 0 And Display_all_data < 10 Then Vb_process_display = 1       'show at the beginning
'If Display_all_data = 10 Then Vb_process_display = 0

If Remote_key = "O" Then Vb_process_display = 1             'Display in Process-View
If Remote_key = "E" Then
  Mobile_aktiv = 1 : Vb_process_display = 0 : Sending_os_data_active = 0 : End If       'finsih Display in Process-View

If Remote_key = "R" Then
  Mobile_aktiv = 0 : Vb_process_display = 0 : Block_count_send = 0 : Sending_os_data_active = 0 : End If       '82 nach 20 Sek auflegen oder "R" empfangen

If Remote_key = "U" Then                                    'Data direct for Logging
  Data_direct_to_pc = 1 : Vb_process_display = 0 : Mobile_aktiv = 0 : End If       'Direct send of Data

Temp1 = 262 : Temp2 = 410                                   'Parameters 1-79
If Remote_key = "V" Then Gosub Load_flash_to_file_on_hd     'Upload
If Remote_key = "W" Then Gosub Get_data_for_flash           'download data to flash

Dim No_send_end As Bit
Temp1 = 501 : Temp2 = 698                                   'Parameters  Universal channel
If Remote_key = "X" Then
 No_send_end = 1 : Gosub Load_flash_to_file_on_hd           'Upload
Temp1 = 901 : Temp2 = 1098                                  'Parameters  Universal channel
 Gosub Load_flash_to_file_on_hd                             'Upload
End If

If Remote_key = "Y" Then
 Gosub Get_data_for_flash                                   'download data to flash
Temp1 = 901 : Temp2 = 1098                                  'Parameters  Universal channel
 Gosub Get_data_for_flash                                   'download data to flash
End If

If Remote_key >= 48 And Remote_key < 58 Then Mobile_aktiv_counter = 0
If Remote_key = 122 Or Remote_key = 111 Then Mobile_aktiv_counter = 0
'If Remote_key_old <> Remote_key Then Mobile_aktiv_counter = 0
Remote_key_old = Remote_key
Return

Incoming_call:
If Delay = 15 And Mobile_aktiv = 0 And Vb_process_display = 0 And Data_direct_to_pc = 0 Then Print #1 , "ATA"       'accept Telefone
'If Delay = 15 And Mobile_aktiv = 0 Then Gosub Reset         'goto groundmenu
'If Delay = 1 And Vb_process_display = 0 Then Mobile_aktiv = 1
If Mobile_aktiv = 0 And Sending_os_data_active = 0 And Data_direct_to_pc = 0 Then
  If Delay = 1 Or Remote_key = 83 Then Print #1 , "CO" : End If       '"Connect" as acknowledge
If Delay > 0 Then Decr Delay
If Mobile_aktiv = 1 Then Incr Mobile_aktiv_counter
If Mobile_aktiv = 1 And Mobile_aktiv_counter > 240 And Vb_process_display <> 1 Then Mobile_aktiv = 0
If Mobile_aktiv = 0 Then Mobile_aktiv_counter = 0
Return

Daten_schreiben:
Readeeprom Temp , 348                                       'SD_Card present
If Temp <> Sd_card_active And Temp = 1 Then
    Value = 0 : Readeeprom Temp4 , 352 : If Temp4 <> Value Then Writeeeprom Value , 352 : Minit : End If       'Initialize the MMCC
Sd_card_active = Temp
Readeeprom Value , 322 : Temp_b1 = Value                    'Scan-Time Data-Recorder
If Temp_b1 = 0 Then Return
If Temp_b1 >= 60 And Temp_b1 < 100 Then Temp_b1 = 59        '> 60 sek does not work
If Temp_b1 > 100 Then Temp_b1 = Temp_b1 - 100
If Temp_b1 > 100 Then Temp_b1 = Temp_b1 - 100
Temp = Second Mod Temp_b1
If Value < 100 And Temp = 0 Then Goto To_ram
Temp = Minute_byte Mod Temp_b1
If Value >= 100 And Value < 200 And Second = 10 And Temp = 0 Then Goto To_ram
Temp = Hour Mod Temp_b1
If Value > 200 And Second = 10 And Minute = 1 And Temp = 0 Then Goto To_ram
Return

To_ram:
If Ram_full = 1 Then Goto To_eeprom
If Zeiger_ram < 1 Then Zeiger_ram = 1                       'Start-Wert ab 1
If Zeiger_ram > Pointer_end_ram Then                        'was there a fill-up?
  Ram_full = 1 : Ram_second_time = 1 : Eeprom_full = 0 : Zeiger_ram = 1 : Zeiger_flash = 400 : Goto To_eeprom : End If

Temp_b1 = Number_of_scans
Write_ram = 1 : Gosub Log_data

Readeeprom Temp , 348                                       'SD_Card presents
If Temp = 1 And Zeiger_ram > 512 Then                       '512 Byte Memory is full
 Adr1 = &H00000000 : Mmc_print = 0 : Mread                  '512 , Adr1 ''new SD-Card? read First Block
Temp_b1 = Indat(368) : Temp = Temp_b1 : Shift Temp , Left , 8 : Temp_b1 = Indat(369) : Temp1 = Temp_b1 : Value = Temp Or Temp1       'Pointer Flash
If Value < 1 Or Value > 62000 Then                          'Pointer to 0 again
   Value = 0 : Writeeeprom Value , 352 : Minit : End If
Zeiger_ram = 1                                              ': Print #1, "write_to_flash"
Readeeprom Value , 352 : Incr Value : If Value > 62000 Then Value = 1 : Writeeeprom Value , 352       'Block-Nr
For I = 1 To 512                                            'Read all EEPROM-Data 'I = 1
 Readeeprom Temp_b1 , I : Indat(i) = Temp_b1 : Next I
Write_header = 1 : Adr1 = &H00000000 : Mwrite               'Header 1-512

Readeeprom Value , 352 : Adr1 = Value * 512                 ': S = Str(adr1) : Print #1, "adr1:"; S
Write_header = 0 : Mwrite                                   'Adr1  'Now data
End If
Return

To_eeprom:
If Zeiger_flash < 1100 Then Zeiger_flash = 1100             '*** Start-Wert ab 1100
If Zeiger_flash >= 4000 Then                                'was there a fill-up?
Eeprom_full = 1 : Eeprom_second_time = 1 : Ram_full = 0 : Zeiger_ram = 1 : Zeiger_flash = 1100 : Goto To_ram : End If

Temp_b1 = Number_of_scans
Write_ram = 0 : Gosub Log_data
Return

Log_data:
Kein_komma = 0
For Channel_nr = 1 To Temp_b1
  Value = Analog_input_channel(channel_nr) : Gosub Write_ram : Next

Value = U_batt_smooth
If Number_of_scans > 6 Then Gosub Write_ram

Value = I_solar
If Number_of_scans > 7 Then Gosub Write_ram                 'Humidity_temp

 Value = Wind_speed
If Number_of_scans > 8 Then Gosub Write_ram                 'Wind If Wind_sensor_detect = 1 Then

Value = Elv_temp
If Number_of_scans > 9 Then Gosub Write_ram                 'Temp

Kein_komma = 1
Value = Elv_humidity
If Number_of_scans > 10 Then Gosub Write_ram                'If Temp_sensor_detect = 1 Then

Value = Elv_rain
If Number_of_scans > 11 Then Gosub Write_ram                'If Rain_sensor_detect = 1 Then

Readeeprom Temp , 338 : Value = Temp * Sum_freq3 : Value = Value / 10
If Number_of_scans > 12 Then Gosub Write_ram
Return

Write_ram:
If Write_ram = 0 Then                                       'Write_Flash?
Writeeeprom Value , Zeiger_flash : Incr Zeiger_flash : Incr Zeiger_flash : Return : End If

Temp3 = Value : Shift Temp3 , Right , 8 : Temp_b1 = Temp3 : Temp3 = Value : Shift Temp3 , Left , 8 : Shift Temp3 , Right , 8 : Temp_b2 = Temp3       '16 bit to 2 Bytes
A(zeiger_ram) = Temp_b1                                     '1.Byte
Incr Zeiger_ram
A(zeiger_ram) = Temp_b2                                     '2.Byte
Incr Zeiger_ram
Return

Data_to_pc:
'Dim Send_datas_first_cycle as bit
Dim Last_value As Bit

'If Vb_process_display = 0 Then Send_datas_first_cycle = 0

If Mobile_aktiv = 0 And Vb_process_display = 0 And Data_direct_to_pc = 0 Then Return
If Vb_process_display = 1 Then
 If Count_data_to_pc = 4 Or Count_data_to_pc = 5 Then Mobile_aktiv = 0 : End If

If Count_data_to_pc < 5 Then
 Block_count_send = 0 : Sending_os_data_active = 0 : Return : End If
Incr Block_count_send
If Block_count_send > 3800 And M_second < 30 Then Block_count_send = 0

Kein_komma = 0

Select Case Block_count_send
'$1;1;;;;;;21,0;;;;;;;;55;;;;20,8;50;1,6;0;0;0 Open Format
Case 10:
If Data_direct_to_pc = 0 Then
 Print #1 , "S_" : Waitms 100
Else
 Print #1 , "$1;1;;" ; : Block_count_send = 130
End If

Case 30:
If Meldung_aktiv = 1 Then                                   'Display that there ia Alarm
 Value = Programm_selector + 101
Else
 Value = Programm_selector + 1
End If
Print #1 , Value

If Vb_process_display = 0 And Block_count_send < 470 Then Block_count_send = 470       'goto end

Case 60:
Mobile_aktiv = 0 : Sending_os_data_active = 1               'no other Data send to PC
Value = Output_digital_1 + 1000 : Print #1 , Value

Case 90:
Value = Output_digital_2 + 1000 : Print #1 , Value

Case 120:
Value = Inputs + 1000 : Print #1 , Value

Case 150:                                                   'actual Values channel
For Channel_nr = 1 To 6                                     ''Analog 1-6
  Value = Analog_input_channel(channel_nr) : Gosub Send_value_to_serial : Waitms 60 : Next

Case 180:                                                   'Analog_7
Value = U_batt_smooth : Gosub Send_value_to_serial

Case 210:                                                   'Analog_8
Value = I_solar : Gosub Send_value_to_serial

Case 240:                                                   'Analog_9
 Value = Wind_speed : Gosub Send_value_to_serial

Case 270:                                                   'Analog_10
Value = Elv_temp : Gosub Send_value_to_serial

Case 300:                                                   'Analog_11
Kein_komma = 1 : Value = Elv_humidity : Gosub Send_value_to_serial

Case 330:                                                   'Analog_12
Value = Elv_rain : Gosub Send_value_to_serial

Case 360:                                                   'Counter
Readeeprom Temp , 338 : Value = Temp * Sum_freq3 : Value = Value / 10 : Gosub Send_value_to_serial

Case 390:                                                   'Ext_temperature free 11
If Data_direct_to_pc = 1 Then
  Last_value = 1 : Block_count_send = 470 : End If          'not the next data!
Value = Ext_temperature : Gosub Send_value_to_serial

Case 420:                                                   'Setpoint Channel 'Analog_14,15, Free_1-4
For Channel_nr = 1 To 6
 Temp5 = Channel_nr * 10 : Temp4 = Temp5 + 895 : Readeeprom Setpoint , Temp4       'Setpoint Humidity from EEprom
  Value = Setpoint : Gosub Send_value_to_serial : Next

Case 450:                                                   'Input-Nr Channel
'Send_datas_first_cycle = 1
For Channel_nr = 1 To 6                                     'free 5-10
 Pointer_eeprom = Channel_nr * 10 : Pointer_eeprom = Pointer_eeprom + 491 : Readeeprom Temp_b1 , Pointer_eeprom       'Channel 1: Input 1
  Value = Temp_b1 : Kein_komma = 1 : Gosub Send_value_to_serial : Next

'W Solar
'Temp_l1 = I_solar : Temp_l2 = U_batt_smooth : Temp_l1 = Temp_l1 * Temp_l2 : Temp_l1 = Temp_l1 / 100.0 'z.B. 28.8V * 20.0A
'Value = Temp_l1 : If Value < 0 Then Value = 0 : Kein_komma = 1 : Gosub Print_value :If VB_Process_Display = 1 Then Print #1 , ""
''W Load
'Temp_l1 = I_load : Temp_l2 = U_batt_smooth : Temp_l1 = Temp_l1 * Temp_l2 : Temp_l1 = Temp_l1 / 100.0 'z.B. 28.8V * 20.0A
'Value = Temp_l1 : If Value < 0 Then Value = 0 : Kein_komma = 1 : Gosub Print_value :If VB_Process_Display = 1 Then Print #1 , ""           'back to integer
'
'Value = Value_ah_solar : Kein_komma = 1 : Gosub Print_value :If VB_Process_Display = 1 Then Print #1 , ""
'Value = Value_wh_solar : Kein_komma = 1 : Gosub Print_value :If VB_Process_Display = 1 Then Print #1 , ""
'Value = Wh_solar_day : Kein_komma = 1 : Gosub Print_value :If VB_Process_Display = 1 Then Print #1 , ""
'
'Value = Value_ah_load : Kein_komma = 1 : Gosub Print_value :If VB_Process_Display = 1 Then Print #1 , ""
'Value = Value_wh_load : Kein_komma = 1 : Gosub Print_value :If VB_Process_Display = 1 Then Print #1 , ""
'Value = Wh_load_day : Kein_komma = 1 : Gosub Print_value :If VB_Process_Display = 1 Then Print #1 , ""
'
'Value = U_max_day :  Gosub Print_value :If VB_Process_Display = 1 Then Print #1 , ""
'Value = U_min_day :  Gosub Print_value :If VB_Process_Display = 1 Then Print #1 , ""
''SOC
'Temp2 = Account_batterie / 10 : Value = 1000 + Temp2 : Value = Value * Temp : Value = Value / 10 : If Value > 2000 Then Value = 0
'Gosub Print_value :If VB_Process_Display = 1 Then Print #1 , ""
''Temp
'value = Sensor_4 : Gosub Print_value :If VB_Process_Display = 1 Then Print #1 , ""

Case 480:
End_data_to_pc:
If Data_direct_to_pc = 0 Then
 Print #1 , "E_"                                            'If Vb_process_display = 0 Then
 'Waitms 280
  Count_data_to_pc = 0
 No_display_basic_menu = 1
 Mobile_aktiv = 1
 Sending_os_data_active = 0
Else
 Printbin #1 , 13                                           ' CR ""
 Printbin #1 , 10                                           'LF
End If

End Select
Return

'########################### Read Data and send to PC ###################################
Daten_auslesen:
If Remote_key <> 76 And Send_flash_to_logview = 0 Then Return       'L gesendet?
If Zeiger_ram <= 1 Then Ram_second_time = 0 : Zeiger_ram_end = Zeiger_ram       'Ende-zeiger
If Ram_second_time = 0 Then Zeiger_ram = 1                  'Anfang
End_pointer_flash = Zeiger_flash                            'Ende-zeiger
If Eeprom_second_time = 0 Then Zeiger_flash = 1100          '*** Anfang -2

'data_header:
If Send_flash_to_logview = 0 Then
If English = 0 Then Print #1 , "Messwerte" ; Else Print #1 , "Measured Values" ;
Waitms 50
If English = 0 Then Print #1 , " Datum: " ; Else Print #1 , " Date: ";
Print #1 , Month;
Print #1 , ".";
Print #1 , Day;
Print #1 , "  ";
If English = 0 Then Print #1 , " Zeit: " ; Else Print #1 , " Time: ";
Print #1 , Hour;
Print #1 , ":";
Print #1 , Minute
Waitms 40

Print #1 , "Min Value Analog Input";
Gosub Display_min_value
Print #1 , " "
Waitms 40
Print #1 , "Max Value Analog Input";
Gosub Display_max_value
Print #1 , " "
Waitms 70
Print #1 , "Runtime Output: ";
Gosub Display_run_time
Print #1 , " "
Waitms 40
Readeeprom Temp , 348 : If Temp = 0 Then Gosub Print_header_data       'SD_Card present
End If                                                      'If Send_Flash_to_Logview = 0 Then

'########################### Read from RAM #################
Loop_read_ram:
Readeeprom Temp , 348                                       'SD_Card present
If Temp = 1 Then                                            '512 Byte Memory is full
 Block_nr_read = 0 : Read_header = 1 : Adr1 = &H00000000
Loop_read_sd_card:
  Remote_key = Inkey(#1) : If Remote_key = 67 Then Goto Loop_read_ram_end       'C from PC for cancel?
  Mmc_print = 1 : Mread                                     '512 , Adr1 'First Block
  Adr1 = Adr1 + 512
If Adr1 >= 512 Then
     Read_header = 0 : Temp_b1 = Indat(368) : Temp = Temp_b1 : Shift Temp , Left , 8 : Temp_b1 = Indat(369) : Temp1 = Temp_b1 : Value = Temp Or Temp1       'Pointer Flash
     If Value < 1 Or Value > 62000 Then Readeeprom Value , 352       'No resonalbe value in MMC; then take it from M128
End If
     Incr Block_nr_read : If Block_nr_read <= Value Then Goto Loop_read_sd_card Else Goto Loop_read_ram_end
End If

If Zeiger_ram < 1 Then Zeiger_ram = 1                       'reasonable values
If Ram_full = 0 And Ram_second_time = 0 And Eeprom_second_time = 0 And End_pointer_flash <= 1100 Then
 If Zeiger_ram >= Zeiger_ram_end Or Zeiger_ram > Pointer_end_ram Then Goto Loop_read_ram_end : End If       'Ende?

If Zeiger_ram > Pointer_end_ram Then
'Print #1 , "now Flash"
  Zeiger_ram = 1 : Zeiger_flash = 1100 : Ram_full = 0 : Eeprom_second_time = 0 : Goto Loop_read_flash : End If

Gosub Print_logview_header
For Temp_b3 = 1 To Temp_b5
Temp_b1 = A(zeiger_ram) : Temp2 = Temp_b1                   'Value 1.2....
Incr Zeiger_ram
Temp_b2 = A(zeiger_ram) : Temp3 = Temp_b2 : Shift Temp2 , Left , 8 : Value = Temp2 Or Temp3 : Gosub Print_log
Incr Zeiger_ram
Next
Gosub Print_new_line
Goto Loop_read_ram

Loop_read_ram_end:
Value = 0 : Writeeeprom Value , 352                         'Reset pointer write SD-Card
Readeeprom Temp , 348                                       'SD_Card present
If Temp = 1 Then Minit                                      '512 Byte Memory is full
Gosub Print_end
Return

Loop_read_flash:
If Zeiger_flash < 1100 Then Zeiger_flash = 1100             'reasonable values
If Ram_full = 0 And Ram_second_time = 0 Then                'No data in Flash
 If Zeiger_flash >= End_pointer_flash Or Zeiger_flash > 4000 Then Goto Loop_read_flash_end : End If       'Ende?

If Zeiger_flash > 4000 Then
Print #1 , "now RAM"
  Eeprom_full = 0 : Zeiger_ram = 1 : Zeiger_flash = 1100 : Eeprom_second_time = 0 : End_pointer_flash = 1100 : Ram_second_time = 0 : Goto Loop_read_ram : End If

Gosub Print_logview_header
For Temp_b3 = 1 To Temp_b1
Readeeprom Value , Zeiger_flash : Gosub Print_log
Incr Zeiger_flash : Incr Zeiger_flash
Next

Gosub Print_new_line
Goto Loop_read_flash
Loop_read_flash_end:
Gosub Print_end
Return

Print_logview_header:
If Send_flash_to_logview = 1 Then Print #1 , "$1;1;;";
Temp_b5 = Number_of_scans
If Number_of_scans < 1 Or Number_of_scans > 13 Then Temp_b5 = 2
Return

Print_log:
Kein_komma = 0 : Gosub Print_value : If Send_flash_to_logview = 0 Then Print #1 , "  " ; Else Print #1 , ";";
Return

Print_new_line:
If Send_flash_to_logview = 0 Then
 Print #1 , " "
 Else
 Print #1 , "0";                                            'new line
 Printbin #1 , 13                                           ' CR ""
 Printbin #1 , 10                                           'LF
 Waitms 50
End If
Waitms 150                                                  '40
Return

Print_end:
If Send_flash_to_logview = 0 Then Print #1 , "End"
Temp = 0 : Writeeeprom Temp , 296                           'Reset Data Send to Logview
Zeiger_ram = 1
Zeiger_flash = 1100
Ram_full = 0
Eeprom_full = 0
Ram_second_time = 0
Eeprom_second_time = 0
Return

Send_value_to_serial:
Gosub Print_value : If Vb_process_display = 1 Then Print #1 , "" : If Data_direct_to_pc = 1 Then Print #1 , ";" ; : If Last_value = 1 Then Print #1 , "0" ; : Last_value = 0
Return

'################################ Load_flash_to_file_on_hd ############################################################
Load_flash_to_file_on_hd:
'Temp1 = start-adr; Temp2 = end-adr
Pointer_eeprom = Temp1
For Pointer_eeprom = Temp1 To Temp2
Readeeprom Temp , Pointer_eeprom
Print #1 , Temp
Incr Pointer_eeprom
Waitms 200
Next
Waitms 100
If No_send_end = 0 Then Print #1 , "End" : No_send_end = 0
Return
'################################ Get_data_for_flash ############################################################
Get_data_for_flash:                                         'message-Text
'Dim loop_counter as Integer
'Temp1 = start-adr; Temp2 = end-adr
'Waitms 300
'cli                                                         'Disable Interrupt
Temp = 0                                                    'Time-out
Temp_b3 = 0                                                 'number of Bytes
Lcd_display_string = ""
Pointer_eeprom = Temp1
For Pointer_eeprom = Temp1 To Temp2                         '368 Bytes 16*(15+8)
Loop_wait_inkey:
Remote_key = Inkey(#1)                                      'get it
 Temp = Temp + 1
Waitus 100
  If Temp > 32000 Then Goto Show_counter                    'Timeout
 If Remote_key = 0 Then
    Goto Loop_wait_inkey
Else                                                        'there is data
   If Remote_key > 47 And Remote_key < 58 Then
      Incr Temp_b3                                          'count sign
      Remote_key = Remote_key - 48 : S = Str(remote_key)
      Lcd_display_string = Lcd_display_string + S : Goto Loop_wait_inkey : End If
  If Remote_key = 10 Or Remote_key = 13 Then
     Value = Val(lcd_display_string)
     Writeeeprom Value , Pointer_eeprom : Incr Pointer_eeprom : Temp = 0 : Lcd_display_string = "" : Waitms 60 : End If       'cr
End If
Next

Show_counter:
'sei                                                         'Enable Interrupt
Lcd_param = 1 : Gosub Lcd_gotoline
If Temp_b3 > 40 Then Lcd_display_string = "ok!" Else Lcd_display_string = "not ok!"
Do_not_accept_keyboard_by_serial = 15                       '15 sec no Input
Lcd_display_pad_with_spaces = 1 : Gosub Lcd_display
Gosub Line_feed
Wait 3
Return

'######################## check_min_max_runtime: ####################
Check_min_max_runtime:
'Min_value
Dim Min_value_nr_old As Byte
Readeeprom Temp , 404 : Temp_b1 = Temp                      'Input-Nr Min 1
Temp_b2 = 0                                                 'check for output
Gosub Map_analog
If Value < Min_value_1_old And Value > 0 Then
  Min_value_1 = Value : End If
Min_value_1_old = Value
If Delay_on < 10 Or Min_value_1 = 0 Then Min_value_1 = Value

'Max_value
Dim Max_value_nr_old As Byte
Readeeprom Temp , 406 : Temp_b1 = Temp                      'Input-Nr Max 1
Temp_b2 = 0                                                 'check for output
Gosub Map_analog
If Value > Max_value_1_old And Delay_on > 10 Then
  Max_value_1 = Value : End If
Max_value_1_old = Value
If Temp_b1 <> Max_value_nr_old Then                         'Reset with output 0
  Max_value_1 = 0 : Max_value_nr_old = Temp_b1 : End If

Dim Run_time_nr_old As Byte
Readeeprom Temp , 408 : Temp_b1 = Temp                      'Run-Time hrs
Temp_b2 = 1                                                 'check for output
Gosub Map_analog
If Value = 999 Then Incr Running_time_1_sec                 'means output on
If Running_time_1_sec > 60 Then
 Incr Running_time_1 : Running_time_1_sec = 0 : End If
If Temp_b1 <> Run_time_nr_old Then                          'Reset with output 0
  Running_time_1 = 0 : Running_time_1_sec = 0 : Run_time_nr_old = Temp_b1 : End If
Return

'################################# SMS-Function ###############################################################
Receive_sms:                                                'SMS: 3 bytes Password:Meta, then 1e d.h. Meta1e = Relais 1 on; 1a=Relais 1 off etc
If Fkt1 = 1 Or Fkt2 = 1 Or Fkt3 = 1 Or Fkt4 = 1 Or Fkt5 = 1 Or Fkt6 = 1 Or Fkt7 = 1 Or Fkt8 = 1 Or Disp_fkt9 = 1 Or Mobile_aktiv = 1 Or Vb_process_display = 1 Or Data_direct_to_pc = 1 Then Return       'andere FKT angew?
'+CMGL: 3,0,,25
'0791947101670000040C9194719580108700007021303262054006CD323D7C8B01
Readeeprom Temp2 , 104 : If Temp2 = 1 Then Mobile_aktiv = 0 'Receive SMS activated-> no Data -> PC
'  Temp = Second Mod 60 : If Temp <> 0 Then Return           'all 60 seconds '***T
If Temp2 <> 1 Or Telephone_on = 1 Or Time_no_seriell_pc > 0 Then Return       'activ?
Lcd_param = 1 : Gosub Lcd_gotoline                          '***T 1.Zeile des Displays wird aktiviert
Lcd_display_string = "0" : No_print_seriell = 1 : Gosub Lcd_display
Stop_read_ai_extended = 1                                   'Analog extended off
  Print #1 , "AT+CMGL"                                      'read SMS from Handy
  Zaehler = 0
Lcd_display_string = "" : No_print_seriell = 1 : Gosub Lcd_display
Repeat_inkey:
  Remote_key = Inkey(#1)
  Zaehler = Zaehler + 1 : If Zaehler > 32000 Then           'Timeout
   Stop_read_ai_extended = 0 : Return : End If              'loop only xx times= Timout
'Kennung: 323D: 48=0; d.h.Kennung: 51; 50; 51; 68
If Remote_key <> "3" Then Goto Repeat_inkey
Lcd_display_string = "1" : No_print_seriell = 1 : Gosub Lcd_display
Remote_key = Inkey(#1)
If Remote_key <> "2" Then Goto Repeat_inkey
Lcd_display_string = "2" : No_print_seriell = 1 : Gosub Lcd_display
Remote_key = Inkey(#1)
If Remote_key <> "3" Then Goto Repeat_inkey
Lcd_display_string = "3" : No_print_seriell = 1 : Gosub Lcd_display
Remote_key = Inkey(#1)                                      'now "D"
If Remote_key <> "D" Then Goto Repeat_inkey
Lcd_display_string = "4" : No_print_seriell = 1 : Gosub Lcd_display
  '7C8 B01 Meta71
  '7C8 301 Meta70
  '6C8 B01 Meta61
  '6C8 301 Meta60
  '1CA E03 Metaau
Now_information:                                            'now the data are coming
  Remote_key = Inkey(#1)                                    '7
  Temp_b1 = Inkey(#1)                                       'C                                    '2.Byte
  Temp_b1 = Inkey(#1)                                       '8
  Temp_b1 = Inkey(#1)                                       'B
Stop_read_ai_extended = 0
Lcd_param = 1 : Gosub Lcd_gotoline                          '1.Zeile des Displays wird aktiviert
Lcd_display_string = "SMS ok" : No_print_seriell = 1 : Gosub Lcd_display : Wait 1       '***T for Test
If Remote_key = "7" Then
 If Temp_b1 = 66 Then
 Relais_7_sms = 1 : Relais_7_off_sms = 0 : End If           '7 C8 B Meta71
 If Temp_b1 = 51 Then
 Relais_7_sms = 0 : Relais_7_off_sms = 1 : End If           '7 C8 3 Meta70
End If
If Remote_key = "6" Then
 If Temp_b1 = 66 Then
  Relais_6_sms = 1 : Relais_6_off_sms = 0 : End If          '6 C8 B Meta61
 If Temp_b1 = 51 Then
  Relais_6_sms = 0 : Relais_6_off_sms = 1 : End If          '6 C8 3 Meta60
End If
If Remote_key = "5" Then
 If Temp_b1 = 66 Then
  Relais_5_sms = 1 : Relais_5_off_sms = 0 : End If          '5 C8 B
  If Temp_b1 = 51 Then
   Relais_5_sms = 0 : Relais_5_off_sms = 1 : End If         '5 C8 3
End If
If Remote_key = "4" Then
 If Temp_b1 = 66 Then
  Relais_4_sms = 1 : Relais_4_off_sms = 0 : End If          '4 C8 B
  If Temp_b1 = 51 Then
   Relais_4_sms = 0 : Relais_4_off_sms = 1 : End If         '4 C8 3
End If
If Remote_key = "3" Then
 If Temp_b1 = 66 Then
  Relais_3_sms = 1 : Relais_3_off_sms = 0 : End If          '3 C8 B
  If Temp_b1 = 51 Then
   Relais_3_sms = 0 : Relais_3_off_sms = 1 : End If         '3 C8 3
End If
If Remote_key = "2" Then
 If Temp_b1 = 66 Then
  Relais_2_sms = 1 : Relais_2_off_sms = 0 : End If          '2 C8 B  Meta21
  If Temp_b1 = 51 Then
   Relais_2_sms = 0 : Relais_2_off_sms = 1 : End If         '2 C8 3  Meta20
End If
If Remote_key = "1" Then
   If Temp_b1 = 66 Then
  Output_1_sms = 1 : Output_1_off_sms = 0 : End If          '1 C8 B
   If Temp_b1 = 51 Then
    Output_1_sms = 0 : Output_1_off_sms = 1 : End If        '1 C8 3'
End If
If Remote_key = "0" And Temp_b1 = 51 Then                   '0 C8 3  Switch off when Meta00
    Output_1_sms = 0 : Relais_2_sms = 0 : Relais_3_sms = 0 : Relais_4_sms = 0 : Relais_5_sms = 0 : Relais_6_sms = 0 : Relais_7_sms = 0       'Automatik ein = 1CAED3DF
    Output_1_off_sms = 0 : Relais_2_off_sms = 0 : Relais_3_off_sms = 0 : Relais_4_off_sms = 0 : Relais_5_off_sms = 0 : Relais_6_off_sms = 0 : Relais_7_off_sms = 0
    End If
Gosub Delete_sms_memory

  Temp_b3 = Temp_b1                                         'Save
  If Remote_key >= 48 And Remote_key <= 69 Then             'Send Quit-SMS
     Wait 2 : Gosub Send_sms_header : Gosub Send_sms_quit : Wait 1 : End If       '
Return

Switch_sms:
If Fkt9 = 1 Then Return                                     'Manual Mode
If Output_1_sms = 1 Then Output_1 = 1
If Relais_2_sms = 1 Then Relais_2 = 1
If Relais_3_sms = 1 Then Relais_3 = 1
If Relais_4_sms = 1 Then Relais_4 = 1
If Relais_5_sms = 1 Then Relais_5 = 1
If Relais_6_sms = 1 Then Relais_6 = 1
If Relais_7_sms = 1 Then Relais_7 = 1

If Output_1_off_sms = 1 Then Output_1 = 0
If Relais_2_off_sms = 1 Then Relais_2 = 0
If Relais_3_off_sms = 1 Then Relais_3 = 0
If Relais_4_off_sms = 1 Then Relais_4 = 0
If Relais_5_off_sms = 1 Then Relais_5 = 0
If Relais_6_off_sms = 1 Then Relais_6 = 0
If Relais_7_off_sms = 1 Then Relais_7 = 0
Return

'SMS-senden
Send_sms_header:
Dim Print_f_ok As Bit
Dim Pointer_sms As Byte
Time_no_seriell_pc = 40
Pointer_eeprom = 130 : Readeeprom Temp_b1 , 130             ''Ist eine Nummer eingegeben?
If Temp_b1 = 0 Then Return
'Gosub Delete_sms_memory
'If Test_anruf = 1 Or Simu = 1 Then '***T
 Lcd_param = 1 : Gosub Lcd_gotoline
 Lcd_display_string = "Send SMS" : Lcd_display_pad_with_spaces = 1 : No_print_seriell = 1 : Gosub Lcd_display : Wait 2
'End If
Print #1 , "AT+CMGW=49"                                     'write SMS to memory
Wait 3                                                      '
  Gosub Get_pointer_to_tel_number
  Pointer_sms = Pointer_eeprom
  '      098100941007363470 F001000081000006417658DE0E01
  'Print #1 , "0001000C91947160430307 1ff106417658DE0E01";      'Text "Alarm" auf 01706343070
'cli                                                         'Disable Interrupt
  Print #1 , "0001000C91";                                  '94 removed
  Readeeprom Temp , 308 : Print #1 , Temp;                  'Country-Code

Temp_b3 = 0                                                 'counter character
Print_f_ok = 0
'1.character allways 0
'  Readeeprom Temp_b1 , Pointer_sms  'sign
'  If Temp_b1 < 10 And Temp_b1 > 0 Then Print #1 , temp_b1;    '71 60 43 03 07
                             'count
Pointer_eeprom = Pointer_sms + 2 : Gosub Print_sms_nr       '7   1
Pointer_eeprom = Pointer_sms + 1 : Gosub Print_sms_nr       '1   2

Pointer_eeprom = Pointer_sms + 4 : Gosub Print_sms_nr       '6   3
Pointer_eeprom = Pointer_sms + 3 : Gosub Print_sms_nr       '0   4

Pointer_eeprom = Pointer_sms + 6 : Gosub Print_sms_nr       '4   5
Pointer_eeprom = Pointer_sms + 5 : Gosub Print_sms_nr       '3   6

Pointer_eeprom = Pointer_sms + 8 : Gosub Print_sms_nr       '0   7
Pointer_eeprom = Pointer_sms + 7 : Gosub Print_sms_nr       '3   8

Pointer_eeprom = Pointer_sms + 10 : Gosub Print_sms_nr      '0  9
Pointer_eeprom = Pointer_sms + 9 : Gosub Print_sms_nr       '7   10

Pointer_eeprom = Pointer_sms + 12 : Gosub Print_sms_nr      '#
Pointer_eeprom = Pointer_sms + 11 : Gosub Print_sms_nr      '#

Pointer_eeprom = Pointer_sms + 14 : Gosub Print_sms_nr
Pointer_eeprom = Pointer_sms + 13 : Gosub Print_sms_nr
Return

Print_sms_nr:
Readeeprom Temp_b1 , Pointer_eeprom
If Temp_b1 < 10 Then
 Print #1 , Temp_b1 ; : Incr Temp_b3 : End If

'check impair number
Temp = Pointer_eeprom + 1                                   'check for last character
Readeeprom Temp_b2 , Temp
If Temp_b2 > 10 And Print_f_ok = 0 Then                     'last character
 Temp_b4 = Temp_b3 Mod 2 : If Temp_b4 = 0 Then Print #1 , "F" ; : Print_f_ok = 1       'Nummer: wenn ungerade dann hinten F anhägen!
End If
Return

'###########################################
'Gosub Get_pointer_to_tel_number : Zeiger_sms = Pointer_eeprom - 2
''      098100941007363470 F001000081000006417658DE0E01
''Print #1 , "0001000C919471604303071ff10 6417658DE0E01";      'Text "Alarm" auf 01706343070
'cli                                                         'Disable Interrupt
'Print #1 , "0001000C9194";
''Third_char:
'Pointer_eeprom = Zeiger_sms + 2 : Readeeprom Temp_b1 , Pointer_eeprom
'If Temp_b1 < 10 And Temp_b1 > 0 Then Print #1 , temp_b1;       'not with first "0"
'Pointer_eeprom = Zeiger_sms + 4 : Gosub Print_sms_nr
'Pointer_eeprom = Zeiger_sms + 3 : Gosub Print_sms_nr
'Pointer_eeprom = Zeiger_sms + 6 : Gosub Print_sms_nr
'Pointer_eeprom = Zeiger_sms + 5 : Gosub Print_sms_nr
'Pointer_eeprom = Zeiger_sms + 8 : Gosub Print_sms_nr
'Pointer_eeprom = Zeiger_sms + 7 : Gosub Print_sms_nr
'Pointer_eeprom = Zeiger_sms + 10 : Gosub Print_sms_nr
'Pointer_eeprom = Zeiger_sms + 9 : Gosub Print_sms_nr
'Pointer_eeprom = Zeiger_sms + 12 : Gosub Print_sms_nr
'Pointer_eeprom = Zeiger_sms + 11 : Gosub Print_sms_nr
''Pointer_eeprom = zeiger_sms + 14 : Readeeprom Temp_b1 , Pointer_eeprom
''S = Str(temp_b1) : If Temp_b1 < 10 then Print #1 , S;
''Pointer_eeprom = zeiger_sms + 13 : Readeeprom Temp_b1 , Pointer_eeprom
''S = Str(temp_b1) : If Temp_b1 < 10 then Print #1 , S;
''Pointer_eeprom = zeiger_sms + 16 : Readeeprom Temp_b1 , Pointer_eeprom
''S = Str(temp_b1) : If Temp_b1 < 11 then Print #1 , S;
''Pointer_eeprom = zeiger_sms + 15 : Readeeprom Temp_b1 , Pointer_eeprom
''S = Str(temp_b1) : If Temp_b1 < 11 then Print #1 , S;
'Return
'
'Print_sms_nr:
'Readeeprom Temp_b1 , Pointer_eeprom
'If Temp_b1 < 10 Then Print #1 , temp_b1;
'Return

Send_sms_alarm:
Print #1 , "1ff10" ; '6417658de0e01 ";                      '***T Here optional more Alarm Text

'13 CD323DAC0305D961791B 342DBBE76F7908 'Meta: Alarm Sensor!
'11 CD323DAC0305D961791B 240CD3E921 'Meta Alarm Batt!
'11 CD323DAC0305D961791B 444C97C521 'Meta Alarm Dieb!

Print #1 , "11";                                            'Meta Alarm Batt!
If Alarm_from_input = 1 Then Print #1 , "13";               'Meta: Alarm

Print #1 , "CD323DAC0305D961791B" ;                         'Meta: Alarm

Print #1 , "240CD3E921";                                    'Batt!
If Alarm_from_input = 1 And Alarm_thief = 0 Then Print #1 , "342DBBE76F7908";       'Sensor!
If Alarm_thief = 1 Then Print #1 , "444C97C521";            'Dieb!

Gosub Print_sms_codes
Alarm_from_input = 0 : Alarm_thief = 0
Return

Print_sms_codes:
Number = &H1A                                               'CTRL + Z
Printbin #1 , Number
sei                                                         'Enable Interrupt
Wait 1
'Number = &H1A                                               'CTRL + Z
Printbin #1 , Number
Wait 3                                                      '
For Temp_b1 = 1 To 3
Print #1 , "AT+CMSS=" ; : Print #1 , Temp_b1                'SMS löschen Speicher 1
Waitms 3
Next
For Value = 1 To 160                                        'empty Buffer
Temp_b1 = Inkey(#1)
Next
Meldung_aktiv = 0
Time_no_seriell_pc = 40
Return

Send_sms_quit:
'Header/Anzahl Zeichen/Info
'1ff10 8              CD323D0C7AAF43
Print #1 , "1ff108CD323D0C7AAF43";                          'Meta ok!
'Print #1 , "1ff103EF7508";
Gosub Print_sms_codes
Return

Delete_sms_memory:
For Temp_b1 = 1 To 10
Print #1 , "AT+CMGD=" ; : Print #1 , Temp_b1                'SMS löschen Speicher 1
Waitms 250
Next
For Value = 1 To 80                                         'empty Buffer
Temp_b1 = Inkey(#1)
Next
Return

'Grundmenue Anzeige
Grundmenue:
'If Second = 10 Then Incr Back_to_basic_menu : If Back_to_basic_menu = 30 Then Goto Reset       'switch back to Basic Menu
If Fkt1 = 1 Or Fkt2 = 1 Or Fkt3 = 1 Or Fkt4 = 1 Or Fkt5 = 1 Or Fkt6 = 1 Or Fkt7 = 1 Or Fkt8 = 1 Or Disp_fkt9 = 1 Then Return       'andere FKT angew?
'Back_to_basic_menu = 0
If Meldung_aktiv = 1 Then Return                            'Meldung wird gerade angezeigt
If Programm_selector > 3 Then Goto Basic_menu_charge_controller
 Lcd_param = 1 : Gosub Lcd_gotoline
 If English = 0 Then Lcd_display_string = "Kanal " Else Lcd_display_string = "Unit " : Gosub Lcd_display
If Programm_selector = 0 Then
   If English = 0 Then Lcd_display_string = "aus " Else Lcd_display_string = "off " : Gosub Lcd_display : Goto Disp_time : End If
 '   Temp_b3 = Second Mod 2
If Programm_selector = 1 Then
    Lcd_display_string = "1" : If Output(1) = 1 Then Gosub Show_blank : Gosub Lcd_display
    Lcd_display_string = "2" : If Output(2) = 1 Then Gosub Show_blank : Gosub Lcd_display
    Lcd_display_string = "3" : If Output(3) = 1 Then Gosub Show_blank : Gosub Lcd_display : End If
If Programm_selector = 2 Then
     Lcd_display_string = "4" : If Output(4) = 1 Then Gosub Show_blank : Gosub Lcd_display
     Lcd_display_string = "5" : If Output(5) = 1 Then Gosub Show_blank : Gosub Lcd_display
     Lcd_display_string = "6" : If Output(6) = 1 Then Gosub Show_blank : Gosub Lcd_display : End If
If Programm_selector = 3 Then
     Lcd_display_string = "7" : If Output(7) = 1 Then Gosub Show_blank : Gosub Lcd_display
     Lcd_display_string = "8" : If Output(8) = 1 Then Gosub Show_blank : Gosub Lcd_display
     Lcd_display_string = "9" : If Output(9) = 1 Then Gosub Show_blank : Gosub Lcd_display : End If

'If Programm_selector = 1 Or Programm_selector = 2 Or Programm_selector = 3 Then Gosub Lcd_display
    Lcd_display_string = " " : Gosub Lcd_display

Disp_time:
If Mobile_aktiv = 1 Then Print #1 , " Time: ";
Gosub Show_time

Lcd_param = 2 : Gosub Lcd_gotoline                          '2.Zeile anw.
Temp_b5 = 0                                                 'for Display
 If Mobile_aktiv = 1 Then Print #1 , " Actual Values:";
 If Programm_selector = 1 Then
 For Channel_nr = 1 To 3
    Value = Analog_input_channel(channel_nr) : Temp_b1 = Channel_type(channel_nr) : Gosub Display_value_and_unit : Next
 End If

 If Programm_selector = 2 Then
 For Channel_nr = 4 To 6
    Value = Analog_input_channel(channel_nr) : Temp_b1 = Channel_type(channel_nr) : Gosub Display_value_and_unit : Next
 End If

 If Programm_selector = 3 Then
 For Channel_nr = 7 To 9
    Value = Analog_input_channel(channel_nr) : Temp_b1 = Channel_type(channel_nr) : Gosub Display_value_and_unit : Next
 End If

 If Programm_selector = 0 Or Programm_selector = 4 Then
   Value = Ext_temperature : Gosub Write_value
   Lcd_display_string = "°C/" : Gosub Lcd_display
   Lcd_display_string = "Batt:" : Gosub Lcd_display
   Value = U_batt_smooth : Gosub Write_value
   Lcd_display_string = "V" : Gosub Lcd_display
End If

Gosub Delete_rest
Return

Show_blank:
If Timer_1_sec = 0 Then Lcd_display_string = " "
Return

'===========================================================================================================================
Basic_menu_charge_controller:
'If Timer_2_sec = 0 Then Incr Multiplex_display : If Multiplex_display > 2 Then Multiplex_display = 0
'If Fkt1 = 1 Or Fkt2 = 1 Or Fkt3 = 1 Or Fkt4 = 1 Or Fkt5 = 1 Or Fkt6 = 1 Or Fkt7 = 1 Or Fkt8 = 1 Or Disp_fkt9 = 1 Then Return       'andere FKT angew?
'If Meldung_aktiv = 1 Then Return                            'wird Meldung gerade angezeigt? And Mobile_aktiv = 1
Lcd_param = 1 : Gosub Lcd_gotoline                          '1.Zeile des Displays wird aktiviert
'Readeeprom Temp , 320
'If Temp <> 0 Then  'Solar active?
  If Programm_selector = 5 Then Goto Anzeige_wh_solar
  If Programm_selector = 6 Then Goto Anzeige_wh_load
  If Programm_selector = 7 Then Goto Anzeige_ah_solar
  If Programm_selector = 8 Then Goto Anzeige_ah_load
  If Programm_selector = 9 Then Goto Anzeige_u_min_max      'Anzeige anhängig von Wahlschalter
  If Programm_selector = 10 Then Goto Anzeige_time_temp
'End If
  If Programm_selector = 11 Then Goto Display_radio_sensors

'If Temp = 0 Then Return 'Solar active?

'Programm_selector = 4
'################ Programm_selector = 4 Solar U/I ##########################################
 Lcd_display_string = "Sol:" : Gosub Lcd_display
 Kein_komma = 0 : Value = U_batt_smooth : Gosub Write_value
 Lcd_display_string = "V " : Gosub Lcd_display

    Value = I_solar : Gosub Write_value
   Lcd_display_pad_with_spaces = 1 : Lcd_display_string = "A" : Gosub Lcd_display

'Solar W
  Lcd_param = 2 : Gosub Lcd_gotoline                        '2.Zeile des Displays wird aktiviert
If Solar_loading = 1 And Timer_1_sec = 0 Then Lcd_display_string = "*" Else Lcd_display_string = " " : Gosub Lcd_display
 '   Lcd_display_string = "*:" : Gosub Lcd_display
    Temp_l1 = I_solar                                       'conversion to single
    Temp_l2 = U_batt_smooth
    Temp_l1 = Temp_l1 * Temp_l2 : Temp_l1 = Temp_l1 / 100.0 'z.B. 28.8V * 20.0A
    Value = Temp_l1 : If Value < 0 Then Value = 0           'back to integer
    Kein_komma = 1 : Gosub Write_value
    Lcd_display_string = "W " : Gosub Lcd_display
'Load_current:
If English = 0 Then Lcd_display_string = "Last:" Else Lcd_display_string = "Load:" : Gosub Lcd_display
 Value = I_load : Gosub Write_value : Temp_b5 = 33 : Gosub Value_with_space : Temp_b5 = 0
  Lcd_display_pad_with_spaces = 1 : Lcd_display_string = "A" : Gosub Lcd_display
  '    If Multiplex_display = 0 Then
'     If English = 0 Then Lcd_display_string = "Last:" Else Lcd_display_string = "Load:" : Value = I_load : End If
'    If Multiplex_display = 1 Then
'     If English = 0 Then Lcd_display_string = "La.1:" Else Lcd_display_string = "Lo.1:" : Value = I_load_1 : End If
'    If Multiplex_display = 2 Then
'     If English = 0 Then Lcd_display_string = "La.2:" Else Lcd_display_string = "Lo.2:" : Value = I_load_2 : End If
'    Gosub Lcd_display
'  If Value < 100 Then
'  Lcd_display_string = " " : Gosub Lcd_display : End If
' Gosub Write_value
' Lcd_display_string = "A  " : Gosub Lcd_display

'    Temp_l1 = I_load                                        'conversion to single
'    Temp_l2 = U_batt_smooth
'    Temp_l1 = Temp_l1 * Temp_l2 : Temp_l1 = Temp_l1 / 100.0 'z.B. 28.8V * 20.0A
'    Value = Temp_l1 : If Value < 0 Then Value = 0           'back to integer
'    If English = 0 Then Lcd_display_string = "L:" Else Lcd_display_string = "L:" : Gosub Lcd_display
'    If Value < 100 Then
'    Lcd_display_string = " " : Gosub Lcd_display : End If
'    Kein_komma = 1 : Gosub Write_value
'    Lcd_display_string = "W       " : Gosub Lcd_display :
Gosub Line_feed
Return

Anzeige_wh_solar:
    Lcd_display_string = "Wh Solar:" : Gosub Lcd_display
    Value = Value_wh_solar : Gosub Value_with_space
    Kein_komma = 1 : Gosub Write_value
    Lcd_display_pad_with_spaces = 1 : Lcd_display_string = "Wh" : Gosub Lcd_display

Lcd_param = 2 : Gosub Lcd_gotoline                          '1.Zeile des Displays wird aktiviert
    If English = 0 Then Lcd_display_string = "Wh/Tag:" Else Lcd_display_string = "Wh/day:" : Gosub Lcd_display
    Value = Wh_solar_day : Gosub Value_with_space
    Kein_komma = 1 : Gosub Write_value
    Lcd_display_pad_with_spaces = 1 : If English = 0 Then Lcd_display_string = "Wh/T" Else Lcd_display_string = "Wh/d" : Gosub Lcd_display
Gosub Line_feed
Return

Anzeige_wh_load:
    If English = 0 Then Lcd_display_string = "Wh Last:" Else Lcd_display_string = "Wh Load:" : Gosub Lcd_display
'    If Multiplex_display = 0 Then
    Value = Value_wh_load                                   ': End If
'    If Multiplex_display = 1 Then
'    Lcd_display_string = "1:" : Value = Value_wh_load_1 : : End If
'    If Multiplex_display = 2 Then
'    Lcd_display_string = "2:" : Value = Value_wh_load_2 : : End If
'    Gosub Lcd_display
   Gosub Value_with_space
    Kein_komma = 1 : Gosub Write_value
    Lcd_display_pad_with_spaces = 1 : Lcd_display_string = "Wh" : Gosub Lcd_display

Lcd_param = 2 : Gosub Lcd_gotoline                          '1.Zeile des Displays wird aktiviert
    If English = 0 Then Lcd_display_string = "Wh/Tag:" Else Lcd_display_string = "Wh/day:" : Gosub Lcd_display
    Value = Wh_load_day
'    If Multiplex_display = 1 Then Value = Wh_load_day_1
'    If Multiplex_display = 2 Then Value = Wh_load_day_2
    Gosub Value_with_space
    Kein_komma = 1 : Gosub Write_value
    Lcd_display_pad_with_spaces = 1 : If English = 0 Then Lcd_display_string = "Wh/T" Else Lcd_display_string = "Wh/d" : Gosub Lcd_display
Gosub Line_feed
Return

Anzeige_ah_solar:
    Lcd_display_string = "Ah Solar:" : Gosub Lcd_display
    Value = Value_ah_solar / 10 : Gosub Value_with_space
    Kein_komma = 1 : Gosub Write_value
    Lcd_display_pad_with_spaces = 1 : Lcd_display_string = "Ah" : Gosub Lcd_display

Lcd_param = 2 : Gosub Lcd_gotoline                          '1.Zeile des Displays wird aktiviert
    If English = 0 Then Lcd_display_string = "Ah/Tag:" Else Lcd_display_string = "Ah/day:" : Gosub Lcd_display
    Value = Ah_solar_day / 10 : Gosub Value_with_space
    Kein_komma = 1 : Gosub Write_value
    Lcd_display_pad_with_spaces = 1 : If English = 0 Then Lcd_display_string = "Ah/T" Else Lcd_display_string = "Ah/d" : Gosub Lcd_display
Gosub Line_feed
Return

Anzeige_ah_load:
    If English = 0 Then Lcd_display_string = "Ah Last:" Else Lcd_display_string = "Ah Load:" : Gosub Lcd_display
'    If Multiplex_display = 0 Then
     Value = Value_ah_load / 10
'    If Multiplex_display = 1 Then
'    Lcd_display_string = "1:" : Value = Value_ah_load_1 / 10 : End If
'    If Multiplex_display = 2 Then
'    Lcd_display_string = "2:" : Value = Value_ah_load_2 / 10 : End If
'    Gosub Lcd_display
    Gosub Value_with_space
    Kein_komma = 1 : Gosub Write_value
    Lcd_display_pad_with_spaces = 1 : Lcd_display_string = "Ah" : Gosub Lcd_display

Lcd_param = 2 : Gosub Lcd_gotoline                          '1.Zeile des Displays wird aktiviert
    If English = 0 Then Lcd_display_string = "Ah/Tag:" Else Lcd_display_string = "Ah/day:" : Gosub Lcd_display
     Value = Ah_load_day / 10
'    If Multiplex_display = 1 Then Value = Ah_load_day_1 / 10
'    If Multiplex_display = 2 Then Value = Ah_load_day_2 / 10
    Gosub Value_with_space
    Kein_komma = 1 : Gosub Write_value
    Lcd_display_pad_with_spaces = 1 : If English = 0 Then Lcd_display_string = "Ah/T" Else Lcd_display_string = "Ah/d" : Gosub Lcd_display
Gosub Line_feed
Return

Anzeige_u_min_max:
    Lcd_display_string = "U-max:" : Gosub Lcd_display
    Value = U_max_day : Gosub Value_with_space
    Gosub Write_value
    Lcd_display_string = "V     " : Gosub Lcd_display

    Lcd_param = 2 : Gosub Lcd_gotoline
    Lcd_display_string = "U-min:" : Gosub Lcd_display
    Value = U_min_day : Gosub Value_with_space
    Gosub Write_value
    Lcd_display_pad_with_spaces = 1 : Lcd_display_string = "V" : Gosub Lcd_display
    Gosub Line_feed
Return

'Display_soc:
'    If English = 0 Then Lcd_display_string = "Ladezust:" Else Lcd_display_string = "B-Status:" : Gosub Lcd_display
'    Readeeprom Temp , 126                                   '126 = 34 Correction SOC
'    Temp2 = Account_batterie / 10 : Value = 1000 + Temp2 : Value = Value * Temp : Value = Value / 10 : If Value > 1900 Then Value = 0 : If Value < 100 Then
'   Lcd_display_string = " " : Gosub Lcd_display : End If
'    Gosub Write_value
'    Lcd_display_string = "%         " : Gosub Lcd_display : Gosub Write_leerz :
'    Gosub Line_feed :
' Return

Anzeige_time_temp:
'1234567890123456
'Temp:22.3°/27.8°
   Lcd_display_string = "Temp:" : Gosub Lcd_display
   Value = Sensor_temp_kompensation : Gosub Write_value
   Lcd_display_string = "°/" : Gosub Lcd_display
'   Value = Analog_10 : Gosub Write_value
'   Lcd_display_string = "°" : Gosub Lcd_display
 Gosub Show_time

    Lcd_param = 2 : Gosub Lcd_gotoline
  Lcd_display_string = "Solar " : Gosub Lcd_display
  If Solar_loading = 0 Then
  Lcd_display_string = "no " : Gosub Lcd_display
  Else
  If Charge_to_14_4v = 1 Then
  Lcd_display_string = "Boost " : Gosub Lcd_display : End If
  If Batt_pwm_charge = 1 Then
    Lcd_display_string = "PWM " : Gosub Lcd_display : End If
  End If
  Lcd_display_pad_with_spaces = 1 : If No_sun = 1 Then Lcd_display_string = "sun" Else Lcd_display_string = "loading" : Gosub Lcd_display

    Gosub Line_feed
Return

Display_radio_sensors:
 Dim Display_count As Byte
 If Timer_1_sec = 0 Then Incr Display_count
 If Display_count > 3 Then Display_count = 0

Kein_komma = 1 : Lcd_display_string = "no Radio Sensor!" : Value = 0

If Rain_sensor_detect = 1 And Display_count = 0 Then
    Lcd_param = 2 : Gosub Lcd_gotoline
       Lcd_display_string = "Rain:" : Value = Elv_rain : Gosub Lcd_display : Gosub Write_value : Lcd_display_string = " " : End If
If Rain_sensor_detect = 0 And Display_count = 0 Then Incr Display_count

If Wind_sensor_detect = 1 And Display_count = 1 Then
      Lcd_param = 1 : Gosub Lcd_gotoline
        Lcd_display_string = "Wind:" : Kein_komma = 0 : Value = Wind_speed : Gosub Lcd_display : Gosub Write_value : Lcd_display_string = "km/h" : End If
If Wind_sensor_detect = 0 And Display_count = 1 Then Incr Display_count

If Humidity_sensor_detect = 1 And Display_count = 2 Then
  Lcd_param = 2 : Gosub Lcd_gotoline
       Lcd_display_string = "Humidity:" : Kein_komma = 1 : Value = Elv_humidity : Gosub Lcd_display : Gosub Write_value : Lcd_display_string = "%" : End If
If Humidity_sensor_detect = 0 And Display_count = 2 Then Incr Display_count

If Temp_sensor_detect = 1 And Display_count = 3 Then
     Lcd_param = 1 : Gosub Lcd_gotoline
       Lcd_display_string = "Radio Temp:" : Kein_komma = 0 : Value = Elv_temp : Gosub Lcd_display : Gosub Write_value : Lcd_display_string = "°C" : End If
If Temp_sensor_detect = 0 And Display_count = 3 Then Display_count = 0

   Lcd_display_pad_with_spaces = 1 : Gosub Lcd_display
 Gosub Line_feed : Return

'Anzeige_u_batt_block:
'Gosub Print_u_i
'Lcd_param = U_ : Gosub Lcd_writechar
'Lcd_param = Doppelp : Gosub Lcd_writechar
'If U_batt_smooth < 200 Then Temp2 = 105 Else Temp2 = 210
'If U_batt_smooth < Temp2 Then Goto Write_blank
'Lcd_param = Char_block : Gosub Lcd_writechar
'If U_batt_smooth < 200 Then Temp2 = 108 Else Temp2 = 216
'If U_batt_smooth < Temp2 Then Goto Write_blank
'Lcd_param = Char_block : Gosub Lcd_writechar
'If U_batt_smooth < 200 Then Temp2 = 111 Else Temp2 = 222
'If U_batt_smooth < Temp2 Then Goto Write_blank
'Lcd_param = Char_block : Gosub Lcd_writechar
'If U_batt_smooth < 200 Then Temp2 = 114 Else Temp2 = 228
'If U_batt_smooth < Temp2 Then Goto Write_blank
'Lcd_param = Char_block : Gosub Lcd_writechar
'If U_batt_smooth < 200 Then Temp2 = 117 Else Temp2 = 234
'If U_batt_smooth < Temp2 Then Goto Write_blank
'Lcd_param = Char_block : Gosub Lcd_writechar
'If U_batt_smooth < 200 Then Temp2 = 120 Else Temp2 = 240
'If U_batt_smooth < Temp2 Then Goto Write_blank
'Lcd_param = Char_block : Gosub Lcd_writechar
'If U_batt_smooth < 200 Then Temp2 = 123 Else Temp2 = 246
'If U_batt_smooth < Temp2 Then Goto Write_blank
'Lcd_param = Char_block : Gosub Lcd_writechar
'If U_batt_smooth < 200 Then Temp2 = 126 Else Temp2 = 252
'If U_batt_smooth < Temp2 Then Goto Write_blank
'Lcd_param = Char_block : Gosub Lcd_writechar
'If U_batt_smooth < 200 Then Temp2 = 129 Else Temp2 = 258
'If U_batt_smooth < Temp2 Then Goto Write_blank
'Lcd_param = Char_block : Gosub Lcd_writechar
'If U_batt_smooth < 200 Then Temp2 = 132 Else Temp2 = 264
'If U_batt_smooth < Temp2 Then Goto Write_blank
'Lcd_param = Char_block : Gosub Lcd_writechar
'If U_batt_smooth < 200 Then Temp2 = 135 Else Temp2 = 270
'If U_batt_smooth < Temp2 Then Goto Write_blank
'Lcd_param = Char_block : Gosub Lcd_writechar
'If U_batt_smooth < 200 Then Temp2 = 138 Else Temp2 = 276
'If U_batt_smooth < Temp2 Then Goto Write_blank
'Lcd_param = Char_block : Gosub Lcd_writechar
'If U_batt_smooth < 200 Then Temp2 = 141 Else Temp2 = 282
'If U_batt_smooth < Temp2 Then Goto Write_blank
'Lcd_param = Char_block : Gosub Lcd_writechar
'If U_batt_smooth < 200 Then Temp2 = 144 Else Temp2 = 288
'If U_batt_smooth < Temp2 Then Goto Write_blank
'Lcd_param = Char_block : Gosub Lcd_writechar
'Return

'Anzeige_i_solar_block:
'Gosub Print_u_i
'Lcd_param = I_ : Gosub Lcd_writechar
'Lcd_param = Doppelp : Gosub Lcd_writechar
'Temp3 = I_solar : Goto I_bar
'
'Anzeige_i_load_block:
'Gosub Print_u_i
'Lcd_param = I_ : Gosub Lcd_writechar
'Lcd_param = Doppelp : Gosub Lcd_writechar
'Temp3 = I_load
'
'I_bar:
'If Temp3 < 10 Then Goto Write_blank
'Lcd_param = Char_block : Gosub Lcd_writechar
'If Temp3 < 20 Then Goto Write_blank
'Lcd_param = Char_block : Gosub Lcd_writechar
'If Temp3 < 30 Then Goto Write_blank
'Lcd_param = Char_block : Gosub Lcd_writechar
'If Temp3 < 40 Then Goto Write_blank
'Lcd_param = Char_block : Gosub Lcd_writechar
'If Temp3 < 50 Then Goto Write_blank
'Lcd_param = Char_block : Gosub Lcd_writechar
'If Temp3 < 60 Then Goto Write_blank
'Lcd_param = Char_block : Gosub Lcd_writechar
'If Temp3 < 70 Then Goto Write_blank
'Lcd_param = Char_block : Gosub Lcd_writechar
'If Temp3 < 80 Then Goto Write_blank
'Lcd_param = Char_block : Gosub Lcd_writechar
'If Temp3 < 90 Then Goto Write_blank
'Lcd_param = Char_block : Gosub Lcd_writechar
'If Temp3 < 100 Then Goto Write_blank
'Lcd_param = Char_block : Gosub Lcd_writechar
'If Temp3 < 110 Then Goto Write_blank
'Lcd_param = Char_block : Gosub Lcd_writechar
'If Temp3 < 120 Then Goto Write_blank
'Lcd_param = Char_block : Gosub Lcd_writechar
'If Temp3 < 130 Then Goto Write_blank
'Lcd_param = Char_block : Gosub Lcd_writechar
'If Temp3 < 140 Then Goto Write_blank
'Lcd_param = Char_block : Gosub Lcd_writechar
'Return

'Print_u_i:
'    Temp_l1 = I_solar                                       'conversion to single
'    Temp_l2 = U_batt_smooth
'    Temp_l1 = Temp_l1 * Temp_l2 : Temp_l1 = Temp_l1 / 100   'z.B. 28.8V * 20.0A
'    Value = Temp_l1                                         'back to integer
'    If Mobile_aktiv = 1 And English = 0 Then Print #1 , "Modul-Leistung:";
'    If Mobile_aktiv = 1 And English = 1 Then Print #1 , "Output Modul:";
'    Kein_komma = 1 : If Mobile_aktiv = 1 Then Gosub Print_value
'    If Mobile_aktiv = 1 Then Print #1 , "W ";
'  Value = Value_ah_solar / 10
'    If Value < 0 Then Value = 0                             'if not reasonable values or no sensor
'    If Mobile_aktiv = 1 And English = 0 Then Print #1 , "Solar-Ertrag:";
'    If Mobile_aktiv = 1 And English = 1 Then Print #1 , "Yield Solar:";
'    Kein_komma = 1 : If Mobile_aktiv = 1 Then Gosub Print_value
'    If Mobile_aktiv = 1 Then Print #1 , "Ah "
'Return

'Funktion Keyboard
Keyboard:
Config Pinc.4 = Output : Portc.4 = 1                        'Tastatur aktiv setzen
Porta = 0 : Portc.0 = 0 : Portc.1 = 0 : Portc.2 = 0 : Portc.3 = 0
Config Porta = Input
Config Pinc.0 = Input : Config Pinc.1 = Input : Config Pinc.2 = Input : Config Pinc.3 = Input
Port1 = 0 : Port2 = 0 : Port3 = 0 : Port4 = 0 : Port5 = 0 : Port6 = 0 : Port7 = 0 : Port8 = 0
Lcd_rs = 0 : Lcd_rw = 0 : Port11 = 0 : Port12 = 0

Keyb = 255

If Check_seriell_keyb = 1 And Do_not_accept_keyboard_by_serial = 0 Then
If Remote_key >= 48 And Remote_key < 58 Then Keyb = Remote_key - 48       'with Modem
If Remote_key = 122 Or Remote_key = 27 Then Keyb = 10       'entspricht Zeichen * als z = 122
If Remote_key = 111 Or Remote_key = 13 Then Keyb = 11       'entspricht Zeichen # als o = 111

If Remote_key = "A" Then Prg_switch_remote = 1
If Remote_key = "B" Then Prg_switch_remote = 2
If Remote_key = "C" Then Prg_switch_remote = 3
If Remote_key = "D" Then Prg_switch_remote = 4
If Remote_key = "G" Then Prg_switch_remote = 5
If Remote_key = "H" Then Prg_switch_remote = 6
If Remote_key = "I" Then Prg_switch_remote = 7
If Remote_key = "J" Then Prg_switch_remote = 8
If Remote_key = "K" Then Prg_switch_remote = 9
If Remote_key = "P" Then Prg_switch_remote = 10
If Remote_key = "M" Then Prg_switch_remote = 11
If Remote_key = "N" Then Prg_switch_remote = 12
Remote_key = 0

If Keyb <> 255 And Delay_next_key = 0 And Mobile_aktiv = 1 Then
 Delay_next_key = 1 : Goto Aktiv : End If
End If

Gosub Tastatur_input                                        'Tastatur abfragen
If Port1 = 1 Then Keyb = 6
If Port2 = 1 Then Keyb = 3
If Port3 = 1 Then Keyb = 11                                 'Tasten abfragen
If Port4 = 1 Then Keyb = 9
If Port5 = 1 Then Keyb = 5
If Port6 = 1 Then Keyb = 2
If Port7 = 1 Then Keyb = 0
If Port8 = 1 Then Keyb = 8
If Lcd_rs = 1 Then Keyb = 4
If Lcd_rw = 1 Then Keyb = 1
If Port11 = 1 Then Keyb = 10
If Port12 = 1 Then Keyb = 7
If Keyb = 255 Then Return
Porte.5 = 1 : Lcd_led = 10                                  'LCD Backlight on
Aktiv:
If Meldung_aktiv = 1 Then
 Lcd_param = &B00001100 : Gosub Lcd_writecmd
 Meldung_aktiv = 0 : Channel_nr_alarm = 0 : Beeper = 0 : Beep_ein = 0 : Sensor_nr_fault = 0 : Alarm_sensor = 0 : Alarm_moving_detector = 0
 Channel_alarm_auto_no_flow = 0 : Channel_alarm_max_time_pump = 0
 For Channel_nr = 1 To Number_of_channel_modules
  Alarm_auto_no_flow(channel_nr) = 0 : Alarm_max_time_pump(channel_nr) = 0 : Delay_check_actual(channel_nr) = 0 : Max_time_pump(channel_nr) = 0
 Next
 Return : End If                                            'or Keyb = 10 or Keyb = 11

If Keyb = 0 And Fkt8 = 1 And Eingabe_teil_2 = 1 Then        'and Timer_2_sec = 0
  If Data_pointer = 72 And Min_value_1 > 0 Then             'Reset Values Min/Max
    Min_value_1 = 0 : Return : End If

If Flag_alarm_if_no_analog = 1 And Meldung_aktiv = 1 Then
  Meldung_aktiv = 0 : Reset_alarm_if_no_analog = 11 : Return : End If

If Data_pointer = 73 And Max_value_1 > 0 Then               'Reset Values Min/Max
   Max_value_1 = 0 : Return : End If

If Data_pointer = 74 And Running_time_1_sec > 0 Then        'Reset Values Min/Max
   Running_time_1_sec = 0 : Running_time_1 = 0 : Return : End If
End If

If Fkt1 = 1 Or Fkt2 = 1 Or Fkt3 = 1 Or Fkt4 = 1 Or Fkt5 = 1 Or Fkt6 = 1 Or Fkt7 = 1 Or Fkt8 = 1 Or Disp_fkt9 = 1 Then Goto K001
'Meldung quit im Grundmenu     Grundmenu-Funktionen
If Keyb = 10 Or Keyb = 11 Then Gosub Read_analog_all_min    'Taste * or #
'Readeeprom Temp , 320 : If Temp = 1 And Keyb = 11 Then      'Solar active?
' If Display_solarmenue = 0 Then Display_solarmenue = 1 Else Display_solarmenue = 0 : End If

K001:
If Data_pointer = 16 And Stelle_1 = 0 And Eingabe_teil_3 = 1 Then Goto No_reset       'Input negative Value
If Keyb = 10 Then Goto Reset                                'Abbruch Taste?
No_reset:
If Fkt1 = 1 Then Goto Input_channel                         'Eingabe läuft Timer?
If Fkt2 = 1 Then Goto Eing_2                                '
If Fkt3 = 1 Then Goto Eing_3                                '
If Fkt4 = 1 Then Goto Eing_4                                '
If Fkt5 = 1 Then Goto Eing_5                                '
If Fkt6 = 1 Then Goto Eing_6                                'Eingabe läuft Verfahren
If Fkt7 = 1 Then Goto Eing_7                                'Eingabe läuft Uhr?
If Fkt8 = 1 Then Goto Eing_8                                'Eingabe läuft Uhr?
If Disp_fkt9 = 1 And Display_submenues = 0 Then Goto Eing_9 'Eingabe läuft Hand?
If Disp_fkt9 = 1 And Display_submenues = 1 Then Goto Eing_9_2
If Disp_fkt9 = 1 And Display_submenues > 1 Then
 Incr Display_submenues : If Display_submenues > 4 Then Display_submenues = 0 : Display_info = 0 : Return : End If

'Universal Channels
If Keyb <> 1 Then Goto Key2
Fkt1 = 1 : Gosub Del_disp                                   '1234567890123456
Lcd_param = 1 : Gosub Lcd_gotoline
If Channel_number = 0 Then Channel_number = 1
If Switch_input_block_channel > 1 Then Incr Switch_input_block_channel       'to go to the same position as before
Ten_times_channel_nr = Channel_number * 10                  'Startwert EEprom
Temp4 = Ten_times_channel_nr + 493 : Readeeprom Channel_typ , Temp4       'Type

If English = 0 Then Lcd_display_string = "Kanal " Else Lcd_display_string = "Channel " : Gosub Lcd_display : Value = Channel_number : Kein_komma = 1 : Gosub Write_value : Gosub Delete_rest_of_display
 Lcd_param = 2 : Gosub Lcd_gotoline
 Gosub Show_channel_info : Waitms 1500

Display_channel:
If Switch_input_block_channel > 23 Then Switch_input_block_channel = 0
Gosub Load_from_flash
If Channel_number < 1 Or Channel_number > 20 Then Channel_number = 1
Ten_times_channel_nr = Channel_number * 10

Temp4 = Ten_times_channel_nr + 493 : Readeeprom Channel_typ , Temp4       'Type

Lcd_param = 1 : Gosub Lcd_gotoline
If Switch_input_block_channel = 5 Or Switch_input_block_channel = 6 Then Goto Analog_delay_on_off
If Switch_input_block_channel = 7 Or Switch_input_block_channel = 8 Then Goto Display_input_output
If Switch_input_block_channel = 9 Or Switch_input_block_channel = 10 Then Goto Display_input2
If Switch_input_block_channel = 11 Or Switch_input_block_channel = 12 Then Goto Display_output_2
If Switch_input_block_channel > 12 And Switch_input_block_channel < 18 Then Goto Display_timer
If Switch_input_block_channel = 18 Or Switch_input_block_channel = 19 Then Goto Display_max_time_auto_sp
If Switch_input_block_channel = 20 Then Goto Display_sensor_alarm
If Switch_input_block_channel = 21 Or Switch_input_block_channel = 22 Then Goto Display_min_max
If Switch_input_block_channel = 23 Then Goto Display_alarm_in

'########################### Channel, Type, Actual/Setpoint #######################
If Show_info_channel_type > 0 Then Goto Show_info_channel_type
Lcd_param = 1 : Gosub Lcd_gotoline                          '1.Zeile anw.
Temp4 = Ten_times_channel_nr + 894 : Readeeprom Temp_b5 , Temp4       'on all ...
If English = 0 Then Lcd_display_string = "Ka" Else Lcd_display_string = "Ch" : Gosub Lcd_display
If Switch_input_block_channel = 0 Then Gosub Write_fragez
Value = Channel_number : Kein_komma = 1 : Gosub Write_value

 If Mobile_aktiv = 1 And Switch_input_block_channel = 1 Then Gosub Write_fragez
   Temp4 = Ten_times_channel_nr + 499 : Readeeprom Temp_b1 , Temp4 : Lcd_display_string = " " : Gosub Lcd_display : If Temp_b1 = 1 Then Gosub Write_on Else Gosub Write_off       'on/off
   Lcd_display_string = "/" : Gosub Lcd_display
  If Channel_typ > 19 And Channel_typ < 29 Then             'Interlock-channel
   If Interlock(channel_number) = 1 Then Lcd_display_string = "lock" Else Lcd_display_string = "free" : Gosub Lcd_display
  Else
   If Output(channel_number) = 1 Then Lcd_display_string = "1" Else Lcd_display_string = "0" : Gosub Lcd_display
  End If

Show_info_channel_type:
If Channel_number <> Channel_number_old Then
 Lcd_param = 1 : Gosub Lcd_gotoline
 Gosub Show_channel_info
 Channel_number_old = Channel_number : Show_info_channel_type = 2
End If

Lcd_display_string = " Typ" : Gosub Lcd_display
If Mobile_aktiv = 1 And Switch_input_block_channel = 2 Then Gosub Write_fragez
Value = Channel_typ : Kein_komma = 1 : Gosub Write_value : Lcd_display_string = "  " : Gosub Lcd_display
'Gosub Delete_rest

Lcd_param = 2 : Gosub Lcd_gotoline
If Display_info_line = 0 Then
 Lcd_param = 2 : Gosub Lcd_gotoline
 If English = 0 Then Lcd_display_string = "Akt.Wert/Sollw. " Else Lcd_display_string = "Actual/Setpoint" : If Switch_input_block_channel <> 2 Then Gosub Lcd_display
 If Switch_input_block_channel = 2 Then
 Lcd_param = 1 : Gosub Lcd_gotoline                         '1234567890123456
 Lcd_display_string = "0=Irrigate; 1=°C" : Gosub Lcd_display
 Lcd_param = 2 : Gosub Lcd_gotoline                         '1234567890123456
 Lcd_display_string = "2=Level;>10=Alar" : Gosub Lcd_display : End If
 Gosub Line_feed : Waitms 2200 : Display_info_line = 1
End If

  Value = Analog_input_channel(channel_number) : Temp3 = Value       'actual
  Gosub Display_value_and_unit

  If Mobile_aktiv = 1 And Switch_input_block_channel = 3 Then Gosub Write_fragez
  Temp4 = Ten_times_channel_nr + 898 : Readeeprom Temp_b2 , Temp4       '< or >
  If Temp_b2 = 0 Then Lcd_display_string = "<" Else Lcd_display_string = ">" : Gosub Lcd_display

 Lcd_display_string = "SP:" : Gosub Lcd_display
 Temp4 = Ten_times_channel_nr + 895 : Readeeprom Value , Temp4       'Setpoint
 '#################### Setpoint from Analog in ############################
Temp4 = Ten_times_channel_nr + 492 : Readeeprom Temp_b1 , Temp4       'Input_2 indicates analog Input if Type = 51..99!
If Temp_b1 > 50 And Temp_b1 < 99 Then Gosub Map_analog      'Map analog Input to Setpoint
'########################################################################
 If Mobile_aktiv = 1 And Switch_input_block_channel = 4 Then Gosub Write_fragez
 Lcd_display_pad_with_spaces = 1 : Temp_b2 = 99 : Gosub Display_value_and_unit : Temp_b2 = 0       'Indicator for Unit


Lcd_param = &B00001111 : Gosub Lcd_writecmd                 'Cursor blinken ein
'01234567890123456
'Ka12 Ein/1 Typ 01
'A:12.3°>SP:12.3°
Lcd_param = &H82
If Switch_input_block_channel = 1 Then Lcd_param = &H86
If Switch_input_block_channel = 2 Then Lcd_param = &H8E
If Switch_input_block_channel = 3 Then
 If Temp3 > 100 Then Lcd_param = &HC5 Else Lcd_param = &HC4 : End If
If Switch_input_block_channel = 4 Then Lcd_param = &HCA
Gosub Lcd_writecmd
Gosub Line_feed
Return

'######################### Display_Analog Delay_on_off ########################
Analog_delay_on_off:
'If Display_info_line = 0 Then Gosub Input_info
Lcd_param = 1 : Gosub Lcd_gotoline
Lcd_display_string = "Del.on:" : If Channel_typ > 30 Then Lcd_display_string = "Impuls:" : Gosub Lcd_display
If Mobile_aktiv = 1 And Switch_input_block_channel = 5 Then Gosub Write_fragez
Temp4 = Ten_times_channel_nr + 497 : Readeeprom Temp_b1 , Temp4       'Input at Adr. 507
Value = Temp_b1 : Kein_komma = 1
If Value > 100 Then
  Kein_komma = 0 : Two_comma = 1 : End If
Gosub Write_value : Lcd_display_string = "/" : Gosub Lcd_display
Time_value_corrected = Analog_delay_on(channel_number) : Gosub Value_range : Value = Time_value_corrected : Kein_komma = 1 : Gosub Write_value
Value = Temp_b1 : Lcd_display_pad_with_spaces = 1 : Gosub Write_time_unit

Lcd_param = 2 : Gosub Lcd_gotoline                          '1.Zeile anw.
Lcd_display_string = "off:"
Gosub Lcd_display
If Mobile_aktiv = 1 And Switch_input_block_channel = 6 Then Gosub Write_fragez
Temp = Ten_times_channel_nr + 498 : Readeeprom Temp_b1 , Temp       'Output at Adr. 504
Value = Temp_b1 : Kein_komma = 1
If Value > 100 Then
  Kein_komma = 0 : Two_comma = 1 : End If
Gosub Write_value : Lcd_display_string = "/" : Gosub Lcd_display
Time_value_corrected = Analog_delay_off(channel_number) : Gosub Value_range : Value = Time_value_corrected : Kein_komma = 1 : Gosub Write_value
Value = Temp_b1 : Lcd_display_pad_with_spaces = 1 : Gosub Write_time_unit

Lcd_param = &B00001111 : Gosub Lcd_writecmd                 'Cursor blinken ein
Lcd_param = &H87
If Switch_input_block_channel = 6 Then Lcd_param = &HC4
Gosub Lcd_writecmd
Gosub Line_feed
Return

'######################### Display_Input_Output ########################
Display_input_output:
If Display_info_line = 0 Then Gosub Input_info

Lcd_param = 1 : Gosub Lcd_gotoline
Lcd_display_string = "Input:" : Gosub Lcd_display
If Mobile_aktiv = 1 And Switch_input_block_channel = 7 Then Gosub Write_fragez
Temp = Ten_times_channel_nr + 491 : Readeeprom Temp_b1 , Temp       'Input at Adr. 501
Value = Temp_b1 : Kein_komma = 1 : Gosub Write_value : Gosub Write_input

Lcd_param = 2 : Gosub Lcd_gotoline                          '1.Zeile anw.
Lcd_display_string = "Output:" : Gosub Lcd_display
If Mobile_aktiv = 1 And Switch_input_block_channel = 8 Then Gosub Write_fragez
Temp = Ten_times_channel_nr + 494 : Readeeprom Temp_b1 , Temp       'Output at Adr. 504
Value = Temp_b1 : Kein_komma = 1 : Gosub Write_value : Gosub Write_output

Lcd_param = &B00001111 : Gosub Lcd_writecmd                 'Cursor blinken ein
Lcd_param = &H86
If Switch_input_block_channel = 8 Then Lcd_param = &HC7
Gosub Lcd_writecmd
Gosub Line_feed
Return

'######################### Display_Input_Type_Sensor_Alarm ###########################
Display_input2:
If Display_info_line = 0 Then
 Lcd_display_pad_with_spaces = 1
 Lcd_param = 1 : Gosub Lcd_gotoline                         '0123456789012345                     '
 Lcd_display_string = "Input 2(Out=1.." : If Switch_input_block_channel = 9 Then Gosub Lcd_display
 Lcd_param = 2 : Gosub Lcd_gotoline                         '0123456789012345                        '
 Lcd_display_string = "Meas:>50;Dig>100" : If Switch_input_block_channel = 9 Then Gosub Lcd_display
Gosub Line_feed : Waitms 2500 : Display_info_line = 1
End If

Lcd_param = 1 : Gosub Lcd_gotoline
Lcd_display_string = "In2:" : Gosub Lcd_display
If Mobile_aktiv = 1 And Switch_input_block_channel = 9 Then Gosub Write_fragez
Temp3 = Ten_times_channel_nr + 492 : Readeeprom Temp_b1 , Temp3       'Input at Adr. 501
Value = Temp_b1 : Kein_komma = 1 : If Value < 100 Then Tel_nr = 1 : Gosub Write_value : If Value > 100 Then Gosub Write_input Else Gosub Write_with_output

Lcd_param = 2 : Gosub Lcd_gotoline                          '0123456778901234567                       '1.Zeile anw.
Lcd_display_string = "ok=0/1?" : Gosub Lcd_display
Temp4 = Ten_times_channel_nr + 500 : Readeeprom Temp_b1 , Temp4       '502+3=505
If Mobile_aktiv = 1 And Switch_input_block_channel = 10 Then Gosub Write_fragez
Value = Temp_b1 : Kein_komma = 1 : Tel_nr = 1 : Gosub Write_value
Lcd_display_string = " Act:" : Gosub Lcd_display
If Analog_input_2_channel(channel_number) = 1 Then Lcd_display_string = "1" Else Lcd_display_string = "0" : Lcd_display_pad_with_spaces = 1 : Gosub Lcd_display

Lcd_param = &B00001111 : Gosub Lcd_writecmd                 'Cursor blinken ein
Lcd_param = &H84
If Switch_input_block_channel = 10 Then Lcd_param = &HC7
Gosub Lcd_writecmd
Gosub Line_feed
Return

'######################### Output 2 + Hysterese ###########################
Display_output_2:
Lcd_param = 1 : Gosub Lcd_gotoline
Lcd_display_string = "Output 2:" : Gosub Lcd_display
If Mobile_aktiv = 1 And Switch_input_block_channel = 11 Then Gosub Write_fragez
Temp = Channel_number + 480 : Readeeprom Temp_b1 , Temp     'Output at Adr. 481
Value = Temp_b1 : Kein_komma = 1 : Gosub Write_value : Gosub Write_output

Lcd_param = 2 : Gosub Lcd_gotoline
Lcd_display_string = "Hyst:" : Gosub Lcd_display
Temp4 = Ten_times_channel_nr + 899 : : Readeeprom Value , Temp4       'Hyst-Value at 9
If Mobile_aktiv = 1 And Switch_input_block_channel = 12 Then Gosub Write_fragez
Temp_b5 = Channel_typ : Lcd_display_pad_with_spaces = 1 : Gosub Display_value_and_unit : Temp_b5 = 0

Lcd_param = &B00001111 : Gosub Lcd_writecmd                 'Cursor blinken ein
Lcd_param = &H89
If Switch_input_block_channel = 12 Then Lcd_param = &HC5
Gosub Lcd_writecmd
Gosub Line_feed
Return

'######################### Display_Timer ###########################
Display_timer:
 Lcd_param = 1 : Gosub Lcd_gotoline                         '0123456789012345                     '
If Display_info_line = 0 Then
 Lcd_display_pad_with_spaces = 1
 Lcd_display_string = "Timer" : Gosub Lcd_display
Gosub Line_feed : Wait 2 : Display_info_line = 1
End If
If English = 0 Then Lcd_display_string = "Std m aktiv/alle" Else Lcd_display_string = "hr mi active/all"
If Switch_input_block_channel = 16 Or Switch_input_block_channel = 17 Then
 If English = 0 Then Lcd_display_string = "alle  für(Takt)" Else Lcd_display_string = "all / for(Pulses" : End If
Lcd_display_pad_with_spaces = 1 : Gosub Lcd_display

    Lcd_param = 2 : Gosub Lcd_gotoline                      '2.Zeile anw.
    Temp4 = Ten_times_channel_nr + 891 : Readeeprom Temp_b1 , Temp4       'hour
    Incr Temp4 : Readeeprom Temp_b2 , Temp4                 'minute
    Incr Temp4 : Readeeprom Temp_b3 , Temp4                 'on for
    Incr Temp4 : Readeeprom Temp_b4 , Temp4                 'all
    Temp4 = Channel_number + 440 : Readeeprom Temp_b5 , Temp4       'Puls on-Time

If Switch_input_block_channel <> 16 And Switch_input_block_channel <> 17 Then
'hour
    If Mobile_aktiv = 1 And Switch_input_block_channel = 13 Then Gosub Write_fragez
    Value = Temp_b1 : Kein_komma = 1 : Gosub Write_value
    Lcd_display_string = ":" : Gosub Lcd_display            '1
'minute
    If Mobile_aktiv = 1 And Switch_input_block_channel = 14 Then Gosub Write_fragez
    Value = Temp_b2 : Kein_komma = 1 : Gosub Write_value
    Lcd_display_string = " " : Gosub Lcd_display
'on for
    If Mobile_aktiv = 1 And Switch_input_block_channel = 15 Then Gosub Write_fragez
    Value = Temp_b3 : Kein_komma = 1 : Display_time_grid = 1 : Gosub Write_value : Gosub Write_unit
End If

'on all
    If Mobile_aktiv = 1 And Switch_input_block_channel = 16 Then Gosub Write_fragez
    Value = Temp_b4 : Kein_komma = 1 : Display_time_grid = 1 : Gosub Write_value       'Alle x ...
    Lcd_display_string = "min "
    If Value > 100 Then Lcd_display_string = "hr "
    If Value > 200 Then Lcd_display_string = "day "
    Gosub Lcd_display
'on Pulse
    If Mobile_aktiv = 1 And Switch_input_block_channel = 17 Then Gosub Write_fragez
    Value = Temp_b5 : Kein_komma = 1 : Display_time_grid = 1 : Gosub Write_value : Lcd_display_pad_with_spaces = 1 : Gosub Write_unit       'Alle x ...

Lcd_param = &B00001111 : Gosub Lcd_writecmd                 '**** Cursor blinken ein
'01234567789012345
'12:20 1.02m 1.02Mi
Lcd_param = &HC1
If Switch_input_block_channel = 14 Then Lcd_param = &HC4    'Cursor auf best. Position
If Switch_input_block_channel = 15 Then Lcd_param = &HC7
'1.20Min 2.01sec
If Switch_input_block_channel = 16 Then Lcd_param = &HC1
If Switch_input_block_channel = 17 Then Lcd_param = &HC7
Gosub Lcd_writecmd
Gosub Line_feed
Return

Write_unit:
Lcd_display_string = "s "
    If Value > 100 Then Lcd_display_string = "m "
    If Value > 200 Then Lcd_display_string = "h "
    Gosub Lcd_display
Return

'######################### Display_Max_Time_Auto_Sp ###########################
Display_max_time_auto_sp:
Lcd_param = 1 : Gosub Lcd_gotoline                          '012234567890
Lcd_display_string = "Max-Time:" : Gosub Lcd_display

If Display_info_line = 0 And Switch_input_block_channel = 19 Then
 Lcd_param = 2 : Gosub Lcd_gotoline
 Lcd_display_string = "Auto Irrig.Time " : Gosub Lcd_display : Gosub Line_feed : Wait 3 : Display_info_line = 1
End If

If Mobile_aktiv = 1 And Switch_input_block_channel = 18 Then Gosub Write_fragez
Temp = Ten_times_channel_nr + 496 : Readeeprom Temp_b1 , Temp       'Input at Adr. 501
Value = Temp_b1 : Kein_komma = 1 : Display_time_grid = 1 : Gosub Write_value
Lcd_display_pad_with_spaces = 1 : Gosub Write_time_unit

Lcd_param = 2 : Gosub Lcd_gotoline                          '1.Zeile anw.
Lcd_display_string = "Auto:" : Gosub Lcd_display
Temp4 = Ten_times_channel_nr + 897 : Readeeprom Temp_b1 , Temp4
If Mobile_aktiv = 1 And Switch_input_block_channel = 19 Then Gosub Write_fragez
Value = Temp_b1 : Kein_komma = 1 : Tel_nr = 1 : Gosub Write_value
'value auto setpoint
Lcd_display_string = " Act:" : Gosub Lcd_display

'Temp = Ten_times_channel_nr + 893 : Readeeprom Temp_b2 , Temp
'Value = Temp_b2
Value = Auto_sp_irrigation_time(channel_number) : Kein_komma = 1 : Display_time_grid = 1 : Gosub Write_value       'Alle x ...
'Unit
Lcd_display_string = "sec   "                               'Sp_irrigation_time_max
If Value >= 100 And Value < 200 Then Lcd_display_string = "min   "
If Value >= 200 Then Lcd_display_string = "hr   "
Gosub Lcd_display

Lcd_param = &B00001111 : Gosub Lcd_writecmd                 'Cursor blinken ein
Lcd_param = &H89
If Switch_input_block_channel = 19 Then Lcd_param = &HC5
Gosub Lcd_writecmd
Gosub Line_feed
Return

'######################### Display Sensor Alarm ########################
Display_sensor_alarm:
If Display_info_line = 0 Then
 Lcd_param = 1 : Gosub Lcd_gotoline                         '1234567890123456
 Lcd_display_string = "Check Sensor" : Lcd_display_pad_with_spaces = 1 : Lcd_display_pad_with_spaces = 1 : Gosub Lcd_display
 Lcd_param = 2 : Gosub Lcd_gotoline
 Lcd_display_string = "value changed?" : Lcd_display_pad_with_spaces = 1 : Gosub Lcd_display
 Gosub Line_feed : Waitms 2500 : Display_info_line = 1
End If

Lcd_param = 1 : Gosub Lcd_gotoline                          '0123456778901234567                       '1.Zeile anw.
Lcd_display_string = "SensorAlarm " : Gosub Lcd_display
Temp4 = Ten_times_channel_nr + 495
If Mobile_aktiv = 1 And Switch_input_block_channel = 20 Then Gosub Write_fragez
Readeeprom Temp_b1 , Temp4 : Value = Temp_b1 : Kein_komma = 1 : Gosub Write_value
Lcd_display_string = "min"
Gosub Lcd_display

Lcd_param = &B00001111 : Gosub Lcd_writecmd                 'Cursor blinken ein
Lcd_param = &H8C
Gosub Lcd_writecmd
Gosub Line_feed
Return

'######################### Display Min/Max-Value ########################
Display_min_max:
'If Display_info_line = 0 Then Gosub Input_info
Lcd_param = 1 : Gosub Lcd_gotoline
Lcd_display_string = "Min Feuchte:" : If English = 1 Then Lcd_display_string = "Min Humidtiy:" : Lcd_display_pad_with_spaces = 0 : Gosub Lcd_display
If Mobile_aktiv = 1 And Switch_input_block_channel = 21 Then Gosub Write_fragez
Temp_b2 = Channel_number * 2 : Temp = Temp_b2 + 818 : Readeeprom Value , Temp       'min at Adr. 820
Kein_komma = 1 : Gosub Write_value : Gosub Delete_rest_of_display

Lcd_param = 2 : Gosub Lcd_gotoline                          '1.Zeile anw.
Lcd_display_string = "Max:" : Lcd_display_pad_with_spaces = 0 : Gosub Lcd_display
If Mobile_aktiv = 1 And Switch_input_block_channel = 22 Then Gosub Write_fragez
Temp_b2 = Channel_number * 2 : Temp = Temp_b2 + 820 : Readeeprom Value , Temp       'max at Adr. 822
Kein_komma = 1 : Gosub Write_value : Gosub Delete_rest

Lcd_param = &B00001111 : Gosub Lcd_writecmd                 'Cursor blinken ein
Lcd_param = &H8D
If Switch_input_block_channel = 22 Then Lcd_param = &HC4
Gosub Lcd_writecmd
Return

'######################### next Alarm in ########################
Display_alarm_in:

'0123456789012345
'Next Alarm:12Min
Lcd_param = 1 : Gosub Lcd_gotoline
Lcd_display_string = "Next Alarm:" : Gosub Lcd_display
If Mobile_aktiv = 1 And Switch_input_block_channel = 23 Then Gosub Write_fragez
Temp = Channel_number + 459 : Readeeprom Temp_b1 , Temp     'Output at Adr. 3691
Value = Temp_b1 : Kein_komma = 1 : Gosub Write_value
Lcd_display_string = "min" : Gosub Lcd_display

Lcd_param = &H8C
Gosub Lcd_writecmd
Gosub Line_feed
Return

'Eingabe Zeit Timer
Input_channel:
Ten_times_channel_nr = Channel_number * 10
Select Case Switch_input_block_channel

'Channel-Nr
Case 0:
Temp = Channel_number
Max_value = 20 : Gosub Input_value_ram : Channel_number = Temp
Goto Display_channel

'on/off
Case 1:
If Keyb = 11 Then
 Display_info_line = 0 : Stelle_1 = 0 : Incr Switch_input_block_channel : Goto Display_channel : End If
Temp = Ten_times_channel_nr + 499
Gosub Input_8_bit_value : Stelle_1 = 0 : Goto Display_channel

'Typ
Case 2:
If Keyb = 11 Then                                           'next Input-Block
  Stelle_1 = 0 : Incr Switch_input_block_channel : Goto Display_channel : End If
Temp = Ten_times_channel_nr + 493
Gosub Input_8_bit_value : Goto Display_channel

'< or >
Case 3:
Temp = Ten_times_channel_nr + 898
Gosub Input_8_bit_value : Stelle_1 = 0 : Goto Display_channel

'Setpoint
Case 4:
Temp = Ten_times_channel_nr + 895
Gosub Input_16_bit_value : Goto Display_channel

'Delay on
Case 5:
Temp = Ten_times_channel_nr + 497
Gosub Input_8_bit_value : Goto Display_channel

'Delay off
Case 6:
Temp = Ten_times_channel_nr + 498
Gosub Input_8_bit_value : Goto Display_channel

'Input 1
Case 7:
Temp = Ten_times_channel_nr + 491
Gosub Input_8_bit_value : Goto Display_channel

'Output 1
Case 8:
Temp = Ten_times_channel_nr + 494
If Keyb = 11 Then Display_info_line = 0
Gosub Input_8_bit_value : Goto Display_channel

'Input 2
Case 9:
Temp = Ten_times_channel_nr + 492
Gosub Input_8_bit_value : Goto Display_channel

'Input 2 =1/=0
Case 10:
Temp = Ten_times_channel_nr + 500
Gosub Input_8_bit_value : Stelle_1 = 0 : Goto Display_channel

'Output 2
Case 11:
Temp = Channel_number + 480                                 '481
Gosub Input_8_bit_value : Goto Display_channel

'Hysteresis
Case 12:
If Keyb = 11 Then
 Display_info_line = 0 : Stelle_1 = 0 : Incr Switch_input_block_channel : Goto Display_channel : End If
Temp = Ten_times_channel_nr + 899
Gosub Input_16_bit_value : Goto Display_channel

'Input hr
Case 13:                                                    'Input hr
Temp = Ten_times_channel_nr + 891
Max_value = 24 : Gosub Input_8_bit_value : Goto Display_channel

'min
Case 14:                                                    '
'Display Unit s/m/h
If Keyb = 11 Then                                           'next Input-Block
   Lcd_param = 2 : Gosub Lcd_gotoline                       '2.Zeile anw.
   Gosub Write_unit_info : End If
Temp = Ten_times_channel_nr + 892
Max_value = 60 : Gosub Input_8_bit_value : Goto Display_channel

'on for....
Case 15:
If Keyb = 11 Then                                           'next Input-Block
   Lcd_param = 2 : Gosub Lcd_gotoline                       '2.Zeile anw.
   Gosub Write_unit_info2 : End If
Temp = Ten_times_channel_nr + 893
Gosub Input_8_bit_value : Goto Display_channel

'all x_min on
Case 16:                                                    '
If Keyb = 11 Then                                           'next Input-Block
   Lcd_param = 2 : Gosub Lcd_gotoline                       '2.Zeile anw.
   Gosub Write_unit_info : End If
Temp = Ten_times_channel_nr + 894
Gosub Input_8_bit_value : Goto Display_channel

'Pulse active-Time
Case 17:                                                    '
Temp = Channel_number + 440
If Keyb = 11 Then Display_info_line = 0
Gosub Input_8_bit_value : Goto Display_channel

'MAX-Time
Case 18:
Temp = Ten_times_channel_nr + 496
Gosub Input_8_bit_value : Goto Display_channel

'Auto
Case 19:
If Keyb = 11 Then Display_info_line = 0
Temp = Ten_times_channel_nr + 897
Gosub Input_8_bit_value : Stelle_1 = 0 : Goto Display_channel

'Sensor_alarm
Case 20:
Temp = Ten_times_channel_nr + 495
Gosub Input_8_bit_value : Goto Display_channel

'Min-value
Case 21:
Temp_b2 = Channel_number * 2 : Temp = Temp_b2 + 818         'min at Adr. 818
Gosub Input_16_bit_value : Goto Display_channel

'Max-value
Case 22:
Temp_b2 = Channel_number * 2 : Temp = Temp_b2 + 820         'max at Adr. 820
Gosub Input_16_bit_value : Goto Display_channel

'No_Alarm_Time
Case 23:
Temp = Channel_number + 459                                 '481
Gosub Input_8_bit_value : Goto Display_channel

End Select
Return

Show_channel_info:
 Lcd_display_string = " "
 If Channel_typ > 9 And Channel_typ < 19 Then
   Lcd_display_string = "Alarm " : Gosub Lcd_display : End If
 If Channel_typ > 19 And Channel_typ > 29 Then
   Lcd_display_string = "Lock " : Gosub Lcd_display : End If
Temp_b5 = Channel_typ Mod 10
 If Temp_b5 = 0 Then Lcd_display_string = "Irrigate"
 If Temp_b5 = 1 Then Lcd_display_string = "°C"
 If Temp_b5 = 2 Then Lcd_display_string = "%"
 If Temp_b5 = 3 Then Lcd_display_string = "Voltage"
 If Temp_b5 = 3 Then Lcd_display_string = "Ampere"
  Lcd_display_pad_with_spaces = 1 : Gosub Lcd_display : Gosub Line_feed
Return

'###################### Temperature-Handling #############################
Key2:
'Temp Act:23.4'
'normal/Temp no Irrigate/Temp do Irrigate
'Temp up:33.3'C / Temp down:12.3'C
If Keyb <> 2 Then Goto Key3
Fkt2 = 1 : Gosub Del_disp                                   '1234567890123456
Lcd_param = 1 : Gosub Lcd_gotoline
'if Programm_selector > 8 Then Goto Display_min_max_values  'show Min_Max
Lcd_display_string = "Temp Min/Max" : Lcd_display_pad_with_spaces = 1 : Gosub Lcd_display
Lcd_param = 2 : Gosub Lcd_gotoline                          '1234567890123456
 If English = 0 Then Lcd_display_string = "Bewässg.aus/ein" Else Lcd_display_string = "Irrigate on/off" : Lcd_display_pad_with_spaces = 1 : Gosub Lcd_display
 Gosub Lcd_display : Gosub Line_feed : Waitms 2500

Display_fkt2:
  If Eingabe_teil_2 = 1 Or Eingabe_teil_3 = 1 Then Goto Anzeige_temp_up
  Lcd_param = 1 : Gosub Lcd_gotoline
  If English = 0 Then Lcd_display_string = "Temp Akt:" Else Lcd_display_string = "Temp Act:" : Gosub Lcd_display
  Value = Ext_temperature : Gosub Write_value
Lcd_display_string = "°C" : Lcd_display_pad_with_spaces = 1 : Gosub Lcd_display

  Lcd_param = 2 : Gosub Lcd_gotoline                        '2.Zeile anw.
  Readeeprom Temp_b1 , 85                                   'Pointer Function
 If Eingabe_teil_2 = 0 And Eingabe_teil_3 = 0 Then Gosub Write_fragez
If Temp_b1 < 1 Or Temp_b1 > 2 Then Lcd_display_string = "off (0/1/2/#)"
If Temp_b1 = 1 Then                                         '1234567890123456
 If English = 0 Then Lcd_display_string = "Temp.Bewässg.ein" Else Lcd_display_string = "Temp.do Irrigate" : End If
If Temp_b1 = 2 Then
 If English = 0 Then Lcd_display_string = "Temp.Bewässg.aus" Else Lcd_display_string = "Temp no Irrigate" : End If
Lcd_display_pad_with_spaces = 1 : Gosub Lcd_display

Lcd_param = &B00001111 : Gosub Lcd_writecmd                 '**** Cursor blinken ein
Lcd_param = &HC0
Gosub Lcd_writecmd
Gosub Line_feed
Return

Anzeige_temp_up:
Lcd_param = 1 : Gosub Lcd_gotoline
Lcd_display_string = "Temp Max:" : Gosub Lcd_display
Readeeprom Value , 86
If Mobile_aktiv = 1 And Eingabe_teil_2 = 1 Then Gosub Write_fragez
Gosub Write_value                                           'Eingabe-Wert
Lcd_display_string = "°C" : Lcd_display_pad_with_spaces = 1 : Gosub Lcd_display

Lcd_param = 2 : Gosub Lcd_gotoline
Lcd_display_string = "Temp Min:" : Gosub Lcd_display
Readeeprom Value , 88
If Mobile_aktiv = 1 And Eingabe_teil_3 = 1 Then Gosub Write_fragez
Lcd_display_string = "-" : Gosub Lcd_display
Gosub Write_value                                           'Eingabe-Wert
Lcd_display_string = "°C" : Lcd_display_pad_with_spaces = 1 : Gosub Lcd_display

Lcd_param = &B00001111 : Gosub Lcd_writecmd                 'Cursor blinken ein
Lcd_param = &H89
If Eingabe_teil_3 = 1 Then Lcd_param = &HC9
Gosub Lcd_writecmd
Gosub Line_feed
Return

Display_min_value:
   Readeeprom Value , 404                                   'Input-Nr Min 1
  Kein_komma = 1 : Gosub Write_value
   Lcd_display_string = ":" : Lcd_display_pad_with_spaces = 0 : Gosub Lcd_display
    Value = Min_value_1 : Gosub Write_value
    Gosub Delete_rest
Return

Display_max_value:
   Readeeprom Value , 406                                   'Input-Nr Max 1
  Kein_komma = 1 : Gosub Write_value
   Lcd_display_string = ":" : Lcd_display_pad_with_spaces = 0 : Gosub Lcd_display
    Value = Max_value_1 : Gosub Write_value
    Gosub Delete_rest
Return

Delete_rest:
    Lcd_display_pad_with_spaces = 1 : Lcd_display_string = " " : Gosub Lcd_display
    Gosub Line_feed
Return

Eing_2:
If Eingabe_teil_2 = 1 Then Goto Su8_eing_teil_1
If Eingabe_teil_3 = 1 Then Goto Su8_eing_teil_2

If Keyb = 11 Then Goto Su8_00                               'keine neue Eingabe?
If Keyb > 3 Then Gosub Write_nein
If Keyb > 3 Then Return
Writeeeprom Keyb , 85 : Goto Display_fkt2
Su8_00:
Stelle_1 = 0 : Eingabe_teil_2 = 1 : Goto Display_fkt2

Su8_eing_teil_1:
If Keyb = 11 Then Goto Su8_01                               'keine neue Eingabe?
If Stelle_1 = 1 Then Goto Su8_stelle2                       'Eingabe Stunde
Lcd_param = 86 : Temp = Keyb : Writeeeprom Temp , Lcd_param 'su_hour
    Stelle_1 = 1 : Goto Display_fkt2                        '1.Stelle
Su8_stelle2:
Lcd_param = 86 : Readeeprom Temp , Lcd_param
    Temp = 10 * Temp : Temp = Temp + Keyb
    Writeeeprom Temp , Lcd_param : Goto Display_fkt2
Su8_01:
Stelle_1 = 0 : Eingabe_teil_2 = 0 : Eingabe_teil_3 = 1 : Goto Display_fkt2

Su8_eing_teil_2:                                            'Eingabe Minute
If Keyb = 11 Then Goto End_su8_02                           'keine neue Eingabe?
If Stelle_1 = 1 Then Goto Su8_2_stelle2
Lcd_param = 88 : Temp = Keyb : Writeeeprom Temp , Lcd_param
    Stelle_1 = 1 : Goto Display_fkt2                        '1.Stelle
Su8_2_stelle2:
Lcd_param = 88 : Readeeprom Temp , Lcd_param
    Temp = 10 * Temp : Temp = Temp + Keyb
    Writeeeprom Temp , Lcd_param : Goto Display_fkt2
End_su8_02:
 Stelle_1 = 0 : Eingabe_teil_3 = 0 : Goto Display_fkt2

'Alarm-System/Moving-Detektor
Key3:
If Keyb <> 3 Then Goto Key4
Fkt3 = 1 : Gosub Del_disp
 Lcd_param = 1 : Gosub Lcd_gotoline                         '1234567890123456                    '1234567890123456
If English = 0 Then Lcd_display_string = "Alarm-Eingang +" Else Lcd_display_string = "Alarm-Input +" : Gosub Lcd_display
 Lcd_param = 2 : Gosub Lcd_gotoline                         '1234567890123456                  '1234567890123456
 If English = 0 Then Lcd_display_string = "Niveau-Steurg." Else Lcd_display_string = "Level-Control"
 Gosub Lcd_display : Gosub Line_feed : Display_info_line = 1 : Waitms 2300
Display_fkt3:
 Lcd_param = 1 : Gosub Lcd_gotoline                         '1234567890123456                    '1234567890123456
'if Programm_selector > 8 Then GoTo Display_Run_Time 'Run-Time hrs
If Switch_input_block > 6 Then Switch_input_block = 0
If Channel_number < 1 Or Channel_number > 5 Then Channel_number = 1
'#################################### Display_Delay_on ###################################
If Switch_input_block >= 0 And Switch_input_block < 3 Then
Lcd_param = 1 : Gosub Lcd_gotoline                          '1.Zeile anw.
Lcd_display_string = "Nr:" : Gosub Lcd_display
If Switch_input_block = 0 Then Gosub Write_fragez
Value = Channel_number : Kein_komma = 1 : Tel_nr = 1 : Gosub Write_value
Lcd_display_string = " " : Gosub Lcd_display
Pointer_eeprom = Channel_number * 10 : Pointer_eeprom = Pointer_eeprom + 691
If Mobile_aktiv = 1 And Switch_input_block = 1 Then Gosub Write_fragez
Readeeprom Temp_b1 , Pointer_eeprom : If Temp_b1 = 0 Then Gosub Write_off Else Gosub Write_on       'on/off
'Display actual
Lcd_display_string = "/" : Gosub Lcd_display
Incr Pointer_eeprom : Readeeprom Temp_b1 , Pointer_eeprom   'Delay on
Incr Pointer_eeprom : Readeeprom Temp_b2 , Pointer_eeprom   'Delay off

'1234567890123456
'Nr:2 Ein/On:23mi
If English = 0 Then Lcd_display_string = "aus" Else Lcd_display_string = "off" : Lcd_display_pad_with_spaces = 1
If Alarm_active_delay_on(channel_number) > 0 Then
  Lcd_display_pad_with_spaces = 0 : Lcd_display_string = "in:" : Gosub Lcd_display
 Value = Alarm_active_delay_on(channel_number) : Kein_komma = 1 : Gosub Write_value : Value = Temp_b1 : Lcd_display_pad_with_spaces = 1 : Gosub Write_time_unit : End If
If Alarm_active(channel_number) > 0 Then
    Lcd_display_pad_with_spaces = 0 : If English = 0 Then Lcd_display_string = "an:" Else Lcd_display_string = "on:" : Gosub Lcd_display
  Value = Alarm_active(channel_number) : Kein_komma = 1 : Gosub Write_value : Value = Temp_b2 : Lcd_display_pad_with_spaces = 1 : Gosub Write_time_unit : End If
Gosub Lcd_display

Lcd_param = 2 : Gosub Lcd_gotoline                          '1234567890123456
If Display_info_line = 0 And Switch_input_block = 2 Then Gosub Write_unit_info
Lcd_param = 2 : Gosub Lcd_gotoline                          '1234567890123456
If English = 0 Then Lcd_display_string = "Verz.ein:" Else Lcd_display_string = "Delay on:" : Gosub Lcd_display
If Mobile_aktiv = 1 And Switch_input_block = 2 Then Gosub Write_fragez
Value = Temp_b1 : Kein_komma = 1 : Display_time_grid = 1 : Gosub Write_value

Lcd_display_pad_with_spaces = 1 : Gosub Write_time_unit

Lcd_param = &B00001111 : Gosub Lcd_writecmd                 '**** Cursor blinken ein
Lcd_param = &H83
If Switch_input_block = 1 Then Lcd_param = &H85
If Switch_input_block = 2 Then Lcd_param = &HC9
Gosub Lcd_writecmd
Gosub Line_feed
End If                                                      'Switch_input_block = 1..

'#################################### Display_Delay_off + Input ###################################
If Switch_input_block = 3 Or Switch_input_block = 4 Then
Lcd_param = 1 : Gosub Lcd_gotoline
Pointer_eeprom = Channel_number * 10 : Pointer_eeprom = Pointer_eeprom + 693
If Display_info_line = 0 And Switch_input_block = 3 Then Gosub Write_unit_info       '1234567890
Lcd_param = 1 : Gosub Lcd_gotoline
If English = 0 Then Lcd_display_string = "Verz.aus:" Else Lcd_display_string = "Delay off:" : Gosub Lcd_display
If Mobile_aktiv = 1 And Switch_input_block = 3 Then Gosub Write_fragez
Readeeprom Temp_b1 , Pointer_eeprom : Value = Temp_b1 : Kein_komma = 1 : Display_time_grid = 1 : Gosub Write_value
Lcd_display_pad_with_spaces = 1 : Gosub Write_time_unit

Lcd_param = 2 : Gosub Lcd_gotoline                          '1234567890123456
If Display_info_line = 0 And Switch_input_block = 4 Then Gosub Input_info
Lcd_param = 2 : Gosub Lcd_gotoline
Lcd_display_string = "Input:" : Gosub Lcd_display
If Mobile_aktiv = 1 And Switch_input_block = 4 Then Gosub Write_fragez
Incr Pointer_eeprom : Readeeprom Temp_b1 , Pointer_eeprom   'Input at Adr. 501
Value = Temp_b1 : Kein_komma = 1 : Gosub Write_value : Gosub Write_input

Lcd_param = &B00001111 : Gosub Lcd_writecmd                 '**** Cursor blinken ein
Lcd_param = &H89
If Switch_input_block = 4 Then Lcd_param = &HC6
Gosub Lcd_writecmd
Gosub Line_feed
End If                                                      'Switch_input_block = 1..

'######################### Display_Output ########################
If Switch_input_block = 5 Or Switch_input_block = 6 Then
Lcd_param = 1 : Gosub Lcd_gotoline
If Display_info_line = 0 And Switch_input_block = 5 Then Gosub Output_info
Pointer_eeprom = Channel_number * 10 : Pointer_eeprom = Pointer_eeprom + 695
Lcd_param = 1 : Gosub Lcd_gotoline
Lcd_display_string = "Output:" : Gosub Lcd_display
If Mobile_aktiv = 1 And Switch_input_block = 5 Then Gosub Write_fragez
Readeeprom Temp_b1 , Pointer_eeprom                         'Input at Adr. 501
Value = Temp_b1 : Kein_komma = 1 : Gosub Write_value : Gosub Write_output

Lcd_param = 2 : Gosub Lcd_gotoline
If Display_info_line = 0 And Switch_input_block = 6 Then Gosub Type_info
Incr Pointer_eeprom
Lcd_param = 2 : Gosub Lcd_gotoline
Lcd_display_string = "Type:" : Gosub Lcd_display
If Mobile_aktiv = 1 And Switch_input_block = 6 Then Gosub Write_fragez
Readeeprom Temp_b1 , Pointer_eeprom                         'Input at Adr. 501
Value = Temp_b1 : Kein_komma = 1 : Tel_nr = 1 : Gosub Write_value : Gosub Write_type_nr

Lcd_param = &B00001111 : Gosub Lcd_writecmd                 '**** Cursor blinken ein
Lcd_param = &H87
If Switch_input_block = 6 Then Lcd_param = &HC5
Gosub Lcd_writecmd
Gosub Line_feed
End If                                                      'Switch_input_block = 1..

Return

Display_run_time:
'   Readeeprom temp_b1, 408 'Ausg-Nr
'    Lcd_display_string = "Run-Time" : Gosub Lcd_display
'  kein_komma = 1 : value = temp_b1 :  Gosub Write_value

'  Lcd_param = 2 : Gosub Lcd_gotoline                      '1.Zeile anw.
   Value = Running_time_1 / 60
   Kein_komma = 1 : Gosub Write_value
   Lcd_display_string = " Std " : Lcd_display_pad_with_spaces = 0 : Gosub Lcd_display
   Value = Running_time_1 Mod 60
   Kein_komma = 1 : Gosub Write_value
   Lcd_display_string = " min  " : Gosub Lcd_display
   Gosub Line_feed
Return

Eing_3:
Pointer_eeprom = Channel_number * 10 : Pointer_eeprom = Pointer_eeprom + 691

Select Case Switch_input_block
'channel nr
Case 0:
If Keyb = 11 Then                                           'next Input-Block
  Keyb = 255 : Stelle_1 = 0 : Incr Switch_input_block : Goto Display_fkt3 : End If
If Keyb < 1 And Keyb > 5 Then
 Gosub Write_nein : Return : End If
Channel_number = Keyb : Goto Display_fkt3

'on/off
Case 1:
Temp = Pointer_eeprom
If Keyb = 11 Then                                           'next Input-Block
    Keyb = 255 : Stelle_1 = 0 : Incr Switch_input_block : Display_info_line = 0 : Goto Display_fkt3 : End If
Writeeeprom Keyb , Pointer_eeprom : Goto Display_fkt3

'Delay_on
Case 2:
Temp = Pointer_eeprom + 1
If Keyb = 11 Then Display_info_line = 0
Gosub Input_8_bit_value : Goto Display_fkt3

'Delay_off
Case 3:
Temp = Pointer_eeprom + 2
If Keyb = 11 Then Display_info_line = 0
Gosub Input_8_bit_value : Goto Display_fkt3

'Input
Case 4:
Temp = Pointer_eeprom + 3
If Keyb = 11 Then Display_info_line = 0
Gosub Input_8_bit_value : Goto Display_fkt3

'Output
Case 5:
Temp = Pointer_eeprom + 4
If Keyb = 11 Then Display_info_line = 0
Gosub Input_8_bit_value : Goto Display_fkt3

'Type
Case 6:
Temp = Pointer_eeprom + 5
Gosub Input_8_bit_value : Stelle_1 = 0 : Goto Display_fkt3

End Select
Return

'Tel-Number
Key4:
If Keyb <> 4 Then Goto Key5
Fkt4 = 1 : Lcd_param = &B00000001 : Gosub Lcd_writecmd      '// Display loeschen
Tel_nr = 1 : Nr_2_waehlen = 0 : Nr_3_waehlen = 0
Pointer_eeprom = 130 : Readeeprom Temp_b1 , Pointer_eeprom  'Erst mal Telefonnumer 1
If Temp_b1 >= 0 And Temp_b1 <= 2 Then Goto Nr_select_ok
If Temp_b1 >= 11 And Temp_b1 <= 12 Then Goto Nr_select_ok
Temp_b1 = 0 : Pointer_eeprom = 130 : Writeeeprom Temp_b1 , Pointer_eeprom : Eingabe_teil_2 = 1 : Stelle_1 = 0
If Temp_b1 = 0 Then Eingabe_teil_2 = 1 : If Temp_b1 = 0 Then Stelle_1 = 0
Nr_select_ok:
Lcd_param = &B00000001 : Gosub Lcd_writecmd
Stelle_1 = 0
Display_input:
Tel_nr = 1
Lcd_param = 1 : Gosub Lcd_gotoline
Lcd_display_string = "Tel-Nr:" : Gosub Lcd_display
Gosub Write_telefon_nr
If Eingabe_teil_3 = 1 And Mobile_aktiv = 1 Then Gosub Write_fragez
Lcd_display_string = " Test(=1)" : Gosub Lcd_display
If Temp_b1 <> 0 Then Gosub Display_nr Else Gosub Write_tel_nr_0

Lcd_param = &B00001111 : Gosub Lcd_writecmd                 '**** Cursor blinken ein
If Eingabe_teil_2 = 0 Then Lcd_param = &H87 Else Lcd_param = &HC0       'Cursor auf best. Position
If Eingabe_teil_3 = 1 Then Lcd_param = &H89                 'Cursor auf best. Position
Gosub Lcd_writecmd
Gosub Line_feed
Return

'Eingabe Nummer
Eing_4:
If Eingabe_teil_2 = 1 Then Goto Input_of_the_number
If Eingabe_teil_3 = 1 Then Goto Test_anruf

'Tel_nr_selection:
If Keyb = 11 Then Goto Tel_anw_end
If Stelle_1 = 1 Then Goto Tel_000
Stelle_1 = 1 : If Keyb < 0 Then Keyb = 1 : If Keyb > 2 Then Keyb = 1
  Writeeeprom Keyb , 130 : Goto Display_input
Tel_000:
Readeeprom Temp_b1 , 130
Temp_b1 = 10 * Temp_b1 : Temp_b1 = Temp_b1 + Keyb :
If Temp_b1 > 12 Then Gosub Write_nein : If Temp_b1 > 12 Then Goto Display_input
If Temp_b1 > 2 And Temp_b1 <= 10 Then Gosub Write_nein : If Temp_b1 > 2 And Temp_b1 <= 10 Then Goto Display_input
Writeeeprom Temp_b1 , 130 : Stelle_1 = 0 : Goto Display_input
Tel_anw_end:
Stelle_1 = 0 : Eingabe_teil_2 = 1 : Goto Display_input

Input_of_the_number:
If Keyb = 11 Then Goto Fkt4_t1_end
If Stelle_1 = 1 Then Goto F4_1
Stelle_1 = 1 : Gosub Delete_number
Pointer_eeprom_tel = 131
If Temp_b1 = 2 Then Pointer_eeprom_tel = 145
'If Temp_b1 = 3 Then Pointer_eeprom_tel = 59
'GoSub Get_pointer_to_tel_number
F4_1:
Writeeeprom Keyb , Pointer_eeprom_tel : Incr Pointer_eeprom_tel
Temp_b1 = Pointer_eeprom_tel : Readeeprom Temp_b2 , Temp_b1 'wurde 000 eingegeben? dann lösche Nummer
Temp_b1 = Pointer_eeprom_tel + 1 : Readeeprom Lcd_param , Temp_b1
Temp_b1 = Pointer_eeprom_tel + 2 : Readeeprom Number , Temp_b1
If Temp_b2 = 0 And Lcd_param = 0 And Number = 0 Then Gosub Delete_number : Goto Display_input
Fkt4_t1_end:
Stelle_1 = 0 : Eingabe_teil_2 = 0 : Eingabe_teil_3 = 1 : Goto Display_input

Test_anruf:
If Keyb = 11 Then
  Stelle_1 = 0 : Eingabe_teil_2 = 0 : Eingabe_teil_3 = 0 : Goto Display_input : End If
If Keyb <> 1 Then Goto Display_input
Stelle_1 = 0 : Eingabe_teil_2 = 0 : Eingabe_teil_3 = 0
' Lcd_param = &B00000001 : Gosub Lcd_writecmd                '// Display loeschen
'Lcd_display_string = "Test!" : No_print_seriell = 1 : Gosub Lcd_display
'Pointer_eeprom = 130 : Readeeprom Keyb , Pointer_eeprom
'If keyb = 2 Then Nr_2_ein = 1
'If keyb = 3 Then Nr_3_ein = 1
Wait 1 : Fkt4 = 0 : Test_anruf = 1 : Stelle_1 = 0 : Eingabe_teil_2 = 0 : Eingabe_teil_3 = 0 : If Delay_on < 30 Then Delay_on = 30 : Goto Anrufen

Delete_number:
Gosub Get_pointer_to_tel_number
For Lcd_param = 1 To 15                                     'alles erst mal löschen
Temp_b1 = 11 : Writeeeprom Temp_b1 , Pointer_eeprom
Incr Pointer_eeprom
Next
Gosub Get_pointer_to_tel_number
Return

Write_telefon_nr:
Tel_nr = 1
If Eingabe_teil_2 = 0 And Eingabe_teil_3 = 0 And Mobile_aktiv = 1 Then Gosub Write_fragez
Pointer_eeprom = 130 : Readeeprom Temp_b1 , Pointer_eeprom : Value = Temp_b1 : Kein_komma = 1 : Gosub Write_value
Return

Display_nr:
Tel_nr = 1 : Lcd_param = 2 : Gosub Lcd_gotoline
If Eingabe_teil_2 = 1 And Mobile_aktiv = 1 Then Gosub Write_fragez
    Gosub Get_pointer_to_tel_number
    Display_zaehler = 1
Next_number:
    Readeeprom Temp_b1 , Pointer_eeprom : Value = Temp_b1
    If Value = 11 Then Goto End_display
    Tel_nr = 1 : Kein_komma = 1 : Gosub Write_value
    Display_zaehler = Display_zaehler + 1
    Pointer_eeprom = Pointer_eeprom + 1
    If Display_zaehler < 15 Then Goto Next_number
End_display:
    For Display_zaehler = 1 To 16
    Lcd_param = Leerz : Gosub Lcd_writechar
    Next
If Mobile_aktiv = 1 Then Print #1 , " ";
   Tel_nr = 0 : Return

Write_tel_nr_0:
    Lcd_param = 2 : Gosub Lcd_gotoline
    Lcd_display_string = "(0=Off,12=all)" : Gosub Lcd_display
Return

'Anrufen_alarm:
'Readeeprom Temp_b1 , 130 : If Temp_b1 = 0 Then Return       'any number selected?
'If Meldung_aktiv = 0 Then Flag_call_alarm = 0
'If Meldung_aktiv = 0 Or Flag_call_alarm = 1 Then Return
''If Flanke_alarm_tuer = 1 Then                               '***Here more Alarm-conditons for call mobile
'' Flag_call_alarm = 1 : Gosub Anrufen : End If
'Return

Anrufen:
Readeeprom Temp_b1 , 130 : If Temp_b1 = 0 Or Delay_on < 30 Then Return       'next calls?
Telephone_on = 1
Nr_2_waehlen = 0 : Nr_3_waehlen = 0
Next_call:
If Send_sms = 0 Then Gosub Mobile                           'SMS senden
If Send_sms = 1 Then
   Gosub Send_sms_header : Gosub Send_sms_alarm : Return : End If       'call on Handy
Readeeprom Temp_b3 , Pointer_eeprom
'Lcd_param = &B00000001 : Gosub Lcd_writecmd
'Lcd_display_string = "Tel-Call!" : Gosub Lcd_display
Gosub Display_nr
Config Pinc.7 = Output
Portc.7 = 1
Waitms 800                                                  'voreinst.: 180 bis Freizeichen
Gosub Get_pointer_to_tel_number : Temp_b1 = Pointer_eeprom : Temp_b2 = Pointer_eeprom + 14
For Pointer_eeprom = Temp_b1 To Temp_b2                     'Zeiger Numer 1
Readeeprom Temp_b3 , Pointer_eeprom                         'Nummern lesen
If Temp_b3 = 11 Then Goto End_call
Gosub Keyboard                                              'Tastatur abfragen
If Port11 = 1 Then Goto Finish_calling                      'Abbruch-Taste "*" gedrückt?
'If Temp_b3 = 0 Then Temp_b3 = 10                            'wenn Nr = 0 dann 10 Pulse
If Temp_b3 < 0 Or Temp_b3 > 9 Then Goto End_call
Dtmfout Temp_b3 , 500
Waitms 400                                                  '840 ms
Next
End_call:
For Value = 1 To 200                                        'Alarmmeldung durch Beep
Sound Portb.5 , 10000 , 10                                  '***T
Gosub Keyboard                                              'Tastatur abfragen
If Port11 = 1 Then Goto Finish_calling                      'Abbruch-Taste "*" gedrückt?
Next
Portc.7 = 0                                                 'auflegen und fertig

Readeeprom Temp_b1 , 130                                    'next calls?
If Temp_b1 > 10 And Nr_2_waehlen = 1 Then Goto Finish_calling       '***T
If Temp_b1 > 10 And Nr_2_waehlen = 0 Then Nr_2_waehlen = 1
If Nr_2_waehlen = 1 Or Nr_3_waehlen = 1 Then Waitms 500
If Nr_2_waehlen = 1 Or Nr_3_waehlen = 1 Then
Print #1 , "ATH" : Wait 1 : Goto Next_call : End If
Finish_calling:
Print #1 , "ATH" : Portc.7 = 0 : Time_no_seriell_pc = 40 : Test_anruf = 0 : Nr_2_waehlen = 0 : Nr_3_waehlen = 0 : Meldung_aktiv = 0 : Telephone_on = 0 : Goto Reset
Return

Get_pointer_to_tel_number:
Readeeprom Temp_b1 , 130
If Nr_2_waehlen = 1 Then Temp_b1 = 2
'If nr_3_waehlen = 1 Then Temp_b1 = 3
If Temp_b1 <= 0 Then Temp_b1 = 1
If Temp_b1 > 2 And Temp_b1 <= 10 Then Temp_b1 = 1
Pointer_eeprom = 131
If Temp_b1 = 2 Then Pointer_eeprom = 145
'If Temp_b1 = 3 Then Pointer_eeprom = 59
Return

Key5:
If Keyb <> 5 Then Goto Key6                                 'Alarm Water / Fill-Time
Fkt5 = 1 : Gosub Del_disp
Display_fkt5:
   Lcd_param = 1 : Gosub Lcd_gotoline                       '1.Zeile des Displays wird aktiviert
   Lcd_display_string = "Temp.int: " : Gosub Lcd_display
   Value = Sensor_temp_kompensation : Gosub Write_value
   Lcd_display_string = "°C" : Gosub Lcd_display
'   Lcd_display_string = "Batt:" : Gosub Lcd_display
'   Value = U_batt_smooth : Gosub Write_value
'   Lcd_display_string = "V" : Gosub Lcd_display

' If timer_2_sec = 0 Then
'   Lcd_display_string = "I Sol:" : Gosub Lcd_display
'   value = I_Solar : GoSub write_value : Lcd_display_string = "A" : Gosub Lcd_display
'Else
'    Lcd_display_string = "I Load:" : Gosub Lcd_display
'   value = I_Load  : GoSub write_value : Lcd_display_string = "A" : Gosub Lcd_display
'End If

   Lcd_param = 2 : Gosub Lcd_gotoline                       '2.Zeile des Displays wird aktiviert
   Lcd_display_string = "Temp.ext: " : Gosub Lcd_display
   Value = Ext_temperature : Gosub Write_value
   Lcd_display_string = "°C" : Gosub Lcd_display

'   If English = 0 Then Lcd_display_string = "U Ausg:" Else Lcd_display_string = "U Out: " : Gosub Lcd_display
'   Value = U_ausg : Gosub Write_value
'   Lcd_display_string = "V " : Lcd_display_pad_with_spaces = 1 : Gosub Lcd_display
'   If English = 0 Then Lcd_display_string = "Füllzeit:" Else Lcd_display_string = "Fill-Time:" : Gosub Lcd_display
'    If Mobile_aktiv = 1 And Eingabe_teil_2 = 1 Then Gosub Write_fragez
'    Readeeprom Temp_b1 , 81 : Value = Temp_b1 : Kein_komma = 1 : Display_time_grid = 1 : Gosub Write_value
'    If Value <= 100 Then Lcd_display_string = "sec"
'    If Value > 100 And Value <= 200 Then Lcd_display_string = "min"
'    If Value > 200 Then Lcd_display_string = "hr" : Gosub Lcd_display

'Lcd_param = &B00001111 : Gosub Lcd_writecmd                 '**** Cursor blinken ein
'If Eingabe_teil_2 = 0 Then Lcd_param = &H8F Else
'Lcd_param = &B11001010                                      'Cursor auf best. Position
'Gosub Lcd_writecmd
Gosub Line_feed
Return

'Alarm Wasser ein
Eing_5:
'If Eingabe_teil_2 = 1 Then Goto Fill2
'If Keyb = 11 Then Goto End_wa_teil_1
'If Keyb = 1 Then Alarm_no_water_flow = 1 Else Alarm_no_water_flow = 0
'If Alarm_no_water_flow = 0 Then Temp_b1 = 0 Else Temp_b1 = 1 : Lcd_param = 80 : Writeeeprom Temp_b1 , Lcd_param : Goto Display_fkt5
'End_wa_teil_1:
'Eingabe_teil_2 = 1 : Goto Display_fkt5
'
'Fill2:
'If Keyb = 11 Then Goto End_wa_teil_2
''If Stelle_1 = 1 Then Goto Wa_stelle2
''Lcd_param = 81 : Writeeeprom Keyb , Lcd_param
''    Stelle_1 = 1 : Goto Display_fkt5                        '1.Stelle
''Wa_stelle2:
''Lcd_param = 81 : Readeeprom Temp_b1 , Lcd_param             'su_hour
''    Value = 10 * Temp_b1 : Value = Value + Keyb :
''    If Value > 255 Then
''      Gosub Write_nein : Goto Display_fkt5 : End If
''  Temp_b1 = Value : Writeeeprom Temp_b1 , Lcd_param : Goto Display_fkt5
'
'End_wa_teil_2:
'Eingabe_teil_2 = 0 : Stelle_1 = 0
'GoTo Display_fkt5
Return

Key6:
If Keyb <> 6 Then Goto Key7
Fkt6 = 1 : Display_info_line = 1 : Gosub Del_disp
Lcd_param = 1 : Gosub Lcd_gotoline
 If English = 0 Then Lcd_display_string = "Lastabw.Spannung" Else Lcd_display_string = "Switch off Volt-" : Gosub Lcd_display
 Lcd_param = 2 : Gosub Lcd_gotoline                         '1234567890123456
 If English = 0 Then Lcd_display_string = " Schaltuhr 1-5  " Else Lcd_display_string = " age/Timer 1-5" : Gosub Lcd_display : Gosub Line_feed : Waitms 2300
Display_fkt6:
Lcd_param = 1 : Gosub Lcd_gotoline
If English = 0 Then Lcd_display_string = "K" Else Lcd_display_string = "C" : Gosub Lcd_display :
If Mobile_aktiv = 1 And Eingabe_teil_2 = 0 And Eingabe_teil_3 = 0 And Eingabe_teil_4 = 0 And Eingabe_teil_5 = 0 And Eingabe_teil_6 = 0 Then Gosub Write_fragez
If Timer_nr = 0 Then Timer_nr = 1 : Value = Timer_nr : Kein_komma = 1 : Tel_nr = 1 : Gosub Write_value : Tel_nr = 0

If English = 0 Then Lcd_display_string = " aus:" Else Lcd_display_string = " off:" : Gosub Lcd_display
No_load_funct:
 Temp4 = Timer_nr * 2 : Temp4 = Temp4 + 240
 Readeeprom Value , Temp4
 If Mobile_aktiv = 1 And Eingabe_teil_2 = 1 Then Gosub Write_fragez
Kein_komma = 0
Gosub Write_value

 Lcd_display_string = "V/" :
 Gosub Lcd_display

 If Mobile_aktiv = 1 And Eingabe_teil_3 = 1 Then Gosub Write_fragez
 If Time_load_shedding(timer_nr) = 1 Then Gosub Write_on Else Gosub Write_off
Gosub Delete_rest_of_display

If Display_info_line = 0 And Eingabe_teil_6 = 1 Then
  Lcd_param = 2 : Gosub Lcd_gotoline : Gosub Write_unit_info : End If
Lcd_param = 2 : Gosub Lcd_gotoline                          '2.Zeile anw.
If English = 0 Then Lcd_display_string = "Zeit:" Else Lcd_display_string = "Time:"
If Eingabe_teil_4 = 1 Then
 If English = 0 Then Lcd_display_string = "Std: " Else Lcd_display_string = "hour:" : End If
If Eingabe_teil_5 = 1 Then Lcd_display_string = "min: "
If Eingabe_teil_6 = 1 Then
  If English = 0 Then Lcd_display_string = "für: " Else Lcd_display_string = "for: " : End If
Gosub Lcd_display

Temp4 = Timer_nr * 3 : Temp4 = Temp4 + 223                  'hr
Readeeprom Temp_b1 , Temp4                                  'hr
If Mobile_aktiv = 1 And Eingabe_teil_4 = 1 Then Gosub Write_fragez
Kein_komma = 1 : Value = Temp_b1 : Gosub Write_value
Lcd_display_string = ":" : Gosub Lcd_display
Temp4 = Timer_nr * 3 : Temp4 = Temp4 + 224                  'min
Readeeprom Temp_b1 , Temp4                                  'min
If Mobile_aktiv = 1 And Eingabe_teil_5 = 1 Then Gosub Write_fragez
Value = Temp_b1 : Gosub Write_value
Lcd_display_string = "/" : Gosub Lcd_display
Temp4 = Timer_nr * 3 : Temp4 = Temp4 + 225                  'for
Readeeprom Temp_b1 , Temp4                                  'for
If Mobile_aktiv = 1 And Eingabe_teil_6 = 1 Then Gosub Write_fragez
Value = Temp_b1 : Display_time_grid = 1 : Gosub Write_value
    If Value <= 100 Then Gosub Write_sec
    If Value > 100 And Value <= 200 Then Gosub Write_min
    If Value > 200 Then Gosub Write_std
    Gosub Delete_rest_of_display

    Lcd_param = &B00001111 : Gosub Lcd_writecmd             'Cursor blinken ein
    Lcd_param = &H81                                        'Cursor auf best. Position
    If Eingabe_teil_2 = 1 Then Lcd_param = &H87
    If Eingabe_teil_3 = 1 Then Lcd_param = &H8D
    If Eingabe_teil_4 = 1 Then Lcd_param = &HC5
    If Eingabe_teil_5 = 1 Then Lcd_param = &HC8
    If Eingabe_teil_6 = 1 Then Lcd_param = &HCB
    Gosub Lcd_writecmd
    Gosub Line_feed
Return

Eing_6:
'Channel
If Eingabe_teil_2 = 0 And Eingabe_teil_3 = 0 And Eingabe_teil_4 = 0 And Eingabe_teil_5 = 0 And Eingabe_teil_6 = 0 Then
If Keyb = 11 Then                                           'next
 Eingabe_teil_2 = 1 : Goto Display_fkt6 : End If
    If Keyb <= 5 Then
     Timer_nr = Keyb : Goto Display_fkt6
    Else
     Gosub Write_nein : Goto Display_fkt6
    End If
End If

'Switch-off Voltage
If Eingabe_teil_2 = 1 Then
 Temp4 = Timer_nr * 2 : Temp4 = Temp4 + 240                 'Pointer Load shedding-values
If Keyb = 11 Then                                           'next
 Eingabe_teil_2 = 0 : Eingabe_teil_3 = 1 : Stelle_1 = 0 : Goto Display_fkt6 : End If
If Stelle_1 = 0 Then
 Value = Keyb
 Writeeeprom Value , Temp4                                  'Switch-off Voltage
 Stelle_1 = 1 : Goto Display_fkt6                           'Stunde '1.Stelle
Else
  Readeeprom Value , Temp4
  Value = 10 * Value : Value = Value + Keyb
  Temp = 50 : Gosub Correction_system_voltage : Temp2 = Temp : Temp = 100 : Gosub Correction_system_voltage :
   If Value > Temp2 And Value < Temp Then                   'Or  min. Input-Voltage 10.0/20.0V
   Gosub Write_nein
   Else
   Writeeeprom Value , Temp4                                '
   End If
   Goto Display_fkt6
End If                                                      'Stelle_1 = 0
End If

'Timer on/off
If Eingabe_teil_3 = 1 Then
If Keyb = 11 Then                                           'next
 Eingabe_teil_3 = 0 : Eingabe_teil_4 = 1 : Goto Display_fkt6 : End If
If Keyb = 0 Then
        Time_load_shedding(timer_nr) = 0
        Goto Display_fkt6
Else
       Time_load_shedding(timer_nr) = 1
       Goto Display_fkt6
End If
End If

'Eingabe Stunde
If Eingabe_teil_4 = 1 Then
 Temp4 = Timer_nr * 3 : Temp4 = Temp4 + 223                 'Pointer
If Keyb = 11 Then                                           'next
 Eingabe_teil_4 = 0 : Eingabe_teil_5 = 1 : Stelle_1 = 0 : Goto Display_fkt6 : End If
If Stelle_1 = 0 Then
 Writeeeprom Keyb , Temp4                                   'hr
 Stelle_1 = 1 : Goto Display_fkt6                           'Stunde '1.Stelle
Else
 Readeeprom Temp_b1 , Temp4                                 'hr
 Temp_b1 = 10 * Temp_b1 : Temp_b1 = Temp_b1 + Keyb
 If Temp_b1 <= 24 Then
 Writeeeprom Temp_b1 , Temp4                                'hr
 Goto Display_fkt6
    Else
     Gosub Write_nein : Goto Display_fkt6
    End If
End If                                                      'Stelle_1 = 0
End If

'Eingabe minute
If Eingabe_teil_5 = 1 Then
 Temp4 = Timer_nr * 3 : Temp4 = Temp4 + 224                 'Pointer
If Keyb = 11 Then                                           'next
 Eingabe_teil_5 = 0 : Eingabe_teil_6 = 1 : Stelle_1 = 0 : Display_info_line = 0 : Goto Display_fkt6 : End If
If Stelle_1 = 0 Then
 Writeeeprom Keyb , Temp4                                   'min
 Stelle_1 = 1 : Goto Display_fkt6                           'Stunde '1.Stelle
Else
 Readeeprom Temp_b1 , Temp4                                 'min
        Temp_b1 = 10 * Temp_b1 : Temp_b1 = Temp_b1 + Keyb
    If Temp_b1 <= 60 Then
Writeeeprom Temp_b1 , Temp4                                 'min
     Goto Display_fkt6
    Else
     Gosub Write_nein : Goto Display_fkt6
    End If
End If                                                      'Stelle_1 = 0
End If

'Eingabe Dauer
If Eingabe_teil_6 = 1 Then
 Temp4 = Timer_nr * 3 : Temp4 = Temp4 + 225                 'Pointer
If Keyb = 11 Then                                           'next
 Eingabe_teil_6 = 0 : Stelle_1 = 0 : Goto Display_fkt6 : End If
If Stelle_1 = 0 Then
 Writeeeprom Keyb , Temp4                                   'for
 Stelle_1 = 1 : Goto Display_fkt6                           'Stunde '1.Stelle
Else
Readeeprom Temp_b1 , Temp4                                  'for
 Temp = 10 * Temp_b1 : Temp = Temp + Keyb : If Temp > 255 Then Temp_b1 = Keyb Else Temp_b1 = Temp
 Writeeeprom Temp_b1 , Temp4                                'for
 Goto Display_fkt6
End If                                                      'Stelle_1 = 0
End If

'Eingabe Uhrzeit
Key7:
If Keyb <> 7 Then Goto Key8                                 '
Fkt7 = 1 : Lcd_param = &B00000001 : Gosub Lcd_writecmd      'Display löschen
 If English = 0 Then Lcd_display_string = "Tag/Monat/Std/Mi" Else Lcd_display_string = "Month/Day/Hr/Min" : Gosub Lcd_display
Lcd_param = 2 : Gosub Lcd_gotoline                          '1234567890123456
If English = 0 Then Lcd_display_string = "U Regelbar" Else Lcd_display_string = "U adjust" : Gosub Lcd_display : Gosub Line_feed : Wait 2

Display_fkt7:
    If Switch_input_block > 4 Then Switch_input_block = 0
    Lcd_param = 1 : Gosub Lcd_gotoline                      '2.Zeile anw.
    If English = 0 Then Lcd_display_string = "Zeit:" Else Lcd_display_string = "Time:"
    Gosub Lcd_display
    If Mobile_aktiv = 1 And Switch_input_block = 0 Then Gosub Write_fragez
    Value = Day : Kein_komma = 1 : Gosub Write_value        'Anzeige Uhrzeit Monat
    Lcd_display_string = "." : Gosub Lcd_display
    If Mobile_aktiv = 1 And Switch_input_block = 1 Then Gosub Write_fragez
    Value = Month : Kein_komma = 1 : Gosub Write_value      'Anzeige Uhrzeit Tag
    Lcd_display_string = " " : Gosub Lcd_display
    If Mobile_aktiv = 1 And Switch_input_block = 2 Then Gosub Write_fragez
    Gosub Show_time

    Lcd_param = 2 : Gosub Lcd_gotoline                      '2.Zeile des Displays wird aktiviert
    If Display_info = 1 Then
    Lcd_display_string = "Auto Time?(0/1)" : Gosub Lcd_display : Gosub Line_feed : Display_info = 0 : Wait 2 : End If

    Lcd_display_string = "Auto:" : Gosub Lcd_display
    If Mobile_aktiv = 1 And Switch_input_block = 4 Then Gosub Write_fragez
    Readeeprom Temp_b1 , 41
If Temp_b1 = 1 Then
    If English = 0 Then Lcd_display_string = "Ja " Else Lcd_display_string = "Yes"
Else
    If English = 0 Then Lcd_display_string = "Nein" Else Lcd_display_string = "No "
End If
Gosub Lcd_display                                           'Anzeige Autodetect Time

    Lcd_display_string = "/" : Gosub Lcd_display
    Value = U_ausg : Gosub Write_value
    Lcd_display_string = "V " : Gosub Lcd_display

Lcd_param = &B00001111 : Gosub Lcd_writecmd                 'Cursor blinken ein
Lcd_param = &H85
If Switch_input_block = 1 Then Lcd_param = &H88             'Cursor auf best. Position
If Switch_input_block = 2 Then Lcd_param = &H8B             'Cursor auf best. Position
If Switch_input_block = 3 Then Lcd_param = &H8E             'Cursor auf best. Position
If Switch_input_block = 4 Then Lcd_param = &HC5             'Cursor auf best. Position
Gosub Lcd_writecmd
Gosub Line_feed
Return

'Eingabe Zeit
Eing_7:

If Keyb = 11 Then                                           'Zeichen #?
 Stelle_1 = 0 : Incr Switch_input_block : If Switch_input_block = 4 Then Display_info = 1 Else Display_info = 0 : Goto Display_fkt7 : End If

Select Case Switch_input_block

Case 0:
'day
Temp = Day
Max_value = 31 : Gosub Input_value_ram : Day = Temp : Goto Display_fkt7

'month
Case 1:
Temp = Month
Max_value = 12 : Gosub Input_value_ram : Month = Temp : Goto Display_fkt7

'Eingabe Stunde
Case 2:
Temp = Hour
Max_value = 24 : Gosub Input_value_ram : Hour = Temp : Goto Display_fkt7

'Eingabe minute
Case 3:
Temp = Minute
Max_value = 60 : Gosub Input_value_ram : Minute = Temp : Goto Display_fkt7

Case 4:
Readeeprom Temp_b1 , 41
If Temp_b1 = 0 And Keyb = 1 Then                            'Preset Start-Time if Auto-Time
For Channel_nr = 1 To Number_of_channel_modules
 Ten_times_channel_nr = Channel_nr * 10
 Temp4 = Ten_times_channel_nr + 493 : Readeeprom Temp_b2 , Temp4       'Type
 Temp5 = Ten_times_channel_nr + 891                         'hour
  Temp_b1 = 4 : If Temp_b2 = 0 Then Writeeeprom Temp_b1 , Temp5       'Preset Time for Irrigate 4 o'clock
Next
End If                                                      'Preset Duration for Irrigate 10 min

If Keyb > 1 Then Keyb = 0 : Writeeeprom Keyb , 41 : Goto Display_fkt7

End Select
Return

'Settings
Key8:
If Keyb <> 8 Then Goto Key9
Fkt8 = 1 : Lcd_param = &B00000001 : Gosub Lcd_writecmd      'Display löschen
Readeeprom Data_pointer , 221                               'Pointer Values
If Data_pointer < 1 Or Data_pointer > 91 Then
  Data_pointer = 1 : Writeeeprom Data_pointer , 221 : End If
Display_fkt8:
    Gosub Load_from_flash
    Lcd_param = 1 : Gosub Lcd_gotoline                      '2.Zeile anw.
    Lcd_display_string = "Nr" : Gosub Lcd_display
    If Mobile_aktiv = 1 And Eingabe_teil_2 = 0 And Eingabe_teil_3 = 0 Then Gosub Write_fragez
    Readeeprom Data_pointer , 221 : Value = Data_pointer : Kein_komma = 1 : Gosub Write_value
    Lcd_display_string = ":" : Gosub Lcd_display

'Data with 2 pointers
Dim Pointer_2_data As Byte
If Data_pointer = 16 Or Data_pointer = 17 Or Data_pointer = 15 Then
   If Mobile_aktiv = 1 And Eingabe_teil_2 = 1 Then Gosub Write_fragez
   If Pointer_2_data = 0 Then Pointer_2_data = 1 : Lcd_display_string = "Ch." : Gosub Lcd_display : Value = Pointer_2_data : Kein_komma = 1 : Gosub Write_value : Lcd_display_string = "=" : Gosub Lcd_display : End If

'############################## write_Value ##############################
    If Mobile_aktiv = 1 Then
     If Data_pointer <> 16 And Data_pointer <> 17 And Data_pointer <> 15 And Eingabe_teil_2 = 1 Then Gosub Write_fragez
     If Data_pointer = 16 Or Data_pointer = 17 Or Data_pointer = 15 Then
      If Eingabe_teil_3 = 1 Then Gosub Write_fragez : End If
  End If
    Temp_b1 = Data_pointer - 1 : Temp_b1 = Temp_b1 * 2 : Pointer_eeprom = Temp_b1 + 262 : Readeeprom Value , Pointer_eeprom

'################################ Display yes/no ###################################
    Lcd_display_string = "          "
 If Data_pointer = 19 Or Data_pointer = 20 Or Data_pointer = 22 Or Data_pointer = 23 Or Data_pointer = 25 Or Data_pointer = 26 Or Data_pointer = 27 Or Data_pointer = 30 Or Data_pointer = 35 Or Data_pointer = 36 Or Data_pointer = 43 Or Data_pointer = 44 Then
  If English = 0 Then
         If Value = 1 Then Lcd_display_string = " Ja(0/1)" Else Lcd_display_string = " Nein(1/0)"
  Else
         If Value = 1 Then Lcd_display_string = " Yes(0/1)" Else Lcd_display_string = " No(1/0)"
  End If
Goto End_write_value                                        'no write_value
End If
'################################ comma? #############################################
    Kein_komma = 0
    If Data_pointer < 4 Then Kein_komma = 1
    If Data_pointer > 9 And Data_pointer < 17 Then Kein_komma = 1       'only the first values with point
    If Data_pointer = 18 Or Data_pointer = 24 Then Kein_komma = 1
    If Data_pointer > 28 And Data_pointer < 33 Then Kein_komma = 1
    If Data_pointer > 18 And Data_pointer < 24 Then Kein_komma = 1
    If Data_pointer > 33 And Data_pointer < 39 Then Kein_komma = 1
    If Data_pointer > 38 And Data_pointer < 78 Then Kein_komma = 1
    If Data_pointer = 57 Then Kein_komma = 0
'    If Data_pointer = 60 Then Kein_komma = 0

    If Data_pointer = 31 Then Two_comma = 1                 'Current Solar/Load
'just one digit
    If Data_pointer > 9 And Data_pointer < 13 Then Tel_nr = 1
    If Data_pointer > 17 And Data_pointer < 24 Then Tel_nr = 1
    If Data_pointer = 30 Or Data_pointer = 18 Then Tel_nr = 1       'solar charger
    If Data_pointer > 34 Then Tel_nr = 1
    If Data_pointer > 39 And Data_pointer <= 44 Then Tel_nr = 1

    If Data_pointer = 31 Then Display_time_grid = 1         'gespeicherter Umax-Wert

If Data_pointer > 14 And Data_pointer < 18 Then             'Data with 2 pointers (Analoy-Type)
  Temp = Pointer_2_data + 750
 If Data_pointer = 16 Then Temp = Pointer_2_data + 770
 If Data_pointer = 17 Then
  Temp = Pointer_2_data + 790 : Two_comma = 1 : End If

 Readeeprom Temp_b1 , Temp : Value = Temp_b1 : If Data_pointer = 15 And Value > 10 Then Value = 0
 End If

Save_value_for_display = Value                              'save for Display at 2.Line
    If Data_pointer = 16 Then Kein_komma = 0 : If Data_pointer = 16 Then Eight_bit_value_neg = 1
    Gosub Write_value

End_write_value:
'############################ end end_write_value ######################

'############################ Unit ###############################
    If Data_pointer > 3 And Data_pointer < 10 Then Lcd_display_string = " V"
    If Data_pointer = 28 Or Data_pointer = 28 Then Lcd_display_string = " V"
    If Data_pointer = 29 Then Lcd_display_string = " mAh"
    If Data_pointer = 37 Then Lcd_display_string = " min"   '334 = 37 Max-Time for Anti-Frost-Irrigation
    If Data_pointer = 1 Then Lcd_display_string = " m"      'U Batt Corr cable length
    If Data_pointer = 2 Then Lcd_display_string = " mm2"    'U Batt Corr cable diameter
    If Data_pointer = 14 Then Lcd_display_string = " sec"   'correction Time

If Data_pointer = 11 Then                                   'Accu-Type
        Lcd_display_string = " Gel"
        If Blei_akku = 1 Then
          If English = 0 Then Lcd_display_string = " Blei" Else Lcd_display_string = " Lead" : End If
End If

 If Data_pointer = 32 Then Lcd_display_string = " 0=V/1=SOC"       'Volt/SOC-Selection

 If Data_pointer = 34 Then                                  'Korrrektur 0-Wert
   If English = 0 Then Lcd_display_string = "/# drücken" Else Lcd_display_string = "press #" : End If       'Volt/SOC-Selection

Lcd_display_pad_with_spaces = 1 : If Data_pointer = 31 Then Gosub Write_time_unit       'Scan-Time Recorder

If Data_pointer = 3 Then                                    'Days without watering
 If English = 0 Then Lcd_display_string = " Tage" Else Lcd_display_string = " days" : End If

If Data_pointer >= 47 And Data_pointer <= 51 Then Gosub Show_output_type       'Output Selection
'If Data_pointer = 21 Then Gosub Show_output_type            'Output Selection
If Data_pointer > 58 And Data_pointer < 72 Then Gosub Show_output_type       'Output Selection

If Data_pointer = 72 Or Data_pointer = 73 Then              'Min/Max-Value
 Temp_b1 = Save_value_for_display : Gosub Write_input : End If

If Data_pointer = 74 Then                                   'Runtime
 Temp_b1 = Save_value_for_display : Gosub Write_output : End If

Gosub Lcd_display

'more Infos
 If Data_pointer = 28 Then                                  'U nicd
  Lcd_display_string = "/" : Gosub Lcd_display : Value = U_nicd / 10 : Kein_komma = 0 : Gosub Write_value : Lcd_display_string = "V" : Gosub Lcd_display : End If

Lcd_display_pad_with_spaces = 1 : Lcd_display_string = " " : Gosub Lcd_display       'delete rest of Display

    Lcd_param = 2 : Gosub Lcd_gotoline                      '2.Zeile anw.
    Readeeprom Data_pointer , 221                           'Zeiger Daten
  Lcd_display_pad_with_spaces = 1
   Lcd_display_string = " "

'############################### Info-Line ###################################
If Data_pointer = 1 Or Data_pointer = 2 Then
     Lcd_display_string = "V Bat.Corr Cable" : End If

If Timer_2_sec = 0 Then
    If Data_pointer = 1 Then
      Lcd_display_string = "length" : End If

    If Data_pointer = 2 Then
      Lcd_display_string = "Area" : End If
End If

   If Data_pointer = 3 Then
     If English = 0 Then Lcd_display_string = "x Tage ohne" Else Lcd_display_string = "x Days without"
      If Timer_2_sec = 0 Then                               '123456789023456       '123456789023456
    If English = 0 Then Lcd_display_string = "Bewässerung" Else Lcd_display_string = "Irrigation" : End If
     End If

    If Data_pointer = 4 Then
      If English = 0 Then Lcd_display_string = "Vorwarnung Umin" Else Lcd_display_string = "Pre-Alarm Umin" : End If

    If Data_pointer = 5 Then
      If English = 0 Then Lcd_display_string = "Hysterese Spg." Else Lcd_display_string = "Hysteresis Volt"
       If Timer_2_sec = 0 Then                              ' 123456789023456
      If English = 0 Then Lcd_display_string = "Batterie leer" Else Lcd_display_string = "Batt.empty" : End If
      End If

    If Data_pointer = 6 Then
     If English = 0 Then Lcd_display_string = "Batterie voll" Else Lcd_display_string = "Battery full" : End If

    If Data_pointer = 7 Then
     If English = 0 Then
      If Blei_akku = 0 Then Lcd_display_string = "Zykl.Laden Gel" Else Lcd_display_string = "Zykl.Laden Blei"
      Else                                                  '123456789023456
      If Blei_akku = 0 Then Lcd_display_string = "Cycl.Load Gel" Else Lcd_display_string = "Cycl.Load Lead" : End If
      End If

    If Data_pointer = 8 Then
    If English = 0 Then Lcd_display_string = "Ausgleichsladen" Else Lcd_display_string = "Equalization-"
    If Timer_2_sec = 0 Then                                 '123456789023456
    If English = 0 Then Lcd_display_string = "Blei-Akkus" Else Lcd_display_string = "Charge Lead" : End If
    End If

    If Data_pointer = 9 Then Lcd_display_string = "U max max"

    If Data_pointer = 10 Then
     If English = 0 Then Lcd_display_string = "Sprache Deutsch" Else Lcd_display_string = "Language English" : End If

    If Data_pointer = 11 Then                               '123456789023456
    If English = 0 Then Lcd_display_string = "Akku-Typ Gel/" Else Lcd_display_string = "Type of Battery:"
    If Timer_2_sec = 0 Then                                 '123456789023456
    If English = 0 Then Lcd_display_string = "Blei(Einst.!)" Else Lcd_display_string = "Gel/Lead(Setup!" : End If
    End If

    If Data_pointer = 12 Then
     If English = 0 Then Lcd_display_string = "Feuchte Mittelw." Else Lcd_display_string = "Nr Humid-Sensors"
    If Timer_2_sec = 0 Then                                 '1234567890123456                            '1234567890123456
     If English = 0 Then Lcd_display_string = "Anzahl Sensor" Else Lcd_display_string = "Average-Calculat" : End If
    End If

If Data_pointer = 13 Then
 Lcd_display_string = "Nr.of Channels"
  If Timer_2_sec = 0 Then Lcd_display_string = "Menu 1(0-20)" : End If

If Data_pointer = 14 Then Lcd_display_string = "Korrektur Uhr"       ': If Timer_2_sec = 1 Then Lcd_display_string = "neg.= * und Wert"

If Data_pointer = 15 Then
        Lcd_display_string = "Sensor Type:0=V"
  If Timer_2_sec = 0 Then Lcd_display_string = "1=°C;3=%;4=free"
     End If

If Data_pointer = 16 Or Data_pointer = 17 Then
If Timer_2_sec = 1 Then
   Lcd_display_pad_with_spaces = 0 : Lcd_display_string = "Corr.Analog " : Gosub Lcd_display : Lcd_display_pad_with_spaces = 1 : Lcd_display_string = "+/-" : If Data_pointer = 17 Then Lcd_display_string = "*"       '
Else
  If Data_pointer = 16 And Tick_1 = 0 Then
   Lcd_display_string = "minus w.*;" : Tick_1 = 1
   Else
  Temp_b1 = Pointer_2_data : Gosub Write_input : Tick_1 = 0
 End If
End If
End If

 If Data_pointer = 18 Then Lcd_display_string = "1=Flash->Logview"

  If Data_pointer = 19 Then
    If English = 0 Then Lcd_display_string = "Standard-Werte" Else Lcd_display_string = "load Standard"
    If Timer_2_sec = 0 Then                                 '123456789023456       '123456789023456
    If English = 0 Then Lcd_display_string = "laden" Else Lcd_display_string = "-Values" : End If
    End If

    If Data_pointer = 22 Then
     If English = 0 Then Lcd_display_string = "SMS empfangen" Else Lcd_display_string = "Receive SMS" : End If

If Data_pointer = 23 Then Lcd_display_string = "Send SMS?"  '
                        '1234567890123456

  If Data_pointer = 24 Then
        Lcd_display_string = "Country-Code SMS"
       If Timer_2_sec = 0 Then Lcd_display_string = "deu=94"
  End If
                         '1234567890123456
 If Data_pointer = 25 Then Lcd_display_string = "CableBreak Alarm"

  If Data_pointer = 26 Then
    Lcd_display_string = "Auto Detect"
    If Timer_2_sec = 0 Then Lcd_display_string = "Min/Max Humidity"
   End If

If Data_pointer = 27 Then Lcd_display_string = "ELV 868 Mhz?"

    If Data_pointer = 28 Then
    Lcd_display_string = "U-NiCd/mH"
    If Timer_2_sec = 0 Then                                 '123456789023456       '123456789023456
    Lcd_display_string = "U=x*1,2V" : End If
    End If

   If Data_pointer = 29 Then
   If English = 0 Then Lcd_display_string = "Kapazität NimH" Else Lcd_display_string = "Capacity NimH"
   If Timer_2_sec = 0 Then                                  '1234567890123456       '1234567890123456
   If English = 0 Then Lcd_display_string = "einer Zelle" Else Lcd_display_string = "of one cell" : End If
   End If

   If Data_pointer = 30 Then
   If English = 0 Then Lcd_display_string = "Solar Lade-" Else Lcd_display_string = "Solar Charge-"
    If Timer_2_sec = 0 Then                                 '1234567890123456          '1234567890123456
   If English = 0 Then Lcd_display_string = "Regler aktiv?" Else Lcd_display_string = "Controller?" : End If
   End If

   If Data_pointer = 31 Then
   If English = 0 Then Lcd_display_string = "Abtastzeit" Else Lcd_display_string = "Scan Time"
      If Timer_2_sec = 0 Then                               '1234567890123456       '1234567890123456
   If English = 0 Then Lcd_display_string = "Daten schreiben" Else Lcd_display_string = "Data Logging" : End If
   End If

   If Data_pointer = 32 Then
    If English = 0 Then Lcd_display_string = "Steuerung Last" Else Lcd_display_string = "Load Control"
     If Timer_2_sec = 0 Then                                '123456789023456       '123456789023456
    If English = 0 Then Lcd_display_string = "mit V/Ladezust?" Else Lcd_display_string = "by V or SOC" : End If
    End If

'   If Data_pointer = 33 Then
'    If English = 0 Then Lcd_display_string = "Korrektur-Fakt." Else Lcd_display_string = "Correction-Fact"
'    If Timer_2_sec = 0 Then                                 '123456789023456       '123456789023456
'    If English = 0 Then Lcd_display_string = "Ladezustand/SOC" Else Lcd_display_string = "SOC(State of Ch" : End If
'    End If

   If Data_pointer = 34 Then
    If English = 0 Then Lcd_display_string = "Korrektur-Fakt." Else Lcd_display_string = "Correction-Fact"
      If Timer_2_sec = 0 Then                               '123456789023456       '123456789023456
    If English = 0 Then Lcd_display_string = "Solar-Strom" Else Lcd_display_string = "Solar Current" : End If
    End If

   If Data_pointer = 35 Then
      If English = 0 Then Lcd_display_string = "Temp-Korrektur" Else Lcd_display_string = "Temp-Correction"
      If Timer_2_sec = 0 Then                               '123456789023456       '123456789023456
     If English = 0 Then Lcd_display_string = "Batterie-Spg" Else Lcd_display_string = "Battery-Voltage" : End If
     End If

   If Data_pointer = 36 Then
      If English = 0 Then Lcd_display_string = "PWM laden" Else Lcd_display_string = "PWM charging" : End If

  If Data_pointer = 37 Then
     If English = 0 Then Lcd_display_string = "Zeit Anti-" Else Lcd_display_string = "Zeit Anti-"
     If Timer_2_sec = 0 Then                                '1234567890123456                           '1234567890123456
     If English = 0 Then Lcd_display_string = "Frost aktiv" Else Lcd_display_string = "Frost aktive" : End If
  End If

'   If Data_pointer = 38 Then                                '136
'      If English = 0 Then Lcd_display_string = "Alarm wenn kein" Else Lcd_display_string = "Alarm if no"
'       If Timer_2_sec = 0 Then                              '1234567890123456              '123456789023456
'      If English = 0 Then Lcd_display_string = "Wasser kommt?" Else Lcd_display_string = "Water is coming?" : End If
'      End If

If Data_pointer = 39 Then                                   '1234567890123456
        Lcd_display_string = "Correction"
  If Timer_2_sec = 0 Then Lcd_display_string = "Factor Counter"
     End If

'  If Data_pointer = 40 Then                                 '1234567890123456
'      If English = 0 Then Lcd_display_string = "Daten sofort->PC" Else Lcd_display_string = "Data direct->PC " : End If

  If Data_pointer = 41 Then Lcd_display_string = "Hardware-Version"

'  If Data_pointer = 42 Then
'     If English = 0 Then Lcd_display_string = "Last 4: 0=Batt " Else Lcd_display_string = "Load 4: 0=Batt "
'        If Timer_2_sec = 0 Then                             '1234567890123456                           '1234567890123456
'    If English = 0 Then Lcd_display_string = "1=Ist>Sol/2=Ist<" Else Lcd_display_string = "1=Act>Set/2=Act<" : End If
'End If

'  If Data_pointer = 43 Then
'     If English = 0 Then Lcd_display_string = "Last 5: 0=Batt " Else Lcd_display_string = "Load 5: 0=Batt "
'        If Timer_2_sec = 0 Then                             '1234567890123456                           '1234567890123456
'    If English = 0 Then Lcd_display_string = "1=Ist>Sol/2=Ist<" Else Lcd_display_string = "1=Act>Set/2=Act<" : End If
'End If

If Data_pointer = 43 Then
  Lcd_display_string = "Start/Stop"
If Timer_2_sec = 0 Then Lcd_display_string = "Boost-Charge?"
End If

  If Data_pointer = 44 Then                                 '1234567890123456
        If English = 0 Then Lcd_display_string = "mit SD-Karte?" Else Lcd_display_string = "with SD-Card?" : End If

   If Data_pointer = 45 Then                                '1234567890123456
        If English = 0 Then Lcd_display_string = "Aufzeichnen" Else Lcd_display_string = "Scan Analog"
  If Timer_2_sec = 0 Then                                   '123456789023456              '123456789023456
        If English = 0 Then Lcd_display_string = "Analoge Eingänge" Else Lcd_display_string = "Inputs" : End If
     End If

   If Data_pointer = 46 Then Lcd_display_string = "SD-Chip Block-Nr"

  If Data_pointer = 47 Then
        Lcd_display_string = "Load 1 Select"
  If Timer_2_sec = 0 Then Gosub Display_output
     End If

 If Data_pointer = 48 Then
        Lcd_display_string = "Load 2 Select"
  If Timer_2_sec = 0 Then Gosub Display_output
     End If

 If Data_pointer = 49 Then
        Lcd_display_string = "Load 3 Select"
  If Timer_2_sec = 0 Then Gosub Display_output
     End If

 If Data_pointer = 50 Then
        Lcd_display_string = "Load 4 Select"
  If Timer_2_sec = 0 Then Gosub Display_output
     End If

 If Data_pointer = 51 Then
        Lcd_display_string = "Load 5 Select"
  If Timer_2_sec = 0 Then Gosub Display_output
     End If


     If Data_pointer > 51 And Data_pointer < 56 Then Lcd_display_string = "Analog Input"

If Timer_2_sec = 0 Then
If Data_pointer = 52 Then Lcd_display_string = "Start Value"

If Data_pointer = 53 Then Lcd_display_string = "End Value"

If Data_pointer = 54 Then Lcd_display_string = "Raw Start"

If Data_pointer = 55 Then Lcd_display_string = "Raw End"
End If

If Data_pointer = 56 Then
        Lcd_display_string = "Simu Input Nr"
     If Timer_2_sec = 0 Then Lcd_display_string = "(Value next Par)"
 End If

If Data_pointer = 57 Then Lcd_display_string = "Simu Value"

'If Data_pointer = 58 Then
'        Lcd_display_string = "Factor for Simu-"
'  If Timer_2_sec = 0 Then Lcd_display_string = "value(* Factor)"
'     End If

If Data_pointer = 59 Or Data_pointer = 61 Or Data_pointer = 63 Or Data_pointer = 65 Then Lcd_display_string = "Output w.Puls on"       '
                        '1234567890123456
If Data_pointer = 60 Or Data_pointer = 62 Or Data_pointer = 64 Or Data_pointer = 66 Then Lcd_display_string = "Output Puls off"       '

If Data_pointer > 66 And Data_pointer < 72 Then
 Lcd_display_string = "Anti-Blocking"                       '
  If Timer_2_sec = 0 Then Lcd_display_string = "Output-Nr"
     End If

If Data_pointer = 72 Then
 Lcd_display_string = "Min.Value Analog"                    '
  If Timer_2_sec = 0 Then Gosub Display_min_value
     End If

If Data_pointer = 73 Then
 Lcd_display_string = "Max.Value Analog"                    '
  If Timer_2_sec = 0 Then Gosub Display_max_value
     End If

If Data_pointer = 74 Then
 Lcd_display_string = "Run-Time Output"                     '
  If Timer_2_sec = 0 Then Gosub Display_run_time
     End If

    Gosub Lcd_display
    Lcd_display_pad_with_spaces = 0
    Lcd_param = &B00001111 : Gosub Lcd_writecmd             'Cursor blinken ein
    Lcd_param = &H82
    If Eingabe_teil_2 = 1 Then Lcd_param = &H86             'Cursor auf best. Position Nr 12:xx
    If Eingabe_teil_3 = 1 Then Lcd_param = &H8B             'Cursor auf best. Position Nr 12:xx
    Gosub Lcd_writecmd
    Gosub Line_feed
Return

Display_output:
Lcd_display_string = "Output (0-...)"
Return

Display_channel_line_2:
  If Timer_2_sec <> 0 Then Return
    If Data_pointer < 70 Then Gosub Display_output Else Lcd_display_string = "Input (0-...)" : Return

'Value-Nr
Eing_8:
If Eingabe_teil_2 = 1 Then Goto Fkt8_teil2
If Eingabe_teil_3 = 1 Then Goto Fkt8_teil3

If Stelle_1 = 0 Then Input_new_parameter = 1                'less than 10 Stelle_1 = 0 if ...
If Input_new_parameter > 3 Then
  Stelle_1 = 0 : Input_new_parameter = 0 : End If

If Keyb = 11 Then
 Eingabe_teil_2 = 1 : Stelle_1 = 0 : Negative_number = 0 : Goto Display_fkt8 : End If

If Keyb = 0 And Stelle_1 = 0 Then
 Readeeprom Data_pointer , 221 : Incr Data_pointer : Writeeeprom Data_pointer , 221 : Goto Display_fkt8 : End If

If Stelle_1 = 0 Then
 Writeeeprom Keyb , 221 : Stelle_1 = 1 : Goto Display_fkt8 : End If       '1.Stelle

Readeeprom Temp_b1 , 221 : Temp_b1 = 10 * Temp_b1 : Temp_b1 = Temp_b1 + Keyb
If Temp_b1 > 80 Then
 If Keyb = 0 Then
  Incr Data_pointer : Writeeeprom Data_pointer , 221 : End If
 Stelle_1 = 0 : Goto Display_fkt8
 Else
 Writeeeprom Temp_b1 , 221 : Stelle_1 = 0 : Goto Display_fkt8
End If

'Value
Fkt8_teil2:
Readeeprom Data_pointer , 221 : Temp_b1 = Data_pointer - 1 : Temp_b1 = Temp_b1 * 2 : Pointer_eeprom = Temp_b1 + 262

If Keyb = 11 Then
  If Data_pointer = 16 Or Data_pointer = 17 Or Data_pointer = 15 Then Eingabe_teil_3 = 1 : Negative_number = 0 : Eingabe_teil_2 = 0 : Stelle_1 = 0 : Goto Display_fkt8 : End If

If Stelle_1 = 0 Then
 If Data_pointer = 16 Then
  If Keyb = 10 And Meldung_aktiv = 0 And Negative_number = 0 Then       'negative for U_Batt
   Negative_number = 1 : Stelle_1 = 0 : Goto Display_fkt8 : End If
  End If

If Data_pointer = 19 And Keyb = 1 Then                      'Standard_laden
    Gosub Standard_laden : Gosub Write_ok : Goto Display_fkt8 : End If

Stelle_1 = 1
If Data_pointer <> 15 And Data_pointer <> 16 And Data_pointer <> 17 Then       '2 Data Input?
    Value = Keyb : If Negative_number = 1 Then Value = Value Or &H8000 : Writeeeprom Value , Pointer_eeprom : Stelle_1 = 1       'set negativ Flag
Else
'////////////////////////// data with second Input ////////////////////////
    Pointer_2_data = Keyb : If Keyb > 1 Then Stelle_1 = 0
End If

 If Data_pointer = 26 Or Data_pointer = 30 Or Data_pointer = 35 Or Data_pointer = 36 Or Data_pointer = 43 Or Data_pointer = 44 Then Stelle_1 = 0
     If Data_pointer >= 10 And Data_pointer <= 12 Then Stelle_1 = 0
     If Data_pointer >= 19 And Data_pointer <= 23 Then Stelle_1 = 0
     If Data_pointer = 11 Or Data_pointer = 32 Then Stelle_1 = 0 : Goto Display_fkt8       '1.Stelle
End If

If Data_pointer <> 15 And Data_pointer <> 16 And Data_pointer <> 17 Then       '2 Data Input?
Readeeprom Value , Pointer_eeprom : Value = 10 * Value : If Negative_number = 0 Then Value = Value + Keyb Else Value = Value - Keyb
Else
'////////////////////////// data with second Input ////////////////////////
 Pointer_2_data = Pointer_2_data * 10 : Pointer_2_data = Pointer_2_data + Keyb
    If Pointer_2_data > 15 Then Pointer_2_data = Keyb Else Stelle_1 = 0
End If

 Writeeeprom Value , Pointer_eeprom : Goto Display_fkt8

'3.Value Type and correction
Fkt8_teil3:
If Keyb = 11 Then
   Eingabe_teil_3 = 0 : Stelle_1 = 0 : Goto Display_fkt8 : End If
Temp = Pointer_2_data + 750                                 'Start with 751
If Data_pointer = 16 Then Temp = Pointer_2_data + 770
If Data_pointer = 17 Then Temp = Pointer_2_data + 790

If Stelle_1 = 0 Then
 Stelle_1 = 1
  If Data_pointer = 16 Then                                 'negatvie Number also for correction?
    If Keyb = 10 And Meldung_aktiv = 0 And Negative_number = 0 Then       'negative
    Negative_number = 1 : Stelle_1 = 0 : Lcd_display_string = "-" : Gosub Lcd_display : Waitms 250 : Goto Display_fkt8 : End If
  End If
    If Negative_number = 1 Then Keyb = Keyb + 128 : Writeeeprom Keyb , Temp : Goto Display_fkt8
Else
 Readeeprom Temp_b3 , Temp : Temp_b3 = 10 * Temp_b3 : Temp_b3 = Temp_b3 + Keyb : If Negative_number = 1 Then Temp_b3 = Temp_b3 + 128 : Writeeeprom Temp_b3 , Temp : Goto Display_fkt8
End If
Return

'################################## Manual Mode ######################################
'Handebene  hören
Key9:
If Keyb <> 9 Then Return                                    '"BaSo P1P2P3P4 P5"
Anzeige_handebene_reset:
Disp_fkt9 = 1 : Lcd_param = &B00000001 : Gosub Lcd_writecmd 'Display löschen
Anzeige_handebene:
'If Fkt9 = 0 Then Gosub Output
Lcd_param = 1 : Gosub Lcd_gotoline                          '1.Zeile anw.
If Display_info < 2 And Display_submenues = 0 Then          '1234567890123456
 Lcd_display_string = "Output Group 1  " : Gosub Write_manual_line_2 : Return : End If

Lcd_param = 1 : Gosub Lcd_gotoline
Lcd_display_string = "L1" : No_print_seriell = 1 : Gosub Lcd_display       'Load 1
If Mobile_aktiv = 1 Then
  Gosub Write_fragez : Print #1 , "1=" ; : If Output_1 = 1 Then Gosub Print_on Else Gosub Print_off : End If

 Lcd_display_string = "R2" : No_print_seriell = 1 : Gosub Lcd_display       'Relais    '
If Mobile_aktiv = 1 Then
 Print #1 , "2=" ; : If Relais_2 = 1 Then Gosub Print_on Else Gosub Print_off : End If

Lcd_display_string = "R3" : No_print_seriell = 1 : Gosub Lcd_display       'Relais
If Mobile_aktiv = 1 Then
 Print #1 , "3=" ; : If Relais_3 = 1 Then Gosub Print_on Else Gosub Print_off : End If

Lcd_display_string = "R4" : No_print_seriell = 1 : Gosub Lcd_display       'Relais
If Mobile_aktiv = 1 Then
 Print #1 , "4=" ; : If Relais_4 = 1 Then Gosub Print_on Else Gosub Print_off : End If

Lcd_display_string = "R5" : No_print_seriell = 1 : Gosub Lcd_display       'Relais
If Mobile_aktiv = 1 Then
 Print #1 , "5=" ; : If Relais_5 = 1 Then Gosub Print_on Else Gosub Print_off : End If

Lcd_display_string = "R6" : No_print_seriell = 1 : Gosub Lcd_display       'Relais
If Mobile_aktiv = 1 Then
 Print #1 , "6=" ; : If Relais_6 = 1 Then Gosub Print_on Else Gosub Print_off : End If

Lcd_display_string = "R7" : No_print_seriell = 1 : Gosub Lcd_display       'Relais
If Mobile_aktiv = 1 Then
 Print #1 , "7=" ; : If Relais_7 = 1 Then Gosub Print_on Else Gosub Print_off : End If

Lcd_display_string = "Be" : No_print_seriell = 1 : Gosub Lcd_display       'Beeper
If Mobile_aktiv = 1 Then
 Print #1 , "8=" ; : If Beeper = 1 Then Gosub Print_on Else Gosub Print_off : End If

Lcd_param = 2 : Gosub Lcd_gotoline
Lcd_param = Eins_ : Gosub Lcd_writechar
If Output_1 = 1 Then Lcd_param = &HFF Else Lcd_param = &HA1 : Gosub Lcd_writechar
Lcd_param = Zwei_ : Gosub Lcd_writechar
If Relais_2 = 1 Then Lcd_param = &HFF Else Lcd_param = &HA1 : Gosub Lcd_writechar
 Lcd_param = Drei_ : Gosub Lcd_writechar
 If Relais_3 = 1 Then Lcd_param = &HFF Else Lcd_param = &HA1 : Gosub Lcd_writechar
 Lcd_param = Vier_ : Gosub Lcd_writechar
 If Relais_4 = 1 Then Lcd_param = &HFF Else Lcd_param = &HA1 : Gosub Lcd_writechar
 Lcd_param = Fuenf_ : Gosub Lcd_writechar
 If Relais_5 = 1 Then Lcd_param = &HFF Else Lcd_param = &HA1 : Gosub Lcd_writechar
 Lcd_param = Sechs_ : Gosub Lcd_writechar
 If Relais_6 = 1 Then Lcd_param = &HFF Else Lcd_param = &HA1 : Gosub Lcd_writechar
 Lcd_param = Sieben_ : Gosub Lcd_writechar
 If Relais_7 = 1 Then Lcd_param = &HFF Else Lcd_param = &HA1 : Gosub Lcd_writechar
 Lcd_param = Acht_ : Gosub Lcd_writechar
 If Beeper = 1 Then Lcd_param = &HFF Else Lcd_param = &HA1 : Gosub Lcd_writechar
 Gosub Line_feed
Return

Print_on:
Print #1 , Lcd_display_string ;
Print #1 , ":on " ;
Return

Print_off:
Print #1 , Lcd_display_string ;
Print #1 , ":off " ;
Return

Display_fkt9_2:
'If Fkt9 = 0 Then Gosub Output
Lcd_param = 1 : Gosub Lcd_gotoline                          '1.Zeile anw.
If Display_info < 2 Then
 Lcd_display_string = "Output Group 2  " : Gosub Write_manual_line_2 : Return : End If
Lcd_param = 1 : Gosub Lcd_gotoline
'Lcd_display_string = "PWNiL2L3L4L5L6L7" : No_print_seriell = 1 : Gosub Lcd_display
If Mobile_aktiv = 1 Then Gosub Write_fragez
Lcd_display_string = "PW" : No_print_seriell = 1 : Gosub Lcd_display       'Load 1
If Mobile_aktiv = 1 Then
  Print #1 , "1=" ; : If Pwm_port = 1 Then Gosub Print_on Else Gosub Print_off : End If

Lcd_display_string = "Ni" : No_print_seriell = 1 : Gosub Lcd_display       'Load 1
If Mobile_aktiv = 1 Then
  Print #1 , "2=" ; : If Nimh_load_rel = 1 Then Gosub Print_on Else Gosub Print_off : End If

Lcd_display_string = "L2" : No_print_seriell = 1 : Gosub Lcd_display       'Load 1
If Mobile_aktiv = 1 Then
  Print #1 , "3=" ; : If Output_9 = 1 Then Gosub Print_on Else Gosub Print_off : End If

Lcd_display_string = "L3" : No_print_seriell = 1 : Gosub Lcd_display       'Load 1
If Mobile_aktiv = 1 Then
  Print #1 , "4=" ; : If Output_10 = 1 Then Gosub Print_on Else Gosub Print_off : End If

Lcd_display_string = "L4" : No_print_seriell = 1 : Gosub Lcd_display       'Load 1
If Mobile_aktiv = 1 Then
  Print #1 , "5=" ; : If Output_11 = 1 Then Gosub Print_on Else Gosub Print_off : End If

Lcd_display_string = "L5" : No_print_seriell = 1 : Gosub Lcd_display       'Load 1
If Mobile_aktiv = 1 Then
  Print #1 , "6=" ; : If Output_12 = 1 Then Gosub Print_on Else Gosub Print_off : End If

Lcd_display_string = "L6" : No_print_seriell = 1 : Gosub Lcd_display       'Load 1
If Mobile_aktiv = 1 Then
  Print #1 , "7=" ; : If Output_13 = 1 Then Gosub Print_on Else Gosub Print_off : End If

Lcd_display_string = "L7" : No_print_seriell = 1 : Gosub Lcd_display       'Load 1
If Mobile_aktiv = 1 Then
  Print #1 , "8=" ; : If Output_14 = 1 Then Gosub Print_on Else Gosub Print_off : End If

Lcd_param = 2 : Gosub Lcd_gotoline
Lcd_param = Eins_ : Gosub Lcd_writechar
If Pwm_port = 1 Then Lcd_param = &HFF Else Lcd_param = &HA1 : Gosub Lcd_writechar
Lcd_param = Zwei_ : Gosub Lcd_writechar
If Nimh_load_rel = 1 Then Lcd_param = &HFF Else Lcd_param = &HA1 : Gosub Lcd_writechar
 Lcd_param = Drei_ : Gosub Lcd_writechar
 If Output_9 = 1 Then Lcd_param = &HFF Else Lcd_param = &HA1 : Gosub Lcd_writechar
 Lcd_param = Vier_ : Gosub Lcd_writechar
 If Output_10 = 1 Then Lcd_param = &HFF Else Lcd_param = &HA1 : Gosub Lcd_writechar
    Lcd_param = Fuenf_ : Gosub Lcd_writechar
 If Output_11 = 1 Then Lcd_param = &HFF Else Lcd_param = &HA1 : Gosub Lcd_writechar
 Lcd_param = Sechs_ : Gosub Lcd_writechar
 If Output_12 = 1 Then Lcd_param = &HFF Else Lcd_param = &HA1 : Gosub Lcd_writechar
 Lcd_param = Sieben_ : Gosub Lcd_writechar
 If Output_13 = 1 Then Lcd_param = &HFF Else Lcd_param = &HA1 : Gosub Lcd_writechar
 Lcd_param = Acht_ : Gosub Lcd_writechar
 If Output_14 = 1 Then Lcd_param = &HFF Else Lcd_param = &HA1 : Gosub Lcd_writechar
Gosub Line_feed
Return

'Analog Inputs 1
Display_fkt9a:
' If Mobile_aktiv = 1 Then Print #1 , "Analog 1: ";
 Lcd_param = 1 : Gosub Lcd_gotoline                         '1.Zeile anw.
If Display_info < 2 Then
 Lcd_display_string = "Analog Group 1  " : Gosub Write_manual_line_2 : Return : End If
Lcd_param = 1 : Gosub Lcd_gotoline
Porte.4 = 1                                                 'read Humid-Sensors
'Lcd_display_string = "A1:" : Gosub Lcd_display
 Value = Getadc(0) : Gosub Display_analog_raw
Value = Getadc(1) : Gosub Display_analog_raw
Value = Getadc(2) : Gosub Display_analog_raw
Value = Getadc(3) : Gosub Display_analog_raw
Gosub Delete_rest_of_display

Lcd_param = 2 : Gosub Lcd_gotoline                          '1.Zeile anw.
Value = Getadc(4) : Gosub Display_analog_raw
Value = Getadc(5) : Gosub Display_analog_raw
Value = Getadc(6) : Gosub Display_analog_raw
Porte.4 = 0                                                 'read Humid-Sensors
Value = Wahlschalter : Gosub Display_analog_raw
Gosub Delete_rest_of_display
Gosub Line_feed
    Return

'Analog Inputs 2^
Display_fkt9a2:
' If Mobile_aktiv = 1 Then Print #1 , "Analog 2: ";
 Lcd_param = 1 : Gosub Lcd_gotoline                         '1.Zeile anw.
If Display_info < 2 Then
 Lcd_display_string = "Analog Group 2  " : Gosub Write_manual_line_2 : Return : End If
Lcd_param = 1 : Gosub Lcd_gotoline
'Lcd_display_string = "A2:" : Gosub Lcd_display
 Value = Ldr_sensor : Gosub Display_analog_raw
Value = Analog_10 : Gosub Display_analog_raw
Value = Analog_11 : Gosub Display_analog_raw
Gosub Delete_rest_of_display
    Lcd_param = 2 : Gosub Lcd_gotoline                      '1.Zeile anw.
Value = I_load_ai_12 : Gosub Display_analog_raw
Value = I_load_ai_13 : Gosub Display_analog_raw
Value = I_solar_ai_14 : Gosub Display_analog_raw
Value = U_nicd_ai_15 : Gosub Display_analog_raw
Gosub Delete_rest_of_display
Gosub Line_feed
Return

Delete_rest_of_display:
Lcd_display_pad_with_spaces = 1 : Lcd_display_string = " " : Gosub Lcd_display
Return

Display_analog_raw:
Kein_komma = 1 : Gosub Write_value : Gosub Write_leerz
Return

'Eingänge
Display_fkt9b:
 Lcd_param = 1 : Gosub Lcd_gotoline                         '  '1.Zeile des Displays wird aktiviert
If Display_info < 2 Then
 Lcd_display_string = "Digital Input   " : Gosub Write_manual_line_2 : Return : End If
If Mobile_aktiv = 1 Then Print #1 , "DI:";
Lcd_display_string = "1" : Gosub Lcd_display
If Input_1 = 1 Then Gosub Show_on Else Gosub Show_off

If Mobile_aktiv = 1 Then Print #1 , " ";
Lcd_display_string = "2" : Gosub Lcd_display
If Input_2 = 1 Then Gosub Show_on Else Gosub Show_off

If Mobile_aktiv = 1 Then Print #1 , " ";
Lcd_display_string = "3" : Gosub Lcd_display
If Input_3 = 1 Then Gosub Show_on Else Gosub Show_off

If Mobile_aktiv = 1 Then Print #1 , " ";
Lcd_display_string = "4" : Gosub Lcd_display
If Input_4 = 1 Then Gosub Show_on Else Gosub Show_off

If Mobile_aktiv = 1 Then Print #1 , " ";
Lcd_display_string = "5" : Gosub Lcd_display
If Input_5 = 1 Then Gosub Show_on Else Gosub Show_off

If Mobile_aktiv = 1 Then Print #1 , " ";
Lcd_display_string = "6" : Gosub Lcd_display
If Input_6 = 1 Then Gosub Show_on Else Gosub Show_off

If Mobile_aktiv = 1 Then Print #1 , " ";
Lcd_display_string = "7" : Gosub Lcd_display
If Input_7 = 1 Then Gosub Show_on Else Gosub Show_off

If Mobile_aktiv = 1 Then Print #1 , " ";
Lcd_display_string = "8" : Gosub Lcd_display
If Input_8 = 1 Then Gosub Show_on Else Gosub Show_off

Lcd_param = 2 : Gosub Lcd_gotoline                          '  '1.Zeile des Displays wird aktiviert
 If Normal_charge = 1 Then Lcd_display_string = "normal Ch" '"normal_charge "
If Batt_pwm_charge = 1 Then Lcd_display_string = "Puls Ch"
 If Full_charge = 1 Then Lcd_display_string = "Boost Ch"
' If Equalization_charge = 1 Then Print #1 , "Equalization_charge=1"
' If No_sun = 1 Then Print #1 , "No_sun=1"
 Gosub Lcd_display

 Lcd_display_string = "/Pu:" : Gosub Lcd_display
' If Boost_voltage_was_ok = 1 Then Print #1, "Boost_voltage_was_ok = 1"
' S = Str(pwm_value) : Print #1 "PWM-Value:" , S
 Value = Slow_switching_time_on : Kein_komma = 1 : Gosub Write_value
' S = Str(time_boost_charge) : If Full_charge = 1 Then Print #1 , S
' value = time_boost_charge: kein_komma = 1 : GoSub write_value
' If Temp_alarm_trans = 1 Then Print #1 , "Temp_alarm"
' If Load_5 = 1 Then Print #1 , "Load_5=1" Else Print #1 , "Load_5=0"
Gosub Delete_rest_of_display
Gosub Line_feed
Return

Show_on:
Lcd_display_string = "#" : Gosub Lcd_display
Return

Show_off:
Lcd_display_string = "." : Gosub Lcd_display
Return

Write_manual_line_2:
Lcd_display_pad_with_spaces = 1 : Gosub Lcd_display : Lcd_param = 2 : Gosub Lcd_gotoline : Lcd_display_string = "For next press #" : Lcd_display_pad_with_spaces = 1 : Gosub Lcd_display : Incr Display_info : Gosub Line_feed : Return

Eing_9:
If Keyb <> 0 And Keyb <> 9 And Keyb <> 11 Then Fkt9 = 1
If Keyb = 1 Then Toggle Output_1
If Keyb = 2 Then Toggle Relais_2
If Keyb = 3 Then Toggle Relais_3
If Keyb = 4 Then Toggle Relais_4
If Keyb = 5 Then Toggle Relais_5
If Keyb = 6 Then Toggle Relais_6
If Keyb = 7 Then Toggle Relais_7
If Keyb = 8 Then Toggle Beeper
If Keyb = 0 Or Keyb = 11 Then
 Incr Display_submenues : If Display_submenues > 4 Then Display_submenues = 0 : Display_info = 0 : End If
Goto Anzeige_handebene_reset

Eing_9_2:
If Keyb <> 0 And Keyb <> 9 And Keyb <> 11 Then Fkt9 = 1
If Keyb = 1 Then Toggle Pwm_port
If Keyb = 2 Then Toggle Nimh_load_rel
If Keyb = 3 Then Toggle Output_9
If Keyb = 4 Then Toggle Output_10
If Keyb = 5 Then Toggle Output_11
If Keyb = 6 Then Toggle Output_12
If Keyb = 7 Then Toggle Output_13
If Keyb = 8 Then Toggle Output_14
If Keyb = 0 Or Keyb = 11 Then
  Incr Display_submenues : If Display_submenues > 4 Then Display_submenues = 0 : Display_info = 0 : End If
Goto Display_fkt9_2

Reset:
Stelle_1 = 0
If Fkt1 = 1 And Delay_next_key_reset = 0 And Switch_input_block_channel > 0 And Back_to_basic_menu <> 30 Then       'go back at Function 1 channels
   Decr Switch_input_block_channel : Delay_next_key_reset = 3 : Stelle_1 = 0 : Goto Display_channel : End If
'reset display
Lcd_param = &B00000001 : Gosub Lcd_writecmd                 'Display löschen
Waitms 50
  Lcd_param = &B00000110 : Gosub Lcd_writecmd               'Auto inkrement
Waitms 50
Lcd_param = &B00001100 : Gosub Lcd_writecmd                 ' Cursor blinken aus
Waitms 200
Porta = 0 : Portc.6 = 0 : Portc.0 = 0

Fkt1 = 0 : Fkt2 = 0 : Fkt3 = 0 : Fkt4 = 0 : Fkt5 = 0
Fkt6 = 0 : Fkt7 = 0 : Fkt8 = 0 : Fkt9 = 0 : Disp_fkt9 = 0
Eingabe_teil_2 = 0 : Eingabe_teil_3 = 0 : Eingabe_teil_4 = 0 : Eingabe_teil_5 = 0 : Eingabe_teil_6 = 0
Switch_input_block = 0
Negative_number = 0 : If Mobile_aktiv = 0 Then Meldung_aktiv = 0 : Display_info = 0 : Tel_nr = 0
Display_info_line = 0
Goto Grundmenue

' Kleine Hilfs Unterprogramme
Beep_ein:
If Delay_on < 30 Then Return                                'Battery_voltage_ok = 0 Battery empty
If Fkt9 = 1 Then Return
If Beep_ein > 0 Then Decr Beep_ein
If Beep_ein > 0 Then Beeper = 1 : Return

Lcd_delete:
Lcd_param = &B00000001 : Gosub Lcd_writecmd : Return

Write_nein:
If English = 0 Then Lcd_display_string = "Nein!" Else Lcd_display_string = "No! " : Gosub Lcd_display : Gosub Line_feed : Wait 1 : Stelle_1 = 0 : Return

'Leerzeichen schreiben
Write_leerz:
Lcd_param = Leerz : Gosub Lcd_writechar : Return

'Wert Batterie umrechnen
Batt_value:
' Y=7.67*(X-133)/365+2.8
Value = Value - 133 : Value = Value * 77 : Value = Value / 365 : Value = Value + 28 : Value = Value / 10
Return

Display_value_and_unit:
Kein_komma = 0 : If Temp_b2 = 99 And Channel_typ = 4 Then Kein_komma = 1
Gosub Write_value
'Unit
Lcd_display_string = " "
Temp_b5 = Channel_typ Mod 10
If Temp_b5 = 0 Then Lcd_display_string = "%"
If Temp_b5 = 1 Then Lcd_display_string = "°"
If Temp_b5 = 2 Then Lcd_display_string = "%"
If Temp_b5 = 3 Then Lcd_display_string = "V"
If Temp_b5 = 4 Then
  If Temp_b2 = 99 Then Lcd_display_string = "P" : End If    'Pasteuer-Units
If Temp_b5 = 5 Then Lcd_display_string = "A"
Gosub Lcd_display
Gosub Value_with_space
Return

Value_with_space:
If Value >= 0 And Value < 100 And Temp_b5 <> 33 Then        'that no blinking of Display temp_b5 = 33 off
  Lcd_display_string = " " : Gosub Lcd_display : End If
Return

Del_disp:
Lcd_param = &B00000001 : Gosub Lcd_writecmd : Return

Write_fragez:
If Mobile_aktiv = 0 Then Return
If Timer_1_sec = 0 Then Print #1 , " ?" ; Else Print #1 , "   " ;
Return

Show_output_type:
 If Value = 0 Then Lcd_display_string = "=off "
 If Value = 1 Then Lcd_display_string = "=MOSFET "
 If Value > 1 And Value < 8 Then Lcd_display_string = "=Relay "
 If Value = 8 Then Lcd_display_string = "=Beep "
 If Value > 8 And Value < 16 Then Lcd_display_string = "=MOSFET "
 If Value = 16 Then Lcd_display_string = "=Telephone"
 If Value > 200 And Value < 300 Then Lcd_display_string = "=2Relais"
 If Value > 300 Then Lcd_display_string = "=3Relais"
Return

Write_ok:
 Lcd_param = 1 : Gosub Lcd_gotoline                         '1.Zeile anw.
 Lcd_display_string = "ok! " : Gosub Lcd_display : Gosub Line_feed : Wait 1 : Return

Write_on:
If English = 0 Then Lcd_display_string = "ein" Else Lcd_display_string = "on " : Gosub Lcd_display
Return

Write_off:
If English = 0 Then Lcd_display_string = "aus" Else Lcd_display_string = "off" : Gosub Lcd_display
Return

Input_value_ram:
If Keyb = 11 Then                                           'next Input-Block
   Keyb = 255 : Stelle_1 = 0 : Incr Switch_input_block_channel : Return : End If
If Stelle_1 = 0 Then
  Temp = Keyb : Stelle_1 = 1 : Return : End If              '1.Stelle
   Temp = 10 * Temp : Temp = Temp + Keyb
  If Max_value > 0 And Temp > Max_value Then                'Max-Value
       Temp = Keyb : Max_value = 0 : Stelle_1 = 1 : Return : End If
   Max_value = 0
Return

Input_8_bit_value:
If Keyb = 11 Then                                           'next Input-Block
   Keyb = 255 : Stelle_1 = 0 : Incr Switch_input_block : Incr Switch_input_block_channel : Return : End If
If Stelle_1 = 0 Then
  Writeeeprom Keyb , Temp : Stelle_1 = 1 : Return : End If  '1.Stelle
  Readeeprom Temp_b2 , Temp : Value = 10 * Temp_b2 : Value = Value + Keyb
  If Value > 255 Then
   Temp_b2 = Keyb
   Else
    Temp_b2 = Value
  End If
'Max-Value
  If Max_value > 0 And Temp_b2 > Max_value Then
    Temp_b2 = Keyb : Stelle_1 = 1 : End If
   Max_value = 0 : Writeeeprom Temp_b2 , Temp
Return

Input_16_bit_value:
If Keyb = 11 Then                                           'next Input-Block
  Stelle_1 = 0 : Incr Switch_input_block : Incr Switch_input_block_channel : Return : End If
If Stelle_1 = 0 Then
Value = Keyb : Writeeeprom Value , Temp : Stelle_1 = 1 : Return : End If       '1.Stelle
  Readeeprom Value , Temp : Value = 10 * Value : Value = Value + Keyb
  Writeeeprom Value , Temp
Return

Write_unit_info:                                            '1234567890123456
Lcd_display_string = "<100=sec;>=min/h" : Gosub Lcd_display : Gosub Line_feed : Waitms 2500 : Display_info_line = 1
Return

Write_unit_info2:                                           '1234567890123456
Lcd_display_string = "<100=min;>=h/day" : Gosub Lcd_display : Gosub Line_feed : Waitms 2500 : Display_info_line = 1
Return

Input_info:
Lcd_param = 1 : Gosub Lcd_gotoline                          '1234567890123456
Lcd_display_string = "Meas=1..Digi=101" : Lcd_display_pad_with_spaces = 1 : Gosub Lcd_display
Lcd_param = 2 : Gosub Lcd_gotoline                          '0123456789012345
Lcd_display_string = "Radio=201..." : Lcd_display_pad_with_spaces = 1 : Gosub Lcd_display : Gosub Line_feed : Wait 3 : Display_info_line = 1
Return

Output_info:
Lcd_param = 1 : Gosub Lcd_gotoline                          '1234567890123456
Lcd_display_string = "Output 1-20" : Lcd_display_pad_with_spaces = 1 : Gosub Lcd_display
Lcd_param = 2 : Gosub Lcd_gotoline                          '0123456789012345
Lcd_display_string = "2-7=Relay" : Lcd_display_pad_with_spaces = 1 : Gosub Lcd_display : Gosub Line_feed : Wait 3 : Display_info_line = 1
Return

Type_info:
Lcd_param = 1 : Gosub Lcd_gotoline                          '1234567890123456
Lcd_display_string = "with Tel-" : Lcd_display_pad_with_spaces = 1 : Gosub Lcd_display
Lcd_param = 2 : Gosub Lcd_gotoline                          '1234567890123456
Lcd_display_string = "Call? (0-2)?" : Lcd_display_pad_with_spaces = 1 : Gosub Lcd_display : Gosub Line_feed : Wait 3 : Display_info_line = 1
Return

Return

Write_type_nr:
Lcd_display_string = " Switch"
If Temp_b1 = 1 Then Lcd_display_string = " Alarm"
If Temp_b1 = 2 Then Lcd_display_string = " Telephone"
'If Temp_b1 = 3 Then Lcd_display_string = " SMS"
Lcd_display_pad_with_spaces = 1 : Gosub Lcd_display
Return

Write_with_output:                                          '1234567890123456
Lcd_display_string = " Out:1-20"
If Timer_2_sec = 0 Then Lcd_display_string = " In:101.."
Lcd_display_pad_with_spaces = 1 : Gosub Lcd_display
Return

Write_time_unit:
Lcd_display_string = "sec"
If Value > 100 Then Lcd_display_string = "min"
If Value > 200 Then Lcd_display_string = "hr"
Gosub Lcd_display
Return

Write_sec:
Lcd_display_string = "sec" : Gosub Lcd_display : Return

Write_min:
  Lcd_display_string = "min" : Gosub Lcd_display : Return

Write_std:
If English = 0 Then Lcd_display_string = "hr" Else Lcd_display_string = "hr"
Gosub Lcd_display
Return

Write_alarm_channel:
If English = 0 Then Lcd_display_string = "Alarm Kanal " Else Lcd_display_string = "Alarm Channel " : Gosub Lcd_display : Kein_komma = 1 : Gosub Write_value
Lcd_display_string = " " : Lcd_display_pad_with_spaces = 1 : Gosub Lcd_display
Return

'Write_blank:
'For Value = 1 To 16
'Gosub Write_leerz
'Next
'Return

Load_from_flash:
'Temp = Hw_version : Version = Temp
System_voltage_24v = 0                                      ': System_voltage_48v = 0
If U_batt_smooth > 200 And U_batt_smooth < 400 Then System_voltage_24v = 1
'If U_batt_smooth > 400 Then System_voltage_48v = 1

Readeeprom Value , 350                                      'Number of scans
Number_of_scans = Value

Readeeprom Value , 332                                      '332 = 36 PWM-charging/slow charging?
 If Value = 1 Then Pwm_charging_on_by_user = 1 Else Pwm_charging_on_by_user = 0
Readeeprom Temp , 306 : If Temp = 1 Then Send_sms = 1 Else Send_sms = 0       'SMS
Readeeprom Temp , 282 : If Temp = 1 Then Blei_akku = 1 Else Blei_akku = 0       'Speicher Blei/Gel hat sich geändert?
Readeeprom Sensor_average , 284
Readeeprom Temp , 280 : If Temp = 1 Then English = 1 Else English = 0       'Language
Pwm_charging = 1                                            'Readeeprom Value , x : If Value = 1 Then Pwm_charging = 1 Else Pwm_charging = 0
Readeeprom Temp , 266 : If Temp > 9 Then Days_without_water = 0 Else Days_without_water = Temp

'Type
For Channel_nr = 1 To Number_of_channel_modules
   Temp = Channel_nr * 10 : Temp4 = Temp + 493 : Readeeprom Temp_b1 , Temp4       'Type at Adr. 503
  Channel_type(channel_nr) = Temp_b1
Next

Readeeprom Temp , 286 : If Temp < 0 Or Temp > 20 Then Temp = 20 : Number_of_channel_modules = Temp
Send_flash_to_logview = 0 : Readeeprom Temp , 296 : If Temp = 1 Then Send_flash_to_logview = 1
Return

Temp_spg_wert:                                              'Berechnung der Ladeschlusspg. aufgrund der Temperatur:
Readeeprom Value , 330 : If Value <> 1 Then Return          'with Temp-Correction? '130 = 35 Temp-Correction Solar
'Y=0,336*(X-50)/-70+13,8558 mit 10 Multipliziert; Y*10 = 33,6(X-50)/-70 + 138
If Analog_11 < 10 Then Return                               'no Temp-Sensor connected Or Sensor_4 > 168
Temp3 = Analog_11                                           'Temperatur
Temp3 = Temp3 / 10
Temp3 = 50 - Temp3 : Temp3 = Temp3 * 33                     'bei 20': 990; bei -20'=2310; bei 45'=14,18V;
Temp3 = Temp3 / 70
Temp = Temp * 10 : Temp3 = Temp3 + Temp                     'temp = Umax =1399 entspricht 13,99V; bei -20'=14,18V; bei 45': 1387
Temp = Temp3 / 10
If Temp < 0 Then Goto Kleiner_null
If Temp <= 105 Then Temp = 105                              'Temp-Kompensation auf minimale Spannung (10.5V) begrenzen!
If Temp <= 210 And System_voltage_24v = 1 Then Temp = 210   'Temp-Kompensation auf minimale Spannung (21.0V) begrenzen!
'If Temp <= 420 And System_voltage_48v = 1 Then Temp = 420   'Temp-Kompensation auf minimale Spannung (21.0V) begrenzen!
Return
Kleiner_null:
Temp = Abs(temp)                                            ': Temp = temp3 + temp : Temp = 2 * Temp : temp3 = temp + Temp : temp = Abs(temp)       'mit einer Nachkommastelle
If Temp <= 105 Then Temp = 105                              'Temp-Kompensation auf minimale Spannung (10.5V) begrenzen!
If Temp <= 210 And System_voltage_24v = 1 Then Temp = 210   'Temp-Kompensation auf minimale Spannung (21.0V) begrenzen!
'If Temp <= 420 And System_voltage_48v = 1 Then Temp = 420   'Temp-Kompensation auf minimale Spannung (21.0V) begrenzen!
Return

Solar_stromwert:
Readeeprom Zero_value_current , 328                         '128 = 34 SP_Zero_value_current
If Solar_loading = 1 Then
  I_solar = I_solar_ai_14 - Zero_value_current              'Solar + Load Current
  If I_solar > 0 Or I_solar_ai_14 > 700 Then                'no charging,  'MOSFET not yet on
       I_solar = 0 : Return : End If
    Temp = I_solar - I_solar_old : Temp = Abs(temp) : I_solar_old = I_solar : If Temp > 20 Then Return       'too much change of value
    I_solar = Abs(i_solar)
   Temp_l2 = I_solar : Temp_l2 = Temp_l2 * 204 : Temp_l2 = Temp_l2 / 100       'first calculation
     Readeeprom Temp_b5 , 804                               'Correction-Factor
    Temp_l2 = Temp_l2 * Temp_b5 : Temp_l2 = Temp_l2 / 100 : I_solar = Temp_l2       'z.B. 1,10
 Else
 I_solar = 0
End If
'If Simu = 1 Then
'  If Getadc(1) > 65 Then I_solar = Getadc(1) - 71 Else I_solar = Getadc(0) : End If
'value changed too much?? Wenn Delta Strom zu groß, nicht verwenden, nur wenn zweimal Delta Strom gross
If Stop_read_ai_extended = 1 Then Return                    'not if check max-Ampere Solar
Temp = I_solar - I_solar_old_1 : Temp2 = Abs(temp)
I_solar_old_1 = I_solar

If Temp2 > 30 Or I_solar > 400 Then                         'And 'too much changed!!
   I_solar = I_solar_old_2
  Else
   I_solar_old_2 = I_solar
   End If

Gosub Average_current_solar                                 'Average Calculation
Return

Last_stromwert:
If Simu = 1 Then
 I_load = U_ausg + 60 : Return : End If

If I_load_ai_13 < 0 Or I_load_ai_13 > 500 Then I_load_ai_13 = 0
        Temp_l1 = I_load_ai_13 : Temp_l1 = Temp_l1 * 58 : Temp_l1 = Temp_l1 / 100       'first calculation
        Readeeprom Temp_b5 , 802                            ' 94                                'Correction
        Temp_l1 = Temp_l1 * Temp_b5 : Temp_l1 = Temp_l1 / 100 : I_load_1 = Temp_l1
If I_load_1 > 300 Then I_load_1 = 0

If I_load_ai_12 < 0 Or I_load_ai_12 > 500 Then I_load_ai_12 = 0
        Temp_l1 = I_load_ai_12 : Temp_l1 = Temp_l1 * 58 : Temp_l1 = Temp_l1 / 100       'first calculation
        Readeeprom Temp_b5 , 803                            '96                                'Correction
        Temp_l1 = Temp_l1 * Temp_b5 : Temp_l1 = Temp_l1 / 100 : I_load_2 = Temp_l1
If I_load_2 > 300 Then I_load_2 = 0

'If I_load_ai_11 < 0 Or I_load_ai_11 > 500 Then I_load_ai_11 = 0
'        Temp_l1 = I_load_ai_11 : Temp_l1 = Temp_l1 * 58 : Temp_l1 = Temp_l1 / 100       'first calculation
'        Readeeprom Temp_b5 , 751 '98                                'Correction
'        Temp_l1 = Temp_l1 * Temp_b5 : Temp_l1 = Temp_l1 / 100 : I_load_3 = Temp_l1
'If I_load_3 > 160 Then I_load_3 = 0

'Readeeprom Temp , 358                                       '358 = 49 Load 3 Select Output 10
I_load = I_load_1 + I_load_2                                'Else I_load = I_load_1
If I_load > 400 Then I_load = 0                             'I_load = I_load + I_load_3 :
Gosub Average_current_load                                  'Average Calculation
Return

'Alarm Batterie U min Voralarm
Batt_pre_alarm:
If Delay_on < 30 Or Sensor_batt < 10 Or Fkt8 = 1 Then Return       'keine Batterie angeschlossen
Readeeprom Temp , 268                                       'Voltage Pre-Alarm
Gosub Temp_spg_wert                                         'Temperaturatur-Korrektur
Temp1 = Temp + 10                                           '1 Volt Pre-Alarm Reset
If U_batt_smooth > Temp1 Then
  Flanke_alarm_batt = 0 : Delay_low_volt_alarm = 0 : End If
If U_batt_smooth < Temp Then Incr Delay_low_volt_alarm      'Alarm switch with delay 50 sec

If Flanke_alarm_batt = 1 And Meldung_aktiv = 1 Then
  Lcd_param = 1 : Gosub Lcd_gotoline : Lcd_display_string = "Alarm Batter" : Gosub Lcd_display
  If English = 0 Then Lcd_display_string = "ie!" Else Lcd_display_string = "y!" : Gosub Lcd_display : Gosub Line_feed
End If

If Delay_low_volt_alarm <= 50 Or Flanke_alarm_batt = 1 Or Meldung_aktiv = 1 Then Return       'Wenn Umin-Wert eingegeben oder Automatische Umin-Bestimmung
Meldung_aktiv = 1 : Flanke_alarm_batt = 1 : Beep_ein = 3
Return

'Alarm Battery Empty
Alarm_batt_empty:
If Delay_on < 30 Or Sensor_batt < 10 Or Fkt8 = 1 Then Return       'keine Batterie angeschlossen
Readeeprom Temp , 260                                       'Voltage Alarm empty
Gosub Temp_spg_wert : Temp1 = Temp + 15                     'Temperaturatur-Korrektur, Hysterese
If U_batt_smooth > Temp1 Then
 Flanke_u_min_batt = 0 : Delay_min_volt_alarm = 0 : End If
If U_batt_smooth < Temp Then Incr Delay_min_volt_alarm      'Alarm switch with delay 50 sec

If Flanke_u_min_batt = 1 And Meldung_aktiv = 1 Then
  Lcd_param = 1 : Gosub Lcd_gotoline : Lcd_display_string = "Alarm Batt." : Gosub Lcd_display
  If English = 0 Then Lcd_display_string = "leer!   " Else Lcd_display_string = " low!" : Gosub Lcd_display : Gosub Line_feed
End If

If Delay_min_volt_alarm <= 50 Or Flanke_u_min_batt = 1 Or Meldung_aktiv = 1 Then Return
Meldung_aktiv = 1 : Flanke_u_min_batt = 1 : Beep_ein = 3 : Return

High_currrent_pulses:
'Pulses alle 30sec für 100 us
If Blei_akku = 0 Then Return                                '17.5.04 only with Gel
Temp_b1 = Second Mod 30 : If Temp_b1 = 0 Then
 Portb.7 = 0 : Gosub Disable_pwm : Waitms 100
Porte.2 = 0 : Waitus 100 : Porte.2 = 1 : End If
Return

''Alarm von der Schaltschranktür z.B.
'Alarm_tuere:
'Alarm_door = 0
'If Alarm_aktive = 1 And Delay_alarm_aktive < 255 Then Incr Delay_alarm_aktive
'If Alarm_aktive = 0 Then Delay_alarm_aktive = 0
'If Delay_alarm_aktive < 90 Then Return
'
'If Alarm_aktive = 0 Then Flanke_alarm_tuer = 0
'If Delay_on < 30 Or Alarm_aktive = 0 Or Fkt9 = 1 Then Return       'Anwahl Alarm
'If Flanke_alarm_tuer = 1 And Meldung_aktiv = 1 Then
' Lcd_param = 1 : Gosub Lcd_gotoline
' If English = 0 Then Lcd_display_string = "Alarm Diebstahl!" Else Lcd_display_string = "Theft Alarm!!!!!" : Gosub Lcd_display : Gosub Line_feed
'End If
'Return

Standard_laden:
Lcd_param = 1 : Gosub Lcd_gotoline                          '2.Zeile anw.
Lcd_display_string = "loading..." : Gosub Lcd_display
Blei_akku_old = Blei_akku

Temp_b1 = 0
For I = 262 To 267                                          'first Parameter
  Writeeeprom Temp_b1 , I : Next I

Temp = Min_spannung : If Blei_akku = 0 Then Temp = Temp - 5 : Gosub Correction_system_voltage : Writeeeprom Temp , 260

Temp = Lastabwurf_1 : Gosub Correction_system_voltage : Writeeeprom Temp , 242

Temp = Lastabwurf_2 : Gosub Correction_system_voltage : Writeeeprom Temp , 244

Temp = Lastabwurf_3 : Gosub Correction_system_voltage : Writeeeprom Temp , 246

Temp = Lastabwurf_4 : Gosub Correction_system_voltage : Writeeeprom Temp , 248

Temp = Lastabwurf_5 : Gosub Correction_system_voltage : Writeeeprom Temp , 250

Temp = Vorwarnung : : Gosub Correction_system_voltage : Writeeeprom Temp , 268

Temp = Hysterese_rueckschaltung : Writeeeprom Temp , 270

Temp = Ladeendspg : Gosub Correction_system_voltage : Writeeeprom Temp , 272

Temp = Zylisches_laden_blei : If Blei_akku = 0 Then Temp = Zylisches_laden_gel : Gosub Correction_system_voltage : Writeeeprom Temp , 274

Temp = Ausgleichsladen : Gosub Correction_system_voltage : Writeeeprom Temp , 276

Temp = Max_spannung : Gosub Correction_system_voltage : Writeeeprom Temp , 278

'Reset all Parameters
Temp_b1 = 0
For I = 280 To 420
  Writeeeprom Temp_b1 , I : Next I

'Temp = 0 : Writeeeprom Temp , 280                           'Language
'Temp = 0 : Writeeeprom Temp , 266                           '266 = 3 Days without watering
Temp = 1 : Writeeeprom Temp , 282                           'Gel/Lead 1=Lead
'Temp = 0 : Writeeeprom Temp , 284                           'Irrigation: Average-Calculation
Temp = 10 : Writeeeprom Temp , 286                          'channel-Nr
'Temp = 0 : Writeeeprom Temp , 288                           '
'Temp = 0 : Writeeeprom Temp , 290                           'Sensor-Type
'Temp = 0 : Writeeeprom Temp , 292                         'Analog Input correction +/-
'Temp = 0 : Writeeeprom Temp , 294                         'Analog Input correction Factor
'Temp = 0 : Writeeeprom Temp , 296                           '18 Solar loading triggered by Time
'Temp = 4 : Writeeeprom Temp , 300                           'u_additional_dev_on
Temp = 5 : Writeeeprom Temp , 302                           'Delay_add_device_on
'Temp = 0 : Writeeeprom Temp , 304                           'Receive SMS on
'Temp = 0 : Writeeeprom Temp , 306                           'Send SMS
Temp = 94 : Writeeeprom Temp , 308                          '24 Country_code SMS
'Temp = 0 : Writeeeprom Temp , 310                        '
'Temp = 0 : Writeeeprom Temp , 316                           'Voltage_Nicd_charge
'Temp = 0 : Writeeeprom Temp , 318                           'Capacity NimH
Temp = 1 : Writeeeprom Temp , 320                           'Solar-Charger aktiv
Temp = 60 : Writeeeprom Temp , 322                          '31 Scan-Time Data-Logging
'Temp = 0 : Writeeeprom Temp , 324                           '124 = 32 Discharge: Voltage / SOC
'temp = 10 : Writeeeprom Temp , 326                          'reserve
Temp = 563 : Writeeeprom Temp , 328                         '128 = 34 SP_Zero_value_current
Temp = 1 : Writeeeprom Temp , 330                           '130 = 35 Temp-Correction Solar
Temp = 1 : Writeeeprom Temp , 332                           'PWM-charging
Temp = 30 : Writeeeprom Temp , 334                          ' Max.Time for Anti-Frost-Irriga
'Temp = 0 : Writeeeprom Temp , 336                           '
'Temp = 0 : Writeeeprom Temp , 338                           '39 Correction KWh
'Temp = 0 : Writeeeprom Temp , 340                           '
'Temp = 0 : Writeeeprom Temp , 342                           '  Hardware-Version
'Temp = 0 : Writeeeprom Temp , 346                           'Start/Stop Boost-charge
'Temp = 0 : Writeeeprom Temp , 348                           'SD_Card present
Temp = 4 : Writeeeprom Temp , 350                           'Number of Scans Analog
'Temp = 0 : Writeeeprom Temp , 352                           'Pointer SD-Chip Block
Temp = 1 : Writeeeprom Temp , 354                           'Load 1 Select Output 1
Temp = 9 : Writeeeprom Temp , 356                           'Load 2 Select Output 9
Temp = 10 : Writeeeprom Temp , 358                          'Load 3 Select Output 10
Temp = 11 : Writeeeprom Temp , 360                          'Load 4 Select Output 11
Temp = 12 : Writeeeprom Temp , 362                          'Load 5 Select Output 12
'Temp = 0 : Writeeeprom Temp , 364                           'Start Analog free
Temp = 999 : Writeeeprom Temp , 366                         'Start Analog free
'Temp = 0 : Writeeeprom Temp , 368                           'RAW Start
Temp = 1024 : Writeeeprom Temp , 370                        'RAW End
'Temp = 7 : Writeeeprom Temp , 372                           'Res Level-Pump
'Temp = 1 : Writeeeprom Temp , 374                           'Simu-Value
'Temp = 1 : Writeeeprom Temp , 376                           'Faktor for Simulation with Poti
'Temp = 7 : Writeeeprom Temp , 378                           '
'Temp = 0 : Writeeeprom Temp , 380                           '
'Temp = 0 : Writeeeprom Temp , 382                           '
'Temp = 0 : Writeeeprom Temp , 384                           '
'Temp = 0 : Writeeeprom Temp , 386                           '
'Temp = 0 : Writeeeprom Temp , 388                           '
'Temp = 1 : Writeeeprom Temp , 390                           'Faktor for Simulation with Poti
'Temp = 7 : Writeeeprom Temp , 392                           'Sp_time_pump_on_max_past = 10   in Seconds
'Temp = 1 : Writeeeprom Temp , 394                           'Delta_t_past_off = 1 Degree less
'Temp = 0 : Writeeeprom Temp , 396                           'res
'Temp = 0 : Writeeeprom Temp , 398                           'free
'Temp = 0 : Writeeeprom Temp , 400                           'free

'Reset all Telephone-Numbers
Temp_b1 = 11
For Temp_b3 = 131 To 176
  Writeeeprom Temp_b1 , Temp_b3 : Next
  Temp_b1 = 0 : Writeeeprom Temp_b1 , 130

'Reset Timer-Values
 Temp_b2 = 0
 For Temp = 226 To 240
  Writeeeprom Temp_b2 , Temp
 Next

Gosub Reset_alarm_channels
Gosub Reset_analog_input_corr
Gosub Set_channel_values
Return

Reset_alarm_channels:
Temp_b1 = 0 : Temp = 701                                    'Start at ..
For Temp_b3 = 1 To 49
 Writeeeprom Temp_b1 , Temp
 Incr Temp
Next
Return

Reset_analog_input_corr:
Temp = 751 : Temp_b1 = 0                                    'Type and Correction analog Input +/-
For Temp_b3 = 1 To 40
 Writeeeprom Temp_b1 , Temp
 Incr Temp
Next

Temp = 791 : Temp_b1 = 100                                  'Correction analog Input *
For Temp_b3 = 1 To 11
 Writeeeprom Temp_b1 , Temp
 Incr Temp
Next

For I = 802 To 805
Readeeprom Temp_b2 , I : If Temp_b2 = 0 Or Temp_b2 > 200 Then Writeeeprom Temp_b1 , I       'Load ext
Next

Temp_b1 = 3 : Writeeeprom Temp_b1 , 753                     'input x Channel Humid 1 linear
Writeeeprom Temp_b1 , 754                                   'input x Channel Humid 2
Writeeeprom Temp_b1 , 755                                   'input x Channel Humid 3
Writeeeprom Temp_b1 , 756                                   'input x Channel Humid 4
Writeeeprom Temp_b1 , 757                                   'input x Channel Humid 5

Writeeeprom Temp_b1 , 759                                   'LDR
Temp_b1 = 1 : Writeeeprom Temp_b1 , 760                     'ext.Sensor Temp
Writeeeprom Temp_b1 , 761                                   'Temp-Kompensation Solar
Temp_b1 = 5 : Writeeeprom Temp_b1 , 765                     'Nicd
Return

Temp_b1 = 72 : Writeeeprom Temp_b1 , 803                    'Load 1 factor
Temp_b1 = 54 : Writeeeprom Temp_b1 , 804                    'I solar factor
'///////////////////////// Set_channel_values /////////////////////////////
Set_channel_values:
For Channel_nr = 1 To 20

Temp4 = Channel_nr + 459 : Temp_b1 = 3                      'No_Alarm_Time
Writeeeprom Temp_b1 , Temp4

Temp4 = Channel_nr + 480 : Temp_b1 = 0                      'all data Output 2
Writeeeprom Temp_b1 , Temp4

 Temp_b4 = Channel_nr * 10 : Temp4 = Temp_b4 + 491 : Temp_b1 = 0
 For Temp_b3 = 1 To 10                                      'reset all data block 1
  Writeeeprom Temp_b1 , Temp4                               'all data
  Incr Temp4
 Next

Temp4 = Temp_b4 + 891 : Temp_b1 = 0                         'reset all data block 2
 For Temp_b3 = 1 To 8
  Writeeeprom Temp_b1 , Temp4                               'all data
  Incr Temp4
 Next

Temp = 20 : Writeeeprom Temp , Temp4                        'Hysteresis

Temp4 = Temp_b4 + 895 : Temp = 500                          'Setpoint
 Writeeeprom Temp , Temp4

Temp4 = Temp_b4 + 497 : Temp_b1 = 10                        '507 Analog Delay on/off
  Writeeeprom Temp_b1 , Temp4                               'all data
  Incr Temp4
  Writeeeprom Temp_b1 , Temp4                               '408 Analog Delay off
  Incr Temp4
Next

'Humid 1
Temp_b1 = 4 : Writeeeprom Temp_b1 , 901                     'input x Channel hour
Temp_b1 = 130 : Writeeeprom Temp_b1 , 903                   'input x Channel on for 30 min
Temp_b1 = 3 : Writeeeprom Temp_b1 , 501                     'input x Channel Humid
Temp_b1 = 3 : Writeeeprom Temp_b1 , 504                     'Output x Channel Humid
'Humid 2
Temp_b1 = 4 : Writeeeprom Temp_b1 , 911                     'input x Channel hour
Temp_b1 = 30 : Writeeeprom Temp_b1 , 912                    'input x Channel min
Temp_b1 = 130 : Writeeeprom Temp_b1 , 913                   'input x Channel on for 30 min
Temp_b1 = 4 : Writeeeprom Temp_b1 , 511                     'input x Channel Humid
Temp_b1 = 4 : Writeeeprom Temp_b1 , 514                     'Output x Channel Humid
'Humid 3
Temp_b1 = 5 : Writeeeprom Temp_b1 , 921                     'input x Channel hour
Temp_b1 = 130 : Writeeeprom Temp_b1 , 923                   'input x Channel on for 30 min
Temp_b1 = 5 : Writeeeprom Temp_b1 , 521                     'input x Channel Humid
Temp_b1 = 5 : Writeeeprom Temp_b1 , 524                     'Output x Channel Humid
'Humid 4
Temp_b1 = 5 : Writeeeprom Temp_b1 , 931                     'input x Channel hour
Temp_b1 = 30 : Writeeeprom Temp_b1 , 932                    'input x Channel min
Temp_b1 = 130 : Writeeeprom Temp_b1 , 933                   'input x Channel on for 30 min
Temp_b1 = 6 : Writeeeprom Temp_b1 , 531                     'input x Channel Humid
Temp_b1 = 6 : Writeeeprom Temp_b1 , 534                     'Output x Channel Humid
'Humid 5
Temp_b1 = 6 : Writeeeprom Temp_b1 , 941                     'input x Channel hour
Temp_b1 = 130 : Writeeeprom Temp_b1 , 943                   'input x Channel on for 30 min
Temp_b1 = 7 : Writeeeprom Temp_b1 , 541                     'input x Channel Humid
Temp_b1 = 7 : Writeeeprom Temp_b1 , 544                     'Output x Channel Humid

'channel 6 Alarm Batt empty
'Temp = Lastabwurf_5 : Gosub Correction_system_voltage : Writeeeprom Temp , 355
'Temp_b1 = 3 : Writeeeprom Temp_b1 , 553                     'channel 6 Alarm

'channel 7 Alarm 1: Analog Input / Moving-Detektor
'Temp = 512 : Writeeeprom Temp , 565                         'channel 7 setpoint
'Temp_b1 = 3 : Writeeeprom Temp_b1 , 561                     'Input = Analog 3
''Temp_b1 = 0 : Writeeeprom Temp_b1 , 572                     'Input 2 = 0
'Temp_b1 = 3 : Writeeeprom Temp_b1 , 563                     'Type = 3 = Alarm
'Temp_b1 = 4 : Writeeeprom Temp_b1 , 564                     'Output 4 = Rel 4
''Temp_b1 = 0 : Writeeeprom Temp_b1 , 567                     'Delay on =0
'Temp_b1 = 60 : Writeeeprom Temp_b1 , 568                    'Delay off = 60 sec
'
''channel 8 Lamp 1: Moving-Detektor Light on
''Temp_b1 = 0 : Writeeeprom Temp_b1 , 571                     'Input 1 = _
'Temp_b1 = 105 : Writeeeprom Temp_b1 , 572                   'Input 2 = Digital 5
''Temp_b1 = 0 : Writeeeprom Temp_b1 , 573                     'Type = 0
'Temp_b1 = 2 : Writeeeprom Temp_b1 , 574                     'Output 2 = Rel 2
''Temp_b1 = 0 : Writeeeprom Temp_b1 , 577                     'Delay on =0
'Temp_b1 = 240 : Writeeeprom Temp_b1 , 578                   'Delay off = 240 sec
'
''channel 9 Lamp 2: Moving-Detektor Light on
''Temp_b1 = 0 : Writeeeprom Temp_b1 , 581                     'Input 1 = _
'Temp_b1 = 106 : Writeeeprom Temp_b1 , 582                   'Input 2 = Digital 6
''Temp_b1 = 0 : Writeeeprom Temp_b1 , 583                     'Type = 0
'Temp_b1 = 3 : Writeeeprom Temp_b1 , 584                     'Output 3 = rel 3
''Temp_b1 = 0 : Writeeeprom Temp_b1 , 587                     'Delay on =0
'Temp_b1 = 240 : Writeeeprom Temp_b1 , 588                   'Delay off = 240 sec
'
''channel 10 Lamp 3: Moving-Detektor Light on
''Temp_b1 = 0 : Writeeeprom Temp_b1 , 901                     'Input 1 = _
'Temp_b1 = 107 : Writeeeprom Temp_b1 , 902                   'Input 2 = Digital 7
''Temp_b1 = 0 : Writeeeprom Temp_b1 , 903                     'Type = 0
'Temp_b1 = 5 : Writeeeprom Temp_b1 , 904                     'Output 5 = Rel 5
''Temp_b1 = 0 : Writeeeprom Temp_b1 , 907                     'Delay on =0
'Temp_b1 = 240 : Writeeeprom Temp_b1 , 908                   'Delay off = 240 sec
'
''channel 11 Lamp 4: Moving-Detektor Light on
''Temp_b1 = 0 : Writeeeprom Temp_b1 , 911                     'Input 1 = _
'Temp_b1 = 108 : Writeeeprom Temp_b1 , 912                   'Input 2 = Digital 7
''Temp_b1 = 0 : Writeeeprom Temp_b1 , 913                     'Type = 0
'Temp_b1 = 6 : Writeeeprom Temp_b1 , 914                     'Output 6 = Rel 6
''Temp_b1 = 0 : Writeeeprom Temp_b1 , 917                     'Delay on =0
'Temp_b1 = 240 : Writeeeprom Temp_b1 , 918                   'Delay off = 240 sec
Return

Correction_system_voltage:
If System_voltage_24v = 1 Then Shift Temp , Left , 1        'Voltage * 2
'If System_voltage_24v = 1 And System_voltage_48v = 1 Then Shift Temp , Left , 1       '48 V System-voltage Voltage * 4
Return

'Value to seriell
Print_value:
If Mobile_aktiv = 0 And Sending_os_data_active = 0 And Data_direct_to_pc = 0 And Send_flash_to_logview = 0 Then Return
If Value > 32767 Then                                       'negative?
  Print #1 , "-" ; : Value = 65536 - Value : End If
If Eight_bit_value_neg = 1 And Value > 128 Then
   Print #1 , "-" ; : Value = Value - 128 : End If
If Value > 10000 Then
 Print #1 , "1" ; : Goto Print_01 : End If                  '1
If Value > 19000 Then
 Print #1 , "2" ; : Goto Print_01 : End If                  '2
If Value > 30000 Then
 Print #1 , "3" ; : Goto Print_01 : End If                  '3
'If Value > 40000 Then
' Print #1 , "4"; :  : GoTo print_01 : End  If                      '4
'If Value > 50000 Then
' Print #1 , "5";  : GoTo print_01 : End  If                      '5
'If Value > 60000 Then
' Print #1 , "6";  : GoTo print_01 : End  If                      '6

Print_01:
Temp = Value Mod 10000 : Temp = Temp / 1000                 'Tausender
If Value >= 1000 Then                                       'Tausender
  Print #1 , Temp ; : End If

Temp = Value Mod 1000 : Temp = Temp / 100 :                 'Hunderter
If Value >= 100 Then
 Print #1 , Temp ; : End If

If Tel_nr = 1 Then Goto Print_eine_ziffer
Temp = Value Mod 100 : Temp = Temp / 10
If Two_comma = 1 Then Print #1 , "," ;
If Display_time_grid = 1 And Value > 100 Then Print #1 , "," ;

If Value >= 10 Then                                         ' Zehner-Dezimalstelle mit einer führenden 0
 Print #1 , Temp ; : End If
Goto P03

Print_eine_ziffer:
Temp = Value Mod 100 : Temp = Temp / 10

If Value >= 10 Then                                         ' Zehner-Dezimalstelle ohne eine führenden 0 für Tel-
 Print #1 , Temp ; : End If
P03:
If Kein_komma = 0 And Two_comma = 0 Then
 If Value = 0 Then Print #1 , "0";
 Print #1 , "," ; : End If

Temp = Value Mod 10                                         'einer Dezimalstelle ohne Leerzeichen
 Print #1 , Temp ;
If Tel_nr = 0 And Data_direct_to_pc = 0 And Send_flash_to_logview = 0 Then Print #1 , " ";
Return

'*** LCD_Initialisierung ***
Lcd_init:
Porta = 0 : Portc.0 = 0 : Portc.1 = 0 : Portc.5 = 0
Config Porta = Output : Config Pinc.0 = Output : Config Pinc.1 = Output : Config Pinc.5 = Output
Waitms 700
  Porta = &B00000010 : Portc.5 = 1 : Waitms 5 : Portc.5 = 0 'mit 8-Bit-Command in 4-Bit-Modus umschalten
Waitms 50                                                   'für Hochlauf
  Lcd_param = &B00101100 : Gosub Lcd_writecmd               ' Zeilen und Font einstellen
Waitms 50                                                   'für Hochlauf
  Lcd_param = &B00001100 : Gosub Lcd_writecmd               'Display an
Waitms 50                                                   'für Hochlauf
  Lcd_param = &B00000001 : Gosub Lcd_writecmd               'Display löschen
Waitms 50                                                   'für Hochlauf
  Porta = &B00000110 : Gosub Lcd_writecmd                   'Auto inkrement
Waitms 50                                                   'für Hochlauf

 If Simu = 1 Then
   Lcd_display_string = "   Simu Mode!   " : Gosub Lcd_display
   Else
  Lcd_display_string = "Panta rhei..." : Gosub Lcd_display
End If
  Lcd_param = 2 : Gosub Lcd_gotoline                        '2.Zeile anw.
  Lcd_display_string = "V 18.6.09" : Gosub Lcd_display : Gosub Line_feed : Waitms 800 : Return

'LCD-Programme
Write_value:
If Mobile_aktiv = 1 Then Gosub Print_value
'negative value?
'If Data_pointer = 16 And negative_number = 1 And Eingabe_teil_3 = 1 Then
'  Lcd_param = Minus : Gosub Lcd_writechar : End If
If Eight_bit_value_neg = 1 And Value > 128 Then
   Lcd_param = Minus : Gosub Lcd_writechar : Value = Value - 128 : End If
Eight_bit_value_neg = 0

If Value > 32767 Then                                       'negative?
  Lcd_param = Minus : Gosub Lcd_writechar : Value = 65536 - Value : End If
If Value > 10000 Then Lcd_param = &H31                      '1
If Value > 19000 Then Lcd_param = &H32                      '2
If Value > 30000 Then Lcd_param = &H33                      '2

If Value > 10000 Then Gosub Lcd_writechar
Temp = Value Mod 10000 : Temp = Temp / 1000 : Temp2 = Value
If Temp2 >= 1000 Then Lcd_param = Null + Temp Else Goto W01 ' Tausender-Dezimalstelle
Gosub Lcd_writechar
W01:
Temp = Value Mod 1000 : Temp = Temp / 100 : Temp2 = Value
If Temp2 >= 100 Then Lcd_param = Null + Temp Else Goto W02  ' Hunderter-Dezimalstelle
Gosub Lcd_writechar
W02:
If Tel_nr = 1 Then Goto Eine_ziffer
Temp = Value Mod 100 : Temp = Temp / 10 : Temp2 = Value
If Two_comma = 1 Or Display_time_grid = 1 Then
 If Display_time_grid = 0 Or Value > 100 Then
  Lcd_param = Punkt : Gosub Lcd_writechar : End If
 End If
If Temp2 >= 10 Then Lcd_param = Null + Temp Else Lcd_param = Null       ' Zehner-Dezimalstelle mit einer führenden 0
Gosub Lcd_writechar
Goto W03

Eine_ziffer:
Temp = Value Mod 100 : Temp = Temp / 10 : Temp2 = Value
'Goto W03
If Temp2 >= 10 Then Lcd_param = Null + Temp Else Goto W03   ' Zehner-Dezimalstelle ohne eine führenden 0 für Tel-Nr
Gosub Lcd_writechar
W03:
If Kein_komma = 0 And Two_comma = 0 Then
  Lcd_param = Punkt : Gosub Lcd_writechar : End If
Temp = Value Mod 10
Lcd_param = Null + Temp                                     ' einer Dezimalstelle ohne Leerzeichen
Gosub Lcd_writechar
Kein_komma = 0 : Display_time_grid = 0 : Two_comma = 0 : Tel_nr = 0
Return

' Zeilenwechsel
Lcd_gotoline:
If Lcd_param = 2 And Mobile_aktiv = 1 And No_print_seriell = 0 Then Print #1 , " ";
If Lcd_param = 1 Then Lcd_param = &H80 : If Lcd_param = 2 Then Lcd_param = &HC0       'Code für Zeile

' LCD-Kommando
Lcd_writecmd:
  Portc.0 = 0 : Goto Lcd_write                              'lcd_rs

' Zeichenausgabe
Lcd_writechar:
Portc.0 = 1                                                 '  lcd_rs

' Kommando oder Zeichen an Display senden
Lcd_write:
Temp_lcd = Lcd_param : Shift Temp_lcd , Right , 4
  Porta = Temp_lcd : Portc.5 = 1 : Waitms 2 : Portc.5 = 0   ' Hi-Nibble
  Porta = Lcd_param And &H0F : Portc.5 = 1 : Waitms 2 : Portc.5 = 0       ' Lo-Nibble
  Porta = 0 : Portc.6 = 0 : Portc.0 = 0                     'da eventuell gesetzt
  Return

Lcd_display:
  If Len(lcd_display_string) = 0 Then Return
  If Mobile_aktiv = 1 And No_print_seriell = 0 Then Print #1 , Lcd_display_string ; : No_print_seriell = 0
  'pad with spaces...
  If Lcd_display_pad_with_spaces = 1 Then
      'add spaces to the right of the string passed in to make it 16 chars long...
       Temp_b4 = Len(lcd_display_string)
       If Temp_b4 <= 16 Then
          Temp_b4 = 16 - Temp_b4
          For Temp_b3 = 1 To Temp_b4
          Lcd_display_string = Lcd_display_string + " "
          Next
          End If
  End If

Lcd_display_pad_with_spaces = 0

  'actually display value...
  For Lcd_display_position = 1 To Len(lcd_display_string)
      Lcd_disp_char = Mid(lcd_display_string , Lcd_display_position , 1)       'Lcd_display_position )       'Lcd_display_position

    'check for weird German characters!!! ha ha
    'can have problems displaying ascii numbers >127, this seems to work...
        If Lcd_disp_char = "ö" Then Lcd_param = &HEF
        If Lcd_disp_char = "ä" Then Lcd_param = &HE1
        If Lcd_disp_char = "ü" Then Lcd_param = &HF5
        If Lcd_disp_char = "°" Then Lcd_param = &HDF
        If Lcd_disp_char = "-" Then Lcd_param = Char_minus
        If Lcd_disp_char <> "ö" And Lcd_disp_char <> "ä" And Lcd_disp_char <> "ü" And Lcd_disp_char <> "°" And Lcd_disp_char <> "-" Then
        Lcd_param = Asc(lcd_disp_char)
   End If
   Gosub Lcd_writechar
   Next
Return

Line_feed:
If Mobile_aktiv = 1 Then Print #1 , " "
Return

Tastatur_input:
Next_check:
Debounce Pina.0 , 1 , Port1
Debounce Pina.1 , 1 , Port2
Debounce Pina.2 , 1 , Port3
Debounce Pina.3 , 1 , Port4
Debounce Pina.4 , 1 , Port5
Debounce Pina.5 , 1 , Port6
Debounce Pina.6 , 1 , Port7
Debounce Pina.7 , 1 , Port8
Debounce Pinc.0 , 1 , Lcd_rs
Debounce Pinc.1 , 1 , Lcd_rw
Debounce Pinc.2 , 1 , Port11
Debounce Pinc.3 , 1 , Port12
Goto Input_end
Port1:
Port1 = 1 : Goto Next_check
Port2:
Port2 = 1 : Goto Next_check
Port3:
Port3 = 1 : Goto Next_check
Port4:
Port4 = 1 : Goto Next_check
Port5:
Port5 = 1 : Goto Next_check
Port6:
Port6 = 1 : Goto Next_check
Port7:
Port7 = 1 : Goto Next_check
Port8:
Port8 = 1 : Goto Next_check
Lcd_rs:
Lcd_rs = 1 : Goto Next_check
Lcd_rw:
Lcd_rw = 1 : Goto Next_check
Port11:
Port11 = 1 : Goto Next_check
Port12:
Port12 = 1 : Goto Next_check
Input_end:
Portc.4 = 0                                                 'Tastatur inaktiv setzen
Config Porta = Output : Config Portc = Output
Return

Analog_werte:
Sensor_batt = Getadc(0)
U_ausg_sensor = Getadc(1)
'Humidity_1 = Getadc(2) 'see below
'Humidity_2 = Getadc(3)
'Humidity_3 = Getadc(4)
'Humidity_4 = Getadc(5)
'ext_Temperature = Getadc(6)

'Wahlschalter = Getadc(7) / 4

'I_load_1_ai_12 = Analog_12
'I_load_2_ai_13 = Analog_13

If Simu = 1 Then
'    Readeeprom Temp , 376                                   'Faktor from Parameters
    Temp2 = U_ausg_sensor - 70                              ': Temp2 = Temp2 * Temp
    U_batt_smooth = Temp2 : U_batt = Temp2
'    Ldr_sensor = Temp2 : Sensor_temp_kompensation = Temp2 : Analog_12 = Temp2 : Analog_13 = Temp2
    Return
End If

Temp = Sensor_batt
Gosub Calculate_u_batt : U_batt = Temp
Gosub Smoothen_u_batt

'Temp = Sensor_batt : Temp_b1 = 0 : Gosub Sensor_calc : U_batt_smooth = Temp + 5 : If U_batt_smooth < 0 Then U_batt_smooth = 0 : Readeeprom Temp_b5 , 771 : If Temp_b5 > -100 And Temp_b5 < 100 Then U_batt_smooth = U_ba'tt + Temp_b5

'Ausg_spannungswert:
'Y=10,88*(X-33)/285+1,37
'Value = U_ausg - 33 : Value = Value * 109 : Value = Value / 285 : Value = Value + 14 : U_ausg = Value
Readeeprom Temp_b2 , 772 : Readeeprom Temp_b3 , 792         'correction-values
Temp_b1 = 0 : Temp = U_ausg_sensor : Gosub Sensor_calc : U_ausg = Temp

'Scale Analog 3 Humidity_1
Readeeprom Temp_b1 , 753                                    'Analog_3_typ
Readeeprom Temp_b2 , 773 : Readeeprom Temp_b3 , 793         'correction-values
Temp = Humidity_1_sensor : Gosub Sensor_calc : Humidity_1 = Temp

'Scale Analog 4 Humidity_2
Readeeprom Temp_b1 , 754                                    'Analog_4_typ
Readeeprom Temp_b2 , 774 : Readeeprom Temp_b3 , 794         'correction-values
Temp = Humidity_2_sensor : Gosub Sensor_calc : Humidity_2 = Temp

'Scale Analog 5 Humidity_3
Readeeprom Temp_b1 , 755                                    'Analog_5_typ
Readeeprom Temp_b2 , 775 : Readeeprom Temp_b3 , 795         'correction-values
Temp = Humidity_3_sensor : Gosub Sensor_calc : Humidity_3 = Temp

'Scale Analog 6 Humidity_4
Readeeprom Temp_b1 , 756                                    'Analog_6_typ
Readeeprom Temp_b2 , 776 : Readeeprom Temp_b3 , 796         'correction-values
Temp = Humidity_4_sensor : Gosub Sensor_calc : Humidity_4 = Temp

'Scale Analog 7 Humidity_5
Readeeprom Temp_b1 , 757                                    'Analog_7_typ
Readeeprom Temp_b2 , 777 : Readeeprom Temp_b3 , 797         'correction-values
Temp = Humidity_5_sensor : Gosub Sensor_calc : Humidity_5 = Temp

'Scale Analog 9 Ldr_sensor
Readeeprom Temp_b1 , 759                                    'Analog_9_typ
Readeeprom Temp_b2 , 779 : Readeeprom Temp_b3 , 799         'correction-values
Temp = Analog_9 : Gosub Sensor_calc : Ldr_sensor = Temp

'Scale Analog 10 Sensor_temp_kompensation
Readeeprom Temp_b1 , 760                                    'Analog_10_typ Temp int
Readeeprom Temp_b2 , 780 : Readeeprom Temp_b3 , 800         'correction-values
Temp = Analog_10 : Gosub Sensor_calc : Sensor_temp_kompensation = Temp

'Scale Analog 11 Ext_temperature
Readeeprom Temp_b1 , 761                                    'Analog_11_typ Temp ext
Readeeprom Temp_b2 , 781 : Readeeprom Temp_b3 , 801         'correction-values
Temp = Analog_11 : Gosub Sensor_calc : Ext_temperature = Temp

'Scale Analog 15 Nicd
Readeeprom Temp_b1 , 765                                    'Analog_15_typ
Readeeprom Temp_b2 , 785 : Readeeprom Temp_b3 , 805         'correction-values
Temp = Analog_15 : Gosub Sensor_calc : U_nicd_ai_15 = Temp
Return

Sensor_calc:
'Type = 0 'voltage
Mess_ug = Mess_1_ug : Mess_og = Mess_1_og : Mess_anfang = Mess_1_anfang : Mess_ende = Mess_1_ende

If Temp_b1 = 1 Then                                         '10 K NTC
   Gosub Ntc_calc : Goto End_sensor_calc : End If

'If Temp_b1 = 2 Then                                         '4,7K
' Temp_s1 = Temp : Temp_s1 = Temp_s1 / 1.428 : Temp_s1 = Temp_s1 / 4 : Temp_b4 = Temp_s1 : Temp = Lookup(temp_b4 , Dta) : Temp4 = Abs(temp) : If Temp > 450 Then Temp = 0 : Goto End_sensor_calc : End If

'Type 3 linear
If Temp_b1 = 3 Then                                         'linear 1
Mess_ug = Mess_3_ug : Mess_og = Mess_3_og : Mess_anfang = Mess_3_anfang : Mess_ende = Mess_3_ende : End If

'Type 4 free
If Temp_b1 = 4 Then                                         'freier Typ
  Readeeprom Temp2 , 62 : Mess_ug = Temp2
  Readeeprom Temp2 , 64 : Mess_og = Temp2
  Readeeprom Temp2 , 66 : Mess_anfang = Temp2
  Readeeprom Temp2 , 68 : Mess_ende = Temp2 : End If

If Temp_b1 = 5 Then                                         'NimH
Mess_ug = Mess_15_ug : Mess_og = Mess_15_og : Mess_anfang = Mess_15_anfang : Mess_ende = Mess_15_ende : End If

'now calculation
'Y=((Yb-Ya)*(X-Xa)/(Xb-Xa)+Ya ; Y=27,93*(X-339)/729+1.27
'Ya Mess_ug = 13.7                                        'Ya Meßbereich Anfang /1. Stützpunkt
'Yb Mess_og = 293.0                                      'Yb Meßbereich Ende /2. Stützpunkt
'Xa Mess_anfang = 33.9                                   'Xa 205 für 4-20mA; 0 für 0-20mA 1. Stützpunkt
'Xb Mess_ende = 762.0                                    'Xb 2. Stützpunkt
Temp_s1 = Temp : Temp_s1 = Temp_s1 - Mess_anfang : Temp_s2 = Mess_og - Mess_ug : Temp_s1 = Temp_s1 * Temp_s2 : Temp_s2 = Mess_ende - Mess_anfang : Temp_s1 = Temp_s1 / Temp_s2 : Temp_s1 = Temp_s1 + Mess_ug : Temp = Temp_s1
End_sensor_calc:
'correction +/-
If Temp_b2 < 128 Then
 Temp = Temp + Temp_b2
Else
 Temp_b2 = Temp_b2 - 128 : Temp = Temp - Temp_b2            '+/-
End If
'Factor
Temp_s1 = Temp : Temp_s2 = Temp_b3                          '* Factor
Temp_s1 = Temp_s1 * Temp_s2 : Temp_s1 = Temp_s1 / 100.0 : Temp = Temp_s1       '*
Return

Calculate_u_batt:
Readeeprom Temp_b2 , 771 : Readeeprom Temp_b3 , 791         'correction-values
Temp_b1 = 0 : Gosub Sensor_calc : If Temp < 0 Then Temp = 0 'Temp_b1 = 0 = voltage
'If System_voltage_24v = 1 And System_voltage_48v = 1 Then Shift Temp , Left , 1       '*2 if 48V

'Correction Voltage-Drop
'Spannungabfall auf Leitung: R = länge / A * Leitf; (A = querschnitt); Leitf = 56,2;
'U = R * I = Länge * Strom (Solar - Last) / (Querschnitt * 56,2);
'U = Ugemessen + U Spgs-Abfall
Readeeprom Temp1 , 262                                      '202 = 71 U Batt Corr cable length
Readeeprom Temp2 , 264                                      '204 = 72 U Batt Corr cable Area
If I_solar < 50 Or Temp1 = 0 Or Temp2 = 0 Then Return       'start with 5 A compensation
Temp_s1 = Temp2                                             'Area 2,0 qm->20
Temp_s1 = Temp_s1 * 56.2                                    '* Leitfähigkeit with 2,0 qm * 56.2 = 1124
Temp3 = I_solar - I_load                                    '200
Temp3 = Temp1 * Temp3                                       'Länge * Strom (Solar - Last) 20m*200=4000 Am
Temp_s2 = Temp3 : Temp_s2 = Temp_s2 * 10.0                  'in mm 40000
Temp_s1 = Temp_s2 / Temp_s1 : Temp3 = Temp_s1               '40000 / 1124 = 35,7
Temp = Temp - Temp3                                         'Voltage-Correction : Batt: 13,8V; MP: 16,8V
Return

'channel Irrigate
Transfer_input_to_channels:
For Channel_nr = 1 To Number_of_channel_modules             '10 Channels
 Pointer_eeprom = Channel_nr * 10 : Pointer_eeprom = Pointer_eeprom + 491 : Readeeprom Temp_b1 , Pointer_eeprom       'Channel 1: Input 1
 Temp_b2 = 0 : Gosub Map_analog                             'Input 1
 Temp4 = Pointer_eeprom + 2 : Readeeprom Temp_b1 , Temp4    'Type
 If Value <> 0 Then Gosub Temp_korrection : Analog_input_channel(channel_nr) = Value       '503 = Sensor-Type
 Temp4 = Pointer_eeprom + 1 : Readeeprom Temp_b1 , Temp4    'Input 2
  If Temp_b1 < 50 Then Temp_b2 = 1 : Gosub Map_analog : If Value > 500 Then Analog_input_2_channel(channel_nr) = 1 Else Analog_input_2_channel(channel_nr) = 0       'Input 2
Next

'Alarm-channels
For Channel_nr = 1 To 5                                     '5 Alarms
 Pointer_eeprom = Channel_nr * 10 : Pointer_eeprom = Pointer_eeprom + 694       ' Alarm_Input(channel_nr)
 Readeeprom Temp_b1 , Pointer_eeprom : Temp_b2 = 0 : Gosub Map_analog
 Alarm_input(channel_nr) = Value                            'now write value to Array
Return

'################################# Digital Inputs ########################################
Eingaenge:
Input_1_old = Input_1 : Input_2_old = Input_2 : Input_3_old = Input_3 : : Input_4_old = Input_4 : Input_5_old = Input_5 : Input_6_old = Input_6 : Input_7_old = Input_7 : Input_8_old = Input_8
Porta = 0
Config Porta = Input
Config Pinc.3 = Output : Portc.3 = 1                        'Eingänge Port 12 aktiv setzen; Read Humidity
Waitms 50
Input_1 = Pina.0 : Input_2 = Pina.1 : Input_3 = Pina.2 : Input_4 = Pina.3 : Input_5 = Pina.4 : Input_6 = Pina.5 : Input_7 = Pina.6 : Input_8 = Pina.7
Portc.3 = 0                                                 'Eingänge Port 12 inaktiv setzen
Next

If Simu = 1 Then
 If U_ausg < 128 Then
   Input_1 = 0 : Input_2 = 0 : Input_3 = 0 : Input_4 = 0 : Input_5 = 0 : Input_6 = 0 : Input_7 = 0 : Input_8 = 0
  Else
  Input_1 = 1 : Input_2 = 1 : Input_3 = 1 : Input_4 = 1 : Input_5 = 1 : Input_6 = 1 : Input_7 = 1 : Input_8 = 1
  End If
End If
Return

Read_analog_all_min:
Porte.4 = 1                                                 'activate Analog-Sensors:
'If Simu = 0 Then Wait 1
Humidity_1_sensor = Getadc(2)                               'just Temporally stored in this
Humidity_2_sensor = Getadc(3)
Humidity_3_sensor = Getadc(4)
Humidity_4_sensor = Getadc(5)
Humidity_5_sensor = Getadc(6)
Porte.4 = 0                                                 'read Humid-Sensors End
Return

Map_analog:                                                 'Temp_b1 = Sensor-Nr; Temp_b2 = 1 then Output
If Temp_b1 > 50 And Temp_b1 < 100 Then Temp_b1 = Temp_b1 - 50       'if Input 2 = Analog!!
Value = 0 : If Temp_b1 > 100 And Temp_b1 < 109 Then Value = 1
If Temp_b1 = 1 Then Value = U_batt_smooth                   'Analog Sensors
If Temp_b1 = 2 Then Value = U_ausg
If Temp_b1 = 3 Then Value = Humidity_1                      'Getadc(2)
If Temp_b1 = 4 Then Value = Humidity_2                      'Getadc(3)
If Temp_b1 = 5 Then Value = Humidity_3                      'Getadc(4)
If Temp_b1 = 6 Then Value = Humidity_4                      'Getadc(5)
If Temp_b1 = 7 Then Value = Humidity_5                      'Getadc(6)
If Temp_b1 = 8 Then Value = Wahlschalter                    'for Simulation
If Temp_b1 = 9 Then Value = Ldr_sensor
If Temp_b1 = 10 Then Value = Sensor_temp_kompensation
If Temp_b1 = 11 Then Value = Ext_temperature
If Temp_b1 = 12 Then Value = I_load_ai_12
If Temp_b1 = 13 Then Value = I_load_ai_13
If Temp_b1 = 14 Then Value = I_solar
If Temp_b1 = 15 Then Value = U_nicd_ai_15

If Temp_b1 = 16 Then Value = Min_value_1                    '
If Temp_b1 = 17 Then Value = Max_value_1
If Temp_b1 = 18 Then Value = Running_time_1

If Temp_b1 = 21 Then Value = Counter_1
If Temp_b1 = 22 Then Value = Counter_2
'#################### Map Digital-Sensors ####################
If Temp_b1 = 101 And Input_1 = 1 Then Value = 999
If Temp_b1 = 102 And Input_2 = 1 Then Value = 999
If Temp_b1 = 103 And Input_3 = 1 Then Value = 999
If Temp_b1 = 104 And Input_4 = 1 Then Value = 999
If Temp_b1 = 105 And Input_5 = 1 Then Value = 999
If Temp_b1 = 106 And Input_6 = 1 Then Value = 999
If Temp_b1 = 107 And Input_7 = 1 Then Value = 999
If Temp_b1 = 108 And Input_8 = 1 Then Value = 999
'######################### Radio Sensors #########################
If Temp_b1 = 201 Then Value = Wind_speed                    'Radio Sensors
If Temp_b1 = 202 Then Value = Elv_temp
If Temp_b1 = 203 Then Value = Elv_humidity
If Temp_b1 = 204 Then Value = Elv_rain
'######################### Radio Sensors Humidity #########################
If Temp_b1 = 212 Then Value = Elv_temp_2                    'Radio Sensors
If Temp_b1 = 213 Then Value = Elv_humidity_2                'Radio Sensors
'If Temp_b1 = 212 Then Value = Humidity_by_radio_2
'If Temp_b1 = 213 Then Value = Humidity_by_radio_3
'If Temp_b1 = 214 Then Value = Humidity_by_radio_4
'If Temp_b1 = 215 Then Value = Humidity_by_radio_5
'If Temp_b1 = 216 Then Value = Humidity_by_radio_6

'################### Sensor Fault ############################################
Readeeprom Temp5 , 310                                      'Alarm if no analog Signal
If Value = 0 Or Value > 32767 Then
If Temp5 = 1 And Temp_b1 > 0 And Temp_b1 < 15 And Temp_b2 = 0 And Flag_alarm_if_no_analog = 0 And Delay_on > 10 Then       'Alarm if no analog Signal
  Flag_alarm_if_no_analog = 1 : Meldung_aktiv = 1 : Alarm_no_analog_nr = Temp_b1 : Goto Anrufen : End If
End If
'######################### for Input 2 only #########################
If Temp_b2 = 0 Then Return                                  'with Input 2
Value = 0
If Temp_b1 = 1 And Output_1 = 1 Then Value = 999            'Interlock with Output
If Temp_b1 = 2 And Relais_2 = 1 Then Value = 999
If Temp_b1 = 3 And Relais_3 = 1 Then Value = 999
If Temp_b1 = 4 And Relais_4 = 1 Then Value = 999
If Temp_b1 = 5 And Relais_5 = 1 Then Value = 999
If Temp_b1 = 6 And Relais_6 = 1 Then Value = 999
If Temp_b1 = 7 And Relais_7 = 1 Then Value = 999
'If Temp_b1 = 8 And Beeper = 1 Then Value = 999
If Temp_b1 = 9 And Output_9 = 1 Then Value = 999
If Temp_b1 = 10 And Output_10 = 1 Then Value = 999
If Temp_b1 = 11 And Output_11 = 1 Then Value = 999
If Temp_b1 = 12 And Output_12 = 1 Then Value = 999
If Temp_b1 = 13 And Output_13 = 1 Then Value = 999
If Temp_b1 = 14 And Output_14 = 1 Then Value = 999
'If Temp_b1 = 15 And Nimh_load_rel = 1 Then Value = 999
'virtuell Outputs
If Temp_b1 = 17 And Output_17 = 1 Then Value = 999
If Temp_b1 = 18 And Output_18 = 1 Then Value = 999
If Temp_b1 = 19 And Output_19 = 1 Then Value = 999
If Temp_b1 = 20 And Output_20 = 1 Then Value = 999
Return

Write_input:
If Temp_b1 > 50 And Temp_b1 < 100 Then Temp_b1 = Temp_b1 - 50       'if Input 2 = Analog!!
Lcd_display_string = "_"
If Temp_b1 = 1 Then Lcd_display_string = "/59+60 Batt"      'Analog
If Temp_b1 = 2 Then Lcd_display_string = "/45+46"
If Temp_b1 = 3 Then Lcd_display_string = "/59+61"
If Temp_b1 = 4 Then Lcd_display_string = "/62+63"
If Temp_b1 = 5 Then Lcd_display_string = "/62+64"
If Temp_b1 = 6 Then Lcd_display_string = "/71+72"
If Temp_b1 = 7 Then Lcd_display_string = "/71+73"
If Temp_b1 = 8 Then Lcd_display_string = "/Prog-Sw"
If Temp_b1 = 9 Then Lcd_display_string = "/74+75"
If Temp_b1 = 10 Then Lcd_display_string = "/74+76"
If Temp_b1 = 11 Then Lcd_display_string = "/77+78"
If Temp_b1 = 12 Then Lcd_display_string = "/77+79"
If Temp_b1 = 13 Then Lcd_display_string = "/80+81"
If Temp_b1 = 11 Then Lcd_display_string = "/77+78 Load ext"
If Temp_b1 = 12 Then Lcd_display_string = "/77+79 Load 2"
If Temp_b1 = 13 Then Lcd_display_string = "/80+81 Load 1"
If Temp_b1 = 14 Then Lcd_display_string = "/80+82 Solar"
If Temp_b1 = 18 Then Lcd_display_string = "/Run-Time"
Gosub Write_zaehler

If Temp_b1 = 101 Then Lcd_display_string = "/47+48"         'Digital
If Temp_b1 = 102 Then Lcd_display_string = "/47+49"
If Temp_b1 = 103 Then Lcd_display_string = "/50+51"
If Temp_b1 = 104 Then Lcd_display_string = "/50+52"
If Temp_b1 = 105 Then Lcd_display_string = "/53+54"
If Temp_b1 = 106 Then Lcd_display_string = "/53+55"
If Temp_b1 = 107 Then Lcd_display_string = "/56+57"
If Temp_b1 = 108 Then Lcd_display_string = "/56+58"

If Temp_b1 = 201 Then Lcd_display_string = "(Wind Speed)"   'Radio-Sensors
If Temp_b1 = 202 Or Temp_b1 = 212 Then Lcd_display_string = "(Temp)"
If Temp_b1 = 203 Or Temp_b1 = 213 Then Lcd_display_string = "(Humid"
If Temp_b1 = 204 Then Lcd_display_string = "(Rain)"

Lcd_display_pad_with_spaces = 1 : Gosub Lcd_display
Return

Write_output:
Lcd_display_string = "_"
If Temp_b1 = 1 Then Lcd_display_string = "/35+36 Load1"
If Temp_b1 = 2 Then Lcd_display_string = "/30+31 R2"
If Temp_b1 = 3 Then Lcd_display_string = "/22+24 R3"
If Temp_b1 = 4 Then Lcd_display_string = "/22+23 R4"
If Temp_b1 = 5 Then Lcd_display_string = "/8+12 R5"
If Temp_b1 = 6 Then Lcd_display_string = "/7+12 R6"
If Temp_b1 = 7 Then Lcd_display_string = "/2+3 R7"
If Temp_b1 = 8 Then Lcd_display_string = "/Beep"
If Temp_b1 = 9 Then Lcd_display_string = "/Load2"
If Temp_b1 = 10 Then Lcd_display_string = "/Load3"
If Temp_b1 = 11 Then Lcd_display_string = "/Load4"
If Temp_b1 = 12 Then Lcd_display_string = "/Load5"
If Temp_b1 = 13 Then Lcd_display_string = "/Load6"
If Temp_b1 = 14 Then Lcd_display_string = "/Load7"
If Temp_b1 = 15 Then Lcd_display_string = "/NimH"
If Temp_b1 = 16 Then Lcd_display_string = "/Teleph"
If Temp_b1 > 16 And Temp_b1 < 21 Then Lcd_display_string = "(virt.Out"       ': value = Temp_b1 - 16 : kein_komma = 1 : gosub write_value : End if
Gosub Write_zaehler
If Temp_b1 = 30 Then Lcd_display_string = "(Text)"
Lcd_display_pad_with_spaces = 1 : Gosub Lcd_display
Return

Write_zaehler:
If Temp_b1 = 21 Then Lcd_display_string = "Count 1"
If Temp_b1 = 22 Then Lcd_display_string = "Count 2"
Return

Temp_korrection:
If Temp_b1 > 0 Or Analog_10 < 23 Or Analog_10 > 168 Then Return       'Humidity-Sensor? Sollte der Wert negativ werden, so ergibt sich eine umgekehrte Addtion
Temp_b2 = Analog_10 / 4 : Temp_b3 = Temp_b2 - 113 : Temp_b3 = Temp_b3 / 4       'ext_Temperature = Temperatur-Wert; 113 = 20 Grad, 4(6) = Korrektur-WErt
Value = Value - Temp_b3
Return

Average_current_solar:
If I_solar < 0 Then Return
If Average_pointer_solar < 1 Or Average_pointer_solar > 5 Then Average_pointer_solar = 1       'number of values
Array_average_solar(average_pointer_solar) = I_solar        'write to Array
Incr Average_pointer_solar

Temp_b1 = 1 : Temp = 0                                      'read
Loop_average_solar:
'if array_average_solar(temp_b1) = 0 then goto finish_get_array_solar
Temp = Temp + Array_average_solar(temp_b1)                  'read it
Incr Temp_b1
If Temp_b1 > 5 Then Goto Finish_get_array_solar
Goto Loop_average_solar

Finish_get_array_solar:
Decr Temp_b1 : I_solar = Temp / Temp_b1
Return

Average_current_load:
If Average_pointer_load < 1 Or Average_pointer_load > 5 Then Average_pointer_load = 1       'number of values
Array_average_load(average_pointer_load) = I_load           'write to Array
Incr Average_pointer_load

Temp_b1 = 1 : Temp = 0                                      'read
Loop_average:
'if Array_average_Load_1(temp_b1) = 0 then goto finish_get_array
Temp = Temp + Array_average_load(temp_b1)                   'read it
Incr Temp_b1
If Temp_b1 > 5 Then Goto Finish_get_array
Goto Loop_average

Finish_get_array:
Decr Temp_b1 : I_load = Temp / Temp_b1
Return

'Ausgänge rausgeben
Output:
If Fkt9 = 1 Then Goto Direkt

'################## Irrigation days without water ##############
If Programm_selector = 0 Then Gosub Kein_giessen            'am Anfang kein Pulse
If Day = 11 And Days_without_water > 0 Then Gosub Kein_giessen
If Day = 12 And Days_without_water > 1 Then Gosub Kein_giessen
If Day = 13 And Days_without_water > 2 Then Gosub Kein_giessen
If Day = 14 And Days_without_water > 3 Then Gosub Kein_giessen
If Day = 15 And Days_without_water > 4 Then Gosub Kein_giessen
If Day = 16 And Days_without_water > 5 Then Gosub Kein_giessen
If Day = 17 And Days_without_water > 6 Then Gosub Kein_giessen
If Day = 18 And Days_without_water > 7 Then Gosub Kein_giessen
'If Day = 19 And Days_without_water > 8 Then Gosub Kein_giessen

If Days_without_water = 0 Then Temp_b1 = 5 Else Temp_b1 = Days_without_water       'if no selected days = 5
If Day_learning_mode < Temp_b1 Then                         '5 days no irrigate
For Channel_nr = 1 To Number_of_channel_modules
 If Learning_mode(channel_nr) = 2 Then Output(channel_nr) = 0       'no irrigate ... for learning
 Next
End If

'end Learning-Mode
 Readeeprom Temp , 312                                      '312 = 26 Learning mode
Temp2 = 0 : If Day_learning_mode = Temp_b1 And Hour = 3 And Temp > 0 Then Writeeeprom Temp2 , 312

For Temp_b5 = 1 To Number_of_channel_modules
Temp = Temp_b5 * 10 : Temp = Temp + 491 : Readeeprom Temp_b1 , Temp       'Input 1 at Adr. 501
Incr Temp : Readeeprom Temp_b2 , Temp                       'Input 2 at Adr. 502
Incr Temp : Readeeprom Temp_b3 , Temp                       'Type at Adr. 503

'################ no Irrigation with Temp ################################
 If Temp_b3 = 0 And No_irrigation = 1 Then Output(i) = 0    'Temp_b3 = 0 = Channel Type Irrigation

'################ do Irrigation with Temp min / max ################################
 If Temp_b3 = 0 And Do_irrigation = 1 And Act_do_irrigation_time > 0 Then Output(i) = 1       'Temp_b3 = 0 = Channel Type Irrigation

'############# Interlock Start with Output Channel 1-6 (Dosing-Function) ###############
'Input 1 < 100 + Input 2  < 100: Analog with Enable by Channel 1-6
If Temp_b1 < 100 And Temp_b2 < 100 Then
 Gosub Check_output_active
If Temp_b3 = 1 Then                                         'Temp_b3 = Interlock
   Output(i) = 0 : End If
End If
'################ Interlock Start with Digital Input (Empty-Level) ################################
'Input 1 < 100 + Input 2  > 100: Analog with Enable by Digital Input 1-8 (101-108)
If Temp_b1 < 100 And Temp_b2 > 100 Then
 Gosub Check_input_active
If Temp_b3 = 1 Then                                         'Temp_b3 = Interlock
   Output(i) = 0 : End If
End If

Next

Gosub Relais_transfer
Gosub Pulsed_output
Gosub Antiblocking
Gosub Alarm_no_analog

Direkt:
If Programm_selector = 0 Then Gosub Reset_outputs           'off

Gosub Switch_sms
Gosub Check_min_max_runtime

Config Porta = Output
Porta.0 = Output_1
Porta.1 = Relais_2
Porta.2 = Relais_3
Porta.3 = Relais_4                                          'Relais 2 Port4
Porta.4 = Relais_5                                          'Relais 3 Port5
Porta.5 = Relais_6                                          'Relais 4 Port 6
Porta.6 = Relais_7                                          'Relais 5 Port 7
Porta.7 = Beeper
Config Pinc.6 = Output
Portc.6 = 1 : Waitms 20 : Portc.6 = 0                       'Übergabe an HC573
Porta = 0
'If Fkt9 = 1 Then Return

' If Pwm_port = 1 Then Portb.7 = 0 Else Portb.7 = 1
Portg.1 = Output_9                                          'Load 2; N-Channel MOSFET
Portg.3 = Output_10                                         'Load 3; N-Channel MOSFET
Portg.4 = Output_11                                         'Load 4; N-Channel MOSFET
Porte.7 = Output_12                                         'Load 5; N-Channel MOSFET
Portg.2 = Output_13                                         'Load 6; N-Channel MOSFET
Portd.7 = Output_14                                         'Load 7; N-Channel MOSFET
Portb.0 = Nimh_load_rel                                     'Load 7; N-Channel MOSFET

'PWM-Port
If Fkt9 = 0 Then                                            'manual
 If Solar_loading = 1 Then Pwm_port = 1 Else Pwm_port = 0   'PWM-Port and charge_to_14_4V  = 1 and
 If Delay_on < 60 Then Pwm_port = 1                         '29.8.07
End If

 If Pwm_port = 1 Then
 If Batt_pwm_charge = 1 And Pwm_charging = 1 And Fkt9 = 0 And Delay_on > 60 Then       '29.8.07
'  Temp_b1 = 250 - Pwm_value : Ocr2 = Temp_b1 : Tccr2 = &B01100101 : Enable Timer2       '***M128 250 = 0A; 0 = 5A; 128 = 2,7A; 196=1,7A
  Temp_b1 = 250 - Pwm_value : Ocr1ch = 0 : Ocr1cl = Temp_b1 : Tccr1a = &B00001001 : Tccr1b = &B00000101 : Enable Timer1       '***M25 250 = 0A; 0 = 5A; 128 = 2,7A; 196=1,7A
 Else
  Gosub Disable_pwm
 End If
End If

If Pwm_port = 0 Or Fkt9 = 1 Or Delay_on <= 60 Then Gosub Disable_pwm       '29.8.07

If Pwm_port = 1 Then Portb.7 = 0 Else Portb.7 = 1
Return

Disable_pwm:
'Ocr2 = 255 : Tccr2 = &B00000000 : Disable Timer2            '***M128
Ocr1cl = 255 : Tccr1a = &B00000000 : Tccr1b = &B00000000 : Disable Timer1       '***M256
Return

Relais_transfer:
Temp_b1 = Load_1 : Readeeprom Value , 354 : Temp_b2 = Value : Gosub Output_q
Temp_b1 = Load_2 : Readeeprom Value , 356 : Temp_b2 = Value : Gosub Output_q
Temp_b1 = Load_3 : Readeeprom Value , 358 : Temp_b2 = Value : Gosub Output_q
Temp_b1 = Load_4 : Readeeprom Value , 360 : Temp_b2 = Value : Gosub Output_q
Temp_b1 = Load_5 : Readeeprom Value , 362 : Temp_b2 = Value : Gosub Output_q

For Channel_nr = 1 To Number_of_channel_modules
 Temp_b1 = Channel_nr * 10 : Temp3 = Temp_b1 + 494
 Temp_b1 = Output(channel_nr)
 Readeeprom Temp_b2 , Temp3 : Gosub Output_q

'Output 2
 Temp4 = Channel_nr + 480
 Readeeprom Temp_b2 , Temp4 : Gosub Output_q
Next

'Alarm-channels
For Channel_nr = 1 To 5                                     '5 Alarms
 Pointer_eeprom = Channel_nr * 10 : Pointer_eeprom = Pointer_eeprom + 695       ' Alarm_Output(channel_nr)
 Temp_b1 = Alarm_active(channel_nr)                         'Output active?
 Readeeprom Temp_b2 , Pointer_eeprom : Gosub Output_q       'Output
Next

'Temp_b1 = Delay_add_device_on : Readeeprom Value , 302 : temp_b2 = value : Gosub Output_q
Return

Output_q:
Dim Flag_channel_nr_alarm As Bit
If Temp_b2 = 16 And Temp_b1 = 0 Then Flag_call_telephone_by_output = 0
If Temp_b2 = 30 And Temp_b1 = 0 Then Flag_channel_nr_alarm = 0

If Temp_b1 = 0 Then Temp_b2 = Temp_b2 - 100                 'Output not active but Invers

If Interlock(channel_nr) = 1 Then
  If Temp_b2 = 1 Then Output_1 = 0                          'normal Output
  If Temp_b2 = 2 Then Relais_2 = 0
  If Temp_b2 = 3 Then Relais_3 = 0
  If Temp_b2 = 4 Then Relais_4 = 0
  If Temp_b2 = 5 Then Relais_5 = 0
  If Temp_b2 = 6 Then Relais_6 = 0
  If Temp_b2 = 7 Then Relais_7 = 0
  If Temp_b2 = 9 Then Output_9 = 0
  If Temp_b2 = 10 Then Output_10 = 0
  If Temp_b2 = 11 Then Output_11 = 0
  If Temp_b2 = 12 Then Output_12 = 0
  If Temp_b2 = 13 Then Output_13 = 0
  If Temp_b2 = 14 Then Output_14 = 0
  If Temp_b2 = 15 Then Nimh_load_rel = 0
  If Temp_b2 = 17 Then Output_17 = 0
  If Temp_b2 = 18 Then Output_18 = 0
  If Temp_b2 = 19 Then Output_19 = 0
  If Temp_b2 = 20 Then Output_20 = 0 : Return : End If

  If Temp_b2 = 1 Then Output_1 = 1
If Temp_b2 = 2 Then Relais_2 = 1
If Temp_b2 = 3 Then Relais_3 = 1
If Temp_b2 = 4 Then Relais_4 = 1
If Temp_b2 = 5 Then Relais_5 = 1
If Temp_b2 = 6 Then Relais_6 = 1
If Temp_b2 = 7 Then Relais_7 = 1
If Temp_b2 = 8 Then Beeper = 1
If Temp_b2 = 9 Then Output_9 = 1
If Temp_b2 = 10 Then Output_10 = 1
If Temp_b2 = 11 Then Output_11 = 1
If Temp_b2 = 12 Then Output_12 = 1
If Temp_b2 = 13 Then Output_13 = 1
If Temp_b2 = 14 Then Output_14 = 1
If Temp_b2 = 15 Then Nimh_load_rel = 1

If Temp_b2 = 16 And Flag_call_telephone_by_output = 0 Then
 Flag_call_telephone_by_output = 1 : Alarm_from_input = 1 : Goto Anrufen : End If

If Temp_b2 = 17 Then Output_17 = 1                          'virtuell Outputs
If Temp_b2 = 18 Then Output_18 = 1
If Temp_b2 = 19 Then Output_19 = 1
If Temp_b2 = 20 Then Output_20 = 1

If Temp_b1 = 21 Then Counter_1 = 0
If Temp_b1 = 22 Then Counter_2 = 0

'Alarm?
 If Temp_b2 = 30 And Flag_channel_nr_alarm = 0 Then
  Flag_channel_nr_alarm = 1 : Channel_nr_alarm = Channel_nr : End If

If Temp_b2 = 202 Or Temp_b2 = 212 Then
 Relais_2 = 1 : Relais_3 = 1 : If Temp_b2 = 212 Then Relais_4 = 1 : End If
If Temp_b2 = 203 Or Temp_b2 = 213 Then
 Relais_3 = 1 : Relais_4 = 1 : If Temp_b2 = 213 Then Relais_5 = 1 : End If
If Temp_b2 = 204 Or Temp_b2 = 214 Then
 Relais_4 = 1 : Relais_5 = 1 : If Temp_b2 = 214 Then Relais_6 = 1 : End If
If Temp_b2 = 205 Or Temp_b2 = 215 Then
 Relais_5 = 1 : Relais_6 = 1 : If Temp_b2 = 215 Then Relais_7 = 1 : End If
Return

Pulsed_output:
Dim Pulsed_output(15) As Byte
Dim Pulsed_output_off(15) As Byte

Temp2 = 378                                                 ''378 = 59 Pulsed Output on-Pulse
Loop_pulse:
 Readeeprom Temp , Temp2 : Temp_b2 = Temp : Gosub Sub_pulsed_output       'Pulsed Output on-Pulse
  Temp2 = Temp2 + 2
If Temp2 < 392 Then Goto Loop_pulse
Return

Sub_pulsed_output:
Gosub Check_status_output

'on-Pulse
    If Temp_bit1 = 0 And Pulsed_output(temp_b2) > 8 Then Pulsed_output(temp_b2) = 0
  If Temp_bit1 = 1 And Pulsed_output(temp_b2) = 0 Then Pulsed_output(temp_b2) = 1
  If Pulsed_output(temp_b2) > 0 And Pulsed_output(temp_b2) < 10 Then Incr Pulsed_output(temp_b2)
   If Pulsed_output(temp_b2) > 8 Then Temp_bit2 = 0 Else Temp_bit2 = 1       'x sec then Output off

'off-Pulse
Temp2 = Temp2 + 2
Readeeprom Temp , Temp2 : Temp_b2 = Temp                    'Pulsed Output off-Pulse
Gosub Check_status_output
    If Temp_bit1 = 1 And Pulsed_output_off(temp_b2) > 8 Then Pulsed_output_off(temp_b2) = 0
  If Temp_bit1 = 0 And Pulsed_output_off(temp_b2) = 0 Then Pulsed_output_off(temp_b2) = 1
  If Pulsed_output_off(temp_b2) > 0 And Pulsed_output_off(temp_b2) < 10 Then Incr Pulsed_output_off(temp_b2)
  If Pulsed_output_off(temp_b2) > 0 And Pulsed_output_off(temp_b2) < 8 Then Temp_bit3 = 1 Else Temp_bit3 = 0       'x sec Output on

Gosub Switch_on_output

Return

Switch_on_output:
If Temp_b2 = 1 Then
 If Temp_bit3 = 1 Then Output_1 = 1
 If Temp_bit2 = 0 Then Output_1 = 0 : End If

If Temp_b2 = 2 Then
 If Temp_bit3 = 1 Then Relais_2 = 1
 If Temp_bit2 = 0 Then Relais_2 = 0 : End If

If Temp_b2 = 3 Then
 If Temp_bit3 = 1 Then Relais_3 = 1
 If Temp_bit2 = 0 Then Relais_3 = 0 : End If

If Temp_b2 = 4 Then
 If Temp_bit3 = 1 Then Relais_4 = 1
 If Temp_bit2 = 0 Then Relais_4 = 0 : End If

If Temp_b2 = 5 Then
 If Temp_bit3 = 1 Then Relais_5 = 1
 If Temp_bit2 = 0 Then Relais_5 = 0 : End If

If Temp_b2 = 6 Then
 If Temp_bit3 = 1 Then Relais_6 = 1
 If Temp_bit2 = 0 Then Relais_6 = 0 : End If

If Temp_b2 = 7 Then
 If Temp_bit3 = 1 Then Relais_7 = 1
 If Temp_bit2 = 0 Then Relais_7 = 0 : End If

If Temp_b2 = 9 Then
 If Temp_bit3 = 1 Then Output_9 = 1
 If Temp_bit2 = 0 Then Output_9 = 0 : End If

If Temp_b2 = 10 Then
 If Temp_bit3 = 1 Then Output_10 = 1
 If Temp_bit2 = 0 Then Output_10 = 0 : End If

If Temp_b2 = 11 Then
 If Temp_bit3 = 1 Then Output_11 = 1
 If Temp_bit2 = 0 Then Output_11 = 0 : End If

If Temp_b2 = 12 Then
 If Temp_bit3 = 1 Then Output_12 = 1
 If Temp_bit2 = 0 Then Output_12 = 0 : End If

If Temp_b2 = 13 Then
 If Temp_bit3 = 1 Then Output_13 = 1
 If Temp_bit2 = 0 Then Output_13 = 0 : End If

If Temp_b2 = 14 Then
 If Temp_bit3 = 1 Then Output_14 = 1
 If Temp_bit2 = 0 Then Output_14 = 0 : End If
Return

Check_status_output:
If Temp < 1 Or Temp > 16 Then Return                        'Limits
If Temp_b2 = 1 Then Temp_bit1 = Output_1
If Temp_b2 = 2 Then Temp_bit1 = Relais_2
If Temp_b2 = 3 Then Temp_bit1 = Relais_3
If Temp_b2 = 4 Then Temp_bit1 = Relais_4
If Temp_b2 = 5 Then Temp_bit1 = Relais_5
If Temp_b2 = 6 Then Temp_bit1 = Relais_6
If Temp_b2 = 7 Then Temp_bit1 = Relais_7

If Temp_b2 = 9 Then Temp_bit1 = Output_9
If Temp_b2 = 10 Then Temp_bit1 = Output_10
If Temp_b2 = 11 Then Temp_bit1 = Output_11
If Temp_b2 = 12 Then Temp_bit1 = Output_12
If Temp_b2 = 13 Then Temp_bit1 = Output_13
If Temp_b2 = 14 Then Temp_bit1 = Output_14
Return

Kein_giessen:
If Fkt9 = 1 Then Return
For Channel_nr = 1 To Number_of_channel_modules
If Channel_type(channel_nr) = 0 Then Output(channel_nr) = 0 : Next       'Mode 0 = Irrigation
Return

Check_output_active:
Temp_b3 = 0
For Temp_b4 = 1 To Number_of_channel_modules
If Temp_b2 = Temp_b4 And Output(temp_b4) = 0 Then Temp_b3 = 1       'Output not active
Next
Return

Check_input_active:
Temp_b3 = 0
If Temp_b2 = 101 And Input_1 = 0 Then Temp_b3 = 1           'Input active
If Temp_b2 = 102 And Input_2 = 0 Then Temp_b3 = 1
If Temp_b2 = 103 And Input_3 = 0 Then Temp_b3 = 1
If Temp_b2 = 104 And Input_4 = 0 Then Temp_b3 = 1
If Temp_b2 = 105 And Input_5 = 0 Then Temp_b3 = 1
If Temp_b2 = 106 And Input_6 = 0 Then Temp_b3 = 1
If Temp_b2 = 107 And Input_7 = 0 Then Temp_b3 = 1
If Temp_b2 = 108 And Input_8 = 0 Then Temp_b3 = 1
Return

Reset_outputs:
If Fkt9 = 1 Then Return                                     'Manual mode
Output_1 = 0
Relais_2 = 0
Relais_3 = 0
Relais_4 = 0
Relais_5 = 0
Relais_6 = 0
Relais_7 = 0
Beeper = 0

Output_9 = 0
Output_10 = 0
Output_11 = 0
Output_12 = 0
Output_13 = 0
Output_14 = 0
Nimh_load_rel = 0

Output_17 = 0
Output_18 = 0
Output_19 = 0
Output_20 = 0
Return

Smoothen_u_batt:
If Fkt8 = 1 And Data_pointer = 91 Then Return               'if input simu value
If Pointer_u_batt < 1 Or Pointer_u_batt > 5 Then Pointer_u_batt = 1       'number of values
Array_smooth_u_batt(pointer_u_batt) = U_batt                'write to Array
Incr Pointer_u_batt

Temp_b1 = 1 : Temp = 0                                      'read
Loop_smooth_u_batt:
'if Array_average_Load_1(temp_b1) = 0 then goto finish_get_array
Temp = Temp + Array_smooth_u_batt(temp_b1)                  'read it
Incr Temp_b1
If Temp_b1 > 5 Then Goto Finish_array_u_batt
Goto Loop_smooth_u_batt

Finish_array_u_batt:
Decr Temp_b1 : U_batt_smooth = Temp / Temp_b1
Return

Collect_io_info:
Output_digital_1 = 0
If Output_1 = 1 Then Output_digital_1.0 = 1
If Relais_2 = 1 Then Output_digital_1.1 = 1
If Relais_3 = 1 Then Output_digital_1.2 = 1
If Relais_4 = 1 Then Output_digital_1.3 = 1
If Relais_5 = 1 Then Output_digital_1.4 = 1
If Relais_6 = 1 Then Output_digital_1.5 = 1
If Relais_7 = 1 Then Output_digital_1.6 = 1
If Beeper = 1 Then Output_digital_1.7 = 1

Output_digital_2 = 0
If Output_9 = 1 Then Output_digital_2.0 = 1
If Output_10 = 1 Then Output_digital_2.1 = 1
If Output_11 = 1 Then Output_digital_2.2 = 1
If Output_12 = 1 Then Output_digital_2.3 = 1
If Output_13 = 1 Then Output_digital_2.4 = 1
If Output_14 = 1 Then Output_digital_2.5 = 1
If Nimh_load_rel = 1 Then Output_digital_2.6 = 1
If Pwm_port = 1 Then Output_digital_2.7 = 1

Inputs = 0
If Input_1 = 1 Then Inputs.0 = 1
If Input_2 = 1 Then Inputs.1 = 1
If Input_3 = 1 Then Inputs.2 = 1
If Input_4 = 1 Then Inputs.3 = 1
If Input_5 = 1 Then Inputs.4 = 1
If Input_6 = 1 Then Inputs.5 = 1
If Input_7 = 1 Then Inputs.6 = 1
If Input_8 = 1 Then Inputs.7 = 1
Return

Show_time:
   Value = Hour : Kein_komma = 1 : Gosub Write_value        'Anzeige Uhrzeit hour
      Lcd_display_string = ":" : Gosub Show_blank : Gosub Lcd_display
    Value = Minute : Kein_komma = 1 : Gosub Write_value     'minute
     Gosub Delete_rest_of_display
Return

Print_header_data:
If English = 0 Then Print #1 , "Kanal" Else Print #1 , "Channel"
Waitms 70
Print #1 , " 1    2    3    4    5    6";
If Number_of_scans > 6 Then Print #1 , " Batt  Solar Wind Temp Humidity Rain Count";
Print #1 , " "
Waitms 100

'now Unit
For Channel_nr = 1 To 6
 Temp_b1 = Channel_type(channel_nr) : Gosub Print_unit : Next
If Number_of_scans > 6 Then Print #1 , "V     A   km/h  °C     % ";
Print #1 , " "
Waitms 40
Return

Print_unit:
Temp_b2 = Temp_b1 Mod 10
If Temp_b2 = 0 Or Temp_b1 = 2 Then Print #1 , " %   " ;
If Temp_b2 = 1 Then Print #1 , " °C   ";
If Temp_b2 = 3 Then Print #1 , "  V   ";
Return

'*** INITIALIZATION OF MMC ***
Sub Minit
Set Cs
Dat = &HFF
For Temp_b3 = 1 To 10
  Shiftout Mosi , Clk , Dat , Msbl
Next I
Resp = 255
Reset Cs

Cmd0:
Dat = &H40
Shiftout Mosi , Clk , Dat , Msbl
Addr = &H00000000
Shiftout Mosi , Clk , Addr , Msbl
Dat = &H95
Shiftout Mosi , Clk , Dat , Msbl

Chkresp &H01

Set Cs
Waitms 50
Reset Cs
Dat = &HFF
'If it does not initialize correctly it will hang in the following loop
Cmd1:
While Resp <> &H00
Set Cs
Shiftout Mosi , Clk , Dat , Msbl
Shiftin Miso , Clk , Resp , Msbl
Reset Cs
Dat = &H41
Shiftout Mosi , Clk , Dat , Msbl
Addr = 0
Shiftout Mosi , Clk , Addr , Msbl
Dat = &HFF
Shiftout Mosi , Clk , Dat , Msbl
Shiftout Mosi , Clk , Dat , Msbl
Shiftin Miso , Clk , Resp , Msbl
Wend

Dat = &HFF
Set Cs
Print #1 , "MMC initialized"
End Sub

'** WRITE Routine assumes ADDR, BOUT uses Status subroutine **
Sub Mwrite
Set Cs
Dat = &HFF
Shiftout Mosi , Clk , Dat , Msbl
Shiftin Miso , Clk , Resp , Msbl
Reset Cs
Dat = &H58
Shiftout Mosi , Clk , Dat , Msbl
Shiftout Mosi , Clk , Adr1 , Msbl
Dat = &HFF
Shiftout Mosi , Clk , Dat , Msbl
Shiftout Mosi , Clk , Dat , Msbl
Shiftin Miso , Clk , Resp , Msbl

Waitms 100 : Chkresp &H00
'Send data token
Dat = &HFE
Shiftout Mosi , Clk , Dat , Msbl
'Print #1, "Write_loop";
Waitms 20                                                   '
For I = 1 To 512
   If Write_header = 1 Then Dat = Indat(i) Else Dat = A(i)  'Array for Input-Data / Analog-Data
's= Str(Dat) : Print #1, S
'   If write_header = 0 Then Dat = A(I) 'Analog-Values
   Shiftout Mosi , Clk , Dat , Msbl
'waitms 10 '
Next I

Waitms 400                                                  ' Wait till Flash is written 1.part

Shiftout Mosi , Clk , Dat , Msbl
Shiftin Miso , Clk , Resp , Msbl

'If Y = &H05 write is a success
Y = Resp And &H0F

'If Resp = 0 the MMC is busy
Shiftin Miso , Clk , Resp , Msbl
Waitms 40 : Chkresp &H00                                    '
'Lowerline
Set Cs
Mstatus
End Sub

'**** READ routine assumes ADDR uses Status subroutine *****
Sub Mread
Set Cs
Dat = &HFF
Shiftout Mosi , Clk , Dat , Msbl
Shiftin Miso , Clk , Resp , Msbl
Reset Cs
Dat = &H51
Shiftout Mosi , Clk , Dat , Msbl
Shiftout Mosi , Clk , Adr1 , Msbl
Dat = &HFF
Shiftout Mosi , Clk , Dat , Msbl
Shiftin Miso , Clk , Resp , Msbl

Waitms 100 : Chkresp &H00

Waitms 100 : Chkresp &HFE
If Read_header = 1 Then
If Mmc_print = 1 Then Print #1 , "EEPROM-Data:"
 For I = 1 To 512
  Shiftin Miso , Clk , Temp_b1 , Msbl : Indat(i) = Temp_b1 : Temp3 = I - 2 : If Temp3 < 0 Then Temp3 = 0 : If Mmc_print = 1 Then Print #1 , Temp3 ; : If Mmc_print = 1 Then Print #1 , " " ; : If Mmc_print = 1 Then Print #1 , Temp_b1 : Waitms 5 : Next I       'correction of 2 for right display
Waitms 100 : Gosub Print_header_data : Waitms 300
Else
'For I = 1 To 4 '2->6 8.8.07 ***T
Waitms 50
Shiftin Miso , Clk , Temp_b1 , Msbl                         '  value is invalid!
Waitms 40
Shiftin Miso , Clk , Temp_b1 , Msbl                         '  value is invalid!
Waitms 40
'Shiftin Miso , Clk , Temp_b1 , Msbl '  value is invalid!
'waitms 40
'Shiftin Miso , Clk , Temp_b1 , Msbl '  value is invalid!
'waitms 40
'Shiftin Miso , Clk , Temp_b1 , Msbl '  value is invalid!
'waitms 40
'Shiftin Miso , Clk , Temp_b1 , Msbl '  value is invalid!
'waitms 40
'Next I
Number_of_scan = 0
Readeeprom Temp2 , 348                                      'Number of Scans Analog
'For I = 1 To 2 '2->6 8.8.07
'Shiftin Miso , Clk , Temp_b1 , Msbl 'first value is invalid!
'Next I
For I = 1 To 254                                            '***T vorher 256 512
    Shiftin Miso , Clk , Temp_b1 , Msbl
    Temp1 = Temp_b1                                         '2.Value U Batt
    Shiftin Miso , Clk , Temp_b2 , Msbl
    Temp3 = Temp_b2 : Shift Temp1 , Left , 8 : Value = Temp1 Or Temp3
    Kein_komma = 0
If Mmc_print = 1 Then
     Gosub Print_value : Print #1 , "  ";
  End If                                                    '1.Value U batt
Waitms 15                                                   'vorher 10 16.7.07
        Incr Number_of_scan : If Number_of_scan = 6 Then Waitms 30
        If Number_of_scan >= Temp2 Then
            Number_of_scan = 0 : If Mmc_print = 1 Then Print #1 , "" : Waitms 70 : End If       '***T geht's schneller? vorher 30 16.7.07
Next I
If Mmc_print = 1 Then Print #1 , ""
Waitms 800                                                  'vorher 600 16.7.07
End If

Shiftin Miso , Clk , Resp , Msbl
Shiftin Miso , Clk , Resp , Msbl
Set Cs
Mstatus
End Sub

'Get MMC Status
Sub Mstatus
Cmd13:
Set Cs
Shiftout Mosi , Clk , Dat , Msbl
Shiftin Miso , Clk , Resp , Msbl
Reset Cs
Dat = &H4D
Shiftout Mosi , Clk , Dat , Msbl
Addr = 0
Shiftout Mosi , Clk , Addr , Msbl
Dat = &HFF
Shiftout Mosi , Clk , Dat , Msbl
Shiftout Mosi , Clk , Dat , Msbl
Shiftin Miso , Clk , Resp2 , Msbl
Set Cs
End Sub

Sub Chkresp(byval Chkres As Byte)
''NOTE:If the addr is incorrect it will
''never exit the following loop!
''You may want to loop it approx 255 times
''and then if it fails go to an error routine
'   While Resp <> Chkres
   Shiftin Miso , Clk , Resp , Msbl
'   Wend
 End Sub

Program_switch:
'Temp = Getadc(7) / 4
'Temp = Getadc(7) / 4 'now with Multiplexer
If Wahlschalter > Prg_selector_pos_1 Then Goto Prg2         'Programm_selector
Programm_selector = 0 : Return                              ': Return
Prg2:
If Wahlschalter > Prg_selector_pos_2 Then Goto Prg3         'Programm_selector
Programm_selector = 1 : Return
Prg3:
If Wahlschalter > Prg_selector_pos_3 Then Goto Prg4         'Programm_selector
Programm_selector = 2 : Return
Prg4:
If Wahlschalter > Prg_selector_pos_4 Then Goto Prg5         'Programm_selector
Programm_selector = 3 : Return
Prg5:
If Wahlschalter > Prg_selector_pos_5 Then Goto Prg6         'Programm_selector
Programm_selector = 4 : Return
Prg6:
If Wahlschalter > Prg_selector_pos_6 Then Goto Prg7         'Programm_selector
Programm_selector = 5 : Return
Prg7:
If Wahlschalter > Prg_selector_pos_7 Then Goto Prg8         'Programm_selector
Programm_selector = 6 : Return
Prg8:
If Wahlschalter > Prg_selector_pos_8 Then Goto Prg9         'Programm_selector
Programm_selector = 7 : Return
Prg9:
If Wahlschalter > Prg_selector_pos_9 Then Goto Prg10        'Programm_selector
Programm_selector = 8 : Return
Prg10:
If Wahlschalter > Prg_selector_pos_10 Then Goto Prg11       'Programm_selector
Programm_selector = 9 : Return
Prg11:
If Wahlschalter > Prg_selector_pos_11 Then Goto Prg12       'Programm_selector
Programm_selector = 10 : Return
Prg12:
Programm_selector = 11 : Return

Simu_analog:
Readeeprom Temp , 372                                       '372 = 56 Parameter-Nr for Simu
Temp_b1 = Temp
If Temp_b1 = 0 Then Return
Readeeprom Value , 374                                      '374/57 Simu-Value

If Temp_b1 = 1 Then U_batt_smooth = Value                   'Analog Sensors
If Temp_b1 = 2 Then U_ausg = Value
If Temp_b1 = 3 Then Humidity_1 = Value                      'Analog Sensors
If Temp_b1 = 4 Then Humidity_2 = Value
If Temp_b1 = 5 Then Humidity_3 = Value
If Temp_b1 = 6 Then Humidity_4 = Value
If Temp_b1 = 7 Then Humidity_5 = Value
If Temp_b1 = 8 Then Wahlschalter = Value
If Temp_b1 = 9 Then Ldr_sensor = Value
If Temp_b1 = 10 Then Sensor_temp_kompensation = Value
If Temp_b1 = 11 Then Ext_temperature = Value
If Temp_b1 = 12 Then I_load_ai_12 = Value
If Temp_b1 = 13 Then I_load_ai_13 = Value
If Temp_b1 = 14 Then I_solar_ai_14 = Value
If Temp_b1 = 15 Then U_nicd_ai_15 = Value

If Temp_b1 = 101 Then
   Input_1 = 0 : If Value = 1 Then Input_1 = 1 : End If
If Temp_b1 = 102 Then
   Input_2 = 0 : If Value = 1 Then Input_2 = 1 : End If
If Temp_b1 = 103 Then
   Input_3 = 0 : If Value = 1 Then Input_3 = 1 : End If
If Temp_b1 = 104 Then
   Input_4 = 0 : If Value = 1 Then Input_4 = 1 : End If
If Temp_b1 = 105 Then
   Input_5 = 0 : If Value = 1 Then Input_5 = 1 : End If
If Temp_b1 = 106 Then
   Input_6 = 0 : If Value = 1 Then Input_6 = 1 : End If
If Temp_b1 = 107 Then
   Input_7 = 0 : If Value = 1 Then Input_7 = 1 : End If
If Temp_b1 = 108 Then
   Input_8 = 0 : If Value = 1 Then Input_8 = 1 : End If

If Temp_b1 = 201 Then Wind_speed = Value                    'Radio Sensors
If Temp_b1 = 202 Then Elv_temp = Value
If Temp_b1 = 203 Then Elv_humidity = Value
If Temp_b1 = 204 Then Elv_rain = Value
Return

Analog_extended:
Gosub_analog_extended = 0
Start Adc
Incr Analog_block : If Analog_block < 0 Or Analog_block > 7 Then Analog_block = 0

If Analog_block = 0 Then
 Temp = Getadc(7) / 4 : Wahlschalter = Temp
 Portb.2 = 1 : Portd.4 = 0 : Portd.5 = 0 : Return : End If

If Simu = 1 Then
 Portb.2 = 0 : Portd.4 = 0 : Portd.5 = 0 : Return : End If

If Analog_block = 1 Then
 Analog_9 = Getadc(7)
 Portb.2 = 0 : Portd.4 = 1 : Portd.5 = 0 : Return : End If

If Analog_block = 2 Then
 Analog_10 = Getadc(7)
 Portb.2 = 1 : Portd.4 = 1 : Portd.5 = 0 : Return : End If

If Analog_block = 3 Then
 Analog_11 = Getadc(7)
 Portb.2 = 0 : Portd.4 = 0 : Portd.5 = 1 : Return : End If

If Analog_block = 4 Then
 I_load_ai_12 = Getadc(7)
 Portb.2 = 1 : Portd.4 = 0 : Portd.5 = 1 : Return : End If

If Analog_block = 5 Then
 I_load_ai_13 = Getadc(7)
 Portb.2 = 0 : Portd.4 = 1 : Portd.5 = 1 : Return : End If

 If Analog_block = 6 Then
 I_solar_ai_14 = Getadc(7)                                  'If Disable_read_I_Solar = 0 Then
 Portb.2 = 1 : Portd.4 = 1 : Portd.5 = 1 : Return : End If

 If Analog_block = 7 Then
 Analog_15 = Getadc(7)
 Portb.2 = 0 : Portd.4 = 0 : Portd.5 = 0 : Return : End If
Return

Ntc_calc:
'incr Test_counter
'Temp = Test_counter
'I bereich Temp nur von 216...971 relevant
Temp = Temp / 4
Temp_b5 = Temp
Temp_b5 = Temp_b5 - 54
If Temp_b5 < 0 Then
 Temp = 0 : Return : End If
If Temp_b5 > 119 Then
 Temp = 440 : Return : End If

'If Temp < 131 Then
' Temp = 0 : Return : End If
'If Temp > 840 Then
' Temp = 1108 : Return : End If
'Temp = Temp - 131
Temp = Lookup(temp_b5 , Dta_ntc)
Return

'Ntc_calc:
''Temp = Test_counter
'If Temp < 131 Then
'  Temp = 0 : Return : End If
'If Temp > 840 Then
' Temp = 1108 : Return : End If
' '   Temp = Temp - 131 : If Temp < 0 Then Temp = 0 : If Temp > 840 Then Temp = 840 : Temp = Lookup(temp , Dta_ntc) : GoTo End_sensor_calc : End If           '
''Return
'
''Print #1 , " "
''S = Str(temp) : Print #1 , S                                '1
''=(10240-10*Temp)/Temp
'Temp1 = Temp * 10                                           '569 * 10 = 5690
'Temp1 = 10240 - Temp1                                       '4450
'Temp_s1 = Temp : Temp_s2 = Temp1
'Temp_s1 = Temp_s2 / Temp_s1                                 '4450 / 569 = 7,8
''=1/(LN(Temp_s1/10)/4300+1/298)-273
'Temp_s2 = Temp_s1 / 10.0                                    '0,78
''S = Str(temp_s2) : Print #1 , S
'Temp_s1 = Log(temp_s2)                                      '-0,248461
''S = Str(temp_s1) : Print #1 , S                             '3
'Temp_s1 = Temp_s1 / 4300.0                                  '-0,000057781
'
'Temp_s2 = 1.0 / 298.0                                       '0,0033557
'Temp_s1 = Temp_s1 + Temp_s2                                 '0,003297918
'Temp_s1 = 1 / Temp_s1                                       '303
'Temp_s1 = Temp_s1 - 273.0                                   '30
'Temp_s1 = Temp_s1 * 10.0                                    '300
'Temp = Temp_s1                                              '300
'If Temp > 580 Then
'  Temp_s1 = Temp_s1 * 1.052631 : End If                     'Correction if more than 60°C
'Temp = Temp_s1                                              '300
''S = Str(temp_s1) : Print #1 , S
''If Temp < 0 Or Temp > 1050 Then Temp = 0                    'limits
'Return

Tim0_isr:
Incr M_second
If Stop_read_ai_extended = 0 Then
   If M_second = 1 Or M_second = 15 Or M_second = 30 Or M_second = 45 Then Gosub_analog_extended = 1 : End If
If M_second = 40 Then Time_slice_3b = 1
If M_second > 60 Then                                       '4 Mhz: mit Teiler 256:61
If Sd_card_time_out > 0 Then Incr Sd_card_time_out
 If Sd_card_time_out > 3 Then Goto No_sd_card               'Reset SD-Card present
 Incr Second : M_second = 0
End If
Return

Time_date:
Dim Flag_time_correction As Bit
If Hour = 23 And Minute = 59 And Second = 60 And Flag_time_correction = 0 Then       'correct 5 sec every day
Readeeprom Temp , 288                                       ' 63: Korrektur-Wert Uhr
Temp_b1 = Temp Mod 60                                       'correction minute
Temp_b2 = Temp / 60                                         'Correction second
   Second = Second - Temp_b1 : Minute = Minute - Temp_b2 : Flag_time_correction = 1 : End If
If Hour = 1 Then Flag_time_correction = 0

If Hour <> Hour_old Then
  Writeeeprom Month , 201
  Writeeeprom Day , 202
  Writeeeprom Hour , 203
  Writeeeprom Minute , 204 : End If
Hour_old = Hour

If Second > 60 Then
 Incr Minute : Incr Minute_byte : If Minute_byte = 0 Then Minute_byte = 1 : Second = 1 : If Day = 0 Then Day = 1 : Sec_alt = Second : End If
If Minute > 59 Then
  Readeeprom Temp_b1 , 41 : If Temp_b1 <> 1 Then Incr Hour  'Autodetect Hour?
  Minute = 0 : End If
If Hour > 23 Then
 Incr Day : Incr Day_learning_mode : Readeeprom Temp_b1 , 41 : If Temp_b1 = 0 Then Hour = 0 : End If       'Autodetect Hour?
  If Day > 28 Then
     Select Case Month
        Case 1 : Mday = 31
        Case 2 : Mday = Year And &H03
           If Mday = 0 Then
              Mday = 29
           Else
              Mday = 28
           End If
        Case 3 : Mday = 31
        Case 4 : Mday = 30
        Case 5 : Mday = 31
        Case 6 : Mday = 30
        Case 7 : Mday = 31
        Case 8 : Mday = 31
        Case 9 : Mday = 30
        Case 10 : Mday = 31
        Case 11 : Mday = 30
        Case 12 : Mday = 31
     End Select
     If Day > Mday Then
        Day = Day - Mday : Incr Month
        If Month > 12 Then
           Month = 1 : Incr Year
        End If
     End If
  End If
Return


End

Dta_ntc:
'Data -600% , -576% , -499% , -450% , -414% , -386% , -362% , -341% , 8
'Data -322% , -306% , -291% , -277% , -264% , -252% , -241% , -230% , 8
'Data -220% , -211% , -202% , -193% , -185% , -177% , -169% , -161% , 8
'Data -154% , -147% , -140% , -134% , -127% , -121% , -115% , -109% , 8
'Data -103% , -98% , -92% , -87% , -81% , -76% , -71% , -66% , -61% , 9
'Data -56% , -51% , -47% , -42% , -37% , -33% , -28% , -24% , -20% ,  9
'Data -15% , -11% , -7% , -3% , 4 = 54
Data 1% , 5% , 9% , 13% , 17% , 21% , 25% ,                 '7
Data 29% , 33% , 36% , 40% , 44% , 47% , 51% , 55% , 58% , 62% , 66% ,       '11
Data 69% , 73% , 76% , 80% , 83% , 86% , 90% , 93% , 97% , 100% , 103% ,       '11
Data 107% , 110% , 113% , 117% , 120% , 123% , 127% , 130% , 133% ,       '9
Data 136% , 140% , 143% , 146% , 149% , 153% , 156% , 159% , 162%,       '9
Data 165% , 169% , 172% , 175% , 178% , 181% , 184% , 188%, '8
Data 191% , 194% , 197% , 200% , 204% , 207% , 210% , 213% ,       '8
Data 216% , 219% , 223% , 226% , 229% , 232% , 235% , 239% , 242% ,       '9
Data 245% , 248% , 252% , 255% , 258% , 261% , 265% , 268% , 271% ,       '9
Data 275% , 278% , 281% , 284% , 288% , 291% , 295% , 298% , 301% ,       '9
Data 305% , 308% , 312% , 315% , 319% , 322% , 326% , 329% , 333% ,       '9
Data 336% , 340% , 343% , 347% , 351% , 354% , 358% , 362% , 365% ,       '9
Data 369% , 373% , 377% , 381% , 385% , 388% , 392% , 396% , 400% ,       '9
Data 404% , 408% , 413% , 417% , 421% , 425% , 429% , 434% , 438% ,       '9 =119
'Data 442% , 447% , 451% , 456% , 461% , 465% , 470% , 475% , 479% ,   '9
'Data 484% , 489% , 494% , 499% , 505% , 510% , 515% , 520% , 526% ,      '9
'Data 531% , 537% , 543% , 549% , 555% , 561% , 567% , 573% , 579% ,      '9
'Data 586% , 592% , 599% , 606% , 613% , 620% , 628% , 635% , 643% ,      '9
'Data 651% , 659% , 668% , 676% , 685% , 694% , 704% , 713% , 723% ,      '9
'Data 734% , 744% , 756% , 767% , 779% , 792% , 805% , 818% , 833% ,      '9
'Data 848% , 864% , 880% , 898% , 917% , 937% , 959% , 982% , 1007% ,     '9
'Data 1035% , 1065% , 1099% , 1136% , 1179% , 1229% , 1287% , 1358% ,   '8
'Data 1449% , 1571% , 1754% , 2106% , 2200%                '5