DS1302读写程序

来源:本站
导读:目前正在解读《DS1302读写程序》的相关信息,《DS1302读写程序》是由用户自行发布的知识型内容!下面请观看由(电工技术网 - www.9ddd.net)用户发布《DS1302读写程序》的详细说明。
简介:本文主要介绍了DS1302读写程序。

#include<reg51.h>

#define uchar unsigned char

#define uint unsigned int

uchar sec,min,hr;

sbit clk=P1^0;

sbit dat=P1^1;

sbit rst=P1^2;

sbit A0=ACC^0;

sbit A1=ACC^1;

sbit A2=ACC^2;

sbit A3=ACC^3;

sbit A4=ACC^4;

sbit A5=ACC^5;

sbit A6=ACC^6;

sbit A7=ACC^7;

sbit blue=P1^5;

sbit green=P1^6;

sbit red=P1^7;

void InputByte(uchar dd)//mcu to ds1302

{

uchar i;

ACC=dd;

for(i=8;i>0;i--)

{

dat=A0;

clk=1;

clk=0;

ACC=ACC>>=1;

}

}

//-------------------------------------------------------

uchar OutputByte(void) //ds1302 to mcu

{

uchar i;

dat=1;

for(i=8;i>0;i--)

{

ACC=ACC>>1;

A7=dat;

clk=1;

clk=0;

}

return(ACC);

}

//--------------------------------------------------

void Write(uchar addr,uchar num)

{

rst=0;

clk=0;

rst=1;

InputByte(addr); // address

InputByte(num); //data

clk=1;

rst=0;

}

//-------------------------------------------------

uchar Read(uchar addr)

{

uchar dd=0;

rst=0;

clk=0;

rst=1;

InputByte(addr);

dd=OutputByte();

clk=1;

rst=0;

return(dd);

}

//--------------------------------------------------------------

uchar ReadSec()

{

uchar dd;

dd=Read(0x81);

return(dd);

}

//--------------------------------------------------------------

uchar ReadMin()

{

uchar dd;

dd=Read(0x83);

return(dd);

}

//--------------------------------------------------------------

uchar ReadHr()

{

uchar dd;

dd=Read(0x85);

return(dd);

}

//------------------------------------------------------------

uchar ReadWe()

{

uchar dd;

dd=Read(0x8b);

return(dd);

}

//------------------------------------------------------------

uchar ReadDay()

{

uchar dd;

dd=Read(0x87);

return(dd);

}

//------------------------------------------------------------

uchar ReadMn()

{

uchar dd;

dd=Read(0x89);

return(dd);

}

//------------------------------------------------------------

uchar ReadYs()

{

uchar dd;

dd=Read(0x8d);

return(dd);

}

//------------------------------------------------------------

void WriteSec(uchar num)

{

Write(0x80,num);

}

//-----------------------------------------------------------

void WriteMin(uchar num)

{

Write(0x82,num);

}

//-----------------------------------------------------------

void WriteHr(uchar num)

{

Write(0x84,num);

}

//-----------------------------------------------------------

void WriteDay(uchar num)

{

Write(0x86,num);

}

//-----------------------------------------------------------

void WriteMn(uchar num)

{

Write(0x88,num);

}

//-----------------------------------------------------------

void WriteWe(uchar num)

{

Write(0x8a,num);

}

//-----------------------------------------------------------

void WriteYs(uchar num)

{

Write(0x8c,num);

}

//-----------------------------------------------------------

void DisableWP(void) //write data,read 0

{

Write(0x8e,0x00);

}

//----------------------------------------------------------

void EnableWP(void) //can''d write,read data

{

Write(0x85,0x80);

}

void delay()

{uint i,j;

for(i=0;i<1000;i++)

{

for(j=0;j<40;j++){}

}

}

void main(void)

{

DisableWP();

WriteSec(0x00);

WriteMin(0x57);

WriteHr(0x10);

WriteDay(0x07);

WriteMn(0x06);

WriteWe(0x02);

WriteYs(0x05);

}

提醒:《DS1302读写程序》最后刷新时间 2024-03-14 01:02:56,本站为公益型个人网站,仅供个人学习和记录信息,不进行任何商业性质的盈利。如果内容、图片资源失效或内容涉及侵权,请反馈至,我们会及时处理。本站只保证内容的可读性,无法保证真实性,《DS1302读写程序》该内容的真实性请自行鉴别。