《2022年DS时钟芯片单片机c语言程序 2.pdf》由会员分享,可在线阅读,更多相关《2022年DS时钟芯片单片机c语言程序 2.pdf(5页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、#ifndef _DS1302_H_#define _DS1302_H_#define uchar unsigned char#define uint unsigned int#include sbit SCLK=P32;sbit IO=P24;sbit RST=P33;#define R_Second 0 x81#define W_Second 0 x80#define R_Minute 0 x83#define W_Minute 0 x82#define R_Hour 0 x85#define W_Hour 0 x84#define R_Day 0 x87#define W_Day 0 x
2、86#define R_Month 0 x89#define W_Month 0 x88#define R_Week 0 x8B#define W_Week 0 x8A#define R_Year 0 x8D#define W_Year 0 x8C#define R_Control 0 x8F#define W_Control 0 x8E void DS1302_Write_Byte(uchar Date);uchar DS1302_Read_Byte();void Write_DS1302(uchar Adr,uchar Date);uchar Read_DS1302(uchar Adr);
3、void Init_DS1302();#endif 名师资料总结-精品资料欢迎下载-名师精心整理-第 1 页,共 5 页 -#include ds1302.h/*函數名稱:DS1302_Write_Byte(uchar Date)函數功能:单字节写輸入參數:写的字节輸出參數:无備注:*/void DS1302_Write_Byte(uchar Date)uchar i;for(i=0;i 1;SCLK=0;/*函數名稱:uchar DS1302_Read_Byte()函數功能:单字节读輸入參數:无輸出參數:读出的数据備注:*/uchar DS1302_Read_Byte()名师资料总结-精品资
4、料欢迎下载-名师精心整理-第 2 页,共 5 页 -uchar i,Temp=0;for(i=0;i 1;SCLK=0;if(IO=1)Temp=Temp|0 x80;SCLK=1;return Temp;/*函數名稱:Write_DS1302(uchar Adr,uchar Date)函數功能:写数据輸入參數:写的寄存器地址和数据輸出參數:无備注:*/void Write_DS1302(uchar Adr,uchar Date)RST=0;SCLK=0;RST=1;DS1302_Write_Byte(Adr);DS1302_Write_Byte(Date);RST=0;/*函數名稱:ucha
5、r Read_DS1302(uchar Adr)名师资料总结-精品资料欢迎下载-名师精心整理-第 3 页,共 5 页 -函數功能:读数据輸入參數:写的寄存器地址輸出參數:读出的数据備注:*/uchar Read_DS1302(uchar Adr)uchar Temp=0;RST=0;SCLK=0;RST=1;DS1302_Write_Byte(Adr);Temp=DS1302_Read_Byte();RST=0;Temp=Temp/16*10+Temp%16;return Temp;/*函數名稱:Init_DS1302()函數功能:初始化 DS1302 輸入參數:无輸出參數:无備注:*/voi
6、d Init_DS1302()Write_DS1302(W_Control,0 x00);Write_DS1302(W_Year,0 x11);Write_DS1302(W_Week,0 x06);Write_DS1302(W_Month,0 x09);Write_DS1302(W_Day,0 x10);Write_DS1302(W_Hour,0 x16);Write_DS1302(W_Minute,0 x11);名师资料总结-精品资料欢迎下载-名师精心整理-第 4 页,共 5 页 -Write_DS1302(W_Second,0 x23);Write_DS1302(W_Control,0 x80);名师资料总结-精品资料欢迎下载-名师精心整理-第 5 页,共 5 页 -