极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 12044|回复: 2

DS1307库文件含农历

[复制链接]
发表于 2015-11-14 01:52:42 | 显示全部楼层 |阅读模式
[pre lang="arduino" line="1" file="ds1307"]
//2015-11-14 01:35:10完成,代码都是上网下载修改的,将DS1307和农历例程合并
//邮箱:[email protected]
// DS1307:  SDA pin   -> Arduino Digital 4
//          SCL pin   -> Arduino Digital 5

#include <DS1307.h>

// Init the DS1307
DS1307  rtc(4, 5);

// Init a Time-data structure
Time  t;

void setup()
{
  //设置时钟的运行模式,还不知道有什么用
  rtc.halt(false);
  

  Serial.begin(9600);


rtc.setWeek(5);        //设置星期
rtc.setTime(23, 59, 50);     //设置时间23:53:00(24小时制)
rtc.setDate(2015, 11, 13);   //设置年、月、日
}

void loop()
{
  // 从DS1307读取数据
  t = rtc.getTime();
  
  // 显示公历
  Serial.print("GL:");
  Serial.print(t.year, DEC);   //公历年
  Serial.print("-");
  Serial.print(t.mon);   //公历月
  Serial.print("-");
  Serial.print(t.date, DEC);   //公历日

//显示农历
  Serial.print("   NL:");
  Serial.print(t.nmon);   //农历月
  Serial.print("-");
  Serial.print(t.ndate, DEC);   //农历日
  
  // Send Day-of-Week and time
  Serial.print("  week:");
  Serial.print(t.week, DEC);
  
  
  Serial.print("  time:");
  Serial.print(t.hour, DEC);
  Serial.print(":");
  Serial.print(t.min, DEC);
  Serial.print(":");
  Serial.println(t.sec, DEC);

  
  // Wait one second before repeating
  delay (1000);
}[/code]


本帖子中包含更多资源

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

x
回复

使用道具 举报

发表于 2016-3-25 09:55:36 | 显示全部楼层
好东西     感谢分享。之前下载的,有些文件不对劲。总之感谢楼主
回复 支持 反对

使用道具 举报

发表于 2017-8-20 08:23:15 | 显示全部楼层
谢谢楼主的分享
回复 支持 反对

使用道具 举报

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

本版积分规则 需要先绑定手机号

Archiver|联系我们|极客工坊

GMT+8, 2024-4-30 21:44 , Processed in 0.040027 second(s), 20 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2021, Tencent Cloud.

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