Professional Documents
Culture Documents
Setting The DS1307 Real Time Clock Using The Seria PDF
Setting The DS1307 Real Time Clock Using The Seria PDF
Setting the DS1307 Real Time Clock using the Serial Monitor
by WWC on May 29, 2013
Table of Contents
Setting the DS1307 Real Time Clock using the Serial Monitor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Intro: Setting the DS1307 Real Time Clock using the Serial Monitor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Step 1: Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Related Instructables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Advertisements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
http://www.instructables.com/id/Setting-the-DS1307-Real-Time-Clock-using-the-Seria/
Author:WWC
Why would i buy something ready made when i can make it myself with half the features for twice the money? DIY!
Intro: Setting the DS1307 Real Time Clock using the Serial Monitor
The hardware is the standard setup and is as follows.
Complete details of this RTC can be found here. Just click on Technical Manual on the left side of the page.
Step 1: Code
Copy and past this into the Arduino IDE and burn to the board. For this i am using an ACEDuino that has a ATMega 328P.
To set the date and time is all done is the serial monitor, which is the easiest i have found.
///////////////////////////////////////////
// RTC data and time setter //
// //
// This sample program allows the user //
// to set the date and time of an RTC //
// using I2C. //
// //
// Codes by: //
// eGizmo Mechatronix Central //
// Taft, Manila, Philippines //
// http://www.egizmo.com //
// April 15, 2013 //
///////////////////////////////////////////
#include <Wire.h>
const int DS1307 = 0x68; // Address of DS1307 see data sheets
const char* days[] =
{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
const char* months[] =
{"January", "February", "March", "April", "May", "June", "July", "August","September", "October", "November", "December"};
void setup() {
http://www.instructables.com/id/Setting-the-DS1307-Real-Time-Clock-using-the-Seria/
Wire.begin();
Serial.begin(9600);
delay(2000); // This delay allows the MCU to read the current date and time.
// This set of functions allows the user to change the date and time
{
Serial.read();
setTime();
Serial.print("The current date and time is now: ");
printTime();
}
Serial.println("Thank you.");
}
byte readByte() {
while (!Serial.available()) delay(10);
byte reading = 0;
byte incomingByte = Serial.read();
while (incomingByte != '\n') {
if (incomingByte >= '0' & incomingByte <= '9')
reading = reading * 10 + (incomingByte - '0');
else;
incomingByte = Serial.read();
}
http://www.instructables.com/id/Setting-the-DS1307-Real-Time-Clock-using-the-Seria/
Serial.flush();
return reading;
}
void printTime() {
char buffer[3];
const char* AMPM = 0;
readTime();
Serial.print(days[weekday-1]);
Serial.print(" ");
Serial.print(months[month-1]);
Serial.print(" ");
Serial.print(monthday);
Serial.print(", 20");
Serial.print(year);
Serial.print(" ");
if (hour > 12) {
hour -= 12;
AMPM = " PM";
}
else AMPM = " AM";
Serial.print(hour);
Serial.print(":");
sprintf(buffer, "%02d", minute);
Serial.print(buffer);
Serial.println(AMPM);
}
void readTime() {
Wire.beginTransmission(DS1307);
Wire.write(byte(0));
Wire.endTransmission();
Wire.requestFrom(DS1307, 7);
second = bcdToDec(Wire.read());
minute = bcdToDec(Wire.read());
hour = bcdToDec(Wire.read());
weekday = bcdToDec(Wire.read());
monthday = bcdToDec(Wire.read());
month = bcdToDec(Wire.read());
year = bcdToDec(Wire.read());
}
http://www.instructables.com/id/Setting-the-DS1307-Real-Time-Clock-using-the-Seria/
Step 2: Open the Serial Monitor
Open up the serial monitor and this what you will see. The date and time will not be the same but that's OK we are here to correct this.
Please follow along with the pictures for the input sequence.
If you mess up just start over until you enter everything correctly.
Image Notes
1. After loading the sketch, open up the serial monitor.
Image Notes
1. Change to Newline in the bottom right of the monitor.
http://www.instructables.com/id/Setting-the-DS1307-Real-Time-Clock-using-the-Seria/
Image Notes
Image Notes 1. Input the month and hit enter
1. Input 13 and hit enter
http://www.instructables.com/id/Setting-the-DS1307-Real-Time-Clock-using-the-Seria/
Image Notes
Image Notes 1. Input the minutes and hit enter
1. Input the hour in 24hr format. If you do not know the 24 hr format. Take the
current time and add 12. If after noon. So 2:00 AM would be, 2:00. 2:00 PM would
be 14:00.
Image Notes
1. Everything inputted and now shows the time you have entered.
Image Notes
1. Change back to No line ending.
Related Instructables
Build yourself a
clock and
DS1307 Mental Clock with thermometer by Remake the
Health for Meggy Jr RGB arick Mosquito
Arduino Users Pong Clock by Killer(Arduino) Lunchtime
by florinc
by RayBurne mrnick1234567 by jack1986 Clock by randofo
http://www.instructables.com/id/Setting-the-DS1307-Real-Time-Clock-using-the-Seria/
Advertisements
http://www.instructables.com/id/Setting-the-DS1307-Real-Time-Clock-using-the-Seria/