ELECTRONIC BRICK - DS1307 REAL TIME CLOCK BRICK

4,00 EUR

inkl. 19 % MwSt zzgl. Versandkosten

Gewicht: 0,02 KG

Lieferzeit: Gewöhnlich versandfertig in 24 Stunden

Geringer Lagerbestand

Geringer Lagerbestand

0 Bewertung(en) | Bewertung schreiben

Art.Nr.: ITS-IM120710020

This is a electronic brick based on the clock chip DS1307 which supports the I2C protocol. It uses a Lithium cell battery (CR1225). The clock/calendar provides seconds, minutes, hours, day, date,month, and year information. The end of the month date is automatically adjusted for months with fewer than 31 days, including corrections for leap year. The clock operates in either the 24-hour or 12-hour format with AM/PM indicator. 

Note: Battery is not included.

Features

  • Real-Time Clock (RTC) counts seconds,minutes, hours, date of the month, month,day of the week, and year with Leap-Year compensation valid up to 2100
  • 56-Byte, Battery-Backed, Nonvolatile (NV)RAM for data storage
  • I2C serial interface
  • 5V DC supply
  • Programmable Square-Wave output signal
  • Automatic Power-Fail detect and switch circuitry
  • Consumes less than 500nA in Battery-Backup Mode with Oscillator Running

 

Programming

The following sketch demonstrates a simple application of setting the time and reading it out.First, you should send the command “T” followed by the time you want to set through the Serial Monitor. Then you can see the current time through the Serial Monitor.

The command format is as below./*T(00-59)(00-59)(00-23)(1-7)(01-31)(01-12)(00-99) */ which means */T(sec)(min)(hour)(dayOfWeek)(dayOfMonth)(month)(year) */ - T Sets the date of the RTC DS1307 Chip. For example, to set the time for 02-DEC-10 @ 19:57:11 for the 3 day of the week, send this command - T1157193021210.

Demo code like :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include "Wire.h"
#define DS1307_I2C_ADDRESS 0x68  // This is the I2C address
// Global Variables
int command = 0;       // This is the command char, in ascii form, sent from the serial port    
int i;
long previousMillis = 0;        // will store last time Temp was updated
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year;
byte test;
  
// Convert normal decimal numbers to binary coded decimal
byte decToBcd(byte val)
{
  return ( (val/10*16) + (val%10) );
}
  
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val)
{
  return ( (val/16*10) + (val%16) );
}
  
// 1) Sets the date and time on the ds1307
// 2) Starts the clock
// 3) Sets hour mode to 24 hour clock
// Assumes you're passing in valid numbers, Probably need to put in checks for valid numbers.
  
void setDateDs1307()               
{
  
   second = (byte) ((Serial.read() - 48) * 10 + (Serial.read() - 48)); // Use of (byte) type casting and ascii math to achieve result. 
   minute = (byte) ((Serial.read() - 48) *10 +  (Serial.read() - 48));
   hour  = (byte) ((Serial.read() - 48) *10 +  (Serial.read() - 48));
   dayOfWeek = (byte) (Serial.read() - 48);
   dayOfMonth = (byte) ((Serial.read() - 48) *10 +  (Serial.read() - 48));
   month = (byte) ((Serial.read() - 48) *10 +  (Serial.read() - 48));
   year= (byte) ((Serial.read() - 48) *10 +  (Serial.read() - 48));
   Wire.beginTransmission(DS1307_I2C_ADDRESS);
   Wire.send(0x00);
   Wire.send(decToBcd(second));    // 0 to bit 7 starts the clock
   Wire.send(decToBcd(minute));
   Wire.send(decToBcd(hour));      // If you want 12 hour am/pm you need to set
                                   // bit 6 (also need to change readDateDs1307)
   Wire.send(decToBcd(dayOfWeek));
   Wire.send(decToBcd(dayOfMonth));
   Wire.send(decToBcd(month));
   Wire.send(decToBcd(year));
   Wire.endTransmission();
}
  
// Gets the date and time from the ds1307 and prints result
void getDateDs1307()
{
  // Reset the register pointer
  Wire.beginTransmission(DS1307_I2C_ADDRESS);
  Wire.send(0x00);
  Wire.endTransmission();
  
  Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
  
  // A few of these need masks because certain bits are control bits
  second     = bcdToDec(Wire.receive() & 0x7f);
  minute     = bcdToDec(Wire.receive());
  hour       = bcdToDec(Wire.receive() & 0x3f);  // Need to change this if 12 hour am/pm
  dayOfWeek  = bcdToDec(Wire.receive());
  dayOfMonth = bcdToDec(Wire.receive());
  month      = bcdToDec(Wire.receive());
  year       = bcdToDec(Wire.receive());
  
  Serial.print(hour, DEC);
  Serial.print(":");
  Serial.print(minute, DEC);
  Serial.print(":");
  Serial.print(second, DEC);
  Serial.print("  ");
  Serial.print(month, DEC);
  Serial.print("/");
  Serial.print(dayOfMonth, DEC);
  Serial.print("/");
  Serial.print(year, DEC);
  Serial.print("  ");
}
void setup() {
  Wire.begin();
  Serial.begin(57600);
}
void loop() {
  delay(2000);
  /*T(00-59)(00-59)(00-23)(1-7)(01-31)(01-12)(00-99) - T(sec)(min)(hour)(dayOfWeek)(dayOfMonth)(month)(year) - T Sets the date of the RTC DS1307 Chip.
Example to set the time for 02-DEC-10 @ 19:57:11 for the 3 day of the week, send this command - T1157193021210
  */
     if (Serial.available())
     {      // Look for char in serial que and process if found
      command = Serial.read();
      if (command == 84) {      //If command = "T" Set Date
       setDateDs1307();
       getDateDs1307();
       Serial.println(" ");
      }
      while(1)
      {
        getDateDs1307();
        delay(500);
      }
   }
  }
 

Specification
Brick Type: Misc
Brick Interface: 4PIN Parallel
Brick Power Supply: 5V
Board Size: 37 × 21 × 1.6mm
Weight: 20.00g
Model: IM120710020


Kunden kauften auch

0.56
9,90 EUR
Breadboard durchsichtig
3,90 EUR
Jumper Wires F/F 155mm yellow
0,32 EUR
Solarmodul 4,4V 95,0mA
13,90 EUR
DS1307Z+
1,85 EUR
Atmel JTAGICE3
138,90 EUR