新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > DS1302用1602顯示加按鍵調時

DS1302用1602顯示加按鍵調時

作者: 時間:2016-12-02 來源:網(wǎng)絡 收藏

/*********************向1602寫入時間****************************/
void write_second()
{
uchar shi,ge;
shi=second/10;
ge=second%10;
Write1602(0x80+0x40+9,0x30+shi);
Write1602(0x80+0x40+10,0x30+ge);
}
void write_minute()
{
uchar shi,ge;
shi=minute/10;
ge=minute%10;
Write1602(0x80+0x40+6,0x30+shi);
Write1602(0x80+0x40+7,0x30+ge);
}
void write_hour()
{
uchar shi,ge;
shi=hour/10;
ge=hour%10;
Write1602(0x80+0x40+3,0x30+shi);
Write1602(0x80+0x40+4,0x30+ge);
}

本文引用地址:http://m.butianyuan.cn/article/201612/324681.htm

void write_day()
{
uchar shi,ge;
shi=day/10;
ge=day%10;
Write1602(0x80+8,0x30+shi);
Write1602(0x80+9,0x30+ge);
}
void write_month()
{
uchar shi,ge;
shi=month/10;
ge=month%10;
Write1602(0x80+5,0x30+shi);
Write1602(0x80+6,0x30+ge);
}
void write_year()
{
uchar shi,ge;
shi=year/10;
ge=year%10;
Write1602(0x80+2,0x30+shi);
Write1602(0x80+3,0x30+ge);
}
void write_week()
{
Write1602(0x80+12,0x30+week);
//uchar week;
switch(week)
{
case 1: Write1602(0x80+12,M);
Write1602(0x80+13,O);
Write1602(0x80+14,N);
break;
case 2:Write1602(0x80+12,T);
Write1602(0x80+13,U);
Write1602(0x80+14,E);
break;
case 3:Write1602(0x80+12,W);
Write1602(0x80+13,E);
Write1602(0x80+14,N);
break;
case 4:Write1602(0x80+12,T);
Write1602(0x80+13,H);
Write1602(0x80+14,U);
break;
case 5:Write1602(0x80+12,F);
Write1602(0x80+13,R);
Write1602(0x80+14,I);
break;
case 6:Write1602(0x80+12,S);
Write1602(0x80+13,A);
Write1602(0x80+14,T);
break;
case 7:Write1602(0x80+12,S);
Write1602(0x80+13,U);
Write1602(0x80+14,N);
break;
}
}
/*********************鍵盤掃描****************************/
void keyscan()
{
if(key==0)
{
delay(5);
if(key==0);//防止誤動作
{

S1num++;
while(!key);
switch(S1num)
{
case 1:
keyflag=1;
write_1302(0x8e,0x00);//去除寫保護
write_1302(0x80,0x80);//時鐘停下
write_1602com(0x80+0x40+10);
write_1602com(0x0f);
break;
case 2:
write_1602com(0x80+0x40+7);
break;
case 3:
write_1602com(0x80+0x40+4);
break;
case 4:
write_1602com(0x80+9);
break;
case 5:
write_1602com(0x80+6);
break;
case 6:
write_1602com(0x80+3);
break;
case 7:
write_1602com(0x80+12);
break;
case 8:
S1num=0;
keyflag=0;

write_1602com(0x0c);//不顯示光標
write_1302(0x80,0x00);//禁止寫保護
write_1302(0x80,(second/10)<<4|second%10);//將調節(jié)后的秒寫入DS1302
write_1302(0x82,(minute/10)<<4|minute%10);//將調節(jié)后的分寫入DS1302
write_1302(0x84,(hour/10)<<4|hour%10);//將調節(jié)后的時寫入DS1302
write_1302(0x8a,(week/10)<<4|week%10);//將調節(jié)后的星期寫入DS1302
write_1302(0x86,(day/10)<<4|day%10);//將調節(jié)后的日寫入DS1302
write_1302(0x88,(month/10)<<4|month%10);//將調節(jié)后的月寫入DS1302
write_1302(0x8c,(year/10)<<4|year%10);//
//write_1302(0x80,0x00);//時鐘繼續(xù)走這一句不能加在這,否則每次調 完時后秒會歸O
write_1302(0x8e,0x80);//寫保護關
//write_1602com(0x0c);
break;
}
}
}
if(S1num!=0)
{
if(K1==0)
{
delay(5);
while(!K1);
switch(S1num)
{
case 1:
second++;
if(second==60)second=0;
//write_1302(0x8e,0x00);//去除寫保護
write_second();
write_1602com(0x80+0x40+10);
break;
case 2:
minute++;
if(minute==60)minute=0;
write_minute();
write_1602com(0x80+0x40+7);
break;
case 3:
hour++;
if(hour==24)hour=0;
write_hour();
write_1602com(0x80+0x40+4);
break;
case 4:
day++;
write_day();
write_1602com(0x80+9);
break;
case 5:
month++;
write_month();
write_1602com(0x80+6);
break;
case 6:
year++;
write_year();
write_1602com(0x80+3);
break;
case 7:
week++;
write_week();
write_1602com(0x80+12);
break;
// default:break;
}
}
if(K2==0)
{
delay(5);
while(!K2);
switch(S1num)
{
case 1:
second--;
if(second<0)second=59;
write_second();
write_1602com(0x80+0x40+10);
break;
case 2:
minute--;
if(minute<0)minute=59;
write_minute();
write_1602com(0x80+0x40+7);
break;
case 3:
hour--;
if(hour<0)hour=23;
write_hour();
write_1602com(0x80+0x40+4);
break;
case 4:
day--;
write_day();
write_1602com(0x80+9);
break;
case 5:
month--;
write_month();
write_1602com(0x80+6);
break;
case 6:
year--;
write_year();
write_1602com(0x80+3);
break;
case 7:
week--;
write_week();
write_1602com(0x80+12);
break;
// default:break;
}
}
}
}

void main()
{
GND=0;
delay(100);
init1602();
init_1302();
while(1)
{
keyscan();
if(keyflag==0)
{
readtime();
write_second();
write_minute();
write_hour();
write_day();
write_month();
write_year();
write_week();
}
}
}


上一頁 1 2 下一頁

關鍵詞: DS13021602按鍵調

評論


技術專區(qū)

關閉