DAYOFWEEK/de

From MCS Wiki AVR
< DAYOFWEEK(Difference between revisions)
Jump to: navigation, search
(See Also)
(Example)
 
Line 124: Line 124:
 
<span style="font-family: Arial;">&nbsp;</span>
 
<span style="font-family: Arial;">&nbsp;</span>
  
= <span class="f_Header">Example</span> =
+
= <span class="f_Header">Beispiel</span> =
  
 
<br/><source lang="bascomavr">
 
<br/><source lang="bascomavr">
 
'-----------------------------------------------------------------------------------------
 
'-----------------------------------------------------------------------------------------
'name : datetime_test1,bas
+
'name : datetime_test1.bas
 
'copyright : (c) 1995-2005, MCS Electronics
 
'copyright : (c) 1995-2005, MCS Electronics
 
'purpose : show how to use the Date-Time routines from the DateTime.Lib
 
'purpose : show how to use the Date-Time routines from the DateTime.Lib
Line 136: Line 136:
 
'-----------------------------------------------------------------------------------------
 
'-----------------------------------------------------------------------------------------
 
   
 
   
$regfile = "m103def.dat" ' specify the used micro
+
$regfile = "m103def.dat" ' Mikrocontroller
$crystal = 4000000 ' used crystal frequency
+
$crystal = 4000000 ' Taktfrequenz
$baud = 19200 ' use baud rate
+
$baud = 19200 ' Baudrate
 
$hwstack = 32 ' default use 32 for the hardware stack
 
$hwstack = 32 ' default use 32 for the hardware stack
 
$swstack = 10 ' default use 10 for the SW stack
 
$swstack = 10 ' default use 10 for the SW stack
Line 147: Line 147:
 
   
 
   
 
#if Clockmode = 1
 
#if Clockmode = 1
Config Clock = Soft ' we use build in clock
+
Config Clock = Soft ' Interne Softclock benutzen
 
Disable Interrupts
 
Disable Interrupts
 
#else
 
#else
Config Clock = User ' we use I2C for the clock
+
Config Clock = User ' I2C Clock benutzen
'configure the scl and sda pins
+
'scl und sda Pins definieren
 
Config Sda = Portd.6
 
Config Sda = Portd.6
 
Config Scl = Portd.5
 
Config Scl = Portd.5
 
   
 
   
'address of ds1307
+
'Addresse des ds1307
Const Ds1307w = &HD0 ' Addresses of Ds1307 clock
+
Const Ds1307w = &HD0 ' Addressen der Ds1307 Clock
 
Const Ds1307r = &HD1
 
Const Ds1307r = &HD1
 
#endif
 
#endif
 
   
 
   
 
   
 
   
'configure the date format
+
'DAtumsformat konfigurieren
 
Config Date = Ymd , Separator = - ' ANSI-Format
 
Config Date = Ymd , Separator = - ' ANSI-Format
'This sample does not have the clock started so interrupts are not enabled
+
'Dieses Beispiel startet die Clock nicht. Die Interrupts werden nicht enabled
 
' Enable Interrupts
 
' Enable Interrupts
 
   
 
   
'dim the used variables
+
'VAriablen dimensionieren
 
Dim Lvar1 As Long
 
Dim Lvar1 As Long
 
Dim Mday As Byte
 
Dim Mday As Byte
Line 183: Line 183:
 
   
 
   
 
' =================== DayOfWeek =============================================
 
' =================== DayOfWeek =============================================
' Example 1 with internal RTC-Clock
+
' Beispiel 1 mit interner RTC-Clock
 
   
 
   
_day = 4 : _month = 11 : _year = 2 ' Load RTC-Clock for example - testing
+
_day = 4 : _month = 11 : _year = 2 ' Beispielwerte zuweisen
 
Bweekday = Dayofweek()
 
Bweekday = Dayofweek()
 
Strweekday = Lookupstr(bweekday , Weekdays)
 
Strweekday = Lookupstr(bweekday , Weekdays)
Print "Weekday-Number of " ; Date$ ; " is " ; Bweekday ; " = " ; Strweekday
+
Print "Wochentag von " ; Date$ ; " ist " ; Bweekday ; " = " ; Strweekday
 
   
 
   
 
   
 
   
' Example 2 with defined Clock - Bytes (Day / Month / Year)
+
' Beispiel 2 mit benutzerdefinierten Clock-Bytes (Day / Month / Year)
 
Bday = 26 : Bmonth = 11 : Byear = 2
 
Bday = 26 : Bmonth = 11 : Byear = 2
 
Bweekday = Dayofweek(bday)
 
Bweekday = Dayofweek(bday)
 
Strweekday = Lookupstr(bweekday , Weekdays)
 
Strweekday = Lookupstr(bweekday , Weekdays)
 
Strdate = Date(bday)
 
Strdate = Date(bday)
Print "Weekday-Number of Day=" ; Bday ; " Month=" ; Bmonth ; " Year=" ; Byear ; " is " ; Bweekday ; " (" ; Date(bday) ; ") = " ; Strweekday
+
Print "Wochentag von Tag=" ; Bday ; " Monat=" ; Bmonth ; " Jahr=" ; Byear ; " ist " ; Bweekday ; " (" ; Date(bday) ; ") = " ; Strweekday
 
   
 
   
 
   
 
   
' Example 3 with System Day
+
' Beispiel 3 mit Systemtag
Wsysday = 2000 ' that is 2005-06-23
+
Wsysday = 2000 ' das ist der 23.6.2005
 
Bweekday = Dayofweek(wsysday)
 
Bweekday = Dayofweek(wsysday)
 
Strweekday = Lookupstr(bweekday , Weekdays)
 
Strweekday = Lookupstr(bweekday , Weekdays)
Print "Weekday-Number of System Day " ; Wsysday ; " (" ; Date(wsysday) ; ") is " ; Bweekday ; " = " ; Strweekday
+
Print "Wochentag von Systemtag " ; Wsysday ; " (" ; Date(wsysday) ; ") ist " ; Bweekday ; " = " ; Strweekday
 
   
 
   
 
   
 
   
 
   
 
   
' Example 4 with System Second
+
' Beispiel 4 mit Systemsekunde
Lsyssec = 123456789 ' that is 2003-11-29 at 21:33:09
+
Lsyssec = 123456789 ' das ist 29.11.2003 um 21:33:09
 
Bweekday = Dayofweek(lsyssec)
 
Bweekday = Dayofweek(lsyssec)
 
Strweekday = Lookupstr(bweekday , Weekdays)
 
Strweekday = Lookupstr(bweekday , Weekdays)
Print "Weekday-Number of System Second " ; Lsyssec ; " (" ; Date(lsyssec) ; ") is " ; Bweekday ; " = " ; Strweekday
+
Print "Wochentag von Systemsekunde " ; Lsyssec ; " (" ; Date(lsyssec) ; ") ist " ; Bweekday ; " = " ; Strweekday
 
   
 
   
 
   
 
   
 
   
 
   
 
   
 
   
' Example 5 with Date-String
+
' Beispiel 5 mit Datums-String
Strdate = "04-11-02" ' we have configured Date in ANSI
+
Strdate = "04-11-02" ' wir haben das Datum im ANSI-Format definiert
 
Bweekday = Dayofweek(strdate)
 
Bweekday = Dayofweek(strdate)
 
Strweekday = Lookupstr(bweekday , Weekdays)
 
Strweekday = Lookupstr(bweekday , Weekdays)
Print "Weekday-Number of " ; Strdate ; " is " ; Bweekday ; " = " ; Strweekday
+
Print "Wochentag von" ; Strdate ; " ist " ; Bweekday ; " = " ; Strweekday
 
   
 
   
 
   
 
   
Line 226: Line 226:
 
   
 
   
 
' ================= Second of Day =============================================
 
' ================= Second of Day =============================================
' Example 1 with internal RTC-Clock
+
' Beispiel 1 mit interner RTC-Clock
_sec = 12 : _min = 30 : _hour = 18 ' Load RTC-Clock for example - testing
+
_sec = 12 : _min = 30 : _hour = 18 ' Interne Clockwerte zuweisen
 
   
 
   
 
Lsecofday = Secofday()
 
Lsecofday = Secofday()
Print "Second of Day of " ; Time$ ; " is " ; Lsecofday
+
Print "Sekunde des Tages von " ; Time$ ; " ist " ; Lsecofday
 
   
 
   
 
   
 
   
' Example 2 with defined Clock - Bytes (Second / Minute / Hour)
+
' Beispiel 2 mit benutzerdefinierter Clock - Bytes (Second / Minute / Hour)
 
Bsec = 20 : Bmin = 1 : Bhour = 7
 
Bsec = 20 : Bmin = 1 : Bhour = 7
 
Lsecofday = Secofday(bsec)
 
Lsecofday = Secofday(bsec)
Print "Second of Day of Sec=" ; Bsec ; " Min=" ; Bmin ; " Hour=" ; Bhour ; " (" ; Time(bsec) ; ") is " ; Lsecofday
+
Print "Second of Day von Sec=" ; Bsec ; " Min=" ; Bmin ; " Hour=" ; Bhour ; " (" ; Time(bsec) ; ") ist " ; Lsecofday
 
   
 
   
 
   
 
   
' Example 3 with System Second
+
' Beispiel 3 mit Systemsekunde
 
Lsyssec = 1234456789
 
Lsyssec = 1234456789
 
Lsecofday = Secofday(lsyssec)
 
Lsecofday = Secofday(lsyssec)
Print "Second of Day of System Second " ; Lsyssec ; "(" ; Time(lsyssec) ; ") is " ; Lsecofday
+
Print "Second of Day von Systemsekunde " ; Lsyssec ; "(" ; Time(lsyssec) ; ") ist " ; Lsecofday
 
   
 
   
 
   
 
   
' Example 4 with Time - String
+
' Beispiel 4 mit Zeit-String
 
Strtime = "04:58:37"
 
Strtime = "04:58:37"
 
Lsecofday = Secofday(strtime)
 
Lsecofday = Secofday(strtime)
Print "Second of Day of " ; Strtime ; " is " ; Lsecofday
+
Print "Second of Day von " ; Strtime ; " ist " ; Lsecofday
 
   
 
   
 
   
 
   
Line 254: Line 254:
 
' ================== System Second ============================================
 
' ================== System Second ============================================
 
   
 
   
' Example 1 with internal RTC-Clock
+
' Beispiel 1 mit interner RTC-Clock
  ' Load RTC-Clock for example - testing
+
  ' Testwerte zuweisen
 
_sec = 17 : _min = 35 : _hour = 8 : _day = 16 : _month = 4 : _year = 3
 
_sec = 17 : _min = 35 : _hour = 8 : _day = 16 : _month = 4 : _year = 3
 
   
 
   
 
Lsyssec = Syssec()
 
Lsyssec = Syssec()
Print "System Second of " ; Time$ ; " at " ; Date$ ; " is " ; Lsyssec
+
Print "Systemsekunde von " ; Time$ ; " at " ; Date$ ; " ist " ; Lsyssec
 
   
 
   
 
   
 
   
' Example 2 with with defined Clock - Bytes (Second, Minute, Hour, Day / Month / Year)
+
' Beispiel 2 wmit benutzerdefinierten Clock-Bytes (Second, Minute, Hour, Day / Month / Year)
 
Bsec = 20 : Bmin = 1 : Bhour = 7 : Bday = 22 : Bmonth = 12 : Byear = 1
 
Bsec = 20 : Bmin = 1 : Bhour = 7 : Bday = 22 : Bmonth = 12 : Byear = 1
 
Lsyssec = Syssec(bsec)
 
Lsyssec = Syssec(bsec)
 
Strtime = Time(bsec)
 
Strtime = Time(bsec)
 
Strdate = Date(bday)
 
Strdate = Date(bday)
Print "System Second of " ; Strtime ; " at " ; Strdate ; " is " ; Lsyssec
+
Print "Systemsekunde von" ; Strtime ; " at " ; Strdate ; " ist " ; Lsyssec
 
   
 
   
 
   
 
   
' Example 3 with System Day
+
' Beispiel 3 mit Systemtag
 
   
 
   
 
Wsysday = 2000
 
Wsysday = 2000
 
Lsyssec = Syssec(wsysday)
 
Lsyssec = Syssec(wsysday)
Print "System Second of System Day " ; Wsysday ; " (" ; Date(wsysday) ; " 00:00:00) is " ; Lsyssec
+
Print "Systemsekunde von System Day " ; Wsysday ; " (" ; Date(wsysday) ; " 00:00:00) ist " ; Lsyssec
 
   
 
   
 
   
 
   
' Example 4 with Time and Date String
+
' Beispiel 4 mit Time- und Date-String
 
Strtime = "10:23:50"
 
Strtime = "10:23:50"
Strdate = "02-11-29" ' ANSI-Date
+
Strdate = "02-11-29" ' ANSI-Datum
 
Lsyssec = Syssec(strtime , Strdate)
 
Lsyssec = Syssec(strtime , Strdate)
Print "System Second of " ; Strtime ; " at " ; Strdate ; " is " ; Lsyssec ' 91880630
+
Print "System Second von " ; Strtime ; " am " ; Strdate ; " ist " ; Lsyssec ' 91880630
 
   
 
   
 
   
 
   
Line 287: Line 287:
 
   
 
   
 
' ==================== Day Of Year =========================================
 
' ==================== Day Of Year =========================================
' Example 1 with internal RTC-Clock
+
' Beispiel 1 mit interner RTC-Clock
_day = 20 : _month = 11 : _year = 2 ' Load RTC-Clock for example - testing
+
_day = 20 : _month = 11 : _year = 2 ' Testwerte zuweisen
 
Wdayofyear = Dayofyear()
 
Wdayofyear = Dayofyear()
 
Print "Day Of Year of " ; Date$ ; " is " ; Wdayofyear
 
Print "Day Of Year of " ; Date$ ; " is " ; Wdayofyear
 
   
 
   
 
   
 
   
' Example 2 with defined Clock - Bytes (Day / Month / Year)
+
' Beispiel 2 mit benutzerdefinierten Clock-Bytes (Day / Month / Year)
 
Bday = 24 : Bmonth = 5 : Byear = 8
 
Bday = 24 : Bmonth = 5 : Byear = 8
 
Wdayofyear = Dayofyear(bday)
 
Wdayofyear = Dayofyear(bday)
Print "Day Of Year of Day=" ; Bday ; " Month=" ; Bmonth ; " Year=" ; Byear ; " (" ; Date(bday) ; ") is " ; Wdayofyear
+
Print "Day Of Year von Tag=" ; Bday ; " Monat=" ; Bmonth ; " Jahr=" ; Byear ; " (" ; Date(bday) ; ") ist " ; Wdayofyear
 
   
 
   
 
   
 
   
 
   
 
   
' Example 3 with Date - String
+
' Beispiel 3 mit Datums-String
Strdate = "04-10-29" ' we have configured ANSI Format
+
Strdate = "04-10-29" ' ANSI-Format
 
Wdayofyear = Dayofyear(strdate)
 
Wdayofyear = Dayofyear(strdate)
Print "Day Of Year of " ; Strdate ; " is " ; Wdayofyear
+
Print "Day Of Year von " ; Strdate ; " ist " ; Wdayofyear
 
   
 
   
 
   
 
   
' Example 4 with System Second
+
' Beispiel 4 mit Systemsekunde
 
   
 
   
 
Lsyssec = 123456789
 
Lsyssec = 123456789
 
Wdayofyear = Dayofyear(lsyssec)
 
Wdayofyear = Dayofyear(lsyssec)
Print "Day Of Year of System Second " ; Lsyssec ; " (" ; Date(lsyssec) ; ") is " ; Wdayofyear
+
Print "Day Of Year von Systemsekunde " ; Lsyssec ; " (" ; Date(lsyssec) ; ") ist " ; Wdayofyear
 
   
 
   
 
   
 
   
' Example 5 with System Day
+
' Beispiel 5 mit System Day (Systemtag)
 
Wsysday = 3000
 
Wsysday = 3000
 
Wdayofyear = Dayofyear(wsysday)
 
Wdayofyear = Dayofyear(wsysday)
Print "Day Of Year of System Day " ; Wsysday ; " (" ; Date(wsysday) ; ") is " ; Wdayofyear
+
Print "Day Of Year von Systemtag " ; Wsysday ; " (" ; Date(wsysday) ; ") ist " ; Wdayofyear
 
   
 
   
 
   
 
   
 
' =================== System Day ======================================
 
' =================== System Day ======================================
' Example 1 with internal RTC-Clock
+
' Beispiel 1 mit internaer RTC-Clock
_day = 20 : _month = 11 : _year = 2 ' Load RTC-Clock for example - testing
+
_day = 20 : _month = 11 : _year = 2 ' Testwerte zuweisen
 
Wsysday = Sysday()
 
Wsysday = Sysday()
 
Print "System Day of " ; Date$ ; " is " ; Wsysday
 
Print "System Day of " ; Date$ ; " is " ; Wsysday
 
   
 
   
 
   
 
   
' Example 2 with defined Clock - Bytes (Day / Month / Year)
+
' Beispiel 2 mit benutzerdefinierten Clock-Bytes (Day / Month / Year)
 
Bday = 24 : Bmonth = 5 : Byear = 8
 
Bday = 24 : Bmonth = 5 : Byear = 8
 
Wsysday = Sysday(bday)
 
Wsysday = Sysday(bday)
Print "System Day of Day=" ; Bday ; " Month=" ; Bmonth ; " Year=" ; Byear ; " (" ; Date(bday) ; ") is " ; Wsysday
+
Print "System Day von Tag=" ; Bday ; " Monat=" ; Bmonth ; " Jahr=" ; Byear ; " (" ; Date(bday) ; ") ist " ; Wsysday
 
   
 
   
 
   
 
   
' Example 3 with Date - String
+
' Beispiel 3 mit Date-String
 
Strdate = "04-10-29"
 
Strdate = "04-10-29"
 
Wsysday = Sysday(strdate)
 
Wsysday = Sysday(strdate)
Print "System Day of " ; Strdate ; " is " ; Wsysday
+
Print "System Day von " ; Strdate ; " ist " ; Wsysday
 
   
 
   
' Example 4 with System Second
+
' Beispiel 4 mit Systemsekunde
 
Lsyssec = 123456789
 
Lsyssec = 123456789
 
Wsysday = Sysday(lsyssec)
 
Wsysday = Sysday(lsyssec)
Print "System Day of System Second " ; Lsyssec ; " (" ; Date(lsyssec) ; ") is " ; Wsysday
+
Print "System Day von Systemsekunde " ; Lsyssec ; " (" ; Date(lsyssec) ; ") ist " ; Wsysday
 
   
 
   
 
   
 
   
 
   
 
   
 
' =================== Time ================================================
 
' =================== Time ================================================
' Example 1: Converting defined Clock - Bytes (Second / Minute / Hour) to Time - String
+
' Beispiel 1: Umwandlung benutzerdefinierter Clock-Bytes (Second / Minute / Hour) zu Time-String
 
Bsec = 20 : Bmin = 1 : Bhour = 7
 
Bsec = 20 : Bmin = 1 : Bhour = 7
 
Strtime = Time(bsec)
 
Strtime = Time(bsec)
Print "Time values: Sec=" ; Bsec ; " Min=" ; Bmin ; " Hour=" ; Bhour ; " converted to string " ; Strtime
+
Print "Time values: Sec=" ; Bsec ; " Min=" ; Bmin ; " Hour=" ; Bhour ; " umgewandelt zu String " ; Strtime
 
   
 
   
 
   
 
   
' Example 2: Converting System Second to Time - String
+
' Beispiel 2: Umwandlung Systemsekunde zu Time-String
 
Lsyssec = 123456789
 
Lsyssec = 123456789
 
Strtime = Time(lsyssec)
 
Strtime = Time(lsyssec)
Line 357: Line 357:
 
   
 
   
 
   
 
   
' Example 3: Converting Second of Day to Time - String
+
' Beispiel 3: Umwandlung Second of Day zu Time-String
 
Lsecofday = 12345
 
Lsecofday = 12345
 
Strtime = Time(lsecofday)
 
Strtime = Time(lsecofday)
Print "Time of Second of Day " ; Lsecofday ; " is " ; Strtime
+
Print "Time von Second of Day " ; Lsecofday ; " ist " ; Strtime
 
   
 
   
 
   
 
   
' Example 4: Converting System Second to defined Clock - Bytes (Second / Minute / Hour)
+
' Beispiel 4: Umwandlung System Second zu benutzerdefinierten Clock-Bytes (Second / Minute / Hour)
 
   
 
   
 
Lsyssec = 123456789
 
Lsyssec = 123456789
 
Bsec = Time(lsyssec)
 
Bsec = Time(lsyssec)
Print "System Second " ; Lsyssec ; " converted to Sec=" ; Bsec ; " Min=" ; Bmin ; " Hour=" ; Bhour ; " (" ; Time(lsyssec) ; ")"
+
Print "System Second " ; Lsyssec ; " umgewandelt zu Sec=" ; Bsec ; " Min=" ; Bmin ; " Hour=" ; Bhour ; " (" ; Time(lsyssec) ; ")"
 
   
 
   
 
   
 
   
 
   
 
   
' Example 5: Converting Second of Day to defined Clock - Bytes (Second / Minute / Hour)
+
' Beispiel 5: Umwandlung Second of Day zu benutzerdefinierten Clock-Bytes (Second / Minute / Hour)
 
Lsecofday = 12345
 
Lsecofday = 12345
 
Bsec = Time(lsecofday)
 
Bsec = Time(lsecofday)
Print "Second of Day " ; Lsecofday ; " converted to Sec=" ; Bsec ; " Min=" ; Bmin ; " Hour=" ; Bhour ; " (" ; Time(lsecofday) ; ")"
+
Print "Second of Day " ; Lsecofday ; " umgewandelt zu Sec=" ; Bsec ; " Min=" ; Bmin ; " Hour=" ; Bhour ; " (" ; Time(lsecofday) ; ")"
 
   
 
   
' Example 6: Converting Time-string to defined Clock - Bytes (Second / Minute / Hour)
+
' Beispiel 6: Umwandlung Time-string zu benutzerdefinierten Clock-Bytes (Second / Minute / Hour)
 
Strtime = "07:33:12"
 
Strtime = "07:33:12"
 
Bsec = Time(strtime)
 
Bsec = Time(strtime)
Print "Time " ; Strtime ; " converted to Sec=" ; Bsec ; " Min=" ; Bmin ; " Hour=" ; Bhour
+
Print "Time " ; Strtime ; " umgewandelt zu Sec=" ; Bsec ; " Min=" ; Bmin ; " Hour=" ; Bhour
 
   
 
   
 
   
 
   
Line 385: Line 385:
 
' ============================= Date ==========================================
 
' ============================= Date ==========================================
 
   
 
   
' Example 1: Converting defined Clock - Bytes (Day / Month / Year) to Date - String
+
' Beispiel 1: Umwandlung benutzerdefinierter Clock-Bytes (Day / Month / Year) zu Date-String
 
Bday = 29 : Bmonth = 4 : Byear = 12
 
Bday = 29 : Bmonth = 4 : Byear = 12
 
Strdate = Date(bday)
 
Strdate = Date(bday)
Print "Dat values: Day=" ; Bday ; " Month=" ; Bmonth ; " Year=" ; Byear ; " converted to string " ; Strdate
+
Print "Datumswerte: Tag=" ; Bday ; " Monat=" ; Bmonth ; " Jahr=" ; Byear ; " umgewandelt zu String " ; Strdate
 
   
 
   
 
   
 
   
' Example 2: Converting from System Day to Date - String
+
' Beispiel 2: Umwandlung von Systemtag zu Dat- String
 
Wsysday = 1234
 
Wsysday = 1234
 
Strdate = Date(wsysday)
 
Strdate = Date(wsysday)
Print "System Day " ; Wsysday ; " is " ; Strdate
+
Print "System Day " ; Wsysday ; " ist " ; Strdate
 
   
 
   
 
   
 
   
' Example 3: Converting from System Second to Date String
+
' Beispiel 3: Umwandlung von Systemsekunde zu Date-String
 
Lsyssec = 123456789
 
Lsyssec = 123456789
 
Strdate = Date(lsyssec)
 
Strdate = Date(lsyssec)
Print "System Second " ; Lsyssec ; " is " ; Strdate
+
Print "Systemsekunde " ; Lsyssec ; " ist " ; Strdate
 
   
 
   
 
   
 
   
' Example 4: Converting SystemDay to defined Clock - Bytes (Day / Month / Year)
+
' Beispiel 4: Umwandlung SystemDay zu benutzerdefinierten Clock-Bytes (Day / Month / Year)
 
   
 
   
 
Wsysday = 2000
 
Wsysday = 2000
 
Bday = Date(wsysday)
 
Bday = Date(wsysday)
Print "System Day " ; Wsysday ; " converted to Day=" ; Bday ; " Month=" ; Bmonth ; " Year=" ; Byear ; " (" ; Date(wsysday) ; ")"
+
Print "Systemtag " ; Wsysday ; " umgewandelt zu Tag=" ; Bday ; " Monat=" ; Bmonth ; " Jahr=" ; Byear ; " (" ; Date(wsysday) ; ")"
 
   
 
   
 
   
 
   
' Example 5: Converting Date - String to defined Clock - Bytes (Day / Month / Year)
+
' Beispiel 5: Umwandlung Date-String zu benutzerdefinierten Clock-Bytes (Day / Month / Year)
 
Strdate = "04-08-31"
 
Strdate = "04-08-31"
 
Bday = Date(strdate)
 
Bday = Date(strdate)
Print "Date " ; Strdate ; " converted to Day=" ; Bday ; " Month=" ; Bmonth ; " Year=" ; Byear
+
Print "Datum " ; Strdate ; " umgewandelt zu Tag=" ; Bday ; " Monat=" ; Bmonth ; " Jahr=" ; Byear
 
   
 
   
 
   
 
   
' Example 6: Converting System Second to defined Clock - Bytes (Day / Month / Year)
+
' Beispiel 6: Umwandlung Systemsekunde zu benutzerdefinierten Clock-Bytes (Day / Month / Year)
 
Lsyssec = 123456789
 
Lsyssec = 123456789
 
Bday = Date(lsyssec)
 
Bday = Date(lsyssec)
Print "System Second " ; Lsyssec ; " converted to Day=" ; Bday ; " Month=" ; Bmonth ; " Year=" ; Byear ; " (" ; Date(lsyssec) ; ")"
+
Print "Systemsekunde " ; Lsyssec ; " umgewandelt zu Tag=" ; Bday ; " Monat=" ; Bmonth ; " Jahr=" ; Byear ; " (" ; Date(lsyssec) ; ")"
 
   
 
   
 
   
 
   
Line 438: Line 438:
 
Looptest:
 
Looptest:
 
   
 
   
' Initialising for testing
+
' Testwerte
 
_day = 1
 
_day = 1
 
_month = 1
 
_month = 1
Line 582: Line 582:
 
   
 
   
 
Weekdays:
 
Weekdays:
Data "Monday" , "Tuesday" , "Wednesday" , "Thursday" , "Friday" , "Saturday" , "Sunday"
+
Data "Montag" , "Dienstag" , "Mittwoch" , "Donnerstag" , "Freitag" , "Sonnabend" , "Sonntag"
 
</source><br/>{{Languages}}
 
</source><br/>{{Languages}}
  
 
[[Category:BASCOM Language Reference/de]]
 
[[Category:BASCOM Language Reference/de]]

Latest revision as of 01:05, 19 March 2013

Contents

Funktion

Gibt den Wochentag für ein Datum zurück.

 

 

Syntax

Target = DayOfWeek()

Target = DayOfWeek(bDayMonthYear)

Target = DayOfWeek(strDate)

Target = DayOfWeek(wSysDay)

Target = DayOfWeek(lSysSec)

 

 

Anmerkungen

Target

Bytevariable der die Nummer des Wochentags zugewiesen wird.

BDayMonthYear

Bytevariable, die den Tag enthält - gefolgt vom Monat (Byte) und Jahr (Byte)

StrDate

String der das Datum als Zeichenkette enthält im Format wie im CONFIG DATE Befehl beschreiben.


WSysDay

Wordvariable die den Systemtag (SysDay) enthält.

LSysSec

Longvariable die die Systemsekunde (SysSec) enthält.

 

 

Die Funktion kann mit fünf verschiedenen Arten von Input benutzt werden:

 

1. Ohne Parameter. Die internen Werte der SOFTCLOCK (_day, _month, _year) werden benutzt.
2. Mit einem benutzerdefinierten Array. Dieses muss in derselben Art angeordnet sein (Day, Month, Year) wie das interne SOFTCLOCK-Datum. Das erste Byte (Day) ist der Eingabewert bei dieser Art der Benutzung. Auf diese Weise kann der Wochentag für jedes Daum berechnet werden.
3. Mit einem Datums-String. Der Datums-String muss im selben Format wie im CONFIG DATE Befehl angegeben werden.
4. Mit einer Systemtag-Zahl.
5. Mit einer Systemsekunden-Zahl.

 

 

Der Rückgabewert ist im Bereich 0 bis 6 wobei dem Montag eine 0 entspricht.

 

Die Funktion funktioniert im 21. Jahrhundert(von 1.1.2000 bis 31.12.2099).

 

 

Siehe auch

Date and Time routines , CONFIG DATE , CONFIG CLOCKSYSDAYSYSSEC

 

 

Beispiel


'-----------------------------------------------------------------------------------------
'name : datetime_test1.bas
'copyright : (c) 1995-2005, MCS Electronics
'purpose : show how to use the Date-Time routines from the DateTime.Lib
'micro : Mega103
'suited for demo : no
'commercial addon needed : no
'-----------------------------------------------------------------------------------------
 
$regfile = "m103def.dat" ' Mikrocontroller
$crystal = 4000000 ' Taktfrequenz
$baud = 19200 ' Baudrate
$hwstack = 32 ' default use 32 for the hardware stack
$swstack = 10 ' default use 10 for the SW stack
$framesize = 40 ' default use 40 for the frame space
 
Const Clockmode = 1
'use i2c for the clock
 
#if Clockmode = 1
Config Clock = Soft ' Interne Softclock benutzen
Disable Interrupts
#else
Config Clock = User ' I2C Clock benutzen
'scl und sda Pins definieren
Config Sda = Portd.6
Config Scl = Portd.5
 
'Addresse des ds1307
Const Ds1307w = &HD0 ' Addressen der Ds1307 Clock
Const Ds1307r = &HD1
#endif
 
 
'DAtumsformat konfigurieren
Config Date = Ymd , Separator = - ' ANSI-Format
'Dieses Beispiel startet die Clock nicht. Die Interrupts werden nicht enabled
' Enable Interrupts
 
'VAriablen dimensionieren
Dim Lvar1 As Long
Dim Mday As Byte
Dim Bweekday As Byte , Strweekday As String * 10
Dim Strdate As String * 8
Dim Strtime As String * 8
Dim Bsec As Byte , Bmin As Byte , Bhour As Byte
Dim Bday As Byte , Bmonth As Byte , Byear As Byte
Dim Lsecofday As Long
Dim Wsysday As Word
Dim Lsyssec As Long
Dim Wdayofyear As Word
 
 
 
 
' =================== DayOfWeek =============================================
' Beispiel 1 mit interner RTC-Clock
 
_day = 4 : _month = 11 : _year = 2 ' Beispielwerte zuweisen
Bweekday = Dayofweek()
Strweekday = Lookupstr(bweekday , Weekdays)
Print "Wochentag von " ; Date$ ; " ist " ; Bweekday ; " = " ; Strweekday
 
 
' Beispiel 2 mit benutzerdefinierten Clock-Bytes (Day / Month / Year)
Bday = 26 : Bmonth = 11 : Byear = 2
Bweekday = Dayofweek(bday)
Strweekday = Lookupstr(bweekday , Weekdays)
Strdate = Date(bday)
Print "Wochentag von Tag=" ; Bday ; " Monat=" ; Bmonth ; " Jahr=" ; Byear ; " ist " ; Bweekday ; " (" ; Date(bday) ; ") = " ; Strweekday
 
 
' Beispiel 3 mit Systemtag
Wsysday = 2000 ' das ist der 23.6.2005
Bweekday = Dayofweek(wsysday)
Strweekday = Lookupstr(bweekday , Weekdays)
Print "Wochentag von Systemtag " ; Wsysday ; " (" ; Date(wsysday) ; ") ist " ; Bweekday ; " = " ; Strweekday
 
 
 
' Beispiel 4 mit Systemsekunde
Lsyssec = 123456789 ' das ist 29.11.2003 um 21:33:09
Bweekday = Dayofweek(lsyssec)
Strweekday = Lookupstr(bweekday , Weekdays)
Print "Wochentag von Systemsekunde " ; Lsyssec ; " (" ; Date(lsyssec) ; ") ist " ; Bweekday ; " = " ; Strweekday
 
 
 
 
' Beispiel 5 mit Datums-String
Strdate = "04-11-02" ' wir haben das Datum im ANSI-Format definiert
Bweekday = Dayofweek(strdate)
Strweekday = Lookupstr(bweekday , Weekdays)
Print "Wochentag von" ; Strdate ; " ist " ; Bweekday ; " = " ; Strweekday
 
 
 
 
' ================= Second of Day =============================================
' Beispiel 1 mit interner RTC-Clock
_sec = 12 : _min = 30 : _hour = 18 ' Interne Clockwerte zuweisen
 
Lsecofday = Secofday()
Print "Sekunde des Tages von " ; Time$ ; " ist " ; Lsecofday
 
 
' Beispiel 2 mit benutzerdefinierter Clock - Bytes (Second / Minute / Hour)
Bsec = 20 : Bmin = 1 : Bhour = 7
Lsecofday = Secofday(bsec)
Print "Second of Day von Sec=" ; Bsec ; " Min=" ; Bmin ; " Hour=" ; Bhour ; " (" ; Time(bsec) ; ") ist " ; Lsecofday
 
 
' Beispiel 3 mit Systemsekunde
Lsyssec = 1234456789
Lsecofday = Secofday(lsyssec)
Print "Second of Day von Systemsekunde " ; Lsyssec ; "(" ; Time(lsyssec) ; ") ist " ; Lsecofday
 
 
' Beispiel 4 mit Zeit-String
Strtime = "04:58:37"
Lsecofday = Secofday(strtime)
Print "Second of Day von " ; Strtime ; " ist " ; Lsecofday
 
 
 
' ================== System Second ============================================
 
' Beispiel 1 mit interner RTC-Clock
 ' Testwerte zuweisen
_sec = 17 : _min = 35 : _hour = 8 : _day = 16 : _month = 4 : _year = 3
 
Lsyssec = Syssec()
Print "Systemsekunde von " ; Time$ ; " at " ; Date$ ; " ist " ; Lsyssec
 
 
' Beispiel 2 wmit benutzerdefinierten Clock-Bytes (Second, Minute, Hour, Day / Month / Year)
Bsec = 20 : Bmin = 1 : Bhour = 7 : Bday = 22 : Bmonth = 12 : Byear = 1
Lsyssec = Syssec(bsec)
Strtime = Time(bsec)
Strdate = Date(bday)
Print "Systemsekunde von" ; Strtime ; " at " ; Strdate ; " ist " ; Lsyssec
 
 
' Beispiel 3 mit Systemtag
 
Wsysday = 2000
Lsyssec = Syssec(wsysday)
Print "Systemsekunde von System Day " ; Wsysday ; " (" ; Date(wsysday) ; " 00:00:00) ist " ; Lsyssec
 
 
' Beispiel 4 mit Time- und Date-String
Strtime = "10:23:50"
Strdate = "02-11-29" ' ANSI-Datum
Lsyssec = Syssec(strtime , Strdate)
Print "System Second von " ; Strtime ; " am " ; Strdate ; " ist " ; Lsyssec ' 91880630
 
 
 
 
' ==================== Day Of Year =========================================
' Beispiel 1 mit interner RTC-Clock
_day = 20 : _month = 11 : _year = 2 ' Testwerte zuweisen
Wdayofyear = Dayofyear()
Print "Day Of Year of " ; Date$ ; " is " ; Wdayofyear
 
 
' Beispiel 2 mit benutzerdefinierten Clock-Bytes (Day / Month / Year)
Bday = 24 : Bmonth = 5 : Byear = 8
Wdayofyear = Dayofyear(bday)
Print "Day Of Year von Tag=" ; Bday ; " Monat=" ; Bmonth ; " Jahr=" ; Byear ; " (" ; Date(bday) ; ") ist " ; Wdayofyear
 
 
 
' Beispiel 3 mit Datums-String
Strdate = "04-10-29" ' ANSI-Format
Wdayofyear = Dayofyear(strdate)
Print "Day Of Year von " ; Strdate ; " ist " ; Wdayofyear
 
 
' Beispiel 4 mit Systemsekunde
 
Lsyssec = 123456789
Wdayofyear = Dayofyear(lsyssec)
Print "Day Of Year von Systemsekunde " ; Lsyssec ; " (" ; Date(lsyssec) ; ") ist " ; Wdayofyear
 
 
' Beispiel 5 mit System Day (Systemtag)
Wsysday = 3000
Wdayofyear = Dayofyear(wsysday)
Print "Day Of Year von Systemtag " ; Wsysday ; " (" ; Date(wsysday) ; ") ist " ; Wdayofyear
 
 
' =================== System Day ======================================
' Beispiel 1 mit internaer RTC-Clock
_day = 20 : _month = 11 : _year = 2 ' Testwerte zuweisen
Wsysday = Sysday()
Print "System Day of " ; Date$ ; " is " ; Wsysday
 
 
' Beispiel 2 mit benutzerdefinierten Clock-Bytes (Day / Month / Year)
Bday = 24 : Bmonth = 5 : Byear = 8
Wsysday = Sysday(bday)
Print "System Day von Tag=" ; Bday ; " Monat=" ; Bmonth ; " Jahr=" ; Byear ; " (" ; Date(bday) ; ") ist " ; Wsysday
 
 
' Beispiel 3 mit Date-String
Strdate = "04-10-29"
Wsysday = Sysday(strdate)
Print "System Day von " ; Strdate ; " ist " ; Wsysday
 
' Beispiel 4 mit Systemsekunde
Lsyssec = 123456789
Wsysday = Sysday(lsyssec)
Print "System Day von Systemsekunde " ; Lsyssec ; " (" ; Date(lsyssec) ; ") ist " ; Wsysday
 
 
 
' =================== Time ================================================
' Beispiel 1: Umwandlung benutzerdefinierter Clock-Bytes (Second / Minute / Hour) zu Time-String
Bsec = 20 : Bmin = 1 : Bhour = 7
Strtime = Time(bsec)
Print "Time values: Sec=" ; Bsec ; " Min=" ; Bmin ; " Hour=" ; Bhour ; " umgewandelt zu String " ; Strtime
 
 
' Beispiel 2: Umwandlung Systemsekunde zu Time-String
Lsyssec = 123456789
Strtime = Time(lsyssec)
Print "Time of Systemsecond " ; Lsyssec ; " is " ; Strtime
 
 
' Beispiel 3: Umwandlung Second of Day zu Time-String
Lsecofday = 12345
Strtime = Time(lsecofday)
Print "Time von Second of Day " ; Lsecofday ; " ist " ; Strtime
 
 
' Beispiel 4: Umwandlung System Second zu benutzerdefinierten Clock-Bytes (Second / Minute / Hour)
 
Lsyssec = 123456789
Bsec = Time(lsyssec)
Print "System Second " ; Lsyssec ; " umgewandelt zu Sec=" ; Bsec ; " Min=" ; Bmin ; " Hour=" ; Bhour ; " (" ; Time(lsyssec) ; ")"
 
 
 
' Beispiel 5: Umwandlung Second of Day zu benutzerdefinierten Clock-Bytes (Second / Minute / Hour)
Lsecofday = 12345
Bsec = Time(lsecofday)
Print "Second of Day " ; Lsecofday ; " umgewandelt zu Sec=" ; Bsec ; " Min=" ; Bmin ; " Hour=" ; Bhour ; " (" ; Time(lsecofday) ; ")"
 
' Beispiel 6: Umwandlung Time-string zu benutzerdefinierten Clock-Bytes (Second / Minute / Hour)
Strtime = "07:33:12"
Bsec = Time(strtime)
Print "Time " ; Strtime ; " umgewandelt zu Sec=" ; Bsec ; " Min=" ; Bmin ; " Hour=" ; Bhour
 
 
 
' ============================= Date ==========================================
 
' Beispiel 1: Umwandlung benutzerdefinierter Clock-Bytes (Day / Month / Year) zu Date-String
Bday = 29 : Bmonth = 4 : Byear = 12
Strdate = Date(bday)
Print "Datumswerte: Tag=" ; Bday ; " Monat=" ; Bmonth ; " Jahr=" ; Byear ; " umgewandelt zu String " ; Strdate
 
 
' Beispiel 2: Umwandlung von Systemtag zu Dat- String
Wsysday = 1234
Strdate = Date(wsysday)
Print "System Day " ; Wsysday ; " ist " ; Strdate
 
 
' Beispiel 3: Umwandlung von Systemsekunde zu Date-String
Lsyssec = 123456789
Strdate = Date(lsyssec)
Print "Systemsekunde " ; Lsyssec ; " ist " ; Strdate
 
 
' Beispiel 4: Umwandlung SystemDay zu benutzerdefinierten Clock-Bytes (Day / Month / Year)
 
Wsysday = 2000
Bday = Date(wsysday)
Print "Systemtag " ; Wsysday ; " umgewandelt zu Tag=" ; Bday ; " Monat=" ; Bmonth ; " Jahr=" ; Byear ; " (" ; Date(wsysday) ; ")"
 
 
' Beispiel 5: Umwandlung Date-String zu benutzerdefinierten Clock-Bytes (Day / Month / Year)
Strdate = "04-08-31"
Bday = Date(strdate)
Print "Datum " ; Strdate ; " umgewandelt zu Tag=" ; Bday ; " Monat=" ; Bmonth ; " Jahr=" ; Byear
 
 
' Beispiel 6: Umwandlung Systemsekunde zu benutzerdefinierten Clock-Bytes (Day / Month / Year)
Lsyssec = 123456789
Bday = Date(lsyssec)
Print "Systemsekunde " ; Lsyssec ; " umgewandelt zu Tag=" ; Bday ; " Monat=" ; Bmonth ; " Jahr=" ; Byear ; " (" ; Date(lsyssec) ; ")"
 
 
 
' ================ Second of Day elapsed
 
Lsecofday = Secofday()
_hour = _hour + 1
Lvar1 = Secelapsed(lsecofday)
Print Lvar1
 
Lsyssec = Syssec()
_day = _day + 1
Lvar1 = Syssecelapsed(lsyssec)
Print Lvar1
 
 
Looptest:
 
' Testwerte
_day = 1
_month = 1
_year = 1
_sec = 12
_min = 13
_hour = 14
 
 
 
Do
If _year > 50 Then
 Exit Do
End If
 
_sec = _sec + 7
If _sec > 59 Then
 Incr _min
 _sec = _sec - 60
End If
 
_min = _min + 2
If _min > 59 Then
 Incr _hour
 _min = _min - 60
End If
 
_hour = _hour + 1
If _hour > 23 Then
 Incr _day
 _hour = _hour - 24
End If
 
_day = _day + 1
 
 
If _day > 28 Then
 Select Case _month
 Case 1
 Mday = 31
 Case 2
 Mday = _year And &H03
 If Mday = 0 Then
 Mday = 29
 Else
 Mday = 28
 End If
 Case 3
 Mday = 31
 Case 4
 Mday = 30
 Case 5
 Mday = 31
 Case 6
 Mday = 30
 Case 7
 Mday = 31
 Case 8
 Mday = 31
 Case 9
 Mday = 30
 Case 10
 Mday = 31
 Case 11
 Mday = 30
 Case 12
 Mday = 31
 End Select
 If _day > Mday Then
 _day = _day - Mday
 Incr _month
 If _month > 12 Then
 _month = 1
 Incr _year
 End If
 End If
End If
If _year > 99 Then
 Exit Do
End If
 
Lsecofday = Secofday()
Lsyssec = Syssec()
Bweekday = Dayofweek()
Wdayofyear = Dayofyear()
Wsysday = Sysday()
 
 
Print Time$ ; " " ; Date$ ; " " ; Lsecofday ; " " ; Lsyssec ; " " ; Bweekday ; " " ; Wdayofyear ; " " ; Wsysday
 
 
Loop
End
 
 
'only when we use I2C for the clock we need to set the clock date time
#if Clockmode = 0
'called from datetime.lib
Dim Weekday As Byte
Getdatetime:
I2cstart ' Generate start code
I2cwbyte Ds1307w ' send address
I2cwbyte 0 ' start address in 1307
 
I2cstart ' Generate start code
I2cwbyte Ds1307r ' send address
I2crbyte _sec , Ack
I2crbyte _min , Ack ' MINUTES
I2crbyte _hour , Ack ' Hours
I2crbyte Weekday , Ack ' Day of Week
I2crbyte _day , Ack ' Day of Month
I2crbyte _month , Ack ' Month of Year
I2crbyte _year , Nack ' Year
I2cstop
_sec = Makedec(_sec) : _min = Makedec(_min) : _hour = Makedec(_hour)
_day = Makedec(_day) : _month = Makedec(_month) : _year = Makedec(_year)
Return
 
Setdate:
_day = Makebcd(_day) : _month = Makebcd(_month) : _year = Makebcd(_year)
I2cstart ' Generate start code
I2cwbyte Ds1307w ' send address
I2cwbyte 4 ' starting address in 1307
I2cwbyte _day ' Send Data to SECONDS
I2cwbyte _month ' MINUTES
I2cwbyte _year ' Hours
I2cstop
Return
 
Settime:
_sec = Makebcd(_sec) : _min = Makebcd(_min) : _hour = Makebcd(_hour)
I2cstart ' Generate start code
I2cwbyte Ds1307w ' send address
I2cwbyte 0 ' starting address in 1307
I2cwbyte _sec ' Send Data to SECONDS
I2cwbyte _min ' MINUTES
I2cwbyte _hour ' Hours
I2cstop
Return
 
#endif
 
 
Weekdays:
Data "Montag" , "Dienstag" , "Mittwoch" , "Donnerstag" , "Freitag" , "Sonnabend" , "Sonntag"

Languages   English Deutsch  
Personal tools
Namespaces
Variants
Actions
Navigation
In other languages
Language