I have read the ds1302 program in programming specifications.

Source: Internet
Author: User

Http://www.ourdev.cn/bbs/bbs_content.jsp? Bbs_sn = 5245747 & bbs_page_no = 1 & search_mode = 1 & search_text = 1302 & bbs_id = 9999

 

*--------------------------------------------------------------------

Function Name: a complete write operation of ds1302
Function:
Note: None
Note: None
Input:
Return: None
--------------------------------------------------------------------*/
Void write (uint8 ADDR, uint8 dat)
{
Clr_rst; // before SCL change to low level, RST must keep low level
Clr_sck;
Set_rst;

// Clr_sck; // also OK !!!
// Clr_rst;
// Set_rst;

// Clr_rst; // Error
// Set_rst;
// Clr_sck;

Operdata = 0x80 | (ADDR <1 );
Writebyte ();
Operdata = dat;
Writebyte ();
/* The following sentence here is not indispensable,
But insert this sentence here can prevent ariseing error!
Because when start operating, RST must keep low level! */
Clr_rst;
}
/*--------------------------------------------------------------------
Function Name: a complete read operation of ds1302
Function:
Note: None
Note: None
Input:
Return: None
--------------------------------------------------------------------*/
Uint8 read (uint8 cmd)
{
// Clr_rst;
Clr_sck;
Set_rst;
Operdata = (CMD <1) | 0x81;
Writebyte ();
Readbyte ();
/* The following sentence here is not indispensable,
But insert this sentence here can prevent ariseing error!
Because when start operating, RST must keep low level! */
Clr_rst;
Return (operdata );
}
/*--------------------------------------------------------------------
Function Name: ds1302 read time
Function:
Note: None
Note: None
Input:
Return: None
--------------------------------------------------------------------*/
Void ds1302_gettime (uint8 * BUF)
{
Uint8 houradr = 2, minuteadr = 1, secondadr = 0;

Buf [0] = read (secondadr );
Buf [0] = changehextoint (BUF [0]);

Buf [1] = read (minuteadr );
Buf [1] = changehextoint (BUF [1]);

Buf [2] = read (houradr );
Buf [2] = changehextoint (BUF [2]);

// Ds1302_speatime ();
}
/*--------------------------------------------------------------------
Function Name: ds1302 read date
Function:
Note: None
Note: None
Input: None
Return: None
--------------------------------------------------------------------*/
// Void ds1302_getdate (void)
//{
//
//}
/*--------------------------------------------------------------------
Function Name: ds1302 split time
Function:
Note: None
Note: the lower layer splits the time to facilitate upper layer calls.
Input: None
Return: None
--------------------------------------------------------------------*/
// Void ds1302_speatime (void)
//{
// Speadata (ds1302second, 2 );
// Ds1302sechi = dataelem [1];
// Ds1302seclow = dataelem [0];
//
// Speadata (ds1302minute, 2 );
// Ds1302minhi = dataelem [1];
// Ds1302minlow = dataelem [0];
//
// Speadata (ds1302hour, 2 );
// Ds1302hourhi = dataelem [1];
// Ds1302hourlow = dataelem [0];
//}
/*--------------------------------------------------------------------
Function Name: ds1302 split date
Function:
Note: None
Note: None
Input: None
Return: None
--------------------------------------------------------------------*/
// Void ds1302_speadate (void)
//{
//
//}
/*--------------------------------------------------------------------
Function Name: ds1302 set time
Function:
Note: None
Note: None
Input:
Return: None
--------------------------------------------------------------------*/
Void ds1302_settime (uint8 hour, uint8 minute, uint8 second)
{
Uint8 houradr = 2, minuteadr = 1, secondadr = 0;

Hour = changeinttohex (hour );
Minute = changeinttohex (minute );
Second = changeinttohex (second );

Openwp ();
Write (houradr, hour );
Write (minuteadr, minute );
Write (secondadr, second );
Closewp ();
}
/*--------------------------------------------------------------------
Function Name: ds1302 set date
Function:
Note: None
Note: None
Input:
Return: None
--------------------------------------------------------------------*/
// Void ds1302_setdate (uint8 year, uint8 month, uint8 Day)
//{
//
//}
/*--------------------------------------------------------------------
Function Name: ds1302 Initialization
Function:
Note: None
Note: None
Input: None
Return: None
--------------------------------------------------------------------*/
Void ds1302_init (void)
{
Out_sck;
Out_sio;
Out_rst;
Openwp ();
Setchargeprmt ();
Closewp ();
}

# Endif

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.