DS1307如何实现掉电自动走时
用ds1307做了个小钟,可每次断电就成一开始设定的时间了,如何实现让它自己走时啊?#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <WProgram.h>
#include <Wire.h>
#include <DS1307.h>
LiquidCrystal_I2C lcd(0x27,16,2);// set the LCD address to 0x27 for a 16 chars and 2 line display
int rtc;
int ledPin =13;
void setup()
{
lcd.init(); // initialize the lcd
// Print a message to the LCD.
DDRC|=_BV(2) |_BV(3);// POWER:Vcc Gnd
PORTC |=_BV(3);// VCC PINC3
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
RTC.stop();
RTC.set(DS1307_SEC,1);
RTC.set(DS1307_MIN,16);
RTC.set(DS1307_HR,20);
RTC.set(DS1307_DOW,2);
RTC.set(DS1307_DATE,30);
RTC.set(DS1307_MTH,9);
RTC.set(DS1307_YR,14);
RTC.start();
lcd.backlight();
}
void loop()
{
RTC.get(rtc,true);
for(int i=0; i<7; i++)
{
Serial.print(rtc);
Serial.print(" ");
lcd.setCursor(1,0);
lcd.print(rtc);
lcd.setCursor(5, 0);
lcd.print("/");
lcd.setCursor(6, 0);
lcd.print(rtc);
lcd.print("/");
lcd.print(rtc);
lcd.setCursor(1, 1);
lcd.print(rtc);
lcd.setCursor(3, 1);
lcd.print(":");
lcd.setCursor(4, 1);
lcd.print(rtc);
lcd.setCursor(6, 1);
lcd.print(":");
lcd.setCursor(7, 1);
lcd.print(rtc);
}
Serial.println();
//digitalWrite(ledPin, HIGH);
delay(500);
//digitalWrite(ledPin, LOW);
delay(500);
} 把设置分成2个程序一个是MAIN,一个专门用来设置DS1307时间,断电后认为DS1307有后备电源,时间也一直在走,在上电后因为没下面的这些程序,时间就不会从新更新了。
void setup()
{
lcd.init(); // initialize the lcd
// Print a message to the LCD.
DDRC|=_BV(2) |_BV(3);// POWER:Vcc Gnd
PORTC |=_BV(3);// VCC PINC3
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
RTC.stop();
RTC.set(DS1307_SEC,1);
RTC.set(DS1307_MIN,16);
RTC.set(DS1307_HR,20);
RTC.set(DS1307_DOW,2);
RTC.set(DS1307_DATE,30);
RTC.set(DS1307_MTH,9);
RTC.set(DS1307_YR,14);
RTC.start();
lcd.backlight();
} 504835618 发表于 2014-9-30 21:27 static/image/common/back.gif
把设置分成2个程序一个是MAIN,一个专门用来设置DS1307时间,断电后认为DS1307有后备电源,时间也一直在走, ...
谢谢谢谢,意识到了 吧setup里的设置时间的代码干掉就行了。。。 加个纽扣电池作为备用电源 shihaipeng04 发表于 2014-10-1 12:05 static/image/common/back.gif
吧setup里的设置时间的代码干掉就行了。。。
已经解决了,谢谢大家
页:
[1]