3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

arduinoでRTC

Last updated at Posted at 2015-08-19

オークションで購入したDS1307を、arduino unoに、つないで見ました。

写真

MVC-016S.JPG

回路図

ds1307kairo.PNG

ハイパーターミナル

ds1307.PNG

ライブラリー作りました。ide1.6.5用

サンプルコード

# include <Wire.h>
# include <Time.h>
# include "Ds1307.h"

Ds1307 rtc;
void printDigits(int digits)
{
	Serial.print(":");
	if (digits < 10) Serial.print('0');
	Serial.print(digits);
}
void digitalClockDisplay()
{
    Serial.print(year());
    Serial.print("/");
    Serial.print(month());
    Serial.print("/");
    Serial.print(day());
    Serial.print(" ");
	Serial.print(hour());
	printDigits(minute());
	printDigits(second());
	Serial.println();
}
void setup()
{
	pinMode(13, OUTPUT);
	rtc = Ds1307();
	Serial.begin(9600);
	Serial.println("\r\nread rtc ->");
	setSyncProvider(rtc.get);
	if (timeStatus() != timeSet) Serial.println("Unable to sync with the RTC");
	else  Serial.println("RTC has set the system time");
}
void loop()
{
	digitalClockDisplay();
	digitalWrite(13, HIGH);
	delay(3000);
	digitalWrite(13, LOW);
	delay(3000);
}

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?