|
发表于 2012-7-1 21:55:37
|
显示全部楼层
//头文件
#include <REG52.h>
#include <string.h>
#include <intrins.h>
#define uint unsigned int
#define uchar unsigned char
/*****************************************************************************/
sbit LCM_cs = P2^5;
sbit LCM_std = P2^6;
sbit LCM_sclk = P2^7;
sbit LCM_psb = P2^3; //H=并口; L=串口;
sbit LCM_rst = P2^4; //Reset Signal 低电平有效
sbit beep = P1^2;
/*****************************************************************************/
//温度传感器定义
sbit DQ = P1^ 0;//ds18B20
/*****************************************************************************/
//键盘引脚定义
sbit KEY_1 = P3^4; //左上
sbit KEY_2 = P3^5; //左下
sbit KEY_3 = P3^6; //右上
sbit KEY_4 = P3^7; //右下
//定义DS1302时钟接口
sbit DS1302_CLK = P1^3; //实时时钟时钟线引脚
sbit DS1302_IO = P1^4; //实时时钟数据线引脚
sbit DS1302_RST = P1^7; //实时时钟复位线引脚/*****************************************************************************/
//定义累加器A中的各位
sbit ACC0 = ACC^0;
sbit ACC7 = ACC^7;
/*****************************************************************************/
//定义全局变量
unsigned char yy,mo,dd,xq,hh,mm,ss,e;//定义时间映射全局变量(专用寄存器)
bit c_moon;
data uchar year_moon,month_moon,day_moon,week;
bit w = 0; //调时标志位
static unsigned char menu = 0;//定义静态小时更新用数据变量
static unsigned char keys = 0;//定义静态小时更新用数据变量
static unsigned char timecount = 0;//定义静态软件计数器变量
uchar code tab1[]={
" 电子万年历 "
" 版本: V1.0 "
" 制作者:颜靖峰 "
"2012暑假荣誉出品"
};
/****************************************************************************/
void DelayM(unsigned int a) //延时函数 1MS/次
{
unsigned char i;
while( --a != 0)
{
for(i = 0; i < 125; i++); //一个 ; 表示空语句,CPU空转。
} //i 从0加到125,CPU大概就耗时1毫秒
}
/****************************************************************************/
//函数声明
void LCM_WriteString(unsigned char *str) ; //写字符 例:LCM_WriteString("您好!");
void LCM_WriteDatOrCom(bit ,unsigned char ); //(0,指令) (1,数据)
void LCM_w_byte(unsigned char bbyte); //写一个字节给LCM
void delaynms(unsigned int di); //延时
void LCM_init(void); //LCM初始化
void LCM_clr(void); //清屏
void Delay(int num);
bit get_moon_day(uchar month_p,uint table_addr);
void Conversion(bit c,uchar year,uchar month,uchar day);
void nl();
void days (viod) //公历节日数据库
{
LCM_WriteDatOrCom(0,0x80);
// LCM_WriteString("[Dis] [Set]");
LCM_WriteDatOrCom(0,0x98);
// ----|----------------|
if ( mo == 0x01 && dd == 0x01 ){ LCM_WriteString("Happy New Year!!"); }//1月
if ( mo == 0x01 && dd == 0x28 ){ LCM_WriteString(" 世界麻风日 "); }
if (month_moon== 0x01 && day_moon == 0x01 ){ LCM_WriteString(" 今日春节 "); }
if (month_moon== 0x01 && day_moon == 0x15 ){ LCM_WriteString(" 元宵节快乐 "); }
if (month_moon== 0x02 && day_moon == 0x02 ){ LCM_WriteString(" 青龙节 "); }
if ( mo == 0x02 && dd == 0x02 ){ LCM_WriteString(" 世界湿地日 "); }//2月
if ( mo == 0x02 && dd == 0x13 ){ LCM_WriteString(" 明天情人节了 "); }
if ( mo == 0x02 && dd == 0x14 ){ LCM_WriteString(" 今天是情人节 "); }
if ( mo == 0x03 && dd == 0x01 ){ LCM_WriteString(" 国际海豹日 "); }//3月
if ( mo == 0x03 && dd == 0x03 ){ LCM_WriteString(" 全国爱耳日 "); }
if ( mo == 0x03 && dd == 0x08 ){ LCM_WriteString(" 3.8妇女节 "); }
if ( mo == 0x03 && dd == 0x12 ){ LCM_WriteString(" 植树节 "); }
if ( mo == 0x03 && dd == 0x14 ){ LCM_WriteString(" 国际警察日 "); }
if ( mo == 0x03 && dd == 0x15 ){ LCM_WriteString(" 消费者权益日 "); }
if ( mo == 0x03 && dd == 0x17 ){ LCM_WriteString(" 国际航海日 "); }
if ( mo == 0x03 && dd == 0x21 ){ LCM_WriteString(" 世界森林日 "); }
if ( mo == 0x03 && dd == 0x22 ){ LCM_WriteString(" 世界水日 "); }
if ( mo == 0x03 && dd == 0x23 ){ LCM_WriteString(" 世界气象日 "); }
if ( mo == 0x03 && dd == 0x24 ){ LCM_WriteString("世界防治结核病日"); }
if ( mo == 0x04 && dd == 0x01 ){ LCM_WriteString("愚人节 小心上当"); }//4
if ( mo == 0x04 && dd == 0x07 ){ LCM_WriteString(" 世界卫生日 "); }
if ( mo == 0x04 && dd == 0x08 ){ LCM_WriteString(" 复活节 "); }
if ( mo == 0x04 && dd == 0x13 ){ LCM_WriteString(" 黑色星期五 "); }
if (month_moon== 0x05 && day_moon == 0x05 ){ LCM_WriteString(" 端午节 "); }
if ( mo == 0x05 && dd == 0x01 ){ LCM_WriteString(" 劳动节 放假 "); }//5
if ( mo == 0x05 && dd == 0x04 ){ LCM_WriteString(" 青年节 "); }
if ( mo == 0x05 && dd == 0x08 ){ LCM_WriteString(" 世界红十字日 "); }
if ( mo == 0x05 && dd == 0x12 ){ LCM_WriteString(" 国际护士节 "); }
if ( mo == 0x05 && dd == 0x05 ){ LCM_WriteString("近日注意母亲节 "); }
if ( mo == 0x05 && dd == 0x15 ){ LCM_WriteString(" 国际家庭日 "); }
if ( mo == 0x05 && dd == 0x31 ){ LCM_WriteString(" 世界无烟日 "); }
if ( mo == 0x06 && dd == 0x01 ){ LCM_WriteString(" 国际儿童节 "); }//6
if ( mo == 0x06 && dd == 0x05 ){ LCM_WriteString(" 世界环境日 "); }
if ( mo == 0x06 && dd == 0x26 ){ LCM_WriteString(" 国际禁毒日 "); }
if ( mo == 0x06 && dd == 0x06 ){ LCM_WriteString(" 全国爱眼日 "); }
if ( mo == 0x06 && dd == 0x13 ){ LCM_WriteString("近日注意父亲节 "); }
if ( mo == 0x06 && dd == 0x15 ){ LCM_WriteString("近日注意父亲节 "); }
if (month_moon== 0x07 && day_moon == 0x07 ){ LCM_WriteString("乞巧节中国情人节"); }
if (month_moon== 0x07 && day_moon == 0x15 ){ LCM_WriteString(" 中元节 "); }
if ( mo == 0x07 && dd == 0x01 ){ LCM_WriteString("香港回归记念日 "); }//7
if ( mo == 0x07 && dd == 0x07 ){ LCM_WriteString("抗日战争记念日 "); }
if ( mo == 0x07 && dd == 0x11 ){ LCM_WriteString(" 世界人口日 "); }
if (month_moon== 0x08 && day_moon == 0x15 ){ LCM_WriteString(" 中秋节快乐 "); }
if ( mo == 0x08 && dd == 0x01 ){ LCM_WriteString(" 八一建军节 "); }//8
if ( mo == 0x08 && dd == 0x08 ){ LCM_WriteString(" 中国男子节 "); }
if ( mo == 0x08 && dd == 0x15 ){ LCM_WriteString("抗战胜利记念日 "); }
if (month_moon== 0x09 && day_moon == 0x09 ){ LCM_WriteString(" 今日重阳节 "); }
if ( mo == 0x09 && dd == 0x10 ){ LCM_WriteString(" 中国教师节 "); }//9
if ( mo == 0x09 && dd == 0x18 ){ LCM_WriteString("九·一八事变记念"); }
if ( mo == 0x09 && dd == 0x20 ){ LCM_WriteString(" 国际爱牙日 "); }
if ( mo == 0x09 && dd == 0x27 ){ LCM_WriteString(" 世界旅游日 "); }
if ( mo == 0x10 && dd == 0x01 ){ LCM_WriteString(" 中国国庆节 "); }//10
if ( mo == 0x10 && dd == 0x04 ){ LCM_WriteString(" 世界动物日 "); }
if ( mo == 0x10 && dd == 0x24 ){ LCM_WriteString(" 联合国日 "); }
if ( mo == 0x10 && dd == 0x12 ){ LCM_WriteString("明天国际教师节 "); }
if ( mo == 0x10 && dd == 0x13 ){ LCM_WriteString(" 国际教师节 "); }
if ( mo == 0x11 && dd == 0x10 ){ LCM_WriteString(" 世界青年节 "); }//11
if ( mo == 0x11 && dd == 0x17 ){ LCM_WriteString(" 世界学生节 "); }
if (month_moon== 0x12 && day_moon == 0x08 ){ LCM_WriteString(" 今日腊八节 "); }
if (month_moon== 0x12 && day_moon == 0x15 ){ LCM_WriteString(" 过小年 "); }
if (month_moon== 0x12 && day_moon == 0x29 ){ LCM_WriteString(" 腊月二十九 "); }
if (month_moon== 0x12 && day_moon == 0x30 ){ LCM_WriteString(" 大年三十(^o^) "); }
if ( mo == 0x12 && dd == 0x01 ){ LCM_WriteString(" 世界艾滋病日 "); }//12
if ( mo == 0x12 && dd == 0x23 ){ LCM_WriteString(" 明晚平安夜 "); }
if ( mo == 0x12 && dd == 0x24 ){ LCM_WriteString(" 今晚平安夜 "); }
if ( mo == 0x12 && dd == 0x25 ){ LCM_WriteString(" 圣诞快乐 "); }
if ( mo == 0x12 && dd == 0x31 ){ LCM_WriteString(" 明日新年 "); }
else{
if ( hh >= 0x04 && hh < 0x06 ){ LCM_WriteString("★★__▲▲__凌晨"); }
if ( hh >= 0x06 && hh < 0x08 ){ LCM_WriteString("☆○__▲△__早晨"); }
if ( hh >= 0x08 && hh < 0x12 ){ LCM_WriteString("__●__▲▲__上午"); }
if ( hh == 0x12) { LCM_WriteString("____▲●▲__中午"); }
if ( hh >= 0x13 && hh < 0x18 ){ LCM_WriteString("__▲▲__●__下午"); }
if ( hh >= 0x18 && hh < 0x22 ){ LCM_WriteString("△▲__●☆__晚上"); }
if ( hh >= 0x22 && hh <= 0x23 ){ LCM_WriteString("△▲__★☆__夜里"); }
if ( hh >= 0x00 && hh < 0x04 ){ LCM_WriteString("__★▲▲★__深夜"); }
}
}
/****************************************************************************/
//初始化LCM
void LCM_init(void)
{
LCM_rst=1;
LCM_psb=0;
LCM_WriteDatOrCom (0,0x30); /*30---基本指令动作*/
LCM_WriteDatOrCom (0,0x01); /*清屏,地址指针指向00H*/
Delay (100);
LCM_WriteDatOrCom (0,0x06); /*光标的移动方向*/
LCM_WriteDatOrCom(0,0x0c); /*开显示,关游标*/
}
/******************************************************************************/
//写指令或数据 (0,指令) (1,数据)
void LCM_WriteDatOrCom(bit dat_comm,uchar content)
{
uchar a,i,j;
Delay(50);
a=content;
LCM_cs=1;
LCM_sclk=0;
LCM_std=1;
for(i=0;i<5;i++)
{
LCM_sclk=1;
LCM_sclk=0;
}
LCM_std=0;
LCM_sclk=1;
LCM_sclk=0;
if(dat_comm)
LCM_std=1; //data
else
LCM_std=0; //command
LCM_sclk=1;
LCM_sclk=0;
LCM_std=0;
LCM_sclk=1;
LCM_sclk=0;
for(j=0;j<2;j++)
{
for(i=0;i<4;i++)
{
a=a<<1;
LCM_std=CY;
LCM_sclk=1;
LCM_sclk=0;
}
LCM_std=0;
for(i=0;i<4;i++)
{
LCM_sclk=1;
LCM_sclk=0;
}
}
}
/*********************************************************************************/
void chn_disp (uchar code *chn)
{
uchar i,j;
LCM_WriteDatOrCom (0,0x30);
LCM_WriteDatOrCom (0,0x80);
for (j=0;j<4;j++)
{
for (i=0;i<16;i++)
LCM_WriteDatOrCom (1,chn[j*16+i]);
}
}
/*****************************************************************************/
//清屏函数
void LCM_clr(void)
{
LCM_WriteDatOrCom (0,0x30);
LCM_WriteDatOrCom (0,0x01);
Delay (180);
}
/*****************************************************************************/
//向LCM发送一个字符串,长度64字符之内。
//应用:LCM_WriteString("您好!");
void LCM_WriteString(unsigned char *str)
{
while(*str != '\0')
{
LCM_WriteDatOrCom(1,*str++);
}
*str = 0;
}
/******************************************************************************/
void Delay(int num)//延时函数
{
while(num--);
}
/******************************************************************************
void Init_DS18B20(void)//初始化ds1820
{
unsigned char x=0;
DQ = 1; //DQ复位
Delay(8); //稍做延时
DQ = 0; //单片机将DQ拉低
Delay(80); //精确延时 大于 480us
DQ = 1; //拉高总线
Delay(14);
x=DQ; //稍做延时后 如果x=0则初始化成功 x=1则初始化失败
Delay(20);
}
/******************************************************************************
unsigned char ReadOneChar(void)//读一个字节
{
unsigned char i=0;
unsigned char dat = 0;
for (i=8;i>0;i--)
{
DQ = 0; // 给脉冲信号
dat>>=1;
DQ = 1; // 给脉冲信号
if(DQ)
dat|=0x80;
Delay(4);
}
return(dat);
}
/******************************************************************************
void WriteOneChar(unsigned char dat)//写一个字节
{
unsigned char i=0;
for (i=8; i>0; i--)
{
DQ = 0;
DQ = dat&0x01;
Delay(5);
DQ = 1;
dat>>=1;
}
}
/******************************************************************************
unsigned int ReadTemperature(void)//读取温度
{
unsigned char a=0;
unsigned char b=0;
unsigned int t=0;
float tt=0;
Init_DS18B20();
WriteOneChar(0xCC); // 跳过读序号列号的操作
WriteOneChar(0x44); // 启动温度转换
Init_DS18B20();
WriteOneChar(0xCC); //跳过读序号列号的操作
WriteOneChar(0xBE); //读取温度寄存器
a=ReadOneChar(); //读低8位
b=ReadOneChar(); //读高8位
t=b;
t<<=8;
t=t|a;
tt=t*0.0625;
t= tt*10+0.5; //放大10倍输出并四舍五入
return(t);
}
/*****************************************************************************/
//声明
void LCM_w_ss(void);
void LCM_w_mm(void);
void LCM_w_hh(void);
void LCM_w_dd(void);
void LCM_w_mo(void);
void LCM_w_yy(void);
void LCM_w_xq(void);
void DS1302InputByte(unsigned char d) ;
unsigned char DS1302OutputByte(void) ;
void Init_1302(void);
unsigned char Read1302(unsigned char);
void Set_time(unsigned char sel);
void Write1302(unsigned char , unsigned char );
void updata (void);
/*****************************************************************************/
/*****************************************************************************/
//调时用加1程序
void Set_time(unsigned char sel) //根据选择调整的相应项目加1并写入DS1302
{
signed char address,item;
signed char max,mini;
LCM_WriteDatOrCom(0,0x9a);
LCM_WriteString("调整");
//if(sel==6) {LCM_WriteString("秒钟");address=0x80; max=0;mini=0;} //秒7
if(sel==5) {LCM_WriteString("分钟");address=0x82; max=59;mini=0;} //分钟6
if(sel==4) {LCM_WriteString("小时");address=0x84; max=23;mini=0;} //小时5
if(sel==3) {LCM_WriteString("星期");address=0x8a; max=7;mini=1;} //星期4
if(sel==2) {LCM_WriteString("日期");address=0x86; max=31;mini=1;} //日3
if(sel==1) {LCM_WriteString("月份");address=0x88; max=12;mini=1;} //月2
if(sel==0) {LCM_WriteString("年份");address=0x8c; max=99; mini=0;} //年1
//读取1302某地址上的数值转换成10进制赋给item
item=((Read1302(address+1))/16)*10 + (Read1302(address+1))%16;
if(KEY_2 == 0)
{
item++;//数加 1
}
if(KEY_4 == 0){
item--;//数减 1
}
if(item>max) item=mini;//查看数值有效范围
if(item<mini) item=max;
Write1302(0x8e,0x00);//允许写操作
Write1302(address,(item/10)*16+item%10);//转换成16进制写入1302
Write1302(0x8e,0x80);//写保护,禁止写操作
updata (); //刷新数据
LCM_w_mm();//刷新 分
nl();
}
/*****************************************************************************/
//设置1302的初始时间
void Init_1302(void) //(2007年1月1日00时00分00秒星期一)
{ uchar cctt;
cctt=Read1302(0x80);
if(cctt&0x80)
{
Write1302(0x8e,0x00);//允许写操作
Write1302(0x8c,0x08);//年
Write1302(0x8a,0x02);//星期
Write1302(0x88,0x01);//月
Write1302(0x86,0x01);//日
Write1302(0x84,0x00);//小时
Write1302(0x82,0x00);//分钟
Write1302(0x80,0x00);//秒
// Write1302(0x90,0x55);//充电
Write1302(0x8e,0x80);//禁止写操作
}
}
void DS1302InputByte(unsigned char d) //实时时钟写入一字节(内部函数)
{
unsigned char i;
ACC = d;
for(i=8; i>0; i--)
{
DS1302_IO = ACC0; //相当于汇编中的 RRC
DS1302_CLK = 1;
DS1302_CLK = 0;
ACC = ACC >> 1;
}
}
unsigned char DS1302OutputByte(void) //实时时钟读取一字节(内部函数)
{
unsigned char i;
for(i=8; i>0; i--)
{
ACC = ACC >>1; //相当于汇编中的 RRC
ACC7 = DS1302_IO;
DS1302_CLK = 1;
DS1302_CLK = 0;
}
return(ACC);
}
void Write1302(unsigned char ucAddr, unsigned char ucDa) //ucAddr: DS1302地址, ucData: 要写的数据
{
DS1302_RST = 0;
DS1302_CLK = 0;
DS1302_RST = 1;
DS1302InputByte(ucAddr); // 地址,命令
DS1302InputByte(ucDa); // 写1Byte数据
DS1302_CLK = 1;
DS1302_RST = 0;
}
unsigned char Read1302(unsigned char ucAddr) //读取DS1302某地址的数据
{
unsigned char ucData;
DS1302_RST = 0;
DS1302_CLK = 0;
DS1302_RST = 1;
DS1302InputByte(ucAddr|0x01); // 地址,命令
ucData = DS1302OutputByte(); // 读1Byte数据
DS1302_CLK = 1;
DS1302_RST = 0;
return(ucData);
}
/*****************************************************************************/
//向LCM中填写 年 数据
void LCM_w_yy(void){
//if(Read1302(0x8d) != yy){
yy = Read1302(0x8d);
LCM_WriteDatOrCom(0,0x80);
LCM_WriteString("20");
LCM_WriteDatOrCom(0,0x81);
LCM_WriteDatOrCom(1,(yy/16)+0x30);
LCM_WriteDatOrCom(1,yy%16+0x30);
LCM_WriteDatOrCom(0,0x82);
LCM_WriteString("年");
nl();
} //}
/*****************************************************************************/
//向LCM中填写 月 数据
void LCM_w_mo(void){
//if(Read1302(0x89) != mo){
mo = Read1302(0x89);
LCM_WriteDatOrCom(0,0x83);
if(mo/16 != 0){LCM_WriteDatOrCom(1,(mo/16)+0x30);} //十位消隐
else{LCM_WriteDatOrCom(1,0x20);}//同上
LCM_WriteDatOrCom(1,mo%16+0x30);
LCM_WriteDatOrCom(0,0x84);
LCM_WriteString("月");
nl();
} //}
/*****************************************************************************/
//星期处理并送入LCM的指定区域
void LCM_w_xq(void){
unsigned char sel;
//if(Read1302(0x8b) != xq){
xq = Read1302(0x8b);
sel = (Read1302(0x8b))%16; //字节低4位的BCD码放入sel
LCM_WriteDatOrCom(0,0x97);//写入指定区域(97H 第二行第8个字)
if(sel==7) {LCM_WriteString("日");} //
if(sel==6) {LCM_WriteString("六");} //
if(sel==5) {LCM_WriteString("五");} //
if(sel==4) {LCM_WriteString("四");} //
if(sel==3) {LCM_WriteDatOrCom(1,0xc8);LCM_WriteDatOrCom(1,0xfd);} //此指令等于LCM_WriteString("三"); 因为"三"的内码失效。
if(sel==2) {LCM_WriteString("二");} //
if(sel==1) {LCM_WriteString("一");} //星期一
LCM_WriteDatOrCom(0,0x95);
LCM_WriteString("星期");
//}
}
/*****************************************************************************/
//向LCM中填写 日 数据
void LCM_w_dd(void){
// if(Read1302(0x87) != dd){
dd = Read1302(0x87);
LCM_WriteDatOrCom(0,0x85);
if(dd/16 != 0){LCM_WriteDatOrCom(1,(dd/16)+0x30);} //十位消隐
else{LCM_WriteDatOrCom(1,0x20);}//同上
LCM_WriteDatOrCom(1,dd%16+0x30);
LCM_WriteDatOrCom(0,0x86);
LCM_WriteString("日 ");
nl();
} //}
/*****************************************************************************/
//向LCM中填写 小时 数据
void LCM_w_hh(void){
if(Read1302(0x85) != hh){
hh = Read1302(0x85);
if (hh > 0x07 && hh < 0x22 && w == 0){
beep = 0;
DelayM(100);
beep = 1;
}
}
LCM_WriteDatOrCom(0,0x88);
LCM_WriteDatOrCom(1,(hh/16)+0x30);
LCM_WriteDatOrCom(1,hh%16+0x30);
} //}
/*****************************************************************************/
//向LCM中填写 分钟 数据
void LCM_w_mm(void){
if(Read1302(0x83) != mm){
mm = Read1302(0x83);
if( w == 0){
days(); //节日显示
updata (); //刷新数据
}
}
LCM_WriteDatOrCom(0,0x89);
LCM_WriteDatOrCom(1,0x3a); //":"
LCM_WriteDatOrCom(1,(mm/16)+0x30);
LCM_WriteDatOrCom(1,mm%16+0x30);
LCM_WriteDatOrCom(1,0x3a); //"."
}
/*****************************************************************************/
//刷新数据
void updata (void){
LCM_w_hh();//刷新 小时
LCM_w_dd();//刷新 日
LCM_w_xq();//更新星期值
LCM_w_mo();//刷新 月
LCM_w_yy();//刷新 年
nl();
}
/*****************************************************************************/
//向LCM中填写 秒 数据
void LCM_w_ss(void){
unsigned int i=0;
unsigned char a=0,b=0,c=0;
if(Read1302(0x81) != ss){ //判断是否需要更新
ss = Read1302(0x81); //更新数据
LCM_WriteDatOrCom(0,0x8b); //秒值在LCM上的写入位置
LCM_WriteDatOrCom(1,(ss/16)+0x30); //写十位
LCM_WriteDatOrCom(1,ss%16+0x30); //写个位
LCM_w_mm();//刷新 分
nl();
// LCM_WriteDatOrCom(0,0x8d); //温度在LCM上的写入位置
// i=ReadTemperature();//读温度并送显
// a=i/100;
// LCM_WriteDatOrCom(1,a+0x30); //显示温度十位
// b=i/10-a*10;
// LCM_WriteDatOrCom(1,b+0x30); //个位
// LCM_WriteDatOrCom(1,0x2e); //"."
// c=i-a*100-b*10;
// LCM_WriteDatOrCom(1,c+0x30); //小位1位
// LCM_WriteString("℃"); //度C
} }
/********阳历转换阴历********************************************************************/
code uchar year_code[300]={
0x0C,0x96,0x45, //2000 297
0x4d,0x4A,0xB8, //2001
0x0d,0x4A,0x4C, //2002
0x0d,0xA5,0x41, //2003
0x25,0xAA,0xB6, //2004
0x05,0x6A,0x49, //2005
0x7A,0xAd,0xBd, //2006
0x02,0x5d,0x52, //2007
0x09,0x2d,0x47, //2008
0x5C,0x95,0xBA, //2009
0x0A,0x95,0x4e, //2010
0x0B,0x4A,0x43, //2011
0x4B,0x55,0x37, //2012
0x0A,0xd5,0x4A, //2013
0x95,0x5A,0xBf, //2014
0x04,0xBA,0x53, //2015
0x0A,0x5B,0x48, //2016
0x65,0x2B,0xBC, //2017
0x05,0x2B,0x50, //2018
0x0A,0x93,0x45, //2019
0x47,0x4A,0xB9, //2020
0x06,0xAA,0x4C, //2021
0x0A,0xd5,0x41, //2022
0x24,0xdA,0xB6, //2023
0x04,0xB6,0x4A, //2024
0x69,0x57,0x3d, //2025
0x0A,0x4e,0x51, //2026
0x0d,0x26,0x46, //2027
0x5e,0x93,0x3A, //2028
0x0d,0x53,0x4d, //2029
0x05,0xAA,0x43, //2030
0x36,0xB5,0x37, //2031
0x09,0x6d,0x4B, //2032
0xB4,0xAe,0xBf, //2033
0x04,0xAd,0x53, //2034
0x0A,0x4d,0x48, //2035
0x6d,0x25,0xBC, //2036
0x0d,0x25,0x4f, //2037
0x0d,0x52,0x44, //2038
0x5d,0xAA,0x38, //2039
0x0B,0x5A,0x4C, //2040
0x05,0x6d,0x41, //2041
0x24,0xAd,0xB6, //2042
0x04,0x9B,0x4A, //2043
0x7A,0x4B,0xBe, //2044
0x0A,0x4B,0x51, //2045
0x0A,0xA5,0x46, //2046
0x5B,0x52,0xBA, //2047
0x06,0xd2,0x4e, //2048
0x0A,0xdA,0x42, //2049
0x35,0x5B,0x37, //2050
0x09,0x37,0x4B, //2051
0x84,0x97,0xC1, //2052
0x04,0x97,0x53, //2053
0x06,0x4B,0x48, //2054
0x66,0xA5,0x3C, //2055
0x0e,0xA5,0x4f, //2056
0x06,0xB2,0x44, //2057
0x4A,0xB6,0x38, //2058
0x0A,0xAe,0x4C, //2059
0x09,0x2e,0x42, //2060
0x3C,0x97,0x35, //2061
0x0C,0x96,0x49, //2062
0x7d,0x4A,0xBd, //2063
0x0d,0x4A,0x51, //2064
0x0d,0xA5,0x45, //2065
0x55,0xAA,0xBA, //2066
0x05,0x6A,0x4e, //2067
0x0A,0x6d,0x43, //2068
0x45,0x2e,0xB7, //2069
0x05,0x2d,0x4B, //2070
0x8A,0x95,0xBf, //2071
0x0A,0x95,0x53, //2072
0x0B,0x4A,0x47, //2073
0x6B,0x55,0x3B, //2074
0x0A,0xd5,0x4f, //2075
0x05,0x5A,0x45, //2076
0x4A,0x5d,0x38, //2077
0x0A,0x5B,0x4C, //2078
0x05,0x2B,0x42, //2079
0x3A,0x93,0xB6, //2080
0x06,0x93,0x49, //2081
0x77,0x29,0xBd, //2082
0x06,0xAA,0x51, //2083
0x0A,0xd5,0x46, //2084
0x54,0xdA,0xBA, //2085
0x04,0xB6,0x4e, //2086
0x0A,0x57,0x43, //2087
0x45,0x27,0x38, //2088
0x0d,0x26,0x4A, //2089
0x8e,0x93,0x3e, //2090
0x0d,0x52,0x52, //2091
0x0d,0xAA,0x47, //2092
0x66,0xB5,0x3B, //2093
0x05,0x6d,0x4f, //2094
0x04,0xAe,0x45, //2095
0x4A,0x4e,0xB9, //2096
0x0A,0x4d,0x4C, //2097
0x0d,0x15,0x41, //2098
0x2d,0x92,0xB5, //2099
};
///月份数据表
code uchar day_code1[9]={0x0,0x1f,0x3b,0x5a,0x78,0x97,0xb5,0xd4,0xf3};
code uint day_code2[3]={0x111,0x130,0x14e};
/*
函数功能:输入BCD阳历数据,输出BCD阴历数据(只允许1901-2099年)
调用函数示例:Conversion(c_sun,year_sun,month_sun,day_sun)
如:计算2004年10月16日Conversion(0,0x4,0x10,0x16);
c_sun,year_sun,month_sun,day_sun均为BCD数据,c_sun为世纪标志位,c_sun=0为21世
纪,c_sun=1为19世纪
调用函数后,原有数据不变,读c_moon,year_moon,month_moon,day_moon得出阴历BCD数据
*/
bit c_moon;
data uchar year_moon,month_moon,day_moon,week;
/*子函数,用于读取数据表中农历月的大月或小月,如果该月为大返回1,为小返回0*/
bit get_moon_day(uchar month_p,uint table_addr)
{
uchar temp;
switch (month_p){
case 1:{temp=year_code[table_addr]&0x08;
if (temp==0)return(0);else return(1);}
case 2:{temp=year_code[table_addr]&0x04;
if (temp==0)return(0);else return(1);}
case 3:{temp=year_code[table_addr]&0x02;
if (temp==0)return(0);else return(1);}
case 4:{temp=year_code[table_addr]&0x01;
if (temp==0)return(0);else return(1);}
case 5:{temp=year_code[table_addr+1]&0x80;
if (temp==0) return(0);else return(1);}
case 6:{temp=year_code[table_addr+1]&0x40;
if (temp==0)return(0);else return(1);}
case 7:{temp=year_code[table_addr+1]&0x20;
if (temp==0)return(0);else return(1);}
case 8:{temp=year_code[table_addr+1]&0x10;
if (temp==0)return(0);else return(1);}
case 9:{temp=year_code[table_addr+1]&0x08;
if (temp==0)return(0);else return(1);}
case 10:{temp=year_code[table_addr+1]&0x04;
if (temp==0)return(0);else return(1);}
case 11:{temp=year_code[table_addr+1]&0x02;
if (temp==0)return(0);else return(1);}
case 12:{temp=year_code[table_addr+1]&0x01;
if (temp==0)return(0);else return(1);}
case 13:{temp=year_code[table_addr+2]&0x80;
if (temp==0)return(0);else return(1);}
}
}
/*
函数功能:输入BCD阳历数据,输出BCD阴历数据(只允许1901-2099年)
调用函数示例:Conversion(c_sun,year_sun,month_sun,day_sun)
如:计算2004年10月16日Conversion(0,0x4,0x10,0x16);
c_sun,year_sun,month_sun,day_sun均为BCD数据,c_sun为世纪标志位,c_sun=0为21世
纪,c_sun=1为19世纪
调用函数后,原有数据不变,读c_moon,year_moon,month_moon,day_moon得出阴历BCD数据
*/
void Conversion(bit c,uchar year,uchar month,uchar day)
{ //c=0 为21世纪,c=1 为19世纪 输入输出数据均为BCD数据
uchar temp1,temp2,temp3,month_p;
uint temp4,table_addr;
bit flag2,flag_y;
temp1=year/16; //BCD->hex 先把数据转换为十六进制
temp2=year%16;
year=temp1*10+temp2;
temp1=month/16;
temp2=month%16;
month=temp1*10+temp2;
temp1=day/16;
temp2=day%16;
day=temp1*10+temp2;
//定位数据表地址
if(c==0){
table_addr=(year+0x64-1)*0x3;
}
else {
table_addr=(year-1)*0x3;
}
//定位数据表地址完成
//取当年春节所在的公历月份
temp1=year_code[table_addr+2]&0x60;
temp1=_cror_(temp1,5);
//取当年春节所在的公历月份完成
//取当年春节所在的公历日
temp2=year_code[table_addr+2]&0x1f;
//取当年春节所在的公历日完成
// 计算当年春年离当年元旦的天数,春节只会在公历1月或2月
if(temp1==0x1){
temp3=temp2-1;
}
else{
temp3=temp2+0x1f-1;
}
// 计算当年春年离当年元旦的天数完成
//计算公历日离当年元旦的天数,为了减少运算,用了两个表
//day_code1[9],day_code2[3]
//如果公历月在九月或前,天数会少于0xff,用表day_code1[9],
//在九月后,天数大于0xff,用表day_code2[3]
//如输入公历日为8月10日,则公历日离元旦天数为day_code1[8-1]+10-1
//如输入公历日为11月10日,则公历日离元旦天数为day_code2[11-10]+10-1
if (month<10){
temp4=day_code1[month-1]+day-1;
}
else{
temp4=day_code2[month-10]+day-1;
}
if ((month>0x2)&&(year%0x4==0)){ //如果公历月大于2月并且该年的2月为闰月,天数加1
temp4+=1;
}
//计算公历日离当年元旦的天数完成
//判断公历日在春节前还是春节后
if (temp4>=temp3){ //公历日在春节后或就是春节当日使用下面代码进行运算
temp4-=temp3;
month=0x1;
month_p=0x1; //month_p为月份指向,公历日在春节前或就是春节当日month_p指向首月
flag2=get_moon_day(month_p,table_addr); //检查该农历月为大小还是小月,大月返回1,小月返回0
flag_y=0;
if(flag2==0)temp1=0x1d; //小月29天
else temp1=0x1e; //大小30天
temp2=year_code[table_addr]&0xf0;
temp2=_cror_(temp2,4); //从数据表中取该年的闰月月份,如为0则该年无闰月
while(temp4>=temp1){
temp4-=temp1;
month_p+=1;
if(month==temp2){
flag_y=~flag_y;
if(flag_y==0)month+=1;
}
else month+=1;
flag2=get_moon_day(month_p,table_addr);
if(flag2==0)temp1=0x1d;
else temp1=0x1e;
}
day=temp4+1;
}
else{ //公历日在春节前使用下面代码进行运算
temp3-=temp4;
if (year==0x0){year=0x63;c=1;}
else year-=1;
table_addr-=0x3;
month=0xc;
temp2=year_code[table_addr]&0xf0;
temp2=_cror_(temp2,4);
if (temp2==0)month_p=0xc;
else month_p=0xd; //
/*
month_p为月份指向,如果当年有闰月,一年有十三个月,月指向13,
无闰月指向12
*/
flag_y=0;
flag2=get_moon_day(month_p,table_addr);
if(flag2==0)temp1=0x1d;
else temp1=0x1e;
while(temp3>temp1){
temp3-=temp1;
month_p-=1;
if(flag_y==0)month-=1;
if(month==temp2)flag_y=~flag_y;
flag2=get_moon_day(month_p,table_addr);
if(flag2==0)temp1=0x1d;
else temp1=0x1e;
}
day=temp1-temp3+1;
}
c_moon=c; //HEX->BCD ,运算结束后,把数据转换为BCD数据
temp1=year/10;
temp1=_crol_(temp1,4);
temp2=year%10;
year_moon=temp1|temp2;
temp1=month/10;
temp1=_crol_(temp1,4);
temp2=month%10;
month_moon=temp1|temp2;
temp1=day/10;
temp1=_crol_(temp1,4);
temp2=day%10;
day_moon=temp1|temp2;
}
void nl()
{
unsigned char yy1,yy2;
Conversion(0,yy,mo,dd);
LCM_WriteDatOrCom(0,0x90);
LCM_WriteString("20");
LCM_WriteDatOrCom(1,year_moon/16+'0');
LCM_WriteDatOrCom(1,year_moon%16+'0');
LCM_WriteDatOrCom(1,'/');
LCM_WriteDatOrCom(1,month_moon/16+'0');
LCM_WriteDatOrCom(1,month_moon%16+'0');
LCM_WriteDatOrCom(1,'/');
LCM_WriteDatOrCom(1,day_moon/16+'0');
LCM_WriteDatOrCom(1,day_moon%16+'0');
yy1=(year_moon/16)*10+year_moon%16;
yy2=yy1%12;
switch(yy2)
{
case 0: LCM_WriteDatOrCom(0,0x87);LCM_WriteString("龙");
break;
case 1: LCM_WriteDatOrCom(0,0x87);LCM_WriteString("蛇");
break;
case 2: LCM_WriteDatOrCom(0,0x87);LCM_WriteString("马");
break;
case 3: LCM_WriteDatOrCom(0,0x87);LCM_WriteString("羊");
break;
case 4: LCM_WriteDatOrCom(0,0x87);LCM_WriteString("猴");
break;
case 5: LCM_WriteDatOrCom(0,0x87);LCM_WriteString("鸡");
break;
case 6: LCM_WriteDatOrCom(0,0x87);LCM_WriteString("狗");
break;
case 7: LCM_WriteDatOrCom(0,0x87);LCM_WriteString("猪");
break;
case 8: LCM_WriteDatOrCom(0,0x87);LCM_WriteString("鼠");
break;
case 9: LCM_WriteDatOrCom(0,0x87);LCM_WriteString("牛");
break;
case 10: LCM_WriteDatOrCom(0,0x87);LCM_WriteString("虎");
break;
case 11: LCM_WriteDatOrCom(0,0x87);LCM_WriteString("兔");
break;
}
}
void Disp_Img(unsigned char code *img) //显示图片
{
unsigned int j=0;
unsigned char x,y,i;
for(i=0;i<9;i+=8)
for(y=0;y<32;y++)/*原来 为 y<26 ,上下两个半屏不能正常对接显示,导致显示的图片中间有空隙*/
for(x=0;x<8;x++)
{
LCM_WriteDatOrCom(0,0x36);//功能设置---8BIT控制界面,扩充指令集
LCM_WriteDatOrCom(0,y+0x80); //行地址
LCM_WriteDatOrCom(0,x+0x80+i); //列地址
LCM_WriteDatOrCom(0,0x30);
LCM_WriteDatOrCom(1,img[j++]);
LCM_WriteDatOrCom(1,img[j++]);
}
}
// 图片公鸡
uchar code GM[]=
{
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x80,0x00,0x0F,0xFF,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x0C,0x43,0x01,0x80,0x00,0x7F,0xFF,0xF0,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x19,0xFF,0x07,0x00,0x07,0xFF,0xFF,0xFE,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x01,0x3F,0xFC,0x1E,0x00,0x1F,0xFF,0xFF,0xFF,0x80,0x00,0x00,0x00,
0x00,0x00,0x00,0x01,0xBF,0xFF,0xFC,0x00,0x7F,0xFC,0x00,0x7F,0xC0,0x00,0x00,0x00,
0x00,0x00,0x00,0x01,0xFF,0xFF,0xF0,0x00,0xFF,0xC0,0x00,0x0F,0xE0,0x00,0x00,0x00,
0x00,0x00,0x00,0x01,0xFF,0xFF,0xE0,0x03,0xFF,0xFF,0xFC,0x01,0xF0,0x00,0x00,0x00,
0x00,0x00,0x00,0x01,0xDF,0xFF,0xC0,0x07,0xFF,0xFF,0xFF,0x80,0xF0,0x00,0x00,0x00,
0x00,0x00,0x00,0x03,0xFF,0xFF,0x00,0x0F,0xFF,0xFF,0xFF,0xE0,0x38,0x00,0x00,0x00,
0x00,0x00,0x00,0x07,0xFF,0xF8,0x00,0x1F,0xFF,0xF0,0x03,0xF8,0x38,0x00,0x00,0x00,
0x00,0x00,0x00,0x07,0xFF,0xE0,0x00,0x3F,0xFF,0xFF,0xC0,0x7C,0x18,0x00,0x00,0x00,
0x00,0x00,0x00,0x04,0x7F,0xF0,0x00,0x3F,0xFF,0xFF,0xF8,0x1E,0x08,0x00,0x00,0x00,
0x00,0x00,0x00,0x01,0xFF,0xF8,0x00,0x7F,0xFF,0xFF,0xFE,0x0F,0x08,0x00,0x00,0x00,
0x00,0x00,0x00,0x0F,0xFF,0xFC,0x00,0xFF,0xFF,0xFF,0xFF,0x87,0x08,0x00,0x00,0x00,
0x00,0x00,0x00,0x1F,0xFF,0xFE,0x00,0xFF,0xFF,0xFF,0xFF,0x83,0x88,0x00,0x00,0x00,
0x00,0x00,0x00,0x3F,0xFF,0xFE,0x01,0xFF,0xFF,0xFF,0xFF,0xC3,0x88,0x00,0x00,0x00,
0x00,0x00,0x00,0x7F,0xFF,0xFE,0x01,0xFF,0xFF,0xFF,0xFF,0xE1,0x88,0x00,0x00,0x00,
0x00,0x00,0x00,0xFF,0xFF,0xFE,0x03,0xFF,0xFF,0xFF,0xFF,0xE1,0x88,0x00,0x00,0x00,
0x00,0x00,0x01,0xFF,0xFF,0xFE,0x03,0xFF,0xFF,0xFF,0xFF,0xF1,0x88,0x00,0x00,0x00,
0x00,0x00,0x01,0xFF,0xFF,0xFE,0x03,0xFF,0xFF,0xFF,0xFF,0xF3,0x08,0x00,0x00,0x00,
0x00,0x00,0x01,0xFF,0xFF,0xFF,0x07,0xFF,0xFF,0xFF,0xFF,0xF2,0x10,0x00,0x00,0x00,
0x00,0x00,0x01,0xFF,0xFF,0xFF,0x8F,0xFF,0xFF,0xFF,0xFF,0xF0,0x20,0x00,0x00,0x00,
0x00,0x00,0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xF0,0x00,0x00,0x00,0x00,
0x00,0x00,0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x70,0x00,0x00,0x00,0x00,
0x00,0x00,0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFF,0x70,0x00,0x00,0x00,0x00,
0x00,0x00,0x01,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFF,0x70,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x7F,0xFF,0x7F,0x20,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xBF,0xFF,0x7F,0x20,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFF,0xFF,0xDF,0xFF,0x7E,0x20,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x3F,0xFF,0xFF,0xFF,0xFF,0xDF,0xFF,0x3E,0x40,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x1F,0xFF,0xFF,0xFF,0xFF,0xCF,0xFF,0x3C,0x40,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x0F,0xFF,0xFF,0xFF,0xFF,0xCF,0xFE,0x38,0x40,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x07,0xFF,0xFF,0xFF,0xFF,0x8F,0xFE,0x38,0x40,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x01,0xFF,0xFF,0xFF,0xFF,0x8F,0xFE,0x30,0x40,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x1F,0x7C,0x20,0x40,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x7F,0xFF,0xFF,0xFE,0x1E,0x78,0x00,0x40,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x3F,0xFF,0xFF,0xFE,0x1E,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x1F,0xFF,0xFF,0xDA,0x3C,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x07,0xFF,0xFF,0xF2,0x30,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x01,0xFF,0xFF,0xF1,0x20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xFE,0x7F,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x7C,0x3F,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x78,0x1F,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x72,0x07,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x70,0x00,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x60,0x00,0x78,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x60,0x00,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0xC0,0x03,0xF0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x01,0x40,0x04,0xD8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x01,0x00,0x01,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x02,0x0C,0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x02,0x40,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x0C,0x48,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x38,0x41,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x0F,0xE2,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x40,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
};
/********************************************************************************/
void Keydone()
{
if (w == 0){ //正常走时
LCM_w_ss();//刷新 秒
if(hh==7&&mm==0)
{ Disp_Img(GM);
DelayM(3000); //显示等留3秒
}
}
else { //启动调时
}
//------------------------------------------------------------------
if (KEY_3 == 0) // 设置时间
{
DelayM(20); //去抖
if(KEY_3 == 0 && w == 1) //当是调时状态 本键用于调整下一项
{
e++;
if (e >= 6 ){e = 0;}
Set_time(e);//调整
}
if(KEY_3 == 0 && w == 0) //当是正常状态时就进入调时状态
{
LCM_clr();//清屏
//yy=0xff;mo=0xff;dd=0xff;xq=0xff;hh=0xff;mm=0xff;ss=0xff; //各数据刷新
w=1; //进入调时
/* LCM_WriteDatOrCom(0,0x9e);
LCM_WriteString(" [-]");
LCM_WriteDatOrCom(0,0x80);
LCM_WriteString("[Esc]");
LCM_WriteDatOrCom(0,0x85);
LCM_WriteString("[Next]");
LCM_WriteDatOrCom(0,0x98);
LCM_WriteString("[+]");*/
Set_time(e);//调整
}
while(KEY_3 == 0);//等待键松开
}
//------------------------------------------------------------------
if (KEY_1 == 0) // 当在调时状态时就退出调时
{
DelayM(20);
if(KEY_1 == 0 && w == 1){
w = 0; //退出调时
e = 0; //"下一项"计数器清0
}
if(KEY_1 == 0 && w == 0){
LCM_clr();//清屏
chn_disp(tab1);//显示欢迎字
//----------|-------1-------|-------3-------|-------2-------|-------4-------|-----//标尺
while(KEY_1 == 0);//等待键松开
}
LCM_clr();//清屏
//LCM_WriteString("[Dis] [Set]");
//yy=0xff;mo=0xff;dd=0xff;xq=0xff;hh=0xff;mm=0xff;ss=0xff; //各数据刷新
days(); //节日显示
updata (); //刷新数据
LCM_w_mm();//刷新 分
nl();
while(KEY_1 == 0);//等待键松开
}
//------------------------------------------------------------------
if (KEY_2 == 0 && w == 1){ // 加减调整{
DelayM(20);
if(KEY_2 == 0 && w == 1){
Set_time(e);//调整
}
while(KEY_2 == 0);//等待键松开
}
//------------------------------------------------------------------
if (KEY_4 == 0 && w == 1){ // 加减调整
DelayM(20);
if(KEY_4 == 0 && w == 1){
Set_time(e);//调整
}
while(KEY_4 == 0);//等待键松开
}
//------------------------------------------------------------------
}
/*****************************************************************************/
//---主程序---//
main() {
e=0;
KEY_1 = 1;KEY_2 = 1;KEY_3 = 1;KEY_4 = 1;//初始键盘
yy=0xff;mo=0xff;dd=0xff;xq=0xff;hh=0xff;mm=0xff;ss=0xff; //各数据刷新
beep = 0;
DelayM(900);
beep = 1;
LCM_init();//初始化液晶显示器
LCM_clr();//清屏
chn_disp(tab1);//显示欢迎字
DelayM(3000); //显示等留3秒
LCM_clr();//清屏
Disp_Img(GM);
DelayM(3000); //显示等留3秒
LCM_clr();//清屏
Init_1302();
while(1)
{
Keydone();
}
}
|
|