极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 13051|回复: 3

大家帮我看看问题(1602时钟+DS1307)

[复制链接]
发表于 2013-7-14 11:07:34 | 显示全部楼层 |阅读模式
本帖最后由 糯米基 于 2013-7-14 11:10 编辑

我的DS1307终于起振了,可是串口读得出来正确的时间,想接在1602上,可是遇到了问题

我包含了头文件,他怎么说没有声明的错误,请哪位帮我看看,先谢谢了
  1. #include <DS1307RTC.h>
  2. #include <Time.h>
  3. #include <Wire.h>
  4. #include <LiquidCrystal.h>

  5. void setup() {
  6.   LiquidCrystal lcd(12,11,5,4,3,2);
  7.   lcd.begin(16,2);
  8.   Serial.begin(9600);
  9.   while (!Serial) ; // wait for serial
  10.   delay(200);
  11.   Serial.println("DS1307RTC Read Test");
  12.   Serial.println("-------------------");
  13. }

  14. void loop() {
  15.   tmElements_t tm;

  16.   if (RTC.read(tm)) {
  17.     Serial.print("Ok, Time = ");
  18.     lcd.setCursor(4, 0);
  19.     print2digits(tm.Hour);
  20.     Serial.write(':');
  21.     print2digits(tm.Minute);
  22.     Serial.write(':');
  23.     print2digits(tm.Second);
  24.     Serial.print(", Date (D/M/Y) = ");
  25.     Serial.print(tm.Day);
  26.     Serial.write('/');
  27.     Serial.print(tm.Month);
  28.     Serial.write('/');
  29.     Serial.print(tmYearToCalendar(tm.Year));
  30.     Serial.println();
  31.   } else {
  32.     if (RTC.chipPresent()) {
  33.       Serial.println("The DS1307 is stopped.  Please run the SetTime");
  34.       Serial.println("example to initialize the time and begin running.");
  35.       Serial.println();
  36.     } else {
  37.       Serial.println("DS1307 read error!  Please check the circuitry.");
  38.       Serial.println();
  39.     }
  40.     delay(9000);
  41.   }
  42.   delay(1000);
  43. }

  44. void print2digits(int number) {
  45.   if (number >= 0 && number < 10) {
  46.     Serial.write('0');
  47.   }
  48.   Serial.print(number);
  49. }
复制代码

下面是我在网上找到的库文件
那个SET time文件可以自己读取电脑的时间哦,很方便

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

发表于 2013-7-14 12:54:24 | 显示全部楼层
lcd是void setup() 函数的局部变量,应该把它声明成全局的
  1. #include <DS1307RTC.h>
  2. #include <Time.h>
  3. #include <Wire.h>
  4. #include <LiquidCrystal.h>
  5.    LiquidCrystal lcd(12,11,5,4,3,2);
  6. void setup() {

  7.   lcd.begin(16,2);
  8.   Serial.begin(9600);
  9.   while (!Serial) ; // wait for serial
  10.   delay(200);
  11.   Serial.println("DS1307RTC Read Test");
  12.   Serial.println("-------------------");
  13. }

  14. void loop() {
  15.   tmElements_t tm;

  16.   if (RTC.read(tm)) {
  17.     Serial.print("Ok, Time = ");
  18.     lcd.setCursor(4, 0);
  19.     print2digits(tm.Hour);
  20.     Serial.write(':');
  21.     print2digits(tm.Minute);
  22.     Serial.write(':');
  23.     print2digits(tm.Second);
  24.     Serial.print(", Date (D/M/Y) = ");
  25.     Serial.print(tm.Day);
  26.     Serial.write('/');
  27.     Serial.print(tm.Month);
  28.     Serial.write('/');
  29.     Serial.print(tmYearToCalendar(tm.Year));
  30.     Serial.println();
  31.   } else {
  32.     if (RTC.chipPresent()) {
  33.       Serial.println("The DS1307 is stopped.  Please run the SetTime");
  34.       Serial.println("example to initialize the time and begin running.");
  35.       Serial.println();
  36.     } else {
  37.       Serial.println("DS1307 read error!  Please check the circuitry.");
  38.       Serial.println();
  39.     }
  40.     delay(9000);
  41.   }
  42.   delay(1000);
  43. }

  44. void print2digits(int number) {
  45.   if (number >= 0 && number < 10) {
  46.     Serial.write('0');
  47.   }
  48.   Serial.print(number);
  49. }
复制代码
回复 支持 反对

使用道具 举报

发表于 2013-7-31 21:40:02 | 显示全部楼层
楼主我想要Time库{:soso_e181:}
回复 支持 反对

使用道具 举报

发表于 2013-8-1 12:23:59 | 显示全部楼层
caizixian 发表于 2013-7-14 12:54
lcd是void setup() 函数的局部变量,应该把它声明成全局的#include
#include
#include

               
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-7 01:03 , Processed in 0.041781 second(s), 21 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表