Hallo,
ok ich habe es jetzt wie folgt gemacht.
Code:
'*******************************************************************************
'*******************************************************************************
'************************ DS1302 RealTimeClock V1.0 ****************************
'*******************************************************************************
'************************** 14.02.2014 by CYBORG *******************************
'*******************************************************************************
'*******************************************************************************
'****************************** Allgemein **************************************
$regfile = "m88def.dat"
$crystal = 8000000
$hwstack = 48
$swstack = 48
$framesize = 48
$baud = 19200
'************************* I2C - DISPLAY 1602 **********************************
$lib "YwRobot_Lcd_i2c.lib" 'I2C LCD
Const Pcf8574_lcd = &H4E 'LCD Adresse
Dim Lcd_backlight As Byte
Lcd_backlight = 1 'Hintergrundbeleuchtung einschalten (1/0)
Config Scl = Portc.5 'i2c SCL
Config Sda = Portc.4 'i2c SDA
Config Lcd = 16 * 2 'nicht unbedingt nötig
Config I2cdelay = 1
Waitms 300 'warte bis Kondensator bei Ta0 geladen, auch für LCD-Init!
Cls
Waitms 300
'************************ DS1302 RealTimeClock *********************************
Declare Function Rtc_get(byval Rtc_cmd As Byte ) As String * 2
Declare Sub Rtc_set(byval Rtc_cmd As Byte , Byval Rtc_data As Byte)
Rtc_rst Alias Portd.6
Config Pind.6 = Output
Rtc_clk Alias Portb.0
Config Pinb.0 = Output
Rtc_in Alias Pind.7
Rtc_out Alias Portd.7
Config Rtc_in = Output
Const Rtc_sec = &H80
Const Rtc_min = &H82
Const Rtc_hour = &H84
Const Rtc_day = &H86
Const Rtc_month = &H88
Const Rtc_wday = &H8A
Const Rtc_year = &H8C
Const Rtc_wp = &H8E
Const Rtc_tcs = &H90
'Uhr konfigurieren
Rtc_set Rtc_wp , &B00000000 'Schreibschutz / WP=BIT7 / &B00000000=aus / &B10000000=an
Rtc_set Rtc_tcs , &B10100101 'Batterieladung einstellen / 1 Diode, 2kOhm ~ 2,2mA
Rtc_set Rtc_sec , &B00000000 'Sekunden einstellen / CH=BIT7 / 0,1=an,aus
Rtc_set Rtc_min , &B01011001 'Minuten einstellen
Rtc_set Rtc_hour , &B00100011 'Stunden einstellen
Rtc_set Rtc_day , &B00010100 'Tag einstellen
Rtc_set Rtc_month , &B00000010 'Monat einstellen
Rtc_set Rtc_year , &B00010100 'Jahr einstellen
Rtc_set Rtc_wday , &B00000101 'Wochentag einstellen
Wait 1
'***************************** HAUPTSCHLEIFE ***********************************
Do
'Zeit
Locate 1 , 1
Lcd Rtc_get(rtc_hour) ; ":" ; Rtc_get(rtc_min) ; ":" ; Rtc_get(rtc_sec)
'Datum
Locate 2 , 1
Lcd Rtc_get(rtc_day) ; "/" ; Rtc_get(rtc_month) ; "/" ; Rtc_get(rtc_year)
'Wochentag
Locate 2 , 12
Lcd "WT:" ; Rtc_get(rtc_wday)
Waitms 300
Loop
End
'***************************** RTC-FUNCTIONS ***********************************
'******************************** RTC-SET **************************************
Sub Rtc_set(byval Rtc_cmd As Byte , Rtc_data As Byte)
Config Rtc_in = Output
Set Rtc_rst
Waitms 1
Shiftout Rtc_out , Rtc_clk , Rtc_cmd , 3 , 8 , 200
Shiftout Rtc_out , Rtc_clk , Rtc_data , 3 , 8 , 200
Waitms 1
Reset Rtc_rst
End Sub
'******************************** RTC-GET **************************************
Function Rtc_get(byval Rtc_cmd As Byte ) As Byte
Rtc_cmd = Rtc_cmd + 1
Config Rtc_in = Output
Set Rtc_rst
Waitms 1
Shiftout Rtc_out , Rtc_clk , Rtc_cmd , 3 , 7 , 500
Config Rtc_in = Input
Shiftin Rtc_in , Rtc_clk , Rtc_cmd , 2 , 8 , 500
Config Rtc_in = Output
Waitms 1
Reset Rtc_rst
Rtc_get = Bcd(rtc_cmd)
End Function
mfG
Mario
Lesezeichen