RTC DS1302 Module (DS1302) [S030]



https://www.youtube.com/watch?v=_TlS8qnRSx8


*GitHubhttps://github.com/rdiot/rdiot-s030.git


* Specs

Color: Green

Material: PCB

Voltage: 2v ~ 5.5v

Length: 43mm

Width: 23mm


* Contents

- Connect

VCC ----- 5V

GND ----- GND

CLK ----- D6

DAT ----- D7

RST ----- D8

 

- Setup Default Value

#define SET_DATE_TIME_JUST_ONCE

  seconds    = 0;

  minutes    = 44;

  hours      = 9;

  dayofweek  = 2;  // Day of week, any day can be first, counts 1...7

  dayofmonth = 2; // Day of month, 1...31

  month      = 2;  // month 1...12

  year       = 2016;



- Key Code

// Set your own pins with these defines !

#define DS1302_SCLK_PIN   6    // Arduino pin for the Serial Clock

#define DS1302_IO_PIN     7    // Arduino pin for the Data I/O

#define DS1302_CE_PIN     8    // Arduino pin for the Chip Enable


#define bcd2bin(h,l)    (((h)*10) + (l))

#define bin2bcd_h(x)   ((x)/10)

#define bin2bcd_l(x)    ((x)%10)


#define DS1302_SECONDS           0x80

#define DS1302_MINUTES           0x82

#define DS1302_HOURS             0x84

#define DS1302_DATE              0x86

#define DS1302_MONTH             0x88

#define DS1302_DAY               0x8A

#define DS1302_YEAR              0x8C

#define DS1302_ENABLE            0x8E

#define DS1302_TRICKLE           0x90

#define DS1302_CLOCK_BURST       0xBE

#define DS1302_CLOCK_BURST_WRITE 0xBE

#define DS1302_CLOCK_BURST_READ  0xBF

#define DS1302_RAMSTART          0xC0

#define DS1302_RAMEND            0xFC

#define DS1302_RAM_BURST         0xFE

#define DS1302_RAM_BURST_WRITE   0xFE

#define DS1302_RAM_BURST_READ    0xFF


#define DS1302_D0 0

#define DS1302_D1 1

#define DS1302_D2 2

#define DS1302_D3 3

#define DS1302_D4 4

#define DS1302_D5 5

#define DS1302_D6 6

#define DS1302_D7 7


// Bit for reading (bit in address)

#define DS1302_READBIT DS1302_D0 // READBIT=1: read instruction


// Bit for clock (0) or ram (1) area, 

// called R/C-bit (bit in address)

#define DS1302_RC DS1302_D6


// Seconds Register

#define DS1302_CH DS1302_D7   // 1 = Clock Halt, 0 = start


// Hour Register

#define DS1302_AM_PM DS1302_D5 // 0 = AM, 1 = PM

#define DS1302_12_24 DS1302_D7 // 0 = 24 hour, 1 = 12 hour


// Enable Register

#define DS1302_WP DS1302_D7   // 1 = Write Protect, 0 = enabled


// Trickle Register

#define DS1302_ROUT0 DS1302_D0

#define DS1302_ROUT1 DS1302_D1

#define DS1302_DS0   DS1302_D2

#define DS1302_DS1   DS1302_D2

#define DS1302_TCS0  DS1302_D4

#define DS1302_TCS1  DS1302_D5

#define DS1302_TCS2  DS1302_D6

#define DS1302_TCS3  DS1302_D7


  ds1302_struct rtc;

  char buffer[80];     // the code uses 70 characters.


  // Read all clock data at once (burst mode).

  DS1302_clock_burst_read( (uint8_t *) &rtc);


  sprintf(buffer, "Date=%d-%d-%d [%d]", \

    2000 + bcd2bin( rtc.Year10, rtc.Year), \

    bcd2bin( rtc.Month10, rtc.Month), \

    rtc.Day, \

    bcd2bin( rtc.Date10, rtc.Date));


  lcd.print(buffer);

'2) Sensor > RTC' 카테고리의 다른 글

DS3231 AT24C32 IIC Clock Module (DS3231SN) [S174]  (0) 2016.09.11
Tiny RTC DS1307 I2C Module (DS1307) [S029]  (0) 2016.09.11
Posted by RDIoT
|