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

📄 1302.h

📁 DS1302的读写程序
💻 H
字号:
#include "General.h"

#ifndef _H_1302
#define _H_1302

#define _USE_1302

#ifdef  _USE_1302

//时间表述
typedef struct tgTime
{
  unsigned char Year;//2000年为0,BCD格式
  unsigned char Month;
  unsigned char Date;
  unsigned char Hour;
  unsigned char Minute;
  unsigned char Second;
} Time;
 
 
 //------------------时钟控制有关-------------------------------------------------
//控制DS1302 FROM DALLAS
#define PIN1302_RST     (0x40) //P6.6
#define RTC1302RSTOUT   (P6DIR |= PIN1302_RST) //P6.6 be out
#define RTC1302RSTH     (P6OUT |= PIN1302_RST) //P6.6 High
#define RTC1302RSTL     (P6OUT &= ~PIN1302_RST) //P6.6 Low, Reset DS1302

#define PIN1302_CLK     (0x10) //P6.4
#define RTC1302SCLKOUT  (P6DIR |= PIN1302_CLK) //P6.4 be out
#define RTC1302SCLKH    (P6OUT |= PIN1302_CLK) //P6.4 High, DS1302 clock high
#define RTC1302SCLKL    (P6OUT &= ~PIN1302_CLK) //P6.4 Low, DS1302 clock Low

#define PIN1302_DATA    (0x20) //P6.5
#define RTC1302SDATAOUT (P6DIR |= PIN1302_DATA) //P6.5 be out
#define RTC1302SDATAIN  (P6DIR &= ~PIN1302_DATA) //P6.5 be in
#define RTC1302SDATAH   (P6OUT |= PIN1302_DATA) //P6.5 High
#define RTC1302SDATAL   (P6OUT &= ~PIN1302_DATA) //P6.5 Low
#define RTC1302SDATA    (P6IN & PIN1302_DATA)
void Init_time(void);

//命令, LSB out first
#define RTCWRSEC        0x80
#define RTCRDSEC        0x81
#define RTCWRMIN        0x82
#define RTCRDMIN        0x83
#define RTCWRHOUR       0x84
#define RTCRDHOUR       0x85
#define RTCWRDATE       0x86
#define RTCRDDATE       0x87
#define RTCWRMON        0x88
#define RTCRDMON        0x89
#define RTCWRWK         0x8A
#define RTCRDWK         0x8B
#define RTCWRYEAR       0x8C
#define RTCRDYEAR       0x8D
#define RTCWRCTL        0x8E
#define RTCRDCTL        0x8F
#define RTCWRCHG        0x90
#define RTCRDCHG        0x91
#define RTCWRBST        0xBE
#define RTCRDBST        0xBF

#endif 

void  Init1302();//DS1302初始化
char  RTCRead(char datum);//read data
void  RTCWrite(char which,char value);//Write data
void  RTCSetTime(const char *tstr);//设置时钟
void  RTCShowTime(uchar row);//显示时间
void  RTCReadTime();//读取系统时钟
void  RTCClearTimeBuffer();//清除缓冲时间
void  RTCGetTime(char com);//输出时间字符串


extern Time  SysTime;//系统时间
extern Time  NewTime;

#endif

⌨️ 快捷键说明

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