[BASCOM] Biblioteka DS1307
: 04 gru 2016, 13:45
Znaleziona w czeluściach internetu biblioteka dla układu DS1307 Jest fajnie zbudowana i świetnie wytłumaczona.
Autor E.Rahmanian
Wklejam tylko kilka reszta dostępna w załączniku.
Autor E.Rahmanian
Wklejam tylko kilka reszta dostępna w załączniku.
Code: [Zaznacz cały] [Rozwiń/Zwiń]
- $nocompile
- Declare Function Ds1307_is_play0_pause1()as Byte
- Declare Sub Ds1307_play()
- Declare Sub Ds1307_pause()
- Declare Sub Ds1307_config()
- Declare Sub Ds1307_set_second(byval Second_0_59 As Byte)
- Declare Function Ds1307_get_second_0_59() As Byte
- Declare Sub Ds1307_set_minute(byval Minute_0_59 As Byte)
- Declare Function Ds1307_get_minute_0_59() As Byte
- Declare Function Ds1307_is_24h_0_12h_1_mode() As Byte
- Declare Sub Ds1307_set_24h_or_12h_mode(byval _24h_0_12h_1 As Byte)
- Declare Function Ds1307_is_pm_1_am_0() As Byte
- Declare Function Ds1307_get_hour_0_23() As Byte
- Declare Function Ds1307_get_hour_0_12() As Byte
- Declare Sub Ds1307_set_hour_0_23(byval Hour_0_23 As Byte )
- Declare Sub Ds1307_set_hour_0_11(byval Hour_0_12 As Byte , Byval Am0_pm1 As Byte )
- Declare Function Ds1307_get_dayofweek_1_7()as Byte
- Declare Sub Ds1307_set_dayofweek(byval Dayofweek_1_7 As Byte )
- Declare Function Ds1307_get_dayofmonth_1_31()as Byte
- Declare Sub Ds1307_set_dayofmonth(byval Dayofmonth_1_31 As Byte )
- Declare Function Ds1307_get_monthofyear_1_12()as Byte
- Declare Sub Ds1307_set_monthofyear(byval Monthofyear_1_12 As Byte )
- Declare Function Ds1307_get_year_0_99()as Byte
- Declare Sub Ds1307_set_year(byval Year_0_99 As Byte )
- Declare Sub Ds1307_external_1hz_on()
- Declare Sub Ds1307_external_4096hz_on()
- Declare Sub Ds1307_external_8192hz_on()
- Declare Sub Ds1307_external_32768hz_on()
- Declare Sub Ds1307_external_off_sqwe_0()
- Declare Sub Ds1307_external_off_sqwe_1()
- Declare Function Ds1307_read_ram(byval Ram_byte_index_0_55 As Byte) As Byte
- Declare Sub Ds1307_write_ram(byval Ram_byte_index_0_55 As Byte , Byval Value As Byte)
Code: [Zaznacz cały] [Rozwiń/Zwiń]
- $nocompile
- Function Ds1307_get_dayofmonth_1_31()as Byte 'ok
- I2cstart
- I2cwbyte &B11010000
- I2cwbyte 4
- I2cstart
- I2cwbyte &B11010001
- I2crbyte A , Nack
- I2cstop
- Ds1307_get_dayofmonth_1_31 = Makedec(a)
- End Function
Code: [Zaznacz cały] [Rozwiń/Zwiń]
- $nocompile
- Function Ds1307_get_dayofweek_1_7()as Byte 'ok
- I2cstart
- I2cwbyte &B11010000
- I2cwbyte 3
- I2cstart
- I2cwbyte &B11010001
- I2crbyte A , Nack
- I2cstop
- Ds1307_get_dayofweek_1_7 = Makedec(a)
- End Function
Code: [Zaznacz cały] [Rozwiń/Zwiń]
- $nocompile
- Function Ds1307_get_hour_0_12() As Byte 'ok
- I2cstart
- I2cwbyte &B11010000
- I2cwbyte 2
- I2cstart
- I2cwbyte &B11010001
- I2crbyte A , Nack
- I2cstop
- B = A And &B01000000
- If B = 0 Then 'is 24h mode
- B = A And &B00111111
- B = Makedec(b)
- If B > 12 Then B = B - 12
- Ds1307_get_hour_0_12 = B
- Else 'is 12h mode
- B = A And &B00011111
- B = Makedec(b)
- Ds1307_get_hour_0_12 = B
- End If
- End Function
Code: [Zaznacz cały] [Rozwiń/Zwiń]
- $nocompile
- Function Ds1307_get_hour_0_23() As Byte 'ok
- I2cstart
- I2cwbyte &B11010000
- I2cwbyte 2
- I2cstart
- I2cwbyte &B11010001
- I2crbyte A , Nack
- I2cstop
- B = A And &B01000000
- If B = 0 Then 'is 24h mode
- B = A And &B00111111
- Ds1307_get_hour_0_23 = Makedec(b)
- Else 'is 12h mode
- B = A And &B00100000 'is am or pm?
- A = A And &B00011111
- A = Makedec(a)
- If B = 0 Then 'is am
- Ds1307_get_hour_0_23 = A
- Else 'is pm
- If A = 12 Then
- Ds1307_get_hour_0_23 = A
- Else
- Ds1307_get_hour_0_23 = A + 12
- End If
- End If
- End If
- End Function
Code: [Zaznacz cały] [Rozwiń/Zwiń]
- $nocompile
- Function Ds1307_get_minute_0_59() As Byte 'ok
- I2cstart
- I2cwbyte &B11010000
- I2cwbyte 1
- I2cstart
- I2cwbyte &B11010001
- I2crbyte A , Nack
- I2cstop
- Ds1307_get_minute_0_59 = Makedec(a)
- End Function
Code: [Zaznacz cały] [Rozwiń/Zwiń]
- $nocompile
- Function Ds1307_get_monthofyear_1_12()as Byte 'ok
- I2cstart
- I2cwbyte &B11010000
- I2cwbyte 5
- I2cstart
- I2cwbyte &B11010001
- I2crbyte A , Nack
- I2cstop
- Ds1307_get_monthofyear_1_12 = Makedec(a)
- End Function
Code: [Zaznacz cały] [Rozwiń/Zwiń]
- $nocompile
- '-------------921205---------
- Function Ds1307_get_second_0_59() As Byte
- I2cstart
- I2cwbyte &B11010000
- I2cwbyte 0
- I2cstart
- I2cwbyte &B11010001
- I2crbyte A , Nack
- I2cstop
- A = A And &B01111111 'clear bit_7
- Ds1307_get_second_0_59 = Makedec(a)
- End Function
Code: [Zaznacz cały] [Rozwiń/Zwiń]
- $nocompile
- Function Ds1307_get_year_0_99()as Byte 'ok
- I2cstart
- I2cwbyte &B11010000
- I2cwbyte 6
- I2cstart
- I2cwbyte &B11010001
- I2crbyte A , Nack
- I2cstop
- Ds1307_get_year_0_99 = Makedec(a)
- End Function
Code: [Zaznacz cały] [Rozwiń/Zwiń]
- $nocompile
- Function Ds1307_is_24h_0_12h_1_mode() As Byte 'ok
- I2cstart
- I2cwbyte &B11010000
- I2cwbyte 2
- I2cstart
- I2cwbyte &B11010001
- I2crbyte A , Nack
- I2cstop
- A = A And &B01000000
- If A = 0 Then
- Ds1307_is_24h_0_12h_1_mode = 0
- Else
- Ds1307_is_24h_0_12h_1_mode = 1
- End If
- End Function
Code: [Zaznacz cały] [Rozwiń/Zwiń]
- $nocompile
- Function Ds1307_is_play0_pause1()as Byte 'timer and date counter is pause or play?
- I2cstart 'i2c start
- I2cwbyte &B11010000 'write mode
- I2cwbyte 0 'set registr in index 0
- I2cstart 'restart i2c for change mode
- I2cwbyte &B11010001 'read mode
- I2crbyte A , Nack 'read defult registr(reister 0)
- I2cstop 'stop i2c
- A = A And &B10000000 '==> 0 or 10000000
- If A = 0 Then 'bit_7 is 0
- Ds1307_is_play0_pause1 = 0
- Else 'bit_7 is 1
- Ds1307_is_play0_pause1 = 1
- End If
- End Function