⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ds1302.c

📁 CVAVR的函数库的源代码。开发AVR的编译器CodeVision AVR最新版本2.53的函数库c语言源代码。函数短小精悍
💻 C
字号:
/*
  CodeVisionAVR C Compiler
  (C) 1998-2004 Pavel Haiduc, HP InfoTech S.R.L.

  Dallas Semiconductors DS1302 Real Time Clock functions
*/

#include <bcd.h>

void rtc_init(unsigned char tc_on,unsigned char diodes,unsigned char res)
{
res&=3;
if (tc_on) res|=0xa0;
if (diodes==1) res|=4;
else if (diodes==2) res|=8;
else res=0;
ds1302_write(0x8e,0);
ds1302_write(0x90,res);
ds1302_write(0x8e,0x80);
}

void rtc_get_time(unsigned char *hour,unsigned char *min,unsigned char *sec)
{
*hour=bcd2bin(ds1302_read(0x85));
*min=bcd2bin(ds1302_read(0x83));
*sec=bcd2bin(ds1302_read(0x81));
}

void rtc_set_time(unsigned char hour,unsigned char min,unsigned char sec)
{
ds1302_write(0x8e,0);
ds1302_write(0x84,bin2bcd(hour));
ds1302_write(0x82,bin2bcd(min));
ds1302_write(0x80,bin2bcd(sec));
ds1302_write(0x8e,0x80);
}

void rtc_get_date(unsigned char *date,unsigned char *month,unsigned char *year)
{
*date=bcd2bin(ds1302_read(0x87));
*month=bcd2bin(ds1302_read(0x89));
*year=bcd2bin(ds1302_read(0x8d));
}

void rtc_set_date(unsigned char date,unsigned char month,unsigned char year)
{
ds1302_write(0x8e,0);
ds1302_write(0x86,bin2bcd(date));
ds1302_write(0x88,bin2bcd(month));
ds1302_write(0x8c,bin2bcd(year));
ds1302_write(0x8e,0x80);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -