?? ds1302.h
字號(hào):
#ifndef _DS1302_h
#define _DS1302_h
#include "c8051f340.h"
#include "intrins.h"
#define NOP _nop_()
#define uchar unsigned char
sbit IO=P3^1;
sbit SCLK=P3^2;
sbit RSTB=P3^3;
void delay(uchar i)
{
while (--i);
}
//*****************************RESET FUNCTION///////////////
void reset()
{
RSTB=0;
SCLK=0;
delay(100);
RSTB=1;
delay(100);
}
//***************************BYTE WRITE************//
void wbyte(uchar w_byte)
{
uchar i;
for(i=0;i<8;++i)
{
IO=0;
if(w_byte&0x01) IO=1;
SCLK=0;
delay(20);
SCLK=1;
delay(20);
w_byte>>=1;
}
}
//*********************** BYTE READ******************//
uchar rbyte()
{
uchar i;
uchar R_BYTE;
uchar TMPBYTE;
R_BYTE=0X00;
IO=1;
for(i=0;i<8;++i)
{
SCLK=1;
delay(20);
SCLK=0;
NOP;
TMPBYTE=(uchar)IO;
TMPBYTE<<=7;
R_BYTE>>=1;
R_BYTE|=TMPBYTE;
delay(20);
}
return(R_BYTE);
}
uchar time_data[8]={1,1,1,1,1,1,1,1};//sec,min,hrs,dte,mon,day,yr
uchar time_diplay[14]={0x31,0x35,0x38,0x32,0x39,0x33,0x34,0x33,0x32,0x37,0x31};
//*********************時(shí)間初始校準(zhǔn)與初始化**************************************//
void time_int_DS1302() //24小時(shí)模式
{
uchar time[8]={0,0,0x12,1,1,1,0,0};//sec,min,hrs,dte,mon,day,yr
// uchar i;
reset();
wbyte(0x8e);//寫保護(hù)控制寄存器
wbyte(0);//允許寫入
reset();
wbyte(0x90); //涓流充電控制寄存器
wbyte(0); //禁止充電
reset();
wbyte(0x80); //秒 //2000年1月1日12點(diǎn)0分13秒 星期一
wbyte(0x13);
reset();
wbyte(0x82); //分
wbyte(0x00);
reset();
wbyte(0x84); //HR
wbyte(0x12);
reset();
wbyte(0x86); //DATA
wbyte(0x00);
reset();
wbyte(0x88); //MOUTH
wbyte(0x00);
reset();
wbyte(0x8A); //DAY
wbyte(0x00);
reset();
wbyte(0x8C); //YEAR
wbyte(0x20);
reset();
// for(i=0;i<8;i++)
// wbyte(time[i]);
// reset();
}
//****************************************************************************
//****************DS1302顯示數(shù)據(jù) ASCII碼數(shù)字轉(zhuǎn)化 ***********************/
//******************************************************************************
void display_xlat()
{
uchar i,j=0,num1,num2;
for(i=0;i<7;i++)
{
num1=time_data[i]&0x0F;
num2=time_data[i];
num2>>=4;
time_diplay[j]=num1+0x30;
time_diplay[j+1]=num2+0x30;
j+=2;
}
}
//**********************時(shí)間顯示***************************************
void time_display_DS1302()
{
// uchar i;
reset();
wbyte(0x81); //burst read
//for(i=0;i<8;i++)
time_data[0]=rbyte();
reset();
// display_xlat();
}
#endif
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -