Hallo,

Hier mein bishäriger code:



Code:
'Mikrocontroller Setup
$lib "mcsbyteint.lbx"
$regfile = "m16def.dat"

$crystal = 20000000
$baud = 19200

'Display Setup
Config Lcdpin = Pin , Db4 = Porta.6 , Db5 = Porta.5 , Db6 = Porta.4 , Db7 = Porta.3 , E = Porta.7 , Rs = Porta.2       ' Natürlich so wie es wirklich angeschlossen ist (4-Bit-Modus)
Config Lcd = 20 * 4


Config Pind.2 = Input	    'taster
Config Pind.4 = Input	    'Taster
Config Pind.7 = Output      'Buzzer
Config Pina.1 = Output	    'Relais (öffner)

'Sende & Empfangs Variablen
Dim Packets(10) As Byte
Dim Packete(8) As Byte

'Allgemeine WR Variablen
Dim Wranzahl As Byte

'Display & Line Variablen
Dim Line1 As String * 20
Dim Line2 As String * 20
Dim Line3 As String * 20
Dim Line4 As String * 20

'Checksum Variablen
Dim Bcclo As Byte
Dim Bcchi As Byte

'Sendepaket Variablen
Dim Adr As Byte
Dim Command As Byte
Dim Par1 As Byte
Dim Par2 As Byte
Dim Par3 As Byte
Dim Par4 As Byte
Dim Par5 As Byte
Dim Par6 As Byte
Dim Par7 As Byte
Dim Par8 As Byte

'Empfangspaket Variablen
Dim Globalstate As Byte
Dim Inverterstate As Byte
Dim Dc1state As Byte
Dim Alarmstate As Byte
Dim Transstate As Byte
Dim Dc2state As Byte
Dim Tglobalstate As String * 20
Dim Talarmstate As String * 20

'Uhr
Dim S As Byte , M As Byte , H As Byte , D As Byte
Dim Wm As Byte , Yd As Byte , Month As Byte

'Checksum
Declare Sub Crc
Declare Sub A_crc16

'Paket subs
Declare Sub Paketinits
Declare Sub Paketinite

'Subroutines
Declare Sub Sendewr
Declare Sub Empfangewr
Declare Sub Lcdout
Declare Sub Status
Declare Sub Abfrageroutine

'Uhr
Declare Sub Gettime
Declare Sub Settime

'configure the used port pin for I2C
Config I2cdelay = 5
Config Sda = Portc.1
Config Scl = Portc.0

'Setup Comports
'Serial 1  Configuration
Config Serialin = Buffered , Size = 8
Config Serialout = Buffered , Size = 10


'Program Paramter init

Wranzahl = 12	'Anzahl der Geräte


'Uhr Variablen setzen
 S = 10
 M = 0
 H = 0
 D = 1
 Month = 1
 Wm = 1
 Yd = 1
 Ddrd = &B00010000
 Cls



 'LCD init
Initlcd
   Line1 = "Test"
   Line2 = "boot"
   Line3 = " 0.1 "
   Line4 = "xeus"
   Gosub Lcdout


Enable Interrupts

Call Settime

Do
      Porta.1 = 1              'relais
      Gosub Abfrageroutine

   Wait 2

Loop

End

 '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

'SUBs



'Paketinitialisierung Senden
Sub Paketinits
'Init Packets
Packets(1) = Adr            'Adr
Packets(2) = Command        'command
Packets(3) = Par1           'Par1
Packets(4) = Par2           'Par2
Packets(5) = Par3           'Par3
Packets(6) = Par4           'Par4
Packets(7) = Par5           'Par5
Packets(8) = Par6           'Par6
Packets(9) = Bcclo          'CRC_L
Packets(10) = Bcchi         'CRC_H
Return
End Sub Paketinit
'--------------------------------------------
'Packetinitialisierung Empfangen
Sub Paketinite
'Init Packete
Transstate = Packete(1)                 'Transmission State
Globalstate = Packete(2)                'Global State
Inverterstate = Packete(3)              ' Stat
Dc1state = Packete(4)                   '1  State
Dc2state = Packete(5)                   '2  State
Alarmstate = Packete(6)                 'Alarm State
Bcclo = Packete(7)                      'CRC_L
Bcchi = Packete(8)                      'CRC_H
End Sub Packetinie
'---------------------------------------------

'Anfrage an gerät stellen
Sub Sendewr

   Gosub Crc
   Gosub Paketinits
   Printbin Packets(1) ; 10		'Paket wird gesende
Return
End Sub Sendewr

 ' - - - - - - - - - - - - - - - - - - - -

'Status vom WR empfangen
Sub Empfangewr
    Inputbin Packete(1) , 8   	' Bytes einlesen 
Return
End Sub Empfangewr

 '- - - - - - - - - - - - - - - - - - - -
 'LCD Ausgabe
Sub Lcdout
   Cls
   Locate 1 , 1              '1. Zeile
   Lcd Line1
   Locate 2 , 1              '2. Zeile
   Lcd Line2
   Locate 3 , 1              '3. Zeile
   Lcd Line3
   Locate 4 , 1              '4. Zeile
   Lcd Line4
   Return
End Sub Lcdout

 '- - - - - - - - - - - - - - - - - - - - 
'PCF8583 stellen
Sub Settime
 S = Makebcd(s)                'Sek
 M = Makebcd(m)                'Min
 H = Makebcd(h)                'Std
 D = Makebcd(d)                'Tag
 Month = Makebcd(month)        'Monat

 'Setzen der vorgebenen Werte

 I2cstart
 I2cwbyte &HA0               'Schreibmodus
 I2cwbyte 0                  'select control register
 I2cwbyte 8                  'set year and day bit for masking
 I2cstart
 I2cwbyte &HA0               'Schreibmodus
 I2cwbyte 2                  'Sekundenregister auswählen
 I2cwbyte S                  'Sek schreiben
 I2cwbyte M                  'min schreiben
 I2cwbyte H                  'std schreiben
 I2cwbyte D                  'tag schreiben
 I2cwbyte Month              'monat schreiben
 I2cstop
End Sub Settime

Sub Gettime
 'Aktuelle Werte auslesen

'---------------------- sekunden --------------------
 I2cstart
 I2cwbyte &HA0
 I2cwbyte 2                   'Sek register auswählen
 I2cstart
 I2cwbyte &HA1
 I2crbyte S , Nack            'lese sek
'---------------------- minuten --------------------
 I2cstart
 I2cwbyte &HA0
 I2cwbyte 3                    'min register auswählen
 I2cstart
 I2cwbyte &HA1
 I2crbyte M , Nack             'lese min
'---------------------- stunden --------------------
 I2cstart
 I2cwbyte &HA0
 I2cwbyte 4                    'Std register auswählen
 I2cstart
 I2cwbyte &HA1
 I2crbyte H , Nack             'lese std
'---------------------- tag --------------------
 I2cstart
 I2cwbyte &HA0
 I2cwbyte 5                     'tag register auswählen
 I2cstart
 I2cwbyte &HA1
 I2crbyte Yd , Nack             'lese jahr und tag
'---------------------- wotag --------------------
 I2cstart
 I2cwbyte &HA0
 I2cwbyte 6                     'mon register auswählen
 I2cstart
 I2cwbyte &HA1
 I2crbyte Wm , Nack             'lese wochentag und monat

 I2cstop
End Sub Gettime


' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

'Abfrageroutine sequenziell

Sub Abfrageroutine



Wranzahl = Wranzahl + 1
Adr = Wranzahl                     'Abrage Commando 2.Byte
For Adr = 2 To Wranzahl

'Adr = Wranzahl
Command = 050


Adr = Adr
Command = Command
Par1 = 000
Par2 = 032
Par3 = 032
Par4 = 032
Par5 = 032
Par6 = 032
Par7 = Bcclo
Par8 = Bcchi

   Gosub Paketinits
   Gosub Sendewr

   Gosub Empfangewr
   Gosub Paketinite
   Gosub Status
   Wait 2
   Next Adr

   If Adr = 13 Then
   Adr = 2
   End If


Return

End Sub Abfrageroutine

'------------------------------------------------------------------------------------------------------------




' - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Sub Crc

'--------------------- make CCITT -----------------------------
   Loadadr Packets(1) , X                                   ' addr of data
   Ldi r19,8                                                ' Anzahl bytes )

'----- berechnet CCITT und schreibt ihn nach Bcclo u. Bcchi -----
   Gosub A_crc16                                            ' callit

   Packets(9) = Bcclo
   Packets(10) = Bcchi



 End Sub





'------------------------------------------------------------------
'  register X  --> first data byte
'  register 19  --> Number of data bytes
'------------------------------------------------------------------
Sub A_crc16:

   ser r16                             ; crc low byte
   ser r17                             ; crc high byte
   ldi r24,&H08                        ; polynome
   ldi r25,&H84

A_crc16_1:
   ld r20,x+                            ; get data byte
   ldi r18,8                            ; 8 bits

A_crc16_2:
   push  r20                           ; save data byte
   andi  r20, 1                        ; mask out 2^^0
   eor   r16, r20                      ; data XOR crc-Lo
   clc                                 ; clear carry for shift
   ror   r17                           ; shift crchi to right
   ror   r16                           ; shift crclo to right
   brcc  A_crc16_3                     ; no carry --> skip
   eor   r17,r25                       ;
   eor   r16,r24                       ; XOR Polynome

A_crc16_3:
   pop   r20                           ; restore databyte
   ror   r20                           ; shift right, too
   dec   r18                           ; bit counter
   brne  A_crc16_2                     ; continue
   dec   r19                           ; byte counter
   brne  A_crc16_1                     ; continue

   ser   r24                           ; make FF
   eor   r17,r24                       ; XOR crchi with FF
   eor   r16,r24                       ; XOR crclo with FF

   Loadadr Bcclo , X                                        ' Address Of Result
   st    x+ , r16                      ; store crclo
   st    x+ , r17                                        ; store crchi

   Return                                                   ' that's it
'-----------------------------------------------------------------------------
 End Sub



'-----------------------------------------------------------------------------
               'STATUS ANALYSE
'-----------------------------------------------------------------------------


 'Status Auswertung
Sub Status

'Init Packete
Transstate = Packete(1)                     'Transmission State
Globalstate = Packete(2)                    'Global State
Inverterstate = Packete(3)                  'Inverter Stat
Dc1state = Packete(4)                       '1 DC State
Dc2state = Packete(5)                       '2 DC State
Alarmstate = Packete(6)                     'Alarm State
Bcclo = Packete(7)                          'CRC_L
Bcchi = Packete(8)			    'CLC_H



'2.Byte Global State
If Globalstate = 006 Then
   Tglobalstate = "Run"
   Porta.1 = 1
   Else
   Tglobalstate = "FEHLER"
   Portd.7 = 1
   Porta.1 = 0
   Wait 1
   Portd.7 = 0


End If

or

If Globalstate = 009 Then
   Tglobalstate = "Ground Fault"
End If

or

If Globalstate = 016 Then
   Tglobalstate = "Waiting for reset"
End If



'6.Byte Alarm State
If Alarmstate < 000 Then
   Talarmstate = "Fehler"
End If

or

If Alarmstate = 001 Then
   Talarmstate = "Fehler: Sun Low"
End If

or

If Alarmstate = 002 Then
   Talarmstate = "Fehler: Input OC"
End If

or

If Alarmstate = 003 Then
   Talarmstate = "Fehler: Input UV"
End If

or

If Alarmstate = 004 Then
   Talarmstate = "Fehler: Input OV"
End If

or

If Alarmstate = 007 Then
   Talarmstate = "Fehler: Bulk OV"
End If

or

If Alarmstate = 009 Then
   Talarmstate = "Fehler: AC OC"
End If

or

If Alarmstate = 013 Then
   Talarmstate = "Fehler: Grid Fail"
End If

or

If Alarmstate = 016 Then
   Talarmstate = "Fehler: DC/DC Fail"
End If

or

If Alarmstate = 018 Then
   Talarmstate = "Fehler: Ground Fault"
End If

or

If Alarmstate = 019 Then
   Talarmstate = "Fehler: Over Temp."
End If

or

If Alarmstate = 020 Then
   Talarmstate = "Fehler: BulkCap Fail"
End If

or

If Alarmstate = 023 Then
   Talarmstate = "Fehler: Ground Fault"
End If

or

If Alarmstate = 024 Then
   Talarmstate = "Degauss ERROR"
End If

or

If Alarmstate = 026 Then
   Talarmstate = "Fehler: DCDC Fail"
End If

or

If Alarmstate = 032 Then
   Talarmstate = "Fehler: Grid OV"
End If

or

If Alarmstate = 033 Then
   Talarmstate = "Fehler: Grid UV"
End If

or

If Alarmstate = 034 Then
   Talarmstate = "Fehler: Grid OF"
End If

or

If Alarmstate = 035 Then
   Talarmstate = "Fehler: Grid UF"
End If

or

If Alarmstate = 036 Then
   Talarmstate = "Fehler: Z Grid Hi"
End If

or

If Alarmstate = 038 Then
   Talarmstate = "Fehler: Riso Low"
End If


Cls

Locate 1 , 1
Lcd "testl"
Locate 2 , 1
Lcd "WR-Adr: " + Str(adr)
Locate 3 , 1
Lcd Tglobalstate
Locate 4 , 1
Lcd Talarmstate



Return
End Sub Status
leider konnte ich bis jetzt noch keines der oben genannten probleme lösen. vielleicht hat von euch jemand eine idee.