Guten Tag zusammen!
Ich möchte mich hier nochmal melden.
Habe die Steuerplatine der alten Uhr um der es hier geht ausgetauscht.
Siehe Bilder im Anhang. Das ging auch ganz gut.
Nach ein par Stunden Verdrahten habe ich zum ersten Mal eingeschaltet.
Und siehe da sie läuft!
Bei genauen Hinsehen bemerkte ich aber das nur Sekunden und Minutenzeiger laufen.
Stundenzeiger nicht.
Die Variablen _hour u.s.w werden durch DCF nicht gesetzt.
DCF Synconisation findet nicht statt.
Mit diesen Problem ärgere ich mich jetzt schon Tage rum.
Habe im Programm zum test Dcf_status über Terminal anzeigen lassen.
Bit 7 wird nie gestzt.
Mit Ozzi am Ausgang des DCF Moduls kann mann Impulse feststellen.
CodeBox BascomAVR
'#####################################################################
' Atmega 128
' DCF77 Conrad, COM2, RTC DS1307
'
'
'##############################################################################
'------------------------------------------------------------------------------
' Compilerinstruktionen und Compilerdirektiven
'------------------------------------------------------------------------------
$Regfile="m128def.dat"
$Crystal=16000000
$hwstack=128
$swstack=128
$framesize=128
'========== Hardware Uart für Terminal ==========
Config com2 = 19200 , Synchrone = 0 , Parity = None , Stopbits = 1 , Databits = 8 , Clockpol = 0
Open "com2:" For Binary As #2 'Uart an Pin: PD2;PD3
' print #2, "test"
' Change the baud rate in a program:
' Baud = 9600
' Eine separate Angabe einer LIB für DCF77 ist bei BASCOM gar nicht notwendig
' ========== TWI i2c ==========
' AVR Controller, die I2C hardwaremäßig Unterstützen, haben das TWI-Modul,
' die Ports für Data und Clock sind dabei vorgegeben. TWI ist bei den meisten
' ATMegas vorhanden, z.B. dem ATMega32.
' $lib "ds1307clock_ger.lib"
$lib "i2c_twi.lbx" ' Für Hardware TWI
Config Twi = 100000 ' wanted clock frequency when using $lib "i2c_twi.lbx"
' bei Software I2C:
'Config Scl = Portd.0 ' Ports angeben wenn Software I2C
'Config Sda = Portd.1
I2cinit ' we need to set the pins in the proper state
' TWI gleich einschalten, das macht Bascom ansonsten erst beim I2CStart !
TWCR = &B00000100 ' nur TWEN setzen
'------------------------------------------------------------------------------
' Definition von Variablen, Konstaten
'------------------------------------------------------------------------------
' ----- DCF77 -----
Dim Dcf77_hour As Byte ' Globale Stundenvariable
Dim Dcf77_min As Byte ' Globale Minutenvariable
Dim Dcf77_sec As Byte ' Globale Sekundenvariable
Dim Dcf77_weekday As Byte ' Globaler Wochentag
Dim Dcf77_day As Byte ' Globale Tagvariable
Dim Dcf77_month As Byte ' Globale Monatsvariable
Dim Dcf77_year As Byte ' Globale Jahresvariable
' ----- RTC DS1307/DS3231 -----
Const Rtc_address_write = &Hd0 'Adresse des DS1307 = &Hd0 (schreiben)
Const Rtc_address_read = &Hd1 ' 'Adresse des DS1307 = &Hd1 (lesen)
Const Rtc_address_seconds = &H00
Const Rtc_address_minutes = &H01
Const Rtc_address_hours = &H02
Const Rtc_address_day = &H03
Const Rtc_address_date = &H04
Const Rtc_address_month = &H05
Const Rtc_address_year = &H06
Const Rtc_address_control = &H07
' ----- RTC DS1307 -----
'Dim Rtc_control_test_value As Byte
'Rtc_control_test_value = &B00000000
' | | || RS1 RS0 SQWE Output Frequency
' | | |+---- RS0 0 0 1 Hz
' | | +----- RS1 0 1 4.096 kHz
' | +-------- SQWE 1 0 8.192 kHz
' +----------- OUT 1 1 32.768 kHz
'========== Fuer Berechnung der Zeigerposition ==========
Dim tempe as byte
dim TempB as byte
dim TreiberIC as byte '1-4 für Minuten, Sekunden und 5-8 für die Stunden (BCD-Treiber)
'--Pausen fuer Muliplex,
'Ueber die nächsten zwei Variablen, reduziere ich die Helligkeit des Sekundenzeigers
'zu Gunsten der Helligkeit von Stunden und Minuten
Const PauseMin = 12
const PauseSec = 2
Dim dayOld as byte 'zu Feststellen, ob die Uhr tägl. syncronisiert
Config porte = Output 'Select Treiber IC 1-8
Config Portc = Output 'Binäre Ausgabe der Zeit
Config porta.0 = Output 'LED auf der Platine
Config porta.1 = Output
' Beispiele:
'PinB.1 auf Ausgang alle anderen auf Eingang
' Ddrb = &B00000010
'Pull-up aktiviert ausser PinB.1
' Portb = &B11111101
' ----- DCF77: Routinen und Einstellungen -----
' CONFIG DCF77 = pin , timer = timer [ INVERTED=inv, CHECK=check, UPDATE=upd, UPDATETIME=updtime , TIMER1SEC=tmr1sec, SWITCHPOWER=swpwr, POWERPIN=pin, POWERLEVEL = pwrlvl , SECONDTICKS=sectick ,DEBUG=dbg , GOSUB = Sectic ]
' PIN = input pin that is connected to the DCF-77 signal
' TIMER = The timer that is used to generate the compare interrupts
' INVERTED = This value is 0 by default. When you specify 1, the compiler will assume you use an inverted DCF signal.
' CHECK = The DCF-77 parity bits are checked
' UPDATE = Upd determines how often the internal date/time variables are updated with the DCF received values.
' UPDATETIME = This value depends on the used UPDATE parameter.
' TIMER1SEC = 16 bit timers with the right crystal value can generate a precise interrupt that fires every second.
' SWITCHPOWER = This option can be used to turn on/off the DCF-77 module with the control of a port pin.
' POWERPIN = The name of a pin like pinB.2 that will be used to turn on/off the DCF module.
' POWERLEVEL = This option controls the level of the output pin that will result in a power ON for the module.
' SECONDTICKS = The number of times that the DCF signal state is read.
' DEBUG = Optional value to fill 2 variables with debug info.
' GOSUB = The Sectic option will call a label in the main program every second.
' Config mit stündlichem Update
' Config Dcf77 = Pinb.2 , Timer = 1 , Inverted = 0 , Check = 1 , Update = 1 , Updatetime = 59 , Timer1sec = 1 , Debug = 1 , Gosub = Sectic
Config Dcf77 = Pina.7 , Timer = 1 , Inverted = 1 , Check = 1 , Update = 0 , Updatetime = 59 , Timer1sec = 1 , Debug = 1 ' , Gosub = Sectic
' | | | | | | | |
' Use PinB.0 ---+ | | | | | | |
' Timer 1 is default ----+ | | | | | |
' DCF77 signal wird invertiert + | | | | |
' Vergleich akt. Minutes mit vorheriger Minute ------+ | | | |
' Perform kontinuierliches Update der empfangenen Daten --------+ | | |
' Updatetime ist nicht relevant da Update = 0 ------------------+ | | |
' Timer sorgt fuer SoftClock Update ------------------------------------------+ | |
' Switchpower, Powerpin und Powerlevel wird nicht benutzt da Interface nicht vorhanden! | |
' Secondticks wird dem Compiler ueberlassen und nicht neu gesetzt! | |
' Debug fuer die Variablen bDCF_Pause und bDCF_Impuls ist aktiv -----------------------------+ |
' Jede Sekunde wird Gosub-Routine Dcf77_sectic angesprungen ----------------------------------------------+
'##############################################################################
' Beim Einstellen der Datum-/Zeitfunktion in BASCOM dabei werden automatisch die Variablen
' _year,
' _month,
' _day,
' _hour,
' _min,
' _sec
' im BCD Format angelegt
' Datumsformat deutsch Tag.Monat.Jahr und als Trennzeichen den Punkt
Config Date = Dmy , Separator = . ' Datumsformat einstellen
Enable Interrupts ' Interrupts aktivieren
' ----- DCF77 -----
Dim Sec_old As Byte ' Schleifenvaraible SoftClock Sec
Sec_old = 99
Dim Dcfsec_old As Byte ' Schleifenvariable DCF77 Sec
Dcfsec_old = 99
Dim Dcf_sync_count As Byte ' Zähler fuer Anzahl der Syncs
Dcf_sync_count = 0
Dim Temp_byte_1 As Byte ' Temporäre Byte Variable
'##############################################################################
' Hauptprogramm
'##############################################################################
Gosub Rtc_set_softclock
' Led Spielerei beim Start
while Temp_byte_1 < 4
set porta.0
waitms 500
reset porta.0
set porta.1
waitms 500
reset porta.1
incr Temp_byte_1
wend
' Folgende Zeilen zum Test Dcf_status
' DCF77 Statusbits abfragen und maskieren
Temp_byte_1 = Dcf_status And &H80
print #2, "Dcf_status"
Print #2, Dcf_status
print #2, "Temp_byte_1"
Print #2, Temp_byte_1
Do
' DCF77 Statusbits abfragen und maskieren
Temp_byte_1 = Dcf_status And &H80
' Pruefung ob SoftClock durch DCF77 synchronisiert (Bit 7 aus Statusbyte)
If Temp_byte_1 = &H80 then
Incr Dcf_sync_count ' Sync-Counter erhören
Reset Dcf_status.7 ' Zur Kontrolle bei erfolgreichem SYNC Status-Bit zuruecksetzen
' DS1307 synchronisieren
Gosub Rtc_set_rtc_clock
End If
' Beim Tageswechsel pruefen ob DCF77 syncronisirt
if dayOld <> _day then
DayOld = _day
if Dcf_sync_count <= 2 then 'wenn nicht mehr als eine Syncronisation
Dcf_sync_count = 0 'Sync zuruecksetzen (noch keine Sync)
Gosub RTC_set_softclock 'Da kein dcf-Empfang, zeit aus RTC holen
else
Dcf_sync_count = 1 'Sync auf 1 stellen, Syncronisation hat stadgefunden
endif
endif
' ----- Datum und Uhrzeit BCD formatieren und formatiert auf LCD ausgeben -----
Dcf77_hour = Makebcd(_hour)
Dcf77_min = Makebcd(_min)
Dcf77_sec = Makebcd(_sec)
'Dcf77_weekday = Makebcd(_weekday)
'Dcf77_day = Makebcd(_day)
'Dcf77_month = Makebcd(_month)
'Dcf77_year = Makebcd(_year)
' ##############################################################################################
' Stunden berechen
' ##############################################################################################
tempe = _hour
'24h zurueck auf 12h
if tempe > 12 then
tempe = tempe - 12
endif
tempe = tempe *5 ' eine Stunde = 60min,
TempB = _min /12 ' Stundenzeiger alle 12min um 1me min weiter
tempe = tempe + TempB
TreiberIC = 5 ' Stunden werden mit Treiber 5-8 angezeigt
while tempe >= 15
tempe = tempe -15
incr TreiberIC
wend
porte = 255 ' alle TreiberIC aus
portc = tempe 'Portc stellen
'TreiberIC auswählen und einschalten
Select Case TreiberIc
'Case 1 : porte.0 = 0
'Case 2 : porte.1 = 0
'Case 3 : porte.2 = 0
'Case 4 : porte.3 = 0
Case 5 : porte.4 = 0
Case 6 : porte.5 = 0
Case 7 : porte.6 = 0
Case 8 : porte.7 = 0
' Folgende 4 Zeilen sind original Original:
' Case 5 : Porte.5 = 0 'Fehler beim Verbinden, Stunden Treiberic mit 2 begonnen
' Case 6 : Porte.6 = 0
' Case 7 : Porte.7 = 0
' Case 8 : Porte.4 = 0
End Select
Waitms PauseMin
' ##############################################################################################
' Minuten berechen
' ##############################################################################################
tempe= _min
TreiberIC = 1
while tempe >= 15
tempe = tempe -15
incr TreiberIC
wend
porte = 255 ' alle TreiberIC aus
portc = tempe 'Portc stellen
Select Case TreiberIc
Case 1 : porte.0 = 0
Case 2 : porte.1 = 0
Case 3 : porte.2 = 0
Case 4 : porte.3 = 0
' Case 5 : porte.5 = 0
' Case 6 : porte.6 = 0
' Case 7 : porte.7 = 0
' Case 8 : porte.4 = 0
End Select
Waitms PauseMin
' ##############################################################################################
' Sechkunden berechen
' ##############################################################################################
tempe= _sec
'wen noch kein DCF sync (Zeiger spingt alle 2 Sekunden)
if Dcf_sync_count = 0 then 'noch keine Syncroniation von DCF
set porta.1 'LED auf Platine Blinkt
TempB = _sec mod 2
if TempB = 0 then 'Bei gerader Sekunde
incr tempe 'Zeiger 1Sekunde weiter stellen
if tempe > 60 then
tempe = 0
endif
else
reset porta.1
endif
endif
'zu Kontrolle beim 2. sync LED auf Plantine ein
if Dcf_sync_count >= 2 then
reset porta.0
else
set porta.0
endif
TreiberIC = 1
while tempe >= 15
tempe = tempe -15
incr TreiberIC
wend
porte = 255 ' alle TreiberIC aus
portc = tempe 'Portc stellen
Select Case TreiberIc
Case 1 : porte.0 = 0
Case 2 : porte.1 = 0
Case 3 : porte.2 = 0
Case 4 : porte.3 = 0
' Case 5 : porte.5 = 0
'Case 6 : porte.6 = 0
' Case 7 : porte.7 = 0
'Case 8 : porte.4 = 0
End Select
Waitms PauseSec
Loop
'## End Hauptprogramm #########################################################
'------------------------------------------------------------------------------
' RTC - Gosub-Routine: Rtc_set_rtc_clock
' Subroutine uebernimmt bei erfolgreicher Synchronisation durch DCF77 die
' aktuellen Zeit und Datumsinformationen in die RTC DS1307
'------------------------------------------------------------------------------
Rtc_set_rtc_clock:
print #2, "Bin in Rtc_set_rtc_clock"
'Daten zum Speichern in BCD Format aufbereiten
Dcf77_hour = Makebcd(_hour)
Dcf77_min = Makebcd(_min)
Dcf77_sec = Makebcd(_sec)
Dcf77_weekday = Makebcd(_weekday)
Dcf77_day = Makebcd(_day)
Dcf77_month = Makebcd(_month)
Dcf77_year = Makebcd(_year)
'RTC DS1307 stellen also synchronisieren
I2cstart ' START-Sequenz senden
I2cwbyte Rtc_address_write ' Daten schreiben initiieren
I2cwbyte Rtc_address_seconds ' Adresse uebertragen = &H00
I2cwbyte Dcf77_sec ' Byte 1 uebertragen
I2cwbyte Dcf77_min ' Byte 2 uebertragen
I2cwbyte Dcf77_hour ' Byte 3 uebertragen
I2cwbyte Dcf77_weekday ' Byte 4 uebertragen
I2cwbyte Dcf77_day ' Byte 5 uebertragen
I2cwbyte Dcf77_month ' Byte 6 uebertragen
I2cwbyte Dcf77_year ' Byte 7 uebertragen
I2cstop ' STOP-Sequenz
Return
'-- End Rtc_set_rtc_clock -----------------------------------------------------
'------------------------------------------------------------------------------
' RTC - Gosub-Routine: Rtc_set_softclock
' Subroutine uebernimmt bei Aufruf der Routine die in der RTC "mitlaufenden"
' Zeitinformationen in die SoftClock.
' Damit kann bereits zu Systemstart ohne DCF77 Empfang mit "realer" Zeit
' gestartet werden.
'------------------------------------------------------------------------------
Rtc_set_softclock:
'RTC DS1307 auslesen
I2cstart ' START-Sequenz senden
I2cwbyte Rtc_address_write ' Daten schreiben initiieren
I2cwbyte Rtc_address_seconds ' Adresse uebertragen = &H00
' I2cstop ' STOP-Sequenz wird nicht zwingend benötigt
I2cstart ' START-Sequenz erneut senden
I2cwbyte Rtc_address_read ' Daten lesen initiieren
I2crbyte Dcf77_sec , Ack ' Byte 1 lesen
I2crbyte Dcf77_min , Ack ' Byte 2 lesen
I2crbyte Dcf77_hour , Ack ' Byte 3 lesen
I2crbyte Dcf77_weekday , Ack ' Byte 4 lesen
I2crbyte Dcf77_day , Ack ' Byte 5 lesen
I2crbyte Dcf77_month , Ack ' Byte 6 lesen
I2crbyte Dcf77_year , Nack ' Byte 7 lesen und fertig (NACK)
I2cstop ' STOP-Sequenz
'ausgelesene Daten in SoftClock Variablen uebernehmen
_hour = Makedec(dcf77_hour)
_min = Makedec(dcf77_min)
_sec = Makedec(dcf77_sec)
_weekday = Makedec(dcf77_weekday)
_day = Makedec(dcf77_day)
_month = Makedec(dcf77_month)
_year = Makedec(dcf77_year)
Return
'-- End Rtc_set_softclock -----------------------------------------------------
End