;**********************************************************
;

printOK
call CRLF
movlw okMsg
movwf strAddr
call printlnString

return
;**********************************************************
;
printERR
call CRLF
movlw errMsg
movwf strAddr
call printlnString
return

printERR1
call CRLF
movlw err1Msg
movwf strAddr
call printlnString
return

printERR2
call CRLF
movlw err2Msg
movwf strAddr
call printlnString
return
;**********************************************************
; gibt string ab strAddr aus + CR LF
printlnString

call printString
call CRLF

return


;**********************************************************
; gibt string ab strAddr aus

printString


movf w strAddr
call EERead

movwf w_temp
tstf w_temp ; wir machen nichts - aber testen ob eine 0 drin steht ...
btfsc STATUS, Z ; ist das Zero Flag gesetzt ?
goto printStringEND


call termSend
incf strAddr

goto printString

printStringEND



return


;**********************************************************
; sende t CR+LF auf das RS232 Terminal
CRLF
movlw 0x0d ; CR
call termSend
movlw 0x0a ; LF
call termSend
return


;**********************************************************
; gibt den Status de s Systems aus

printStatus
movlw statusMsg ;d'8526'-d'8448' ; Status PortA: 1-----8
movwf strAddr
call printString
movlw ' '
call termSend
movlw portMsg ;d'8533'-d'8448'
movwf strAddr
call printString
movlw 'A'
call termSend
movlw ' '
call termSend
movlw ':'
call termSend
movlw ' '
call termSend


movf PORTA,0
call portToString


call CRLF



movlw statusMsg ;d'8526'-d'8448' ; Status PortB: 1-----8
movwf strAddr
call printString
movlw ' '
call termSend
movlw portMsg ;d'8533'-d'8448'
movwf strAddr
call printString
movlw 'B'
call termSend
movlw ' '
call termSend
movlw ':'
call termSend
movlw ' '
call termSend

movf PORTB,0
call portToString


call CRLF
return

;**********************************************************
;

portToString

movwf w_temp

movlw '0'
btfsc w_temp,7
movlw '1'
call termSend
movlw '0'
btfsc w_temp,6
movlw '1'
call termSend
movlw '0'
btfsc w_temp,5
movlw '1'
call termSend
movlw '0'
btfsc w_temp,4
movlw '1'
call termSend
movlw '0'
btfsc w_temp,3
movlw '1'
call termSend
movlw '0'
btfsc w_temp,2
movlw '1'
call termSend
movlw '0'
btfsc w_temp,1
movlw '1'
call termSend
movlw '0'
btfsc w_temp,0
movlw '1'
call termSend

;
; movlw d'170'
; movwf w_temp
; movlw d'8'
; movwf loops

;portToStringLoop
;
; movlw '0'
; btfsc w_temp, loops ; -d'1'
; movlw '1'
;
; call termSend
;
; de cf loops
; tstf loops
; skpz
; goto portToStringLoop

return



;**********************************************************
; Vergleichen zweier Strings eine Adresse liegt in strAddr - zweiter String ist immer cmdBuffer
; ACHTUNG dies ist KEIN vollstaend iger strcmp ! - er geht davon aus, dass die Befehle Einde utig sind ...
;
; Aufruf :
; movlw resetMsg
; movwf strAddr
; call strCmp
;
strCmp


movf w FSR ; sichern von FSR
movwf FSR_temp

movlw cmdBuffer ; anfang vom cmdBuffer ist FSR
movwf FSR



strCmpBEGIN

movf w strAddr
call EERead


movwf w_temp
tstf w_temp
btfsc STATUS, Z
goto strCmpEND


tstf INDF
btfsc STATUS, Z
goto strCmpEND


movf w INDF ; Nehme den inhalt von de r Aktuellen RAM stelle lege sie in W
subwf w_temp, 1 ; ziehe W von de r w_temp ab und speichere Ergebiniss in w_temp
tstf w_temp ; ist w_temp 0 ? - dann waren beide buchstaben gleich ?
skpz ; wenn das zero flag gesetzt ist (also in w_temp == 0) dann
goto strCmpNEq ; springe NICHT zum ende strCmp Not Equal



incf FSR
incf strAddr

goto strCmpBEGIN

strCmpEND

movlw FSR ; ruecksichern von FSR
movwf FSR_temp
retlw 0 ; wenn gleich return 0

strCmpNEq
movf w FSR
movwf FSR_temp

retlw 1 ; wenn ungleich return 1



;**********************************************************
; Auslesen de s EEPROMs - Adresse liegt in W Rückgabewert liegt auch in W

EERead
bsf STATUS, RP0 ; EEADR liegt auf Bank 1
movwf EEADR ; adresse aus de m Arbeitsregister in das EEPROM Adressregister EEADR
bsf EECON1, RD ; EEPROM lesen
movf EEDATA, w ; zelle zum Arbeitregister kopieren
bcf STATUS, RP0 ; zurueck zu Bank 0
return

;**********************************************************
;

bufferLoeschen

clrw
movwf cmdBuffer
movwf cmdBuffer1
movwf cmdBuffer2
movwf cmdBuffer3
movwf cmdBuffer4
movwf cmdBuffer5
movwf cmdBuffer6
movwf cmdBuffer7
movwf cmdBuffer8
movwf cmdBuffer9
movwf cmdBuffer10
movwf cmdBuffer11
movwf cmdBuffer12
movwf cmdBuffer13
movwf cmdBuffer14
movwf cmdBuffer15
movwf cmdBuffer16
movwf cmdBuffer17
movwf cmdBuffer18
movwf cmdBuffer19
movwf cmdBuffer20


return