终版
This commit is contained in:
@@ -33,6 +33,7 @@
|
||||
#define DEC_TO_BCD(dec) ((((dec) / 10) << 4) | ((dec) % 10))
|
||||
|
||||
// 微秒延时
|
||||
/* 函数作用:为 DS1302 时序提供简短的微秒级软件延时。 */
|
||||
static void delay_us(uint32_t us)
|
||||
{
|
||||
volatile uint32_t i;
|
||||
@@ -44,6 +45,7 @@ static void delay_us(uint32_t us)
|
||||
/**
|
||||
* @brief 配置IO口为输出
|
||||
*/
|
||||
/* 函数作用:把 DS1302 数据引脚配置为推挽输出模式。 */
|
||||
static void DS1302_DATAOUT_init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
@@ -56,6 +58,7 @@ static void DS1302_DATAOUT_init(void)
|
||||
/**
|
||||
* @brief 配置IO口为输入
|
||||
*/
|
||||
/* 函数作用:把 DS1302 数据引脚配置为浮空输入模式。 */
|
||||
static void DS1302_DATAINPUT_init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
@@ -67,6 +70,7 @@ static void DS1302_DATAINPUT_init(void)
|
||||
/**
|
||||
* @brief DS1302初始化
|
||||
*/
|
||||
/* 函数作用:初始化 DS1302 的时钟、数据和使能引脚。 */
|
||||
void DS1302_Init(void)
|
||||
{
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
@@ -92,6 +96,7 @@ void DS1302_Init(void)
|
||||
* @brief 向DS1302发送一字节数据(根据demo代码)
|
||||
* @param data 要发送的数据
|
||||
*/
|
||||
/* 函数作用:按 DS1302 时序向芯片写入一个字节。 */
|
||||
static void DS1302_write_onebyte(uint8_t data)
|
||||
{
|
||||
uint8_t count = 0;
|
||||
@@ -119,6 +124,7 @@ static void DS1302_write_onebyte(uint8_t data)
|
||||
* @param address 寄存器地址
|
||||
* @param data 数据
|
||||
*/
|
||||
/* 函数作用:向 DS1302 指定寄存器写入一个字节数据。 */
|
||||
void DS1302_WriteByte(uint8_t address, uint8_t data)
|
||||
{
|
||||
CE_L;
|
||||
@@ -141,6 +147,7 @@ void DS1302_WriteByte(uint8_t address, uint8_t data)
|
||||
* @param address 寄存器地址
|
||||
* @retval 读取到的数据
|
||||
*/
|
||||
/* 函数作用:从 DS1302 指定寄存器读取一个字节数据。 */
|
||||
uint8_t DS1302_ReadByte(uint8_t address)
|
||||
{
|
||||
uint8_t count = 0;
|
||||
@@ -184,6 +191,7 @@ uint8_t DS1302_ReadByte(uint8_t address)
|
||||
* @brief 设置DS1302时间
|
||||
* @param time 时间结构体指针
|
||||
*/
|
||||
/* 函数作用:把时间结构体转换为 BCD 后写入 DS1302。 */
|
||||
void DS1302_SetTime(DS1302_Time* time)
|
||||
{
|
||||
// 关闭写保护
|
||||
@@ -206,6 +214,7 @@ void DS1302_SetTime(DS1302_Time* time)
|
||||
* @brief 读取DS1302时间
|
||||
* @param time 时间结构体指针
|
||||
*/
|
||||
/* 函数作用:读取 DS1302 时间寄存器并转换为十进制时间结构体。 */
|
||||
void DS1302_GetTime(DS1302_Time* time)
|
||||
{
|
||||
uint8_t read_time[7];
|
||||
|
||||
Reference in New Issue
Block a user