欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136
標題:
DS1302是怎么初始化時間的
[打印本頁]
作者:
禮小梔
時間:
2018-6-1 10:18
標題:
DS1302是怎么初始化時間的
程序如下
DS1302頭文件
實現(xiàn)功能:DS1302的控制
補充說明:
***************************************************************/
#ifndef _DS1302_H_
#define _DS1302_H_
#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
/*****************DS1302引腳定義*******************/
sbit SCLK = P1^7; // DS1302時鐘信號 7腳
sbit DIO = P3^2; // DS1302數(shù)據(jù)信號 6腳
sbit CE = P3^4; // DS1302片選 5腳
/*****************位尋址寄存器定義*******************/
sbit ACC_7 = ACC^7;
/*****************DS1302寄存器宏定義*****************/
#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_YEA 0x8c
#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_YEA 0x8d
#define WRITE_PROTECT 0x8E
/*****************DS1302函數(shù)定義*********************/
void Writeds1302 ( uchar addr,dat); //DS1302指定地址,寫數(shù)據(jù)
uchar Read1302 ( uchar addr ); //DS1302指定地址,讀數(shù)據(jù)
uchar Read1302_yuanshi(uchar addr); //DS1302讀原始數(shù)據(jù)函數(shù)
void Read_time(void); //DS1302讀時間日期函數(shù)
void DS1302_init(void); //DS1302初始化函數(shù)
/*****************DS1302變量定義*********************/
uchar data time[]={0x00,0x00,0x00,0x00,0x00,0x00,0x00}; //存儲秒,分,時,日,月,星期,年
/********************************************************
函數(shù)名稱:void Writeds1302 ( unsigned char addr,dat )
函數(shù)作用:DS1302發(fā)送地址,數(shù)據(jù)
參數(shù)說明:addr:地址,dat:數(shù)據(jù)
********************************************************/
void Writeds1302 ( uchar addr,dat )
{
unsigned char i,temp;
CE=0; //CE引腳為低,數(shù)據(jù)傳送中止
SCLK=0; //清零時鐘總線
CE = 1; //CE引腳為高,邏輯控制有效
//發(fā)送地址
for ( i=8; i>0; i-- ) //循環(huán)8次移位
{
SCLK = 0;
temp = addr;
DIO = (bit)(temp&0x01); //每次傳輸?shù)妥止?jié)
addr >>= 1; //右移一位
SCLK = 1;
}
//發(fā)送數(shù)據(jù)
for ( i=8; i>0; i-- )
{
SCLK = 0;
temp = dat;
DIO = (bit)(temp&0x01);
dat >>= 1;
SCLK = 1;
}
SCLK=1;
CE = 0;
}
/********************************************************
函數(shù)名稱:uchar Read1302 ( uchar addr )
函數(shù)作用:DS1302讀取數(shù)據(jù)并轉(zhuǎn)化成十進制
參數(shù)說明:addr參考DS1302寄存器宏定義
********************************************************/
uchar Read1302 ( uchar addr )
{
unsigned char i,temp,dat1,dat2;
CE=0;
SCLK=0;
CE = 1;
//發(fā)送地址
for ( i=8; i>0; i-- ) //循環(huán)8次移位
{
SCLK = 0;
temp = addr;
DIO = (bit)(temp&0x01); //每次傳輸?shù)妥止?jié)
addr >>= 1; //右移一位
SCLK = 1;
}
//讀取數(shù)據(jù)
for ( i=8; i>0; i-- )
{
ACC_7=DIO;
SCLK = 1;
ACC>>=1;
SCLK = 0;
}
SCLK=1;
CE=0;
dat1=ACC;
dat2=dat1/16; //數(shù)據(jù)進制轉(zhuǎn)換
dat1=dat1%16; //十六進制轉(zhuǎn)十進制
dat1=dat1+dat2*10;
return (dat1);
}
/********************************************************
函數(shù)名稱:void Read_time(void)
函數(shù)作用:DS1302讀取時間日期
參數(shù)說明:
********************************************************/
void Read_time(void)
{
time[0]=Read1302(0x81);
time[1]=Read1302(0x83);
time[2]=Read1302(0x85);
time[3]=Read1302(0x87);
time[4]=Read1302(0x89);
time[5]=Read1302(0x8b);
time[6]=Read1302(0x8d);
}
#endif
作者:
baidx_1981
時間:
2019-3-14 14:58
unsigned char time_buf[8] = {0x20,0x18,0x08,0x01,0x00,0x00,0x00,0x03};//20180801 00:00:00 周三
ds1302_init(); //DS13023õê¼»ˉ
ds1302_write_byte(ds1302_control_add,0x00); //關(guān)寫保護
ds1302_write_byte(ds1302_sec_add,0x80); //暫時停掉時鐘
//ds1302_write_byte(ds1302_charger_add,0xa9); //涓涓充電
ds1302_write_byte(ds1302_year_add,time_buf[1]); //年
ds1302_write_byte(ds1302_month_add,time_buf[2]); //月
ds1302_write_byte(ds1302_date_add,time_buf[3]); //日
ds1302_write_byte(ds1302_hr_add,time_buf[4]); //時
ds1302_write_byte(ds1302_min_add,time_buf[5]); //分
ds1302_write_byte(ds1302_sec_add,time_buf[6]); //秒
ds1302_write_byte(ds1302_day_add,time_buf[7]); //周
ds1302_write_byte(ds1302_control_add,0x80); //開寫保護
作者:
lml0508
時間:
2019-3-14 17:50
可以自己寫進初始時間
作者:
stc89cxx
時間:
2019-7-11 00:00
lml0508 發(fā)表于 2019-3-14 17:50
可以自己寫進初始時間
這個初始化時間是怎么計算的啊
作者:
哎呀好氣好氣
時間:
2020-7-4 17:56
stc89cxx 發(fā)表于 2019-7-11 00:00
這個初始化時間是怎么計算的啊
初始時間順序是秒分時日月周年,格式是用BCD碼
歡迎光臨 (http://m.raoushi.com/bbs/)
Powered by Discuz! X3.1