资源简介
DS1302的Arduino函数库,提供的zip,可手动添加在Arduino安装目录的library中
代码片段和文件信息
/*
DS1302.cpp - Arduino library support for the DS1302 Trickle Charge Timekeeping Chip
Copyright (C)2010 Henning Karlsen. All right reserved
You can find the latest version of the library at
http://www.henningkarlsen.com/electronics
This library has been made to easily interface and use the DS1302 RTC with
the Arduino.
If you make any modifications or improvements to the code I would appreciate
that you share the code with me so that I might include it in the next release.
I can be contacted through http://www.henningkarlsen.com/electronics/contact.php
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License or (at your option) any later version.
This library is distributed in the hope that it will be useful
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not write to the Free Software
Foundation Inc. 51 Franklin St Fifth Floor Boston MA 02110-1301 USA
*/
#include “DS1302.h“
#define REG_SEC 0
#define REG_MIN 1
#define REG_HOUR 2
#define REG_DATE 3
#define REG_MON 4
#define REG_DOW 5
#define REG_YEAR 6
#define REG_WP 7
#define REG_TCR 8
/* Public */
Time::Time()
{
this->year = 2010;
this->mon = 1;
this->date = 1;
this->hour = 0;
this->min = 0;
this->sec = 0;
this->dow = 5;
}
DS1302_RAM::DS1302_RAM()
{
for (int i=0; i<31; i++)
cell[i]=0;
}
DS1302::DS1302(uint8_t ce_pin uint8_t data_pin uint8_t sclk_pin)
{
_ce_pin = ce_pin;
_data_pin = data_pin;
_sclk_pin = sclk_pin;
pinMode(_ce_pin OUTPUT);
pinMode(_sclk_pin OUTPUT);
}
Time DS1302::getTime()
{
Time t;
_burstRead();
t.sec = _decode(_burstArray[0]);
t.min = _decode(_burstArray[1]);
t.hour = _decodeH(_burstArray[2]);
t.date = _decode(_burstArray[3]);
t.mon = _decode(_burstArray[4]);
t.dow = _burstArray[5];
t.year = _decodeY(_burstArray[6])+2000;
return t;
}
void DS1302::setTime(uint8_t hour uint8_t min uint8_t sec)
{
if (((hour>=0) && (hour<24)) && ((min>=0) && (min<60)) && ((sec>=0) && (sec<60)))
{
_writeRegister(REG_HOUR _encode(hour));
_writeRegister(REG_MIN _encode(min));
_writeRegister(REG_SEC _encode(sec));
}
}
void DS1302::setDate(uint8_t date uint8_t mon uint16_t year)
{
if (((date>0) && (date<=31)) && ((mon>0) && (mon<=12)) && ((year>=2000) && (year<3000)))
{
year -= 2000;
_writeRegister(REG_YEAR _encode(year));
_writeRegister(REG_MON _encode(mon));
_writeRegister(REG_DATE _encode(date));
}
}
void DS1302::setDOW(uint8_t dow)
{
if ((dow>0) && (dow<8))
_writeRegister(REG_DOW dow);
}
char *DS1302::getTimeStr(uint8_t format)
{
char *output= “xxxxxxxx“;
Time t;
t=getTime();
if
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2014-11-10 12:27 DS1302\
目录 0 2014-11-10 12:27 DS1302\examples\
目录 0 2014-11-10 12:27 DS1302\examples\DS1302_LCD\
目录 0 2014-11-10 12:27 DS1302\examples\DS1302_RAM_Demo\
目录 0 2014-11-10 12:27 DS1302\examples\DS1302_Serial_Easy\
目录 0 2014-11-10 12:27 DS1302\examples\DS1302_Serial_Hard\
文件 203 2012-01-26 03:53 DS1302\version.txt
文件 24356 2010-01-29 07:16 DS1302\LICENSE.txt
文件 847 2010-11-17 04:55 DS1302\keywords.txt
文件 57266 2012-01-26 03:56 DS1302\DS1302.pdf
文件 3298 2012-01-26 04:05 DS1302\DS1302.h
文件 10181 2012-01-26 03:53 DS1302\DS1302.cpp
文件 1668 2010-08-06 05:47 DS1302\examples\DS1302_LCD\DS1302_LCD.pde
文件 1997 2010-08-22 17:23 DS1302\examples\DS1302_RAM_Demo\DS1302_RAM_Demo.pde
文件 1209 2013-11-05 13:56 DS1302\examples\DS1302_Serial_Easy\DS1302_Serial_Easy.ino
文件 1837 2010-08-06 06:39 DS1302\examples\DS1302_Serial_Hard\DS1302_Serial_Hard.pde
- 上一篇:Debian服务器设置入门
- 下一篇:基于51单片机的GPS定位程序
相关资源
- 基于AT89C52单片机的万年历protel原理图
- LCD12864 万年历 单片机 农历 显示 温度
- DS1302实时时钟,LCD1602显示,可调时间
- 基于STC15W408AS的串口DS1302时钟
- DS1302+1602液晶+测温多组闹铃
- zw_DS1302.zip
- 基于AT89C51单片机的电子计时牌设计
- MSP430G2553和DS1302时钟程序
- 用DS1302与LCD12864设计的可调电子钟及仿
- 电子万年历毕业设计基于AT89C51单片机
- 基于DS1302的4位LED滚动日历
- 单片机多功能数字时钟报告1602LCD Ds
- DS1302 VHDL
- arduino和ds1302的基于lcd12864闹钟,按键
- 基于DS1302+AT89C2051制作的红外遥控LED电
- 基于51单片机DS1302四位数码管可调时钟
- 基于单片机和DS1302电子万年历的设计
- 1602液晶显示DS1302实时时钟程序
- TI的msp430f5529读取DS1302时钟芯片,可以
- STM32库函数DS1302驱动文件
- STM32 DS1302驱动
- DS1302 LCD1602显示 protues仿真
- 用51单片机驱动DS1302时间模块+DS18B20温
- 1602电子时钟万年历isis仿真文件,程序
- DS1302 单片机万年历
- 89C2051+DS1302+74HC595+8位LED数码管的电子
- ds1302时钟、温度、LCD1602显示,按键设
- 51单片机1602与DS1302万年历仿真,时钟
- MSP430时钟程序
- 0011、采用实时时钟芯片DS1302+AT89C205
评论
共有 条评论