DS1302控制代碼
/*******************************************
修改小時
*******************************************/
if(cnt==5)
{
temp=read_1302(0x85);
shi=((temp&0x70)>>4)*10+(temp&0x0F);
if(K2==0)
{
delay(5);
if(K2==0)//K2鍵實現(xiàn)加
{
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鍵實現(xiàn)減
{
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鍵實現(xiàn)加
{
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鍵實現(xiàn)減
{
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鍵實現(xiàn)加
{
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鍵實現(xiàn)減
{
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;
}
}
/*************************************
主函數(shù)
*************************************/
void main()
{
lcdInit();
flag1302=read_1302(0x81);
if(flag1302&0x80)//秒鐘的最高位為1才需要初始化
{
Init_1302();
}
while(1)
{
change();
read_date();
看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人
(function(){
var bp = document.createElement('script');
var curProtocol = window.location.protocol.split(':')[0];
if (curProtocol === 'https') {
bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
}
else {
bp.src = 'http://push.zhanzhang.baidu.com/push.js';
}
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(bp, s);
})();
評論