ВУЗ: Не указан

Категория: Не указан

Дисциплина: Не указана

Добавлен: 12.06.2025

Просмотров: 8191

Скачиваний: 1

ВНИМАНИЕ! Если данный файл нарушает Ваши авторские права, то обязательно сообщите нам.

© MCS Electronics, 1995-2007

Print "Second of Day " ; Lsecofday ; " converted to Sec=" ; Bsec ; " Min=" ; Bmin ; " Hour=" ; Bhour ; " (" ; Time(lsecofday) ; ")"

'Example 6: Converting Time-string to defined Clock - Bytes (Second / Minute / Hour)

Strtime = "07:33:12" Bsec = Time(strtime)

Print "Time " ; Strtime ; " converted to Sec=" ; Bsec ; " Min=" ; Bmin ; " Hour=" ; Bhour

'============================= Date

==========================================

'Example 1: Converting defined Clock - Bytes (Day / Month / Year) to Date - String

Bday = 29 : Bmonth = 4 : Byear = 12 Strdate = Date(bday)

Print "Dat values: Day=" ; Bday ; " Month=" ; Bmonth ; " Year=" ; Byear ; " converted to string " ; Strdate

'Example 2: Converting from System Day to Date - String

Wsysday = 1234

Strdate = Date(wsysday)

Print "System Day " ; Wsysday ; " is " ; Strdate

'Example 3: Converting from System Second to Date String Lsyssec = 123456789

Strdate = Date(lsyssec)

Print "System Second " ; Lsyssec ; " is " ; Strdate

'Example 4: Converting SystemDay to defined Clock - Bytes (Day / Month / Year)

Wsysday = 2000

Bday = Date(wsysday)

Print "System Day " ; Wsysday ; " converted to Day=" ; Bday ; " Month=" ; Bmonth ; " Year=" ; Byear ; " (" ; Date(wsysday) ; ")"

'Example 5: Converting Date - String to defined Clock - Bytes (Day / Month / Year)

Strdate = "04-08-31" Bday = Date(strdate)

Print "Date " ; Strdate ; " converted to Day=" ; Bday ; " Month=" ; Bmonth ; " Year=" ; Byear

'Example 6: Converting System Second to defined Clock - Bytes (Day / Month / Year)

Lsyssec = 123456789 Bday = Date(lsyssec)

Print "System Second " ; Lsyssec ; " converted to Day=" ; Bday ; " Month=" ; Bmonth ; " Year=" ; Byear ; " (" ; Date(lsyssec) ; ")"

'================ Second of Day elapsed

Lsecofday = Secofday() _hour = _hour + 1

page -428-


© MCS Electronics, 1995-2007

Lvar1 = Secelapsed(lsecofday)

Print Lvar1

Lsyssec = Syssec() _day = _day + 1

Lvar1 = Syssecelapsed(lsyssec)

Print Lvar1

Looptest:

' Initialising for testing _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

page -429-


© MCS Electronics, 1995-2007

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:

' Generate start

I2cstart

code

' send address

I2cwbyte Ds1307w

I2cwbyte 0

' start address in

1307

I2cstart

' Generate start

code

' send address

I2cwbyte Ds1307r

I2crbyte _sec , Ack

' MINUTES

I2crbyte _min , Ack

I2crbyte _hour , Ack

' Hours

I2crbyte Weekday , Ack

' Day of Week

I2crbyte _day , Ack

' Day of Month

page -430-


© MCS Electronics, 1995-2007

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

' send address

I2cwbyte Ds1307w

I2cwbyte 4

' starting address

in 1307

' Send Data to

I2cwbyte _day

SECONDS

' MINUTES

I2cwbyte _month

I2cwbyte _year

' Hours

I2cstop

Return

Settime:

_sec = Makebcd(_sec) : _min = Makebcd(_min) : _hour = Makebcd(_hour)

I2cstart

' Generate start

code

' send address

I2cwbyte Ds1307w

I2cwbyte 0

' starting address

in 1307

' Send Data to

I2cwbyte _sec

SECONDS

' MINUTES

I2cwbyte _min

I2cwbyte _hour

' Hours

I2cstop

Return

#endif

Weekdays:

Data "Monday" , "Tuesday" , "Wednesday" , "Thursday" , "Friday" , "Saturday" ,

"Sunday"

DAYOFYEAR

Action

Returns the Day of the Year of a Date

Syntax

Target = DayOfYear()

Target = DayOfYear(bDayMonthYear)

Target = DayOfYear(strDate)

Target = DayOfYear(wSysDay)

Target = DayOfYear(lSysSec)

Remarks

Target

A Integer, that is assigned with the Day of the Year

page -431-