void delay(int z)
{
int x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void write_com(char com) //写指令操作
{
rs=0;
lcden=0; //这一步万万不可少,否则不出结果
P0=com;
delay(5);
lcden=1;
delay(5);
lcden=0;
}
void didi()
{
beep=0;
delay(50);
beep=1;
delay(100);
beep=0;
delay(50);
beep=1;
}
void write_data(char date) //写命令操作
{
rs=1;
lcden=0; //这一步万万不可少,否则不出结果
P0=date;
delay(5);
lcden=1;
delay(5);
lcden=0; //使用完毕后一定要释放使能端 即置零
}
void init() //初始化函数
{
char num;
EA=1;
EX0=1;
IT0=1;
wela=0;
dula=0;
lcden=0;
set_alarm(17,13,30);
write_ds(0x0B,0x26);
read_ds(0x0c);
write_com(0x38);
write_com(0x0c);
write_com(0x06);
write_com(0x01);
write_com(0x80);
for(num=0;num<15;num++)
{
write_data(table1[num]);
delay(5);
}
write_com(0x80+0x40);
for(num=0;num<10;num++)
{
write_data(table2[num]);
delay(5);
}
}
void write_time(char clock,char address1)
{
char ge,shi;
shi=clock/10;
ge=clock%10;
write_com(0x80+0x40+address1);
write_data(0x30+shi);
delay(10);
write_data(0x30+ge); //记住此处一定要加0x30 因为char型数字+0x30才能在液晶上显示出来,另外字符如a,b等可直接显示
} //例如write_data(a) write_data(5+0x30)才是对的//不能写write_data('a')或write_data(5)
void keyscan1() //加法检测
{
if(s17==0)
{
delay(50);
if(s17==0&flag1==1)
{
flag1=0;
}
if((s17==0)&&(s13num==1))
{
if(miao==59)
{
miao=0;
}
miao++;
write_time(miao,0x08);
}
if((s17==0)&&(s13num==2))
{
if(fen==59)
{
fen=0;
}
fen++;
write_time(fen,0x05);
}
if((s17==0)&&(s13num==3))
{
if(shi==23)
{
shi=0;
}
shi++;
write_time(shi,0x02);
}
while(!s17);
}
}
void keyscan2() //减法检测
{
if(s21==0)
{
delay(50);
if(s21==0&flag1==1)
{
flag1=0;
}
if((s21==0)&&(s13num==1))
{
if(miao==0)
{
miao=59;
}
miao--;
write_time(miao,0x08);
}
if((s21==0)&&(s13num==2))
{
if(fen==0)
{
fen=59;
}
fen--;
write_time(fen,0x05);
}
if((s21==0)&&(s13num==3))
{
if(shi==0)
{
shi=23;
}
shi--;
write_time(shi,0x02);
}
while(!s21);
}
}
void keyscan() //复位键检测
{
rd=0;
if(s13==0)
{
delay(5);
if(s13==0)
{
flag=1;
TR0=0;
s13num++;
}
while(!s13);
if(flag1==1)
{
s13num=4;
flag1=0;
}
write_com(0x0f);
}
if(s13num==1)
{
write_com(0x80+0x40+0x08);
}
if(s13num==2)
{
write_com(0x80+0x40+0x05);
}
if(s13num==3)
{
write_com(0x80+0x40+0x02);
}
if(s13num==4)
{
s13num=0;
flag=0;
write_com(0x0c);
write_ds(4,shi);
write_ds(2,fen);
write_ds(0,miao);
}
keyscan1();
keyscan2();
}
void write_ds(char add,char date)
{
dscs=0;
dsas=1;
dsds=1;
dsrw=1;
P0=add;
dsas=0;
dsrw=0;
P0=date;
dsrw=1;
dsas=1;
dscs=1;
}
char read_ds(char add)
{
char ds_date;
dscs=0;
dsas=1;
dsds=1;
dsrw=1;
P0=add;
dsas=0;
dsds=0;
P0=0xff; //此处一定要给P0附0xff
ds_date=P0;
dsds=1;
dsas=1;
dscs=1;
return ds_date;
}
void set_time()
{
write_ds(4,15);
write_ds(2,03);
write_ds(0,50);
}
void set_alarm(char ashi,char afen,char amiao)
{
write_ds(1,amiao);
write_ds(3,afen);
write_ds(5,ashi);
}
void main()
{
init();
while(1)
{
keyscan();
if(flag1==1)
didi();
if(flag==0)
{
miao=read_ds(0);
fen=read_ds(2);
shi=read_ds(4);
write_time(miao,0x08);
write_time(fen,0x05);
write_time(shi,0x02);
}
}
}
void ext0() interrupt 0
{
char c;
beep=0;
c=read_ds(0x0C);
flag1=1;
}
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |