LCD1602时钟显示时间日期带闹铃可循环调节
#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;
}
LCD1602时钟显示可循环调 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)