标题: Arduino通信 DS1307 RTC I2C模块 原理图及程序分享 [打印本页]

作者: happy112    时间: 2016-6-6 21:39
标题: Arduino通信 DS1307 RTC I2C模块 原理图及程序分享


功能模块介绍:

1.此电路板采用DS1307作为I2C实时时钟芯片(RTC)

2.24C32作为EEPOM存储器

3.采用LIR2032可充电锂电池,并带充电电路,解决了DS1307带备电池不能读写的问题。

4.可以级联其他的I2C设备

电路图:


  1. /*
  2.   DS1307.h - library for DS1307 rtc
  3. */

  4. // ensure this library description is only included once
  5. #ifndef DS1307_h
  6. #define DS1307_h

  7. // include types & constants of Wiring core API
  8. #include <WConstants.h>

  9. // include types & constants of Wire ic2 lib
  10. #include <../Wire/Wire.h>

  11. #define DS1307_SEC 0
  12. #define DS1307_MIN 1
  13. #define DS1307_HR 2
  14. #define DS1307_DOW 3
  15. #define DS1307_DATE 4
  16. #define DS1307_MTH 5
  17. #define DS1307_YR 6

  18. #define DS1307_BASE_YR 2000

  19. #define DS1307_SQW1HZ  7
  20. #define DS1307_SQW4KHZ 8
  21. #define DS1307_SQW8KHZ 9
  22. #define DS1307_SQW32KHZ 10

  23. #define DS1307_CTRL_ID B1101000  //DS1307

  24. // Define register bit masks
  25. #define DS1307_CLOCKHALT B10000000

  26. #define DS1307_LO_BCD  B00001111
  27. #define DS1307_HI_BCD  B11110000

  28. #define DS1307_HI_SEC  B01110000
  29. #define DS1307_HI_MIN  B01110000
  30. #define DS1307_HI_HR   B00110000
  31. #define DS1307_LO_DOW  B00000111
  32. #define DS1307_HI_DATE B00110000
  33. #define DS1307_HI_MTH  B00110000
  34. #define DS1307_HI_YR   B11110000


  35. // Prescaler
  36. #define DS1307_LOW_BIT      B00000000
  37. #define DS1307_HIGH_BIT     B10000000
  38. #define DS1307_SQW1HZ_BIT   B00010000
  39. #define DS1307_SQW4KHZ_BIT  B00010001
  40. #define DS1307_SQW8KHZ_BIT  B00010010
  41. #define DS1307_SQW32KHZ_BIT B00010011

  42. // library interface description
  43. class DS1307
  44. {
  45.   // user-accessible "public" interface
  46.   public:
  47.     DS1307();
  48.     void get(int *, boolean);
  49.     int get(int, boolean);
  50.     void set(int, int);
  51.     void start(void);
  52.     void stop(void);
  53.     void SetOutput(int c);
  54.     int GetOutput(void);
  55.    
  56.   // library-accessible "private" interface
  57.   private:
  58.     byte rtc_bcd[7]; // used prior to read/set ds1307 registers;
  59.     void read(void);
  60.     void save(void);
  61. };

  62. extern DS1307 RTC;

  63. #endif
复制代码

全部资料(压缩包)下载:
I2CRTC模块.rar (742.75 KB, 下载次数: 74)


作者: fxh_0001    时间: 2017-4-20 23:22
根本没法运行

作者: thoulin    时间: 2017-12-27 10:06
OK,可以参考一下
作者: wpf256    时间: 2017-12-28 17:41
好东西,感谢楼主的分享





欢迎光临 (http://www.51hei.com/bbs/) Powered by Discuz! X3.1