#include
#define uint unsigned int #define uchar unsigned char
sbit LCD_RS=P2^6; //复位端 液晶 sbit LCD_RW=P2^5; //写数据端液晶 sbit LCD_EP=P2^7; //使能端液晶 sbit key1=P2^0;//键盘1 sbit key2=P2^1;//键盘2 sbit key3=P2^2;//键盘3
sbit key4=P2^3;//键盘4 sbit Beep=P1^5;//蜂鸣器 uint num;
uchar keynum,keynum1,shi1,fen1,miao1,aa,nian,shi2,fen2,miao2;
uchar code table[]=\ //设定开始显示的时间
uchar code table1[]=\ 15:57:00\
uchar code table2[]=\ //定义二维字符数组 uchar miao=00; uchar fen=57; uchar shi=15; uchar yue=07; uchar ri=24; uchar week=3; uchar nian=2013;
void delay(uint z)//延时 {
uint x,y;
for(x=z;x>0;x--) for(y=110;y>0;y--); }
void di() {
Beep=1;
delay(1000); Beep=0;
}
void write_com(uchar com)//写指令函数液晶 {
LCD_RS=0; LCD_RW=0; P0=com;
delay(5);//E变为以有个时间 LCD_EP=1;
delay(5);//一个高脉冲 LCD_EP=0;
}
void write_date(uchar date)//写数据函数液晶 {
LCD_RS=1; LCD_RW=0; P0=date;
delay(5);//E变为yi有个时间 LCD_EP=1;
delay(5);//一个高脉冲 LCD_EP=0; }
void init()//初始化函数 {
TMOD=0x01;
TH0=(65536-50000)/256; TL0=(65536-50000)%6; EA=1;
ET0=1; TR0=1; LCD_EP=0;
write_com(0x38);//显示模式
write_com(0x0c);//打开显示,光标不开,不闪烁
write_com(0x01);//清屏
write_com(0x80);//数据指针初始化 }
void year(uchar date)//显示年 {
uchar bai,shi,ge; uint qian; qian=2; bai=0;
shi=date000/10; ge=date;
write_com(0x80);
write_date(0x30+qian);
write_date(0x30+bai); write_date(0x30+shi); write_date(0x30+ge); }
void xianshi(uchar add,uchar date)//显示月,日,时,分,秒 {
uchar shi,ge; shi=date/10; ge=date;
write_com(add+0x80); write_date(0x30+shi); write_date(0x30+ge); }
void xingqi()//显示星期 {
write_com(0x8b);
write_date(table2[week-1]); }
void key() {
if(key1==0) {
delay(5); //去抖延时
if(key1==0) //确认按键1被按下, {
keynum++;
} while(!key1);//松手检测
if(keynum==1)//按下一次 {
TR0=0; //关闭定时器0
write_com(0x83);//光标跳到nian份
write_com(0x0f);//开启光标显示,光标闪烁
标跳到秒
if(keynum==2) {
write_com(0x86);//光标跳到yue }
if(keynum==3) {
write_com(0x89);//光标跳到ri }
if(keynum==4) {
write_com(0x8b);//光标跳到xingqi }
if(keynum==5) {
write_com(0x80+0x44);//光标跳到时 }
if(keynum==6) { write_com(0x80+0x47);//光标跳到分 }
if(keynum==7) {
write_com(0x80+0x4a); //光
}
}
if(keynum==8)
{ keynum=0; //退出调时间模式
TR0=1; //开启定时器0
write_com(0x0c); //关闭光标显示
满清0
月份加1 0
} //当进入调时间模式时 {
if(key2==0) //2按键按下jia {
delay(5); //去抖延时 if(key2==0) {
if(keynum==1)//调nian
{
nian++;//2每按下一次 if(nian==2099)
nian=2000; //加 year(nian); write_com(0x83); //写完数据指针指向月份原来位置 }
if(keynum==2)//调月 {
yue++;//2每按下一次 if(yue==13)
yue=1; //加满清
}
if(keynum)