微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > DS1302控制代码

DS1302控制代码

时间:12-01 来源:互联网 点击:

seconds=((ReadValue&0x70)>>

minutes=((ReadValue&0x70)>>

hours=((ReadValue&0x70)>>

day=((ReadValue&0x70)>>

month=((ReadValue&0x70)>>

year=((ReadValue&0x70)>>

nian=((temp&0x70)>>

if(nian>

yue=((temp&0x70)>>

if(yue>

(0x88,(yue/10)<4|(yue%10));

DisplayMonth(yue);

write_1302(0x8e,0x80);

}

}

}

/*******************************************

修改天数

*******************************************/

if(cnt==3)

{

temp=read_1302(0x87);

ri=((temp&0x70)>>4)*10+(temp&0x0F);

if(K2==0)

{

delay(5);

if(K2==0)//K2键实现加

{

while(!K2);

delay(5);

while(!K2);//确保K2键松开

ri++;

if(ri>=32)

{

ri=1;

}

write_1302(0x8e,0x00);

write_1302(0x86,(ri/10)<4|(ri%10));

DisplayDay(ri);

write_1302(0x8e,0x80);

}

}

if(K3==0)

{

delay(5);

if(K3==0)//K3键实现减

{

while(!K3);

delay(5);

while(!K3);//确保K3键松开

ri--;

if(ri==0)

{

ri=31;

}

write_1302(0x8e,0x00);

write_1302(0x86,(ri/10)<4|(ri%10));

DisplayDay(ri);

write_1302(0x8e,0x80);

}

}

}

/*******************************************

修改周

*******************************************/

if(cnt==4)

{

temp=read_1302(0x8B);

zhou=((temp&0x70)>>4)*10+(temp&0x0F);

if(K2==0)

{

delay(5);

if(K2==0)//K2键实现加

{

while(!K2);

delay(5);

while(!K2);//确保K2键松开

zhou++;

if(zhou>=8)

{

zhou=1;

}

write_1302(0x8e,0x00);

write_1302(0x8a,(zhou/10)<4|(zhou%10));

DisplayWeek(zhou);

write_1302(0x8e,0x80);

}

}

if(K3==0)

{

delay(5);

if(K3==0)//K3键实现减

{

while(!K3);

delay(5);

while(!K3);//确保K3键松开

zhou--;

if(zhou==-1)

{

zhou=7;

}

write_1302(0x8e,0x00);

write_1302(0x8a,(zhou/10)<4|(zhou%10));

DisplayWeek(zhou);

write_1302(0x8e,0x80);

}

}

}

/*******************************************

修改小时

*******************************************/

if(cnt==5)

{

temp=read_1302(0x85);

shi=((temp&0x70)>>4)*10+(temp&0x0F);

if(K2==0)

{

delay(5);

if(K2==0)//K2键实现加

{

while(!K2);

delay(5);

while(!K2);//确保K2键松开

shi++;

if(shi>=24)

{

shi=0;

}

write_1302(0x8e,0x00);

write_1302(0x84,(shi/10)<4|(shi%10));

DisplayHours(shi);

write_1302(0x8e,0x80);

}

}

if(K3==0)

{

delay(5);

if(K3==0)//K3键实现减

{

while(!K3);

delay(5);

while(!K3);//确保K3键松开

shi--;

if(shi==-1)

{

shi=23;

}

write_1302(0x8e,0x00);

write_1302(0x84,(shi/10)<4|(shi%10));

DisplayHours(shi);

write_1302(0x8e,0x80);

}

}

}

/*******************************************

修改分钟

*******************************************/

if(cnt==6)

{

temp=read_1302(0x83);

fen=((temp&0x70)>>4)*10+(temp&0x0F);

if(K2==0)

{

delay(5);

if(K2==0)//K2键实现加

{

while(!K2);

delay(5);

while(!K2);//确保K2键松开

fen++;

if(fen>=60)

{

fen=0;

}

write_1302(0x8e,0x00);

write_1302(0x82,(fen/10)<4|(fen%10));

DisplayMinutes(fen);

write_1302(0x8e,0x80);

}

}

if(K3==0)

{

delay(5);

if(K3==0)//K3键实现减

{

while(!K3);

delay(5);

while(!K3);//确保K3键松开

fen--;

if(fen==-1)

{

fen=59;

}

write_1302(0x8e,0x00);

write_1302(0x82,(fen/10)<4|(fen%10));

DisplayMinutes(fen);

write_1302(0x8e,0x80);

}

}

}

/*******************************************

修改秒钟

*******************************************/

if(cnt==7)

{

temp=read_1302(0x81);

miao=((temp&0x70)>>4)*10+(temp&0x0F);

if(K2==0)

{

delay(5);

if(K2==0)//K2键实现加

{

while(!K2);

delay(5);

while(!K2);//确保K2键松开

miao++;

if(miao>=60)

{

miao=0;

}

write_1302(0x8e,0x00);

write_1302(0x80,(miao/10)<4|(miao%10));

DisplaySeconds(miao);

write_1302(0x8e,0x80);

}

}

if(K3==0)

{

delay(5);

if(K3==0)//K3键实现减

{

while(!K3);

delay(5);

while(!K3);//确保K3键松开

miao--;

if(miao==-1)

{

miao=59;

}

write_1302(0x8e,0x00);

write_1302(0x80,(miao/10)<4|(miao%10));

DisplaySeconds(miao);

write_1302(0x8e,0x80);

}

}

}

if(cnt==8)

{

cnt=0;

}

}

/*************************************

主函数

*************************************/

void main()

{

lcdInit();

flag1302=read_1302(0x81);

if(flag1302&0x80)//秒钟的最高位为1才需要初始化

{

Init_1302();

}

while(1)

{

change();

read_date();

}

}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top