您的位置 首页 解答

LCD1602时钟显现时刻日期带闹铃可循环调理

#includereg52.h>#includeintrins.h>#defineucharunsignedchar#defineuintunsignedintsbitlcdrs=P2^6

#include

#include
#define uchar unsigned char
#define uint unsigned int
sbit lcdrs=P2^6;
sbit lcden=P2^7;
sbit lcdrw=P2^5;
sbit key1=P2^0;//欢迎开屏/显现时刻日期/显现闹铃切换
sbit key3=P2^1; //循环调理
sbit key4=P2^2;//加
sbit key5=P2^3;//减
uchar flag1,flag,flag3,num1,shi,fen,miao,nian,yue,ri,zhou;
uchar _fen,_shi;
uchar aa,bb;
uchar code table[]={0,1,2,3,4,5,6,7,8,9,-};
uchar code table1[]=”wanglushan”;
uchar code table2[]=”welcome you!”;
uchar code table3[]=”time:”;
uchar code table4[]=”date:”;
uchar code table5[]=”alarm:”;
void dispfen();
void dispshi();
void dispzhou();
void dispri();
void dispyue();
void dispnian();
void disp_fen();
void disp_shi();
void delayms(uchar z);
void disptime();
void dispword();
void displing();
void delay5us();
void lcdint();
void lcdcom(uchar com1);
void lcddate(uchar date1);
void intc();
keyscan();
//————–
void main()
{
intc();
while(1)
{
keyscan();
if(flag1==0)//当未按调理键时:
{//功用显现键,按该键将循环显现开机画面/时刻日期/闹铃
//lcdint();
//delayms(10);
if(flag==0)
{
dispword();
}
if(flag==1)
{
disptime();
}
if(flag==2)
{
displing();
}
}
else//当按下调理键时,将独自显现要调理的部分
{ //lcdint();
//delayms(10);
switch(flag1)
{
case 1:
dispfen();break;
case 2:
dispshi();break;
case 3:
dispzhou();break;
case 4:
dispri();break;
case 5:
dispyue();break;
case 6:
dispnian();break;
case 7:
disp_fen();break;
case 8:
disp_shi();break;

}
}
}
}

//———-延时
void delayms(uint z)
{
uint x;
uchar y;
for(x=z;x>0;x–)
for(y=113;y>0;y–);
}
//—————–
void delay5us()
{

_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
}
//———LCD初始化——-

void lcdint()
{

lcdcom(0x38);
delay5us();
lcdcom(0x0c);
delay5us();
lcdcom(0x06);
delay5us();
lcdcom(0x01);
delayms(10);

}
//——LCD写指令———–
void lcdcom(uchar com1)
{
lcdrs=0;
lcdrw=0;
lcden=0;
delay5us();
P0=com1;
delay5us();
lcden=1;
delay5us();
lcden=0;

}
//——LCD写数据——-
void lcddate(uchar date1)
{
lcdrs=1;
lcdrw=0;
lcden=0;
delay5us();
P0=date1;
delay5us();
lcden=1;
delay5us();
lcden=0;
}

//——-键盘扫描——-
keyscan()
{
if(key1==0)
delayms(100);
if(key1==0)
{
while(!key1);
lcdcom(0x01);
delayms(10);
flag++;
if(flag>2)
flag=0;
}

if(key3==0)
delayms(100);
if(key3==0)
{
while(!key3);
lcdcom(0x01);
delayms(10);
flag1++;
if(flag1>8)
flag1=0;
}
if(key4==0)
delayms(100);
if(key4==0)
{
while(!key4);
switch(flag1)
{
case 1:
fen++;
if(fen==60)
fen=0;
break;
case 2:
shi++;
if(shi==24)
shi=0;
break;
case 3:
zhou++;
if(zhou>7)
zhou=1;
break;
case 4:
ri++;
if(ri>31)
ri=1;
break;
case 5:
yue++;
if(yue>12)
yue=1;
break;
case 6:
nian++;
if(nian>99)
nian=0;
break;
case 7:
_fen++;
if(_fen==60)
_fen=0;
break;
case 8:
_shi++;
if(_shi==24)
_shi=0;
break;
default: break;
}
}
if(key5==0)
delayms(100);
if(key5==0)
{
while(!key5);

switch(flag1)
{
case 1:
if(fen==0)
fen=0;
else
fen–;
break;
case 2:
if(shi==0)
shi=0;
else
shi–;
break;
case 3:
if(zhou==1)
zhou=1;
else
zhou–;
break;
case 4:
if(ri==1)
ri=1;
else
ri–;
break;
case 5:
if(yue==1)
yue=1;
else
yue–;
break;
case 6:
if(nian==0)
nian=0;
else
nian–;
break;
case 7:
if(_fen==0)
_fen=0;
else
_fen–;
case 8:
if(_shi==0)
_shi=0;
else
_shi–;
break;
default: break;
}

}
}

//—————
void disptime()
{
lcdcom(0xc0);
num1=0;
while(table3[num1]!=\0)
{

lcddate(table3[num1]);
num1++;
delayms(1);
}
num1=0;
lcddate(table[shi/10]);
delayms(1);
lcddate(table[shi%10]);
delayms(1);
lcddate(table[10]);

lcddate(table[fen/10]);
delayms(1);
lcddate(table[fen%10]);

delayms(1);
lcddate(table[10]);

lcddate(table[miao/10]);
delayms(1);
lcddate(table[miao%10]);
delayms(1);

lcdcom(0x80);
num1=0;
while(table4[num1]!=\0)
{

lcddate(table4[num1]);
num1++;
delayms(1);
}
lcddate(table[nian/10]);
delayms(1);
lcddate(table[nian%10]);
delayms(1);
lcddate(table[10]);

lcddate(table[yue/10]);
delayms(1);
lcddate(table[yue%10]);
delayms(1);
lcddate(table[10]);

lcddate(table[ri/10]);
delayms(1);
lcddate(table[ri%10]);
delayms(1);
//lcddate(table[10]);
lcddate(table[10]);
delayms(1);
lcddate(table[zhou/10]);
delayms(5);

}
//—————-
void dispword()
{
lcdcom(0x80+3);
while(table1[num1]!=\0)
{

lcddate(table1[num1]);
num1++;
}
num1=0;
lcdcom(0xc0+2);
while(table2[num1]!=\0)
{

lcddate(table2[num1]);
num1++;
}
num1=0;
}

//——————-
void timer0() interrupt 1
{TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
aa++;
if(aa==20)
{aa=0;
miao++;}
if(miao==60)
{miao=0;fen++;}
if(fen==60)
{fen=0;shi++;}
if(shi==24)
{shi=0;
ri++;
zhou++;
}
if(ri>7)
{zhou=1;}
if(ri>31)
{ri=0;yue++;}
if(yue>12)
{yue=1;nian++;}
if(nian>99)
nian=0;

}

//————-
void intc()
{
num1=0;
shi=12;
fen=12;
miao=12;
nian=11;
yue=2;
ri=21;
zhou=1;
_fen=12;
_shi=12;
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
lcdint();
}

//———-调理时独自显现程序———-
void dispfen()
{
lcdcom(0xc8);
//delayms(1);
lcddate(table[fen/10]);
lcddate(table[fen%10]);
}
void dispshi()
{
lcdcom(0xc5);
//delayms(1);
lcddate(table[shi/10]);
lcddate(table[shi%10]);
}
void dispzhou()
{
lcdcom(0x8e);
//delayms(1);
lcddate(table[zhou/10]);
//lcddate(table[zhou%10]);
}
void dispri()
{
lcdcom(0x8b);
//delayms(1);
lcddate(table[ri/10]);
lcddate(table[ri%10]);
}
void dispyue()
{
lcdcom(0x88);
//delayms(1);
lcddate(table[yue/10]);
lcddate(table[yue%10]);
}
void dispnian()
{
lcdcom(0x85);
//delayms(1);
lcddate(table[nian/10]);
lcddate(table[nian%10]);
}
void disp_fen()
{
lcdcom(0xc8);
//delayms(1);
lcddate(table[_fen/10]);
lcddate(table[_fen%10]);
}
void disp_shi()
{
lcdcom(0xc5);
//delayms(1);
lcddate(table[_shi/10]);
lcddate(table[_shi%10]);
}

//——————-显现闹铃时刻—-
void displing()
{
//lcdint();
//delayms(10);
lcdcom(0xc0);
num1=0;
while(table5[num1]!=\0)
{
lcddate(table5[num1]);
num1++;
}
delayms(1);
lcddate(table[_shi/10]);
lcddate(table[_shi%10]);
delayms(1);
lcddate(table[10]);
lcddate(table[_fen/10]);
lcddate(table[_fen%10]);
delayms(1);

}
void timer1()

声明:本文内容来自网络转载或用户投稿,文章版权归原作者和原出处所有。文中观点,不代表本站立场。若有侵权请联系本站删除(kf@86ic.com)https://www.86ic.net/changshang/jieda/266119.html

为您推荐

联系我们

联系我们

在线咨询: QQ交谈

邮箱: kf@86ic.com

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

返回顶部