微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > [C51代码]DS1302驱动

[C51代码]DS1302驱动

时间:11-10 来源:互联网 点击:

/*********************ds1302.h**********************/
#ifndef __ds1302_h__
#define __ds1302_h__
#include
#include "Atmel/AT89X51.h"
#include "LINK.h"

/*******************宏定义********************/
#define WRITE_SECOND 0x80
#define WRITE_MINUTE 0x82
#define WRITE_HOUR 0x84
#define WRITE_DAY 0x86
#define WRITE_MONTH 0x88
#define WRITE_WEEK 0x8A
#define WRITE_YEAR 0x8C
#define WRITE_PROTECT 0x8E
#define READ_SECOND 0x81
#define READ_MINUTE 0x83
#define READ_HOUR 0x85
#define READ_DAY 0x87
#define READ_MONTH 0x89
#define READ_WEEK 0x8B
#define READ_YEAR 0x8D
#define BCD2DEC(X) (((X&0x70)/16)*10 + (X&0x0F)) //用于将BCD码转成十进制的宏
#define DEC2BCD(X) ((X/10)*16 + (X%10)) //用于将十进制转成BCD码的宏

/*******************端口定义********************/
sbit RST =P2^3;
sbit SCLK=P2^4;
sbit DIO =P2^5;

/****DS1302的声明函数****/
extern void DS1302Writebyte(uchar addr,uchar dat);
extern uchar DS1302Readbyte(uchar addr);
extern void DS1302Initial(void);
extern uchar WeekDay20(uchar y, uchar m, uchar d);
extern void DS1302Gettime(void);
extern void DS1302DataConvert(void);
extern void DS1302Disp(void);
extern void DS1302DataConvert(void);

/*********************变量定义**********************/
extern uchar DataArrayYear[5];
extern uchar DataArrayMonth[3];
extern uchar DataArrayDay[3];
extern uchar TimeArray[9];
extern uchar WeekArray[7][4];

typedef struct //定义的时间类型结构体,全部数为十进制
{
uchar Second;
uchar Minute;
uchar Hour;
uchar Week;
uchar Day;
uchar Month;
uchar Year;
}systemtime;

extern systemtime Nowtime;

#endif

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top