DS1302用1602显示加按键调时
uchar readday()
{
uchar dat;
dat=read_1302add(0x87);
day=((dat&0x70)>>4)*10+(dat&0x0f);
returnday;
}
/*****************读出月的十进制数***************************/
uchar readmonth()
{
uchar dat;
dat=read_1302add(0x89);
month=((dat&0x70)>>4)*10+(dat&0x0f);
return month;
}
/*****************读出周的十进制数***************************/
uchar readweek()
{
uchar dat;
dat=read_1302add(0x8b);
week=((dat&0x70)>>4)*10+(dat&0x0f);
return week;
}
/*****************读出年的十进制数***************************/
uchar readyear()
{
uchar dat;
dat=read_1302add(0x8d);
year=((dat&0xf0)>>4)*10+(dat&0x0f);
return year;
}
/************************读出所有时间**********************/
readtime()
{
readsecond();
readminute();
readhour();
readday();
readmonth();
readweek();
readyear();
}
/*********************向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);
}
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);//将调节后的秒写入DS1302
write_1302(0x82,(minute/10)<4|minute%10);//将调节后的分写入DS1302
write_1302(0x84,(hour/10)<4|hour%10);//将调节后的时写入DS1302
write_1302(0x8a,(week/10)<4|week%10);//将调节后的星期写入DS1302
write_1302(0x86,(day/10)<4|day%10);//将调节后的日写入DS1302
write_1302(0x88,(month/10)<4|month%10);//将调节后的月写入DS1302
write_1302(0x8c,(year/10)<4|year%10);//
//write_1302(0x80,0x00);//时钟继续走这一句不能加在这,否则每次调 完时后秒会归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;
}
}
}
}
DS13021602按键调 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)