|
|
用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[7];
- 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[i]);
- Serial.print(" ");
- lcd.setCursor(1,0);
- lcd.print(rtc[6]);
- lcd.setCursor(5, 0);
- lcd.print("/");
- lcd.setCursor(6, 0);
- lcd.print(rtc[5]);
-
- lcd.print("/");
-
- lcd.print(rtc[4]);
- lcd.setCursor(1, 1);
- lcd.print(rtc[2]);
- lcd.setCursor(3, 1);
- lcd.print(":");
- lcd.setCursor(4, 1);
- lcd.print(rtc[1]);
- lcd.setCursor(6, 1);
- lcd.print(":");
- lcd.setCursor(7, 1);
- lcd.print(rtc[0]);
- }
- Serial.println();
-
- //digitalWrite(ledPin, HIGH);
- delay(500);
- //digitalWrite(ledPin, LOW);
- delay(500);
- }
复制代码 |
|