Ich habe folgenden Sourcecode geschrieben (Die echtzeituhrteile sind von nem beispiel):



Code:
'declare used subs
Declare Sub Settime(byval S As Byte , Byval M As Byte , Byval H As Byte , Byval D As Byte , Byval Month As Byte)
Declare Sub Gettime


'declare vairables
Dim S As Byte , M As Byte , H As Byte , D As Byte , Month As Byte
Dim Sets As Byte , Setm As Byte , Seth As Byte , Setmode As Byte
Dim Wm As Byte , Yd As Byte


Config Portb = Input
Portb.3 = 1
Portb.2 = 1
Portb.1 = 1
Portb.0 = 1


Sets = 0
Setm = 0
Seth = 0
Setmode = 1
Do


   If Pinb.1 = 0 Then
      Setmode = Setmode + 1
      If Setmode = 4 Then
         Setmode = 1
      End If
   End If


  If Setmode = 1 Then
   If Pinb.3 = 0 Then
      Sets = Sets + 1
      If Sets = 60 Then
         Sets = 0
      End If
   End If
  Elseif Setmode = 2 Then
   If Pinb.3 = 0 Then
      Setm = Setm + 1
      If Setm = 60 Then
         Setm = 0
      End If
   End If
  Else
   If Pinb.3 = 0 Then
      Seth = Seth + 1
      If Seth = 24 Then
         Seth = 0
      End If
   End If
  End If

  If Setmode = 1 Then
   If Pinb.2 = 0 Then
      If Sets = 0 Then
         Sets = 60
      End If
      Sets = Sets - 1
   End If
  Elseif Setmode = 2 Then
   If Pinb.2 = 0 Then
      If Setm = 0 Then
         Setm = 60
      End If
      Setm = Setm - 1
   End If
  Else
   If Pinb.2 = 0 Then
      If Seth = 0 Then
         Seth = 24
      End If
      Seth = Seth - 1
   End If
  End If

Waitms 200

   Print "Setmode: " ; Setmode
   Print Seth ; ":" ; Setm ; ":" ; Sets

Loop Until Pinb.0 = 0


Call Settime(sets , Setm , Seth , 1 , 1)                    'set time

Do
   Call Gettime                                             'get time
   Waitms 1000
Loop
End



Sub Gettime
    Dim Dum As Byte
    I2cstart                                                'generate start
    I2cwbyte &HA0                                           'write addres of PCF8583
    I2cwbyte 2                                              'select second register
    I2cstart                                                'generate repeated start
    I2cwbyte &HA1                                           'write address for reading info
    I2crbyte S , Ack                                        'read seconds
    I2crbyte M , Ack                                        'read minuts
    I2crbyte H , Ack                                        'read hours
    I2crbyte Yd , Ack                                       'read year and days
    I2crbyte Wm , Nack                                      'read weekday and month
    I2cstop                                                 'generate stop

    Print "Time " ;
    Print Bcd(h) ; ":" ; Bcd(m) ; ":" ; Bcd(s)
    Print "Day : " ; Bcd(yd) ; " Month : " ; Bcd(wm)
End Sub


Sub Settime(s As Byte , M As Byte , H As Byte , D As Byte , Month As Byte)
    'values are stored as BCD values so convert the values first
    S = Makebcd(s)                                          'seconds
    M = Makebcd(m)                                          'minuts
    H = Makebcd(h)                                          'hours
    D = Makebcd(d)                                          'days
    Month = Makebcd(month)                                  'months

    I2cstart                                                'generate start
    I2cwbyte &HA0                                           'write address
    I2cwbyte 0                                              'select control register
    I2cwbyte 8                                              'set year and day bit for masking
    I2cstop                                                 'generate stop


    I2cstart                                                'generate start
    I2cwbyte &HA0                                           'write mode
    I2cwbyte 2                                              'select seconds Register
    I2cwbyte S                                              'write seconds
    I2cwbyte M                                              'write minuts
    I2cwbyte H                                              'write hours
    I2cwbyte D                                              'write days
    I2cwbyte Month                                          'write months
    I2cstop
End Sub
Jetzt hab ich folgendes problem, wenn ich zie Uhrzeit eingestellt habe, werden falsche Werte in die Uhr übernommen z.B. 150. Woran kann das liegen? Ich kenne mich in Bascom noch nicht so gut aus.