极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 11336|回复: 3

DS3231 不能正常显示??求大神指导!

[复制链接]
发表于 2014-11-15 13:44:06 | 显示全部楼层 |阅读模式
我的代码是这样的:

  1. #include <DS3231.h>
  2. #include <Wire.h>

  3. DS3231 Clock;
  4. bool Century=false;
  5. bool h12;
  6. bool PM;
  7. byte ADay, AHour, AMinute, ASecond, ABits;
  8. bool ADy, A12h, Apm;

  9. byte year, month, date, DoW, hour, minute, second;

  10. void setup() {
  11.         // Start the I2C interface
  12.         Wire.begin();
  13.         Clock.setSecond(50);//Set the second
  14.         Clock.setMinute(59);//Set the minute
  15.         Clock.setHour(11);  //Set the hour
  16.         Clock.setDoW(5);    //Set the day of the week
  17.         Clock.setDate(31);  //Set the date of the month
  18.         Clock.setMonth(5);  //Set the month of the year
  19.         Clock.setYear(13);  //Set the year (Last two digits of the year)
  20.         // Start the serial interface
  21.         Serial.begin(115200);
  22. }
  23. void ReadDS3231()
  24. {
  25.   int second,minute,hour,date,month,year,temperature;
  26.   second=Clock.getSecond();
  27.   minute=Clock.getMinute();
  28.   hour=Clock.getHour(h12, PM);
  29.   date=Clock.getDate();
  30.   month=Clock.getMonth(Century);
  31.   year=Clock.getYear();
  32.   
  33.   temperature=Clock.getTemperature();
  34.   
  35.   Serial.print("20");
  36.   Serial.print(year,DEC);
  37.   Serial.print('-');
  38.   Serial.print(month,DEC);
  39.   Serial.print('-');
  40.   Serial.print(date,DEC);
  41.   Serial.print(' ');
  42.   Serial.print(hour,DEC);
  43.   Serial.print(':');
  44.   Serial.print(minute,DEC);
  45.   Serial.print(':');
  46.   Serial.print(second,DEC);
  47.   Serial.print('\n');
  48.   Serial.print("Temperature=");
  49.   Serial.print(temperature);
  50.   Serial.print('\n');
  51. }
  52. void loop() {ReadDS3231();delay(1000);}
复制代码



为什么串口打印出来的是

搞不懂啊@@

本帖子中包含更多资源

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

x
回复

使用道具 举报

发表于 2014-11-15 17:43:08 | 显示全部楼层
换个示例程序试试
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-11-15 19:53:52 | 显示全部楼层
是因为我是照http://www.geek-workshop.com/for ... mp;highlight=DS3231的方法做的,不过他用的是uno,我的是leonardo,结果SDA,SCL还是接A4A5是不行的!要接对应SDA,SCL
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-11-15 19:54:18 | 显示全部楼层
小A 发表于 2014-11-15 17:43
换个示例程序试试

是我接错了!
回复 支持 反对

使用道具 举报

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

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-15 17:28 , Processed in 0.037583 second(s), 20 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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