📄 d1302.c
字号:
#include <REG51.H>
#define Uchar unsigned char
#define Uint unsigned int
sbit tclk=P2^3;
sbit tio=P2^4;
sbit trst=P2^5;
/////////////////////////////////////////////
//时钟芯片读写程序
unsigned char byteout(void)
{
unsigned char i;
unsigned char result = 0;
for(i = 0; i < 8; i ++){
result >>= 1;
tio = 1;
if(tio)
result |= 0x80;
tclk = 1;
tclk = 0;
}
return (result);
}
void bytein(unsigned char value){
unsigned char i;
for(i = 0; i < 8; i ++){
if((value & 0x01) > 0)
tio = 1;
else
tio = 0;
tclk = 1;
tclk = 0;
value = value>>1 ;
}
}
void reset_1302(void){
unsigned char i;
trst=0;
for(i = 0; i < 80; i ++);
}
void set_1302(void){
unsigned char i;
trst=1;
for(i = 0; i < 80; i ++);
}
/****************************************/
/* 写时钟芯片 */
/****************************************/
void wtime(unsigned char *data1)
{
unsigned char i,j;
EA=0;
tio=1;
set_1302();
tclk=0;
bytein(0x8e);
bytein(0x00);
reset_1302();
set_1302();
tclk=0;
bytein(0x90);
bytein(0xa5);
reset_1302();
data1[6]=data1[6]&0x7f;
j=0x80;
for(i=0;i<7;i++)
{
set_1302();
bytein(j);
j=j+2;
bytein(data1[(6-i)]);
reset_1302();
}
set_1302();
bytein(0x8e);
bytein(0x80);
reset_1302();
tio=1;
EA=1;
}
/****************************************/
/* 读时钟芯片 */
/****************************************/
void rtime(unsigned char *data2)
{
unsigned char i,j;
EA=0;
tclk=0;
i++;
tio=1;
set_1302();
tclk=0;
j=0x81;
for(i=0;i<7;i++)
{
set_1302();
bytein(j);
j=j+2;
data2[(6-i)]=byteout();
reset_1302();
}
tio=1;
EA=1;
}
/****************************************/
/* 写时钟ram
/****************************************
void wram(Uchar *data1,Uchar num)
{
unsigned char i;
EA=0;
tclk=0;
tio=1;
set_1302();
tclk=0;
bytein(0x8e);
bytein(0);
reset_1302();
set_1302();
bytein(0xfe);
for(i=0;i<num;i++)
{
bytein(data1[i]);
}
reset_1302();
set_1302();
bytein(0x8e);
bytein(0x80);
reset_1302();
EA=1;
}
*/
/****************************************/
/* 读时钟芯片ram */
/***************************************
void rram(Uchar *data2,Uchar num)
{
unsigned char i;
EA=0;
tclk=0;
tio=1;
set_1302();
bytein(0xff);
for(i=0;i<num;i++)
{
data2[i]=byteout();
}
reset_1302();
EA=1;
}
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -