[BASCOM] Biblioteka DS1307

Gotowe kody obsługi układów elektronicznych udostępnione przez użytkowników forum.
ODPOWIEDZ
Pikczu
Posty: 389
Rejestracja: 17 sie 2015, 13:46
Lokalizacja: Dublin, Ireland
Kontakt:

[BASCOM] Biblioteka DS1307

Post autor: Pikczu » 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.
  1. $nocompile
  2.  
  3. Declare Function Ds1307_is_play0_pause1()as Byte
  4. Declare Sub Ds1307_play()
  5. Declare Sub Ds1307_pause()
  6. Declare Sub Ds1307_config()
  7. Declare Sub Ds1307_set_second(byval Second_0_59 As Byte)
  8. Declare Function Ds1307_get_second_0_59() As Byte
  9. Declare Sub Ds1307_set_minute(byval Minute_0_59 As Byte)
  10. Declare Function Ds1307_get_minute_0_59() As Byte
  11. Declare Function Ds1307_is_24h_0_12h_1_mode() As Byte
  12. Declare Sub Ds1307_set_24h_or_12h_mode(byval _24h_0_12h_1 As Byte)
  13. Declare Function Ds1307_is_pm_1_am_0() As Byte
  14. Declare Function Ds1307_get_hour_0_23() As Byte
  15. Declare Function Ds1307_get_hour_0_12() As Byte
  16. Declare Sub Ds1307_set_hour_0_23(byval Hour_0_23 As Byte )
  17. Declare Sub Ds1307_set_hour_0_11(byval Hour_0_12 As Byte , Byval Am0_pm1 As Byte )
  18. Declare Function Ds1307_get_dayofweek_1_7()as Byte
  19. Declare Sub Ds1307_set_dayofweek(byval Dayofweek_1_7 As Byte )
  20. Declare Function Ds1307_get_dayofmonth_1_31()as Byte
  21. Declare Sub Ds1307_set_dayofmonth(byval Dayofmonth_1_31 As Byte )
  22. Declare Function Ds1307_get_monthofyear_1_12()as Byte
  23. Declare Sub Ds1307_set_monthofyear(byval Monthofyear_1_12 As Byte )
  24. Declare Function Ds1307_get_year_0_99()as Byte
  25. Declare Sub Ds1307_set_year(byval Year_0_99 As Byte )
  26. Declare Sub Ds1307_external_1hz_on()
  27. Declare Sub Ds1307_external_4096hz_on()
  28. Declare Sub Ds1307_external_8192hz_on()
  29. Declare Sub Ds1307_external_32768hz_on()
  30. Declare Sub Ds1307_external_off_sqwe_0()
  31. Declare Sub Ds1307_external_off_sqwe_1()
  32. Declare Function Ds1307_read_ram(byval Ram_byte_index_0_55 As Byte) As Byte
  33. Declare Sub Ds1307_write_ram(byval Ram_byte_index_0_55 As Byte , Byval Value As Byte)
  1. $nocompile
  2.  
  3. Function Ds1307_get_dayofmonth_1_31()as Byte                'ok
  4.    I2cstart
  5.    I2cwbyte &B11010000
  6.    I2cwbyte 4
  7.    I2cstart
  8.    I2cwbyte &B11010001
  9.    I2crbyte A , Nack
  10.    I2cstop
  11.    Ds1307_get_dayofmonth_1_31 = Makedec(a)
  12. End Function
  1. $nocompile
  2. Function Ds1307_get_dayofweek_1_7()as Byte                  'ok
  3.    I2cstart
  4.    I2cwbyte &B11010000
  5.    I2cwbyte 3
  6.    I2cstart
  7.    I2cwbyte &B11010001
  8.    I2crbyte A , Nack
  9.    I2cstop
  10.    Ds1307_get_dayofweek_1_7 = Makedec(a)
  11. End Function
  1. $nocompile
  2.  
  3. Function Ds1307_get_hour_0_12() As Byte                     'ok
  4.    I2cstart
  5.    I2cwbyte &B11010000
  6.    I2cwbyte 2
  7.    I2cstart
  8.    I2cwbyte &B11010001
  9.    I2crbyte A , Nack
  10.    I2cstop
  11.    B = A And &B01000000
  12.    If B = 0 Then                                            'is 24h mode
  13.       B = A And &B00111111
  14.       B = Makedec(b)
  15.       If B > 12 Then B = B - 12
  16.       Ds1307_get_hour_0_12 = B
  17.    Else                                                     'is 12h mode
  18.       B = A And &B00011111
  19.       B = Makedec(b)
  20.       Ds1307_get_hour_0_12 = B
  21.    End If
  22. End Function
  1. $nocompile
  2.  
  3. Function Ds1307_get_hour_0_23() As Byte                     'ok
  4.    I2cstart
  5.    I2cwbyte &B11010000
  6.    I2cwbyte 2
  7.    I2cstart
  8.    I2cwbyte &B11010001
  9.    I2crbyte A , Nack
  10.    I2cstop
  11.    B = A And &B01000000
  12.    If B = 0 Then                                            'is 24h mode
  13.       B = A And &B00111111
  14.       Ds1307_get_hour_0_23 = Makedec(b)
  15.    Else                                                     'is 12h mode
  16.       B = A And &B00100000                                  'is am or pm?
  17.       A = A And &B00011111
  18.       A = Makedec(a)
  19.       If B = 0 Then                                         'is am
  20.          Ds1307_get_hour_0_23 = A
  21.       Else                                                  'is pm
  22.          If A = 12 Then
  23.             Ds1307_get_hour_0_23 = A
  24.          Else
  25.             Ds1307_get_hour_0_23 = A + 12
  26.          End If
  27.       End If
  28.    End If
  29. End Function
  1. $nocompile
  2.  
  3.  
  4. Function Ds1307_get_minute_0_59() As Byte                   'ok
  5.    I2cstart
  6.    I2cwbyte &B11010000
  7.    I2cwbyte 1
  8.    I2cstart
  9.    I2cwbyte &B11010001
  10.    I2crbyte A , Nack
  11.    I2cstop
  12.    Ds1307_get_minute_0_59 = Makedec(a)
  13.  End Function
  1. $nocompile
  2.  
  3. Function Ds1307_get_monthofyear_1_12()as Byte               'ok
  4.    I2cstart
  5.    I2cwbyte &B11010000
  6.    I2cwbyte 5
  7.    I2cstart
  8.    I2cwbyte &B11010001
  9.    I2crbyte A , Nack
  10.    I2cstop
  11.    Ds1307_get_monthofyear_1_12 = Makedec(a)
  12. End Function
  1. $nocompile
  2.  
  3. '-------------921205---------
  4.   Function Ds1307_get_second_0_59() As Byte
  5.    I2cstart
  6.    I2cwbyte &B11010000
  7.    I2cwbyte 0
  8.    I2cstart
  9.    I2cwbyte &B11010001
  10.    I2crbyte A , Nack
  11.    I2cstop
  12.    A = A And &B01111111                                     'clear bit_7
  13.    Ds1307_get_second_0_59 = Makedec(a)
  14.  End Function
  1. $nocompile
  2.  
  3. Function Ds1307_get_year_0_99()as Byte                      'ok
  4.    I2cstart
  5.    I2cwbyte &B11010000
  6.    I2cwbyte 6
  7.    I2cstart
  8.    I2cwbyte &B11010001
  9.    I2crbyte A , Nack
  10.    I2cstop
  11.    Ds1307_get_year_0_99 = Makedec(a)
  12. End Function
  1. $nocompile
  2.  
  3. Function Ds1307_is_24h_0_12h_1_mode() As Byte               'ok
  4.    I2cstart
  5.    I2cwbyte &B11010000
  6.    I2cwbyte 2
  7.    I2cstart
  8.    I2cwbyte &B11010001
  9.    I2crbyte A , Nack
  10.    I2cstop
  11.    A = A And &B01000000
  12.    If A = 0 Then
  13.       Ds1307_is_24h_0_12h_1_mode = 0
  14.    Else
  15.       Ds1307_is_24h_0_12h_1_mode = 1
  16.    End If
  17.  End Function
  1. $nocompile
  2.  
  3. Function Ds1307_is_play0_pause1()as Byte                    'timer and date counter is pause or play?
  4.    I2cstart                                                 'i2c start
  5.    I2cwbyte &B11010000                                      'write mode
  6.    I2cwbyte 0                                               'set registr in index 0
  7.    I2cstart                                                 'restart i2c for change mode
  8.    I2cwbyte &B11010001                                      'read mode
  9.    I2crbyte A , Nack                                        'read defult registr(reister 0)
  10.    I2cstop                                                  'stop i2c
  11.    A = A And &B10000000                                     '==> 0 or 10000000
  12.    If A = 0 Then                                            'bit_7 is 0
  13.       Ds1307_is_play0_pause1 = 0
  14.    Else                                                     'bit_7 is 1
  15.       Ds1307_is_play0_pause1 = 1
  16.    End If
  17. End Function
Nie masz wymaganych uprawnień, aby zobaczyć pliki załączone do tego posta.
Awatar użytkownika
niveasoft
Posty: 1213
Rejestracja: 17 sie 2015, 12:13
Kontakt:

Re: Biblioteka DS1307

Post autor: niveasoft » 09 sty 2017, 18:50

Coś mam niedopracowane te powiadomienia bo dopiero teraz mi się to rzuciło na oczy :D
Pisze bo jedna rzecz ostatnio trochę przykróciła moje zapędy w przetłumaczeniu biblioteki Arduino do Bascom.
Otóż opis Constatnt - stałej nie może być w Bascom dłuższy niż 32 znaki :D i dosłowne tłumaczenie nie przejdzie i trzeba szukać skrótu dla wyrażenia :D
ODPOWIEDZ