Hier mal das Testprogramm als Klartext für die Fehlersuche ...
CodeBox BASCOM
'*********************************************************************************************************************
'*********************************************************************************************************************
'****** Programm zum Anzeigen und Stellen einer RTC Uhr mit dem Uhren IC DS1307 **************************************
'****************************** Von Rudolf Kischkel Version 1.0 ******************************************************
'*********************************************************************************************************************
'-----------------------------Dieses Programm ist für den Betrieb auf dem Testboard-----------------------------------
$regfile = "m8def.dat" 'AVR ATMega 8...
$crystal = 8000000 '...mit 8 MHz
$hwstack = 150 'hardware stack
$swstack = 150 'SW stack
$framesize = 40 'frame space
'---------- I²C Einsatellungen ----------
'Config Clock = User
Config Twi = 100000 'i2c Frequenz einstellen
Config Sda = Portb.1 'i2c Port SDA am AVR
Config Scl = Portb.0 'i2c Port SCL am AVR
I2cinit
Config Pind.0 = Input 'UP Taste
Config Pind.1 = Input 'Down Taste
Config Pind.2 = Input 'ENTER Taste
'---------- LCD Einstellungen ----------
Config Lcdpin = Pin , Db4 = Portc.0 , Db5 = Portc.1 , Db6 = Portc.2 , Db7 = Portc.3 , E = Portc.4 , Rs = Portc.5
Config Lcd = 16 * 2
Cursor Off 'Keinen Cursor auf LCD anzeigen
Config Dcf77 = Pinb.5 , Timer = 1 , Debug = 1 , Inverted = 1 , Timer1sec = 1 , Check = 1 'DCF Antenne am PortB.5 angeschlossen
Config Date = Dmy , Separator = . 'Datumsanzeige auf Tag,Monat,Jahr und Trennzeichen ist ein Punkt
Enable Interrupts
'Set Portb.5 'Pullup einschalten für DCF Antenne
Dim Wochentag As String * 2
Dim Monatname As String * 3
Dim Wotag As Byte
Dim Fehler As Byte
Dim Minute_alt As Byte
Const Ds1307w = &B11010000
Const Ds1307r = &B11010001
Cls
Gosub Vorspann
Goto Zeitholen
'----------------------------------Hauptprogramm--------------------------------
Anzeige:
Wotag = Dayofweek()
Wochentag = Lookupstr(wotag , Tagname) 'Tageskürzel aus Datentabelle laden
Locate 1 , 1
Lcd Wochentag ; " ";
If _day < 10 Then Lcd "0" ; _day Else Lcd _day ;
Monatname = Lookupstr(_month , Monatsnamen)
Lcd "-" ; Monatname ; "-" ; "20" ; _year
Locate 2 , 4
Lcd Time$
Locate 2 , 14
Lcd Fehler
Waitms 250
If _min <> Minute_alt Then Goto Zeitholen
Debounce Pind.2 , 1 , Uhr_stellen
Goto Anzeige
Zeitholen:
I2cstart
I2cwbyte Ds1307w
I2cwbyte 0
If Err = 1 Then Goto Fehlerzaehlen
I2cstart
I2cwbyte Ds1307r
I2crbyte _sec , Ack
I2crbyte _min , Ack
I2crbyte _hour , Ack
I2crbyte Wotag , Ack
I2crbyte _day , Ack
I2crbyte _month , Ack
I2crbyte _year , Nack
I2cstop
If Err = 1 Then Goto Fehlerzaehlen
_sec = Makedec(_sec)
_min = Makedec(_min)
_hour = Makedec(_hour)
_day = Makedec(_day)
_month = Makedec(_month)
_year = Makedec(_year)
Minute_alt = _min
Goto Anzeige
'------------------------------------Stellmenü--------------------------------------------
Fehlerzaehlen:
Fehler = Fehler + 1
Minute_alt = _min
Goto Anzeige
'---------------------------------Wochentag stellen---------------------------------------
Uhr_stellen:
Cls
Wochentag_stellen:
Locate 1 , 1
Lcd "Tag:" ; Wotag ; "=" ; Wochentag
If Pind.0 = 1 Then Wotag = Wotag + 1
If Wotag > 7 Then Wotag = 1
If Pind.1 = 1 Then Wotag = Wotag - 1
If Wotag = 0 Then Wotag = 7
Debounce Pind.2 , 1 , Tag_stellen
Wochentag = Lookupstr(wotag , Tagname) 'Tageskürzel aus Datentabelle laden
Waitms 250
Goto Wochentag_stellen
'------------------------------------Tag stellen------------------------------------------
Tag_stellen:
Cls
Tag_stellen_1:
Locate 1 , 1
Lcd Wochentag ; "." ; _day ; " "
If Pind.0 = 1 Then _day = _day + 1
If _day > 31 Then _day = 1
If Pind.1 = 1 Then _day = _day - 1
If _day < 1 Then _day = 31
Debounce Pind.2 , 1 , Monat_stellen
Waitms 250
Goto Tag_stellen_1
'-----------------------------------Monat Stellen-----------------------------------------
Monat_stellen:
Cls
Monat_stellen_1:
Locate 1 , 1
Lcd Wochentag ; "." ; _day ; "." ; _month ; " "
If Pind.0 = 1 Then _month = _month + 1
If _month > 12 Then _month = 1
If Pind.1 = 1 Then _month = _month - 1
If _month < 1 Then _month = 12
Debounce Pind.2 , 1 , Jahr_stellen
Waitms 250
Goto Monat_stellen_1
'-----------------------------------Jahr stellen------------------------------------------
Jahr_stellen:
Cls
Jahr_stellen_1:
Locate 1 , 1
Lcd Wochentag ; "." ; _day ; "." ; _month ; "." ; "20" ; _year ; " "
If Pind.0 = 1 Then _year = _year + 1
If Pind.1 = 1 Then _year = _year - 1
If _year < 10 Then _year = 10
Debounce Pind.2 , 1 , Stunde_stellen
Waitms 250
Goto Jahr_stellen_1
'-----------------------------------Stunde stellen----------------------------------------
Stunde_stellen:
Cls
Stunde_stellen_1:
Locate 1 , 1
Lcd Wochentag ; "." ; _day ; "." ; _month ; "." ; _year
Locate 2 , 1
If _hour < 10 Then Lcd "0" ; _hour Else Lcd _hour ; " "
If Pind.0 = 1 Then _hour = _hour + 1
If _hour > 23 Then _hour = 0
If Pind.1 = 1 Then _hour = _hour - 1
If _hour = 255 Then _hour = 23
Debounce Pind.2 , 1 , Minute_stellen
Waitms 250
Goto Stunde_stellen_1
'-----------------------------------Minute stellen----------------------------------------
Minute_stellen:
Cls
Minute_stellen_1:
Locate 1 , 1
Lcd Wochentag ; "." ; _day ; "." ; _month ; "." ; _year
Locate 2 , 1
Lcd _hour ; ":" ;
If _min < 10 Then Lcd "0" ; _min Else Lcd _min ; " "
If Pind.0 = 1 Then _min = _min + 1
If _min = 60 Then _min = 0
If Pind.1 = 1 Then _min = _min - 1
If _min = 255 Then _min = 59
Debounce Pind.2 , 1 , Zeit_speichern
Waitms 250
Goto Minute_stellen_1
'------------------------------Zeiten in DS1337 speichern---------------------------------
Zeit_speichern:
Wotag = Makebcd(wotag)
_day = Makebcd(_day)
_month = Makebcd(_month)
_year = Makebcd(_year)
Rem Datumsetzen
I2cstart
I2cwbyte Ds1307w
I2cwbyte 3
I2cwbyte Wotag
I2cwbyte _day
I2cwbyte _month
I2cwbyte _year
I2cstop
_sec = 00
_sec = Makebcd(_sec)
_min = Makebcd(_min)
_hour = Makebcd(_hour)
Rem Zeitsetzen
I2cstart
I2cwbyte Ds1307w
I2cwbyte 0
I2cwbyte _sec
I2cwbyte _min
I2cwbyte _hour
I2cstop
Cls
Goto Anzeige
'------------------------------------------------------------------------------------------
Vorspann:
Locate 1 , 1
Lcd "Probe RTC DS1307"
Locate 2 , 7
Lcd "V.1.1"
Wait 2
Cls
Return
'------------------------------------------------------------------------------------------
'Dcfsyncron:
'Enable Interrupts
'Warten:
'If Dcf_status.7 = 1 Then Goto Abgleichen
'Goto Warten
'Abgleichen:
'Waitms 200
'Disable Interrupts
'Sekunde = _sec
'Minute = _min
'Stunde = _hour
'Wotag = Dayofweek()
'Tag = _day
'Monat = _month
'Jahr = _year
'Dcf_status.7 = 0
'Goto Zeit_speichern
End
Tagname:
Data "Mo" , "Di" , "Mi" , "Do" , "Fr" , "Sa" , "So"
'-------------------------------------------------------------------------------
'-----------------------DATENTABELLE FÜR MONATSNAMEN----------------------------
'-------------------------------------------------------------------------------
Monatsnamen:
Data " " , "Jan" , "Feb" , "Mar" , "Apr" , "Mai" , "Jun" , "Jul" , "Aug" , "Sep" , "Okt" , "Nov" , "Dez"
Also das erste was mir aufgefallen ist ... die GOTOs machen alles ungeheuer
unübersichtlich und schlecht zu durchblicken für die Fehlersuche ...
Da sollte man mal den Rotstift ansetzen (nennt man auch Redesign).
Für nen genaueren Blick ist mir das allerdings schon etwas spät.
Wegen der ganzen GOTOs kann ich das Proggi auch nicht mal schnell
durchblicken wie wo was an welcher Stelle abläuft. Außerdem kannst du dir
mit den GOTOs auch schnell nen Stacküberlauf einfangen wenn du zusätzlich
noch GOSUBs/CALLs einsetzt. Also ich würde das an deiner Stelle erst mal
"etwas" überarbeiten
Aber mehr irgendwann später ... (die Tage ...) oder von nem anderen ...
Der Schaltplan sieht (so aus dem Gedächtnis
) erst mal ok aus ...
Gruß
Dino