采用芯片:STC89C16RD+(只要大于22K以上的单片机都是可以的),红外接收采用了VS/HX1838,走时正常,改了下控制器的地址。
程序内容很清楚,自己也容易修改我就不多做介绍了。 程序还暂时没有特别研究,现在实物制作成了,就打算研究程序。
在这我分享下制作心得,之前,在网上找了一些库(这库害我挺惨,引脚跟丝印的方向是不对应的),然后也没查看库的引脚是否有问题,就直接画了板子,最后,当板子做出来的时候,看见屏幕还是一片空白,然后我就顿了顿,想了下是哪里出了问题?忽然间,闻到有股味道(不是特别大的味),也没太在意。最后,我又用手碰了碰上面的器件,格外烫手,(幸好没爆炸)。通过检查,才发现是封装出了问题(一般,普通器件发热,都是引脚接错了),然后去下器件换了方向,发现成了。再度检查,发现修改后的程序中,红外没起作用,想了又想,查了一遍又一遍(通过网上找参考手册,查看PCB,原理图),最后发现,原来之前我采用了DS18B20(错误封装),然后也导致红外没法工作。。。。。。。遇到的一系列问题我就不一一详谈了。下边是我的东西,有PCB(可以直接做),有芯片资料,有程序,有报表。自己慢慢看吧
实物图:
Altium Designer画的原理图和PCB图如下:(51hei附件中可下载工程文件)
单片机源程序如下:
- /*****************************************************************************************************************/
- //12864液晶万年历 时钟2010年最新 V8版本
- //增加了24C02接口,具有开机界面记忆功能、闹钟时间可以掉电保存功能
- //V8.0版本主要特点为三种风格界面显示,功能更强大
- /****************************************************************************************************************/
- //头文件
- #include <AT89X52.h>
- #include <string.h>
- #include <intrins.h> //包含_nop_()延时函数
- #ifndef uchar
- #define uchar unsigned char
- #endif
- #ifndef uint
- #define uint unsigned int
- #endif
- #include "SoundPlay.h"
- #include "ds1302.h"
- #include "ds18b20.h"
- #include "24c02.h"
- #include "lcd12864.h"
- #include "tl1838.h"
- /*****************************************************************************/
- //键盘引脚定义
- //sbit KEY_1 = P2^7; //左上,在音乐文件SoundPlay.h中已定义
- sbit KEY_2 = P2^6; //左下
- sbit KEY_3 = P2^5; //右上
- sbit KEY_4 = P2^4; //右下
- /****************************************************************************/
- //定义全局变量
- unsigned char yy,mo,dd,xq,hh,year,year1;//定义时间映射全局变量(专用寄存器)
- unsigned char shi,ge,sec_temp,min_temp,hour_temp,secl,selx,e=0,hh1,mm1,mm,ss,n,t;
- char xdata n1,n2;
- bit w = 0; //调时标志位
- uchar c_sun,year_sun,month_sun,day_sun; //农历
- /******************************************************************************/
- /*-- 一幅图像 KISS- 正向取模,字节正序*/
- /*-- 宽度x高度=128x64 --*/
- /******************************************************************************/
- uchar code powerOnPhoto []={
-
- 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
- 0xFF,0xFF,0xFF,0x9F,0x00,0x00,0x0F,0x0E,0x00,0x00,0x00,0x00,0x19,0xFF,0xFF,0xFF,
- …………限于本文篇幅 余下字库代码请从51黑下载附件…………
- uchar code powerOnPhoto1[]={ //此处为小东电子图片代码,可以更改为你喜欢的图片代码
-
- /*-- 调入了一幅图像:F:\小东电子.bmp --*/
- /*-- 宽度x高度=128x64 --*/
- //图片数字圆体
- //图片数字方体
- /******************************************************************************/
- {// 图片" "
- 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},
- };
- /******************************************************************************/
- //农历代码
- /*
- 公历年对应的农历数据,每年三字节,
- 格式第一字节BIT7-4 位表示闰月月份,值为0 为无闰月,BIT3-0 对应农历第1-4 月的大小
- 第二字节BIT7-0 对应农历第5-12 月大小,第三字节BIT7 表示农历第13 个月大小
- 月份对应的位为1 表示本农历月大(30 天),为0 表示小(29 天)
- 第三字节BIT6-5 表示春节的公历月份,BIT4-0 表示春节的公历日期
- */
- /******************************************************************************/
- code uchar year_code[] = {
- 0x0C,0x96,0x45, //2000
- …………限于本文篇幅 字库代码请从51黑下载附件…………
- 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)*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;
- }
- /*函数功能:输入BCD阳历数据,输出BCD星期数据(只允许1901-2099年)
- 调用函数示例:Conver_week(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世纪
- 调用函数后,原有数据不变,读week得出阴历BCD数据
- */
- code uchar table_week[12]={0,3,3,6,1,4,6,2,5,0,3,5}; //月修正数据表
- /*
- 算法:日期+年份+所过闰年数+月较正数之和除7 的余数就是星期但如果是在
- 闰年又不到3 月份上述之和要减一天再除7
- 星期数为0
- */
- /*void Conver_week(bit c,uchar year,uchar month,uchar day)
- {//c=0 为21世纪,c=1 为19世纪 输入输出数据均为BCD数据
- uchar temp1,temp2;
- 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){year+=0x64;} //如果为21世纪,年份数加100
- temp1=year/0x4; //所过闰年数只算1900年之后的
- temp2=year+temp1;
- temp2=temp2%0x7; //为节省资源,先进行一次取余,避免数大于0xff,避免使用整型数据
- temp2=temp2+day+table_week[month-1];
- if (year%0x4==0&&month<3)temp2-=1;
- week=temp2%0x7;
- }*/
- //test
- /****************************************************************************************************************************
- 函数功能: 二十四节气数据库
- 入口参数: unsigned char(yy,mo,dd) 对应 年月日
- 出口参数: unsigned char(0-24) 1-24对应二十四节气
- 作者 : TOTOP
- 二十四节气数据库(1901--2050)
- 数据格式说明:
- 如1901年的节气为
- 1月 2月 3月 4月 5月 6月 7月 8月 9月 10月 11月 12月
- [ 6,21][ 4,19][ 6,21][ 5,21][ 6,22][ 6,22][ 8,23][ 8,24][ 8,24][ 8,24][ 8,23][ 8,22]
- [ 9, 6][11, 4][ 9, 6][10, 6][ 9, 7][ 9, 7][ 7, 8][ 7, 9][ 7, 9][ 7, 9][ 7, 8][ 7,15]
- 上面第一行数据为每月节气对应公历日期,15减去每月第一个节气,每月第二个节气减去15得第二
- 行,这样每月两个节气对应数据都小于16,每月用一个字节存放,高位存放第一个节气数据,低位存
- 放第二个节气的数据,可得下表
- ****************************************************************************************************************************/
- uchar code jieqi_code[]=
- {
- 0x96,0xB4,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x86, //2000
- 0xA5,0xB3,0xA5,0xA5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0x87, //2001
- 0xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x78,0x87,0x87, //2002
- 0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0x87, //2003
- 0x96,0xB4,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x86, //2004
- 0xA5,0xB3,0xA5,0xA5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0x87, //2005
- 0xA5,0xB4,0x96,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0x87, //2006
- 0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x69,0x78,0x87, //2007
- 0x96,0xB4,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x87,0x78,0x87,0x86, //2008
- 0xA5,0xB3,0xA5,0xB5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0x87, //2009
- 0xA5,0xB4,0x96,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0x87, //2010
- 0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x78,0x87, //2011
- 0x96,0xB4,0xA5,0xB5,0xA5,0xA6,0x87,0x88,0x87,0x78,0x87,0x86, //2012
- 0xA5,0xB3,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x87, //2013
- 0xA5,0xB4,0x96,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0x87, //2014
- 0x95,0xB4,0x96,0xA5,0x96,0x97,0x88,0x78,0x78,0x79,0x77,0x87, //2015
- 0x95,0xB4,0xA5,0xB4,0xA5,0xA6,0x87,0x88,0x87,0x78,0x87,0x86, //2016
- 0xA5,0xC3,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x87, //2017
- 0xA5,0xB4,0xA6,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0x87, //2018
- 0xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x79,0x77,0x87, //2019
- 0x95,0xB4,0xA5,0xB4,0xA5,0xA6,0x97,0x87,0x87,0x78,0x87,0x86, //2020
- 0xA5,0xC3,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x86, //2021
- 0xA5,0xB4,0xA5,0xA5,0xA6,0x96,0x88,0x88,0x88,0x78,0x87,0x87, //2022
- 0xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x79,0x77,0x87, //2023
- 0x95,0xB4,0xA5,0xB4,0xA5,0xA6,0x97,0x87,0x87,0x78,0x87,0x96, //2024
- 0xA5,0xC3,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x86, //2025
- 0xA5,0xB3,0xA5,0xA5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0x87, //2026
- 0xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x78,0x87,0x87, //2027
- 0x95,0xB4,0xA5,0xB4,0xA5,0xA6,0x97,0x87,0x87,0x78,0x87,0x96, //2028
- 0xA5,0xC3,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x86, //2029
- 0xA5,0xB3,0xA5,0xA5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0x87, //2030
- 0xA5,0xB4,0x96,0xA5,0x96,0x96,0x88,0x78,0x78,0x78,0x87,0x87, //2031
- 0x95,0xB4,0xA5,0xB4,0xA5,0xA6,0x97,0x87,0x87,0x78,0x87,0x96, //2032
- 0xA5,0xC3,0xA5,0xB5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0x86, //2033
- 0xA5,0xB3,0xA5,0xA5,0xA6,0xA6,0x88,0x78,0x88,0x78,0x87,0x87, //2034
- 0xA5,0xB4,0x96,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0x87, //2035
- 0x95,0xB4,0xA5,0xB4,0xA5,0xA6,0x97,0x87,0x87,0x78,0x87,0x96, //2036
- 0xA5,0xC3,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x86, //2037
- 0xA5,0xB3,0xA5,0xA5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0x87, //2038
- 0xA5,0xB4,0x96,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0x87, //2039
- 0x95,0xB4,0xA5,0xB4,0xA5,0xA6,0x97,0x87,0x87,0x78,0x87,0x96, //2040
- 0xA5,0xC3,0xA5,0xB5,0xA5,0xA6,0x87,0x88,0x87,0x78,0x87,0x86, //2041
- 0xA5,0xB3,0xA5,0xB5,0xA6,0xA6,0x88,0x88,0x88,0x78,0x87,0x87, //2042
- 0xA5,0xB4,0x96,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0x87, //2043
- 0x95,0xB4,0xA5,0xB4,0xA5,0xA6,0x97,0x87,0x87,0x88,0x87,0x96, //2044
- 0xA5,0xC3,0xA5,0xB4,0xA5,0xA6,0x87,0x88,0x87,0x78,0x87,0x86, //2045
- 0xA5,0xB3,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x87, //2046
- 0xA5,0xB4,0x96,0xA5,0xA6,0x96,0x88,0x88,0x78,0x78,0x87,0x87, //2047
- 0x95,0xB4,0xA5,0xB4,0xA5,0xA5,0x97,0x87,0x87,0x88,0x86,0x96, //2048
- 0xA4,0xC3,0xA5,0xA5,0xA5,0xA6,0x97,0x87,0x87,0x78,0x87,0x86, //2049
- 0xA5,0xC3,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x78,0x78,0x87,0x87, //2050
- };
- uchar jieqi (uchar y2,m2,d2)
- {
- uchar temp,d,y,y1,m;
- uint addr;
- d=d2/16*10+d2%16;
- m=m2/16*10+m2%16;
- y1=y2/16*10+y2%16+2000;
- y=y1-2000;
- addr=y*12+m-1;
- if(d<15)
- {
- temp=15-d;
- if((jieqi_code[addr]>>4)==temp) return (m*2-1);
- else return (0);
- }
- if(d==15) return (0);
- if(d>15)
- {
- temp=d-15;
- if((jieqi_code[addr]&0x0f)==temp) return (m*2);
- else return (0);
- }
- }
- /******************************************************************************/
- //公历节日数据库表
- /******************************************************************************/
- void days () //公历节日数据库
- {
- uchar j;
- j=jieqi(yy,mo,dd);
- if(t/2%2==0)//设置变化的时间,默认是2秒
- { //以下自己添加生日、节日信息
- if ( month_moon== 0x06 && day_moon== 0x02 ){dispString(3, 0, 1, "后天是 的生日");}
- else if ( month_moon== 0x06 && day_moon== 0x03 ){dispString(3, 0, 1, "明天是 的生日");}
- //农历节日
- else if ( month_moon== 0x12 && day_moon== 0x29 ){dispString(3, 0, 1, " 明天大年 ");}
- else if ( month_moon== 0x12 && day_moon== 0x30 ){dispString(3, 0, 1, " 大年三十 ");}
- else if ( month_moon== 0x05 && day_moon== 0x05 ){dispString(3, 0, 1, " 今天是端午节 ");}
- else if ( month_moon== 0x08 && day_moon== 0x15 ){dispString(3, 0, 1, " 今天是中秋节 ");}
- else if ( month_moon== 0x01 && day_moon== 0x15 ){dispString(3, 0, 1, " 今天是元宵节 ");}
- else if ( month_moon== 0x02 && day_moon== 0x02 ){dispString(3, 0, 1, " 今天是龙抬头 ");}
- else if ( month_moon== 0x07 && day_moon== 0x07 ){dispString(3, 0, 1, " 今天是七夕! ");}
- else if ( month_moon== 0x07 && day_moon== 0x15 ){dispString(3, 0, 1, " 今天是鬼节! ");}
- else if ( month_moon== 0x09 && day_moon== 0x09 ){dispString(3, 0, 1, " 今天是重阳节 ");}
- else if ( month_moon== 0x12 && day_moon== 0x08 ){dispString(3, 0, 1, " 今天是腊八节 ");}
- //国立节日
- else if ( mo == 0x01 && dd == 0x01 ){dispString(3, 0, 1, " 元旦快乐! ");}//1月
- else if ( mo == 0x01 && dd == 0x28 ){dispString(3, 0, 1, "今天是世界麻风日");}
-
- else if ( mo == 0x02 && dd == 0x02 ){dispString(3, 0, 1, "今天是世界湿地日");}//2月
- else if ( mo == 0x02 && dd == 0x13 ){dispString(3, 0, 1, " 明天情人节了 ");}
- else if ( mo == 0x02 && dd == 0x14 ){dispString(3, 0, 1, " 今天是情人节 ");}
-
- else if ( mo == 0x03 && dd == 0x01 ){dispString(3, 0, 1, "今天是国际海豹日");}//3月
- else if ( mo == 0x03 && dd == 0x03 ){dispString(3, 0, 1, "今天是全国爱耳日");}
- else if ( mo == 0x03 && dd == 0x08 ){dispString(3, 0, 1, "今天是3.8 妇女节");}
- else if ( mo == 0x03 && dd == 0x12 ){dispString(3, 0, 1, " 今天是植树节 ");}
- else if ( mo == 0x03 && dd == 0x14 ){dispString(3, 0, 1, "今天是国际警察日");}
- else if ( mo == 0x03 && dd == 0x15 ){dispString(3, 0, 1, "今天消费者权益日");}
- else if ( mo == 0x03 && dd == 0x17 ){dispString(3, 0, 1, "今天是国际航海日");}
- else if ( mo == 0x03 && dd == 0x21 ){dispString(3, 0, 1, "今天是世界森林日");}
- else if ( mo == 0x03 && dd == 0x22 ){dispString(3, 0, 1, "今天是世界水日!");}
- else if ( mo == 0x03 && dd == 0x23 ){dispString(3, 0, 1, "今天是世界气象日");}
- else if ( mo == 0x03 && dd == 0x24 ){dispString(3, 0, 1, "世界防治结核病日");}
-
- else if ( mo == 0x04 && dd == 0x01 ){dispString(3, 0, 1, "愚人节,小心上当");}//4
- else if ( mo == 0x04 && dd == 0x07 ){dispString(3, 0, 1, "今天是世界卫生日");}
- else if ( mo == 0x04 && dd == 0x08 ){dispString(3, 0, 1, " 今天复活节! ");}
- else if ( mo == 0x04 && dd == 0x13 ){dispString(3, 0, 1, " 黑色星期五! ");}
-
- else if ( mo == 0x05 && dd == 0x01 ){dispString(3, 0, 1, " 今天是劳动节 ");}//5
- else if ( mo == 0x05 && dd == 0x04 ){dispString(3, 0, 1, "今天是五四青年节");}
- else if ( mo == 0x05 && dd == 0x08 ){dispString(3, 0, 1, "今天世界红十字日");}
- else if ( mo == 0x05 && dd == 0x12 ){dispString(3, 0, 1, "今天是国际护士节");}
- else if ( mo == 0x05 && dd == 0x05 ){dispString(3, 0, 1, "近日注意母亲节! ");}
- else if ( mo == 0x05 && dd == 0x15 ){dispString(3, 0, 1, "今天是国际家庭日");}
- else if ( mo == 0x05 && dd == 0x31 ){dispString(3, 0, 1, "今天是世界无烟日");}
-
- else if ( mo == 0x06 && dd == 0x01 ){dispString(3, 0, 1, "今天是国际儿童节");}//6
- else if ( mo == 0x06 && dd == 0x05 ){dispString(3, 0, 1, "今天是世界环境日");}
- else if ( mo == 0x06 && dd == 0x26 ){dispString(3, 0, 1, "今天是国际禁毒日");}
- else if ( mo == 0x06 && dd == 0x06 ){dispString(3, 0, 1, "今天是全国爱眼日");}
- else if ( mo == 0x06 && dd == 0x13 ){dispString(3, 0, 1, "近日注意父亲节! ");}
- else if ( mo == 0x06 && dd == 0x15 ){dispString(3, 0, 1, "近日注意父亲节! ");}
-
- else if ( mo == 0x07 && dd == 0x01 ){dispString(3, 0, 1, "香港回归记念日! ");}//7
- else if ( mo == 0x07 && dd == 0x07 ){dispString(3, 0, 1, "抗日战争记念日! ");}
- else if ( mo == 0x07 && dd == 0x11 ){dispString(3, 0, 1, "今天是世界人口日");}
- else if ( mo == 0x08 && dd == 0x01 ){dispString(3, 0, 1, "今天是八一建军节");}//8
- else if ( mo == 0x08 && dd == 0x08 ){dispString(3, 0, 1, "今天是中国男子节");}
- else if ( mo == 0x08 && dd == 0x15 ){dispString(3, 0, 1, "抗战胜利记念日!");}
- else if ( mo == 0x09 && dd == 0x10 ){dispString(3, 0, 1, " 今天是教师节 ");}//9
- else if ( mo == 0x09 && dd == 0x18 ){dispString(3, 0, 1, "九·一八事变记念");}
- else if ( mo == 0x09 && dd == 0x20 ){dispString(3, 0, 1, "今天是国际爱牙日");}
- else if ( mo == 0x09 && dd == 0x27 ){dispString(3, 0, 1, "今天是世界旅游日");}
- else if ( mo == 0x10 && dd == 0x01 ){dispString(3, 0, 1, " 今天是国庆节 ");}//10
- else if ( mo == 0x10 && dd == 0x04 ){dispString(3, 0, 1, "今天是世界动物日");}
- else if ( mo == 0x10 && dd == 0x24 ){dispString(3, 0, 1, "今天是联合国日! ");}
- else if ( mo == 0x10 && dd == 0x12 ){dispString(3, 0, 1, "明天国际教师节! ");}
- else if ( mo == 0x10 && dd == 0x13 ){dispString(3, 0, 1, "今天是国际教师节");}
- else if ( mo == 0x11 && dd == 0x10 ){dispString(3, 0, 1, "今天是世界青年节");}//11
- else if ( mo == 0x11 && dd == 0x17 ){dispString(3, 0, 1, "今天是世界学生节");}
- else if ( mo == 0x12 && dd == 0x01 ){dispString(3, 0, 1, "今天世界艾滋病日");}//12
- else if ( mo == 0x12 && dd == 0x23 ){dispString(3, 0, 1, " 明晚平安夜! ");}
- else if ( mo == 0x12 && dd == 0x24 ){dispString(3, 0, 1, " 今晚平安夜! ");}
- else if ( mo == 0x12 && dd == 0x25 ){dispString(3, 0, 1, " 圣诞快乐 ");}
- else if ( mo == 0x12 && dd == 0x31 ){dispString(3, 0, 1, " 明日元旦 ");}
- }
- else{
- //二十四节气
- if (j==1){dispString(3, 0, 1, " 今天小寒 ");}
- else if (j==2){dispString(3, 0, 1, " 今天大寒 ");}
- else if (j==3){dispString(3, 0, 1, " 今天立春 ");}
- else if (j==4){dispString(3, 0, 1, " 今天雨水 ");}
- else if (j==5){dispString(3, 0, 1, " 今天惊蛰 ");}
- else if (j==6){dispString(3, 0, 1, " 今天春分 ");}
- else if (j==7){dispString(3, 0, 1, " 今天清明 ");}
- else if (j==8){dispString(3, 0, 1, " 今天谷雨 ");}
- else if (j==9){dispString(3, 0, 1, " 今天立夏 ");}
- else if (j==10){dispString(3, 0, 1, " 今天小满 ");}
- else if (j==11){dispString(3, 0, 1, " 今天芒种 ");}
- else if (j==12){dispString(3, 0, 1, " 今天夏至 ");}
- else if (j==13){dispString(3, 0, 1, " 今天小暑 ");}
- else if (j==14){dispString(3, 0, 1, " 今天大暑 ");}
- else if (j==15){dispString(3, 0, 1, " 今天立秋 ");}
- else if (j==16){dispString(3, 0, 1, " 今天处暑 ");}
- else if (j==17){dispString(3, 0, 1, " 今天白露 ");}
- else if (j==18){dispString(3, 0, 1, " 今天秋分 ");}
- else if (j==19){dispString(3, 0, 1, " 今天寒露 ");}
- else if (j==20){dispString(3, 0, 1, " 今天霜降 ");}
- else if (j==21){dispString(3, 0, 1, " 今天立冬 ");}
- else if (j==22){dispString(3, 0, 1, " 今天小雪 ");}
- else if (j==23){dispString(3, 0, 1, " 今天大雪 ");}
- else if (j==24){dispString(3, 0, 1, " 今天冬至 ");}
- //非节日时显示时晨信息
- else { if ( hh >= 0x04 && hh < 0x06 ){dispString(3, 0, 1, " 凌晨 点 分 ");
- lcdWriteCommand(0x9b);
- if(hh1/10 != 0){lcdWriteData((hh1/10)+0x30);} //十位消隐
- else{lcdWriteData(0x20);}//同上
- lcdWriteData(hh1%10+0x30);
- lcdWriteCommand(0x9d); //":"
- if(mm/16 != 0){lcdWriteData((mm/16)+0x30);} //十位消隐
- else{lcdWriteData(0x20);}//同上
- lcdWriteData(mm%16+0x30); }
- if ( hh >= 0x06 && hh < 0x08 ){dispString(3, 0, 1, " 早晨 点 分 ");
- lcdWriteCommand(0x9b);
- if(hh1/10 != 0){lcdWriteData((hh1/10)+0x30);} //十位消隐
- else{lcdWriteData(0x20);}//同上
- lcdWriteData(hh1%10+0x30);
- lcdWriteCommand(0x9d); //":"
- if(mm/16 != 0){lcdWriteData((mm/16)+0x30);} //十位消隐
- else{lcdWriteData(0x20);}//同上
- lcdWriteData(mm%16+0x30); }
- if ( hh >= 0x08 && hh < 0x12 ){dispString(3, 0, 1, " 上午 点 分 ");
- lcdWriteCommand(0x9b);
- if(hh1/10 != 0){lcdWriteData((hh1/10)+0x30);} //十位消隐
- else{lcdWriteData(0x20);}//同上
- lcdWriteData(hh1%10+0x30);
- lcdWriteCommand(0x9d); //":"
- if(mm/16 != 0){lcdWriteData((mm/16)+0x30);} //十位消隐
- else{lcdWriteData(0x20);}//同上
- lcdWriteData(mm%16+0x30); }
- if ( hh == 0x12) {dispString(3, 0, 1, " 中午 点 分 ");
- lcdWriteCommand(0x9b);
- if(hh1/10 != 0){lcdWriteData((hh1/10)+0x30);} //十位消隐
- else{lcdWriteData(0x20);}//同上
- lcdWriteData(hh1%10+0x30);
- lcdWriteCommand(0x9d); //":"
- if(mm/16 != 0){lcdWriteData((mm/16)+0x30);} //十位消隐
- else{lcdWriteData(0x20);}//同上
- lcdWriteData(mm%16+0x30); }
- if ( hh >= 0x13 && hh < 0x18 ){dispString(3, 0, 1, " 下午 点 分 ");
- lcdWriteCommand(0x9b);
- if(hh1/10 != 0){lcdWriteData((hh1/10)+0x30);} //十位消隐
- else{lcdWriteData(0x20);}//同上
- lcdWriteData(hh1%10+0x30);
- lcdWriteCommand(0x9d); //":"
- if(mm/16 != 0){lcdWriteData((mm/16)+0x30);} //十位消隐
- else{lcdWriteData(0x20);}//同上
- lcdWriteData(mm%16+0x30); }
- if ( hh >= 0x18 && hh < 0x22 ){dispString(3, 0, 1, " 晚上 点 分 ");
- lcdWriteCommand(0x9b);
- if(hh1/10 != 0){lcdWriteData((hh1/10)+0x30);} //十位消隐
- else{lcdWriteData(0x20);}//同上
- lcdWriteData(hh1%10+0x30);
- lcdWriteCommand(0x9d); //":"
- if(mm/16 != 0){lcdWriteData((mm/16)+0x30);} //十位消隐
- else{lcdWriteData(0x20);}//同上
- lcdWriteData(mm%16+0x30); }
- if ( hh >= 0x22 && hh <= 0x23 ){dispString(3, 0, 1, " 夜里 点 分 ");
- lcdWriteCommand(0x9b);
- if(hh1/10 != 0){lcdWriteData((hh1/10)+0x30);} //十位消隐
- else{lcdWriteData(0x20);}//同上
- lcdWriteData(hh1%10+0x30);
- lcdWriteCommand(0x9d); //":"
- if(mm/16 != 0){lcdWriteData((mm/16)+0x30);} //十位消隐
- else{lcdWriteData(0x20);}//同上
- lcdWriteData(mm%16+0x30); }
- if ( hh >= 0x00 && hh < 0x04 ){dispString(3, 0, 1, " 深夜 点 分 ");
- lcdWriteCommand(0x9b);
- if(hh1/10 != 0){lcdWriteData((hh1/10)+0x30);} //十位消隐
- else{lcdWriteData(0x20);}//同上
- lcdWriteData(hh1%10+0x30);
- lcdWriteCommand(0x9d); //":"
- if(mm/16 != 0){lcdWriteData((mm/16)+0x30);} //十位消隐
- else{lcdWriteData(0x20);}//同上
- lcdWriteData(mm%16+0x30); }
- }
- }
- }
- /*****************************************************************************/
- //农历显示
- /******************************************************************************/
- void lcmnongli()
- {
- uchar yue,ri;
- year_sun=yy;
- month_sun=mo;
- day_sun=dd;
- Conversion(c_sun,year_sun,month_sun,day_sun);
- yue=(month_moon/16)*10+month_moon%16;
- year1=yue;
- if(k==2)
- {
- ri=(day_moon/16)*10+day_moon%16; //显示农历月
- if(yue==1){dispString(1, 0, 1, "正"); }
- if(yue==2){dispString(1, 0, 1, "二"); }
- if(yue==3){dispString(1, 0, 1, "三"); }
- if(yue==4){dispString(1, 0, 1, "四"); }
- if(yue==5){dispString(1, 0, 1, "五"); }
- if(yue==6){dispString(1, 0, 1, "六"); }
- if(yue==7){dispString(1, 0, 1, "七"); }
- if(yue==8){dispString(1, 0, 1, "八"); }
- if(yue==9){dispString(1, 0, 1, "九"); }
- if(yue==10){dispString(1, 0, 1, "十"); }
- if(yue==11){dispString(1, 0, 1, "冬"); }
- if(yue==12){dispString(1, 0, 1, "腊"); }
- dispString(1, 1, 1, "月");
- if(ri<=10)
- {
- if(ri==1){ dispString(1, 2, 1, "初一"); }
- if(ri==2){ dispString(1, 2, 1, "初二"); }
- if(ri==3){ dispString(1, 2, 1, "初三"); }
- if(ri==4){ dispString(1, 2, 1, "初四");}
- if(ri==5){ dispString(1, 2, 1, "初五"); }
- if(ri==6){ dispString(1, 2, 1, "初六"); }
- if(ri==7){ dispString(1, 2, 1, "初七"); }
- if(ri==8){ dispString(1, 2, 1, "初八"); }
- if(ri==9){ dispString(1, 2, 1, "初九"); }
- if(ri==10){ dispString(1, 2, 1, "初十"); }
- }
- else
- {
- if(ri==11){ dispString(1, 2, 1, "十一");}
- if(ri==12){ dispString(1, 2, 1, "十二");}
- if(ri==13){ dispString(1, 2, 1, "十三"); }
- if(ri==14){ dispString(1, 2, 1, "十四"); }
- if(ri==15){ dispString(1, 2, 1, "十五"); }
- if(ri==16){ dispString(1, 2, 1, "十六"); }
- if(ri==17){ dispString(1, 2, 1, "十七"); }
- if(ri==18){ dispString(1, 2, 1, "十八"); }
- if(ri==19){ dispString(1, 2, 1, "十九"); }
- if(ri==20){ dispString(1, 2, 1, "二十");}
- if(ri==21){ dispString(1, 2, 1, "廿一"); }
- if(ri==22){ dispString(1, 2, 1, "廿二");}
- if(ri==23){ dispString(1, 2, 1, "廿三"); }
- if(ri==24){ dispString(1, 2, 1, "廿四"); }
- if(ri==25){ dispString(1, 2, 1, "廿五"); }
- if(ri==26){ dispString(1, 2, 1, "廿六");}
- if(ri==27){ dispString(1, 2, 1, "廿七"); }
- if(ri==28){ dispString(1, 2, 1, "廿八"); }
- if(ri==29){ dispString(1, 2, 1, "廿九");}
- if(ri==30){ dispString(1, 2, 1, "三十"); }
- }
- }
- else
- {
- ri=(day_moon/16)*10+day_moon%16; //显示农历月
- if(yue==1){dispString(2, 1, 1, "正"); }
- if(yue==2){dispString(2, 1, 1, "二"); }
- if(yue==3){dispString(2, 1, 1, "三"); }
- if(yue==4){dispString(2, 1, 1, "四"); }
- if(yue==5){dispString(2, 1, 1, "五"); }
- if(yue==6){dispString(2, 1, 1, "六"); }
- if(yue==7){dispString(2, 1, 1, "七"); }
- if(yue==8){dispString(2, 1, 1, "八"); }
- if(yue==9){dispString(2, 1, 1, "九"); }
- if(yue==10){dispString(2, 1, 1, "十"); }
- if(yue==11){dispString(2, 1, 1, "冬"); }
- if(yue==12){dispString(2, 1, 1, "腊"); }
- dispString(2, 2, 1, "月");
- if(ri<=10)
- {
- if(ri==1){ dispString(2, 3, 1, "初一"); }
- if(ri==2){ dispString(2, 3, 1, "初二"); }
- if(ri==3){ dispString(2, 3, 1, "初三"); }
- if(ri==4){ dispString(2, 3, 1, "初四");}
- if(ri==5){ dispString(2, 3, 1, "初五"); }
- if(ri==6){ dispString(2, 3, 1, "初六"); }
- if(ri==7){ dispString(2, 3, 1, "初七"); }
- if(ri==8){ dispString(2, 3, 1, "初八"); }
- if(ri==9){ dispString(2, 3, 1, "初九"); }
- if(ri==10){ dispString(2, 3, 1, "初十"); }
- }
- else
- {
- if(ri==11){ dispString(2, 3, 1, "十一");}
- if(ri==12){ dispString(2, 3, 1, "十二");}
- if(ri==13){ dispString(2, 3, 1, "十三"); }
- if(ri==14){ dispString(2, 3, 1, "十四"); }
- if(ri==15){ dispString(2, 3, 1, "十五"); }
- if(ri==16){ dispString(2, 3, 1, "十六"); }
- if(ri==17){ dispString(2, 3, 1, "十七"); }
- if(ri==18){ dispString(2, 3, 1, "十八"); }
- if(ri==19){ dispString(2, 3, 1, "十九"); }
- if(ri==20){ dispString(2, 3, 1, "二十");}
- if(ri==21){ dispString(2, 3, 1, "廿一"); }
- if(ri==22){ dispString(2, 3, 1, "廿二");}
- if(ri==23){ dispString(2, 3, 1, "廿三"); }
- if(ri==24){ dispString(2, 3, 1, "廿四"); }
- if(ri==25){ dispString(2, 3, 1, "廿五"); }
- if(ri==26){ dispString(2, 3, 1, "廿六");}
- if(ri==27){ dispString(2, 3, 1, "廿七"); }
- if(ri==28){ dispString(2, 3, 1, "廿八"); }
- if(ri==29){ dispString(2, 3, 1, "廿九");}
- if(ri==30){ dispString(2, 3, 1, "三十"); }
- }
- }
- }
- /******************************************************************************/
- //十二生肖显示
- /******************************************************************************/
- void lcmshengxiao()
- {
- uint y3;
- y3=(yy/16*10+yy%16+2000-1900)%12;
- if(year<6 & year1>6) y3--;
- switch(y3)
- {
- case 0: dispString(0, 6, 1, "子鼠");
- break;
- case 1: dispString(0, 6, 1, "丑牛");
- break;
- case 2: dispString(0, 6, 1, "寅虎");
- break;
- case 3: dispString(0, 6, 1, "卯兔");
- break;
- case 4: dispString(0, 6, 1, "辰龙");
- break;
- case 5: dispString(0, 6, 1, "巳蛇");
- break;
- case 6: dispString(0, 6, 1, "午马");
- break;
- case 7: dispString(0, 6, 1, "未羊");
- break;
- case 8: dispString(0, 6, 1, "申猴");
- break;
- case 9: dispString(0, 6, 1, "酉鸡");
- break;
- case 10: dispString(0, 6, 1, "戌狗");
- break;
- case 11: dispString(0, 6, 1, "亥猪");
- break;
- }
- }
- /*****************************************************************************/
- //调时用加1程序
- void Set_time(unsigned char sel)//根据选择调整的相应项目加1并写入DS1302
- {
- signed char address,item;
- signed char max,mini;
- dispString(3, 2, 1, "设置");
- if(sel==6) {dispString(3, 4, 1, "秒钟");address=0x80; max=59;mini=0;} //秒7
- if(sel==5) {dispString(3, 4, 1, "分钟");address=0x82; max=59;mini=0;} //分钟6
- if(sel==4) {dispString(3, 4, 1, "小时");address=0x84; max=23;mini=0;} //小时5
- if(sel==3) {dispString(3, 4, 1, "星期");address=0x8a; max=7;mini=1;} //星期4
- if(sel==2) {dispString(3, 4, 1, "日期");address=0x86; max=31;mini=1;} //日3
- if(sel==1) {dispString(3, 4, 1, "月份");address=0x88; max=12;mini=1;} //月2
- if(sel==0) {dispString(3, 4, 1, "年份");address=0x8c; max=99; mini=0;} //年1
- switch(sel)
- {
- case 0: convertChar(0, 1, 2);
- break;
- case 1: convertChar(0, 2, 3);
- break;
- case 2: convertChar(0, 4, 2);
- break;
- case 3: convertChar(1, 7, 2);
- break;
- case 4: convertChar(2, 0, 2);
- break;
- case 5: convertChar(2, 1, 3);
- break;
- case 6: convertChar(2, 3, 2);
- break;
- }
- //读取1302某地址上的数值转换成10进制赋给item
- item=((read_clock(address+1))/16)*10 + (read_clock(address+1))%16;
- if(KEY_2 == 0||workcode==3)
- {
- item++;//数加 1
- workcode=0;
- }
- if(KEY_4 == 0||workcode==7)
- {
- item--;//数减 1
- workcode=0;
- }
- if(item>max) item=mini;//查看数值有效范围
- if(item<mini) item=max;
- write_clock(0x8e,0x00);//允许写操作
- write_clock(address,(item/10)*16+item%10);//转换成16进制写入1302
- write_clock(0x8e,0x80);//写保护,禁止写操作
-
- }
- /*****************************************************************************/
- /*****************************************************************************/
- //扬声器驱动程序(闹钟音乐)
- /*****************************************************************************/
- void Beep(void)
- {//BELL-扬声器--整点报时
- unsigned char a;//定义变量用于发声的长度设置
- for(a=60;a>0;a--){//第一个声音的长度
- beep = ~beep;//取反扬声器驱动口,以产生音频
- Delay(100);//音调设置延时
- }
- for(a=100;a>0;a--){//同上
- beep = ~beep;
- Delay(80);//
- }
- for(a=100;a>0;a--){//同上
- beep = ~beep;
- Delay(30);//
- }
- beep = 1;//音乐结束后扬声器拉高关闭
- }
- /*****************************************************************************/
- void Beep_set(void){//BELL -扬声器--确定设置
- unsigned char a;//定义变量用于发声的长度设置
- for(a=50;a>0;a--){//第一个声音的长度
- beep = ~beep;//取反扬声器驱动口,以产生音频
- Delay(100);//音调设置延时
- }
- for(a=100;a>0;a--){//同上
- beep = ~beep;
- Delay(50);//
- }
- for(a=50;a>0;a--){//同上
- beep = ~beep;
- Delay(100);//
- }
- beep = 1;//音乐结束后扬声器拉高关闭
- }
- /*****************************************************************************/
- void Beep_key(void){//-扬声器--按键音
- unsigned char a;//定义变量用于发声的长度设置
- for(a=100;a>0;a--){//声音的长度
- beep = ~beep;
- Delay(50);//音调设置延时
- }
- beep = 1;//音乐结束后扬声器拉高关闭
- }
- /*****************************************************************************/
- /*****************************************************************************/
- //电子钟应用层程序设计
- /*****************************************************************************/
- //向LCM中填写 年 数据
- void lcm_w_yy(void){
- //if(read_clock(0x8d) != yy){
- yy = read_clock(0x8d);
- dispString(0, 0, 1, "20");
- lcdWriteCommand(0x81);
- lcdWriteData((yy/16)+0x30);
- lcdWriteData(yy%16+0x30);
- } //}
- /*****************************************************************************/
- //向LCM中填写 月 数据
- void lcm_w_mo(void){
- //if(read_clock(0x89) != mo){
- mo = read_clock(0x89);
- lcdWriteCommand(0x82);
- lcdWriteData(0x2d);
- lcdWriteData((mo/16)+0x30); //十位消隐
- lcdWriteData(mo%16+0x30);
- lcdWriteData(0x2d);
- year=(mo/16*10)+mo%16;
- } //}
- /*****************************************************************************/
- //星期处理并送入LCM的指定区域
- void lcm_w_xq(void){
- //if(read_clock(0x8b) != xq){
- xq = read_clock(0x8b);
- selx = (read_clock(0x8b))%16; //字节低4位的BCD码放入selx
- if(selx==7) {dispString(1, 7, 1, "日");} //
- if(selx==6) {dispString(1, 7, 1, "六");} //
- if(selx==5) {dispString(1, 7, 1, "五");} //
- if(selx==4) {dispString(1, 7, 1, "四");} //
- if(selx==3) {dispString(1, 7, 1, "三");} //
- if(selx==2) {dispString(1, 7, 1, "二");} //
- if(selx==1) {dispString(1, 7, 1, "一");} //星期一
- dispString(1, 5, 1, "星期");
- } //}
- /*****************************************************************************/
- //向LCM中填写 日 数据
- void lcm_w_dd(void){
- // if(read_clock(0x87) != dd){
- dd = read_clock(0x87);
- lcdWriteCommand(0x84);
- lcdWriteData((dd/16)+0x30); //十位消隐
- lcdWriteData(dd%16+0x30);
- } //}
- /*****************************************************************************/
- //向LCM中填写 小时 数据
- void lcm_w_hh(void){
- if(read_clock(0x85) != hh){
- hh = read_clock(0x85);
- if (hh > 0x07 && hh < 0x22 && w == 0){
- Beep();//整点报时音
- }
- }
- lcdWriteCommand(0x88);
- lcdWriteData((hh/16)+0x30);
- lcdWriteData(hh%16+0x30);
- hh1=hh/16*10+hh%16;
- if(hh1>12) hh1=(hh1-12);
-
- }
- /*****************************************************************************/
- //向LCM中填写 分钟 数据
- void lcm_w_mm(void){
- if(read_clock(0x83) != mm)
- {
- mm = read_clock(0x83);
- }
- lcdWriteCommand(0x89);
- if(t/1%2==0)lcdWriteData(0x3a); //":"
- else{lcdWriteData(0x20);}
- lcdWriteData((mm/16)+0x30);
- lcdWriteData(mm%16+0x30);
- if(t/1%2==0) lcdWriteData(0x3a); //":"
- else{lcdWriteData(0x20);}
- }
- /*****************************************************************************/
- //向LCM中填写 秒 数据
- void lcm_w_ss(void)
- {
- unsigned int i=0;
- unsigned char a=0,b=0,c=0;
- if(read_clock(0x81) != ss){ //判断是否需要更新
- ss = read_clock(0x81); //更新数据
- if(w==1&&e==6)
- {
- if(t/1%2==0)
- {
- lcdWriteCommand(0x8b); //秒值在LCM上的写入位置
- lcdWriteData((ss/16)+0x30); //写十位
- lcdWriteData(ss%16+0x30); //写个位
- }
- else
- {
- lcdWriteCommand(0x8b); //秒值在LCM上的写入位置
- lcdWriteData(0x20); //写十位
- lcdWriteData(0x20); //写个位
- }
- }
- else
- {
- lcdWriteCommand(0x8b); //秒值在LCM上的写入位置
- lcdWriteData((ss/16)+0x30); //写十位
- lcdWriteData(ss%16+0x30); //写个
- }
- }
- }
- /*****************************************************************************/
- void disp_temper()//温度值显示
- {
- uint temper;
- uchar temper_ge,temper_shi,temper_bai;
- temper=read_temp();//读取温度
- temper_ge=temper%10+0x30;
- temper_shi=temper%100/10+0x30;
- temper_bai=temper/100+0x30;
- if(tflag==1)
- {
- dispString(2, 4, 1, " -");
- }
- else
- {
- dispString(2, 4, 1, " ");
- }
- if(temper_bai==0x30) temper_bai=0x20;
- lcdWriteCommand(0x8d);
- lcdWriteData(temper_bai);
- lcdWriteData(temper_shi);
- lcdWriteData('.');
- lcdWriteData(temper_ge);
- dispString(2, 7, 1, "℃");
- }
- /*****************************************************************************/
- //刷新数据
- void updata (void){
- lcm_w_ss();//刷新 秒
- lcm_w_mm();//刷新 分
- lcm_w_hh();//刷新 小时
- lcm_w_dd();//刷新 日
- lcm_w_xq();//更新星期值
- lcm_w_mo();//刷新 月
- lcm_w_yy();//刷新 年
- ss = read_clock(0x81); //更新数据
- t=ss/16*10+ss%16;
- lcmnongli();
- lcmshengxiao();
- disp_temper();
- if(w == 0)
- {
- days ();//节日显示
- }
- if (n==1||n==2||n==3)
- {
- lcdWriteCommand(0x85); //秒值在LCM上的写入位置
- lcdWriteData(0x20);
- lcdWriteData(0x0e);
- }
- else{
- lcdWriteCommand(0x85); //秒值在LCM上的写入位置
- lcdWriteData(0x20);
- lcdWriteData(0x20);
- }
- }
- /*********************************************************************************************************
- 处理显示函数(被调用层)
- *********************************************************************************************************/
- void deal(uchar sfm)
- {
- shi=sfm/16;
- ge=sfm%16;
- }
- /********************************************************************************************************
- 12864显示时分秒函数(被调用层)
- ********************************************************************************************************/
- void display(uchar add,uchar dat)
- {
- uchar i,j=0;
- if(k==0)
- {
- for(i=16;i<32;i++)
- {
- lcdWriteCommand(0x80+i);
- lcdWriteCommand(0x90+add);
- lcdWriteData(tab[dat][j++]);
- lcdWriteData(tab[dat][j++]);
- }
- for(i=0;i<16;i++)
- {
- lcdWriteCommand(0x80+i);
- lcdWriteCommand(0x88+add);
- lcdWriteData(tab[dat][j++]);
- lcdWriteData(tab[dat][j++]);
- }
- }
- else
- {
- for(i=0;i<16;i++)
- {
- lcdWriteCommand(0x80+i);
- lcdWriteCommand(0x80+add);
- lcdWriteData(tab1[dat][j++]);
- lcdWriteData(tab1[dat][j++]);
- }
- for(i=16;i<32;i++)
- {
- lcdWriteCommand(0x80+i);
- lcdWriteCommand(0x90+add);
- lcdWriteData(tab1[dat][j++]);
- lcdWriteData(tab1[dat][j++]);
- }
- }
- }
- /********************************************************************************************************
- 12864显示时分秒函数(被调用层)2
- ********************************************************************************************************/
- void display1(uchar add,uchar dat)
- {
- uchar i,j=0;
- for(i=0;i<16;i++)
- {
- lcdWriteCommand(0x80+i);
- lcdWriteCommand(0x88+add);
- lcdWriteData(tab1[dat][j++]);
- lcdWriteData(tab1[dat][j++]);
- }
- for(i=16;i<32;i++)
- {
- lcdWriteCommand(0x80+i);
- lcdWriteCommand(0x98+add);
- lcdWriteData(tab1[dat][j++]);
- lcdWriteData(tab1[dat][j++]);
- }
- }
- /*********************************************************************************************************
- 初始化函数(被调用层)
- *********************************************************************************************************/
- void init_dz()
- {
- lcdWriteCommand(0x30); //选择8bit数据流,基本指令集
- lcdWriteCommand(0x0c); //开显示(无游标、不反白)
- lcdWriteCommand(0x01); //清除显示,并且设定地址指针为00H
- if(k==0)
- {
- dispString(0, 2, 1, "年 月 日");
- dispString(3, 0, 1, "星期");
- lcdWriteCommand(0x81); //处理年,并显示
- yy = read_clock(0x8d);
- deal(yy);
- lcdWriteData(shi+0x30);
- lcdWriteData(ge+0x30);
- //处理月,并显示
- lcdWriteCommand(0x83);
- mo = read_clock(0x89);
- deal(mo);
- lcdWriteData(shi+0x30);
- lcdWriteData(ge+0x30);
- lcdWriteCommand(0x85); //处理日,并显示
- dd = read_clock(0x87);
- deal(dd);
- lcdWriteData(shi+0x30);
- lcdWriteData(ge+0x30);
- //处理星期,并显示
- xq = read_clock(0x8b);
- switch(xq)
- {
- case 1: dispString(3, 2, 1, "一");break;
- case 2: dispString(3, 2, 1, "二");break;
- case 3: dispString(3, 2, 1, "三");break;
- case 4: dispString(3, 2, 1, "四");break;
- case 5: dispString(3, 2, 1, "五");break;
- case 6: dispString(3, 2, 1, "六");break;
- case 7: dispString(3, 2, 1, "日");break;
- default:break;
- }
- dispString(3, 7, 1, "℃");
- lcdWriteCommand(0x36); //启动扩充指令集,启动绘图模式
- clear_img(); //清理图片缓冲区
- lcmnongli();
- hh = read_clock(0x85); //处理小时,并显示
- deal(hh);
- display(0,shi);
- display(1,ge);
- display(2,10);
- mm = read_clock(0x83); //处理分钟,并显示
- deal(mm);
- display(3,shi);
- display(4,ge);
- display(5,10);
- ss = read_clock(0x81); //处理秒,并显示
- deal(ss);
- display(6,shi);
- display(7,ge);
- }
- else
- {
- dispString(0, 5, 1, "星期");
- dispString(3, 0, 1, " 20");
- lcdWriteCommand(0x99); //处理年,并显示
- yy = read_clock(0x8d);
- deal(yy);
- lcdWriteData(0x20);
- lcdWriteData(shi+0x30);
- lcdWriteData(ge+0x30);
- lcdWriteData(0x2d);
- //处理月,并显示
- //lcdWriteCommand(0x9a);
- mo = read_clock(0x89);
- deal(mo);
- lcdWriteData(shi+0x30);
- lcdWriteData(ge+0x30);
- //lcdWriteCommand(0x9c); //处理日,并显示
- dd = read_clock(0x87);
- deal(dd);
- lcdWriteData(0x2d);
- lcdWriteData(shi+0x30);
- lcdWriteData(ge+0x30);
- //处理星期,并显示
- xq = read_clock(0x8b);
- switch(xq)
- {
- case 1: dispString(0, 7, 1, "一");break;
- case 2: dispString(0, 7, 1, "二");break;
- case 3: dispString(0, 7, 1, "三");break;
- case 4: dispString(0, 7, 1, "四");break;
- case 5: dispString(0, 7, 1, "五");break;
- case 6: dispString(0, 7, 1, "六");break;
- case 7: dispString(0, 7, 1, "日");break;
- default:break;
- }
- dispString(1, 7, 1, "℃");
- lcdWriteCommand(0x36); //启动扩充指令集,启动绘图模式
- clear_img(); //清理图片缓冲区
- hh = read_clock(0x85); //处理小时,并显示
- deal(hh);
- display(0,shi);
- display(1,ge);
- display(2,10);
- mm = read_clock(0x83); //处理分钟,并显示
- deal(mm);
- display(3,shi);
- display(4,ge);
- ss = read_clock(0x81); //处理秒,并显示
- deal(ss);
- display1(6,shi);
- display1(7,ge);
- }
- }
- /********************************************************************************************************
- 在12864上显示时间,大数字显示主界面1
- ********************************************************************************************************/
- void disp_sfm()
- {
- uint temper;
- uchar temper_ge,temper_shi,temper_bai,day_temp,date_temp,month_temp,year_temp;
- lcdWriteCommand(0x36); //启动扩充指令集,启动绘图模式
- ss = read_clock(0x81); //更新数据
- if(sec_temp!=ss)//读取秒,只要有改变液晶显示也改变
- {
- sec_temp=ss;
- deal(sec_temp);
- if(secl!=shi)
- {
- secl=shi;
- display(6,secl);
- }
- display(7,ge);
- }
- mm = read_clock(0x83); //读取分,只要有改变液晶显示也改变
- if(min_temp!=mm)
- {
- min_temp=mm;
- deal(mm);
- display(3,shi);
- display(4,ge);
- }
- hh = read_clock(0x85); //读取小时,只要有改变液晶显示也改变
- if(hour_temp!=hh)
- {
- hour_temp=hh;
- deal(hh);
- display(0,shi);
- display(1,ge);
- }
- if(ge/1%2==0)
- {
- display(2,10);
- display(5,10);
- }
- else
- {
- display(2,11);
- display(5,11);
- }
-
- lcdWriteCommand(0x30);
- dd = read_clock(0x87); //读取日,只要有改变液晶显示也改变
- if(date_temp!=dd)
- {
- date_temp=dd;
- deal(dd);
- lcdWriteCommand(0x85);
- lcdWriteData(shi+0x30);
- lcdWriteData(ge+0x30);
- }
- mo = read_clock(0x89); //读取月,只要有改变液晶显示也改变
- if(month_temp!=mo)
- {
- month_temp=mo;
- lcdWriteCommand(0x83);
- deal(mo);
- lcdWriteData(shi+0x30);
- lcdWriteData(ge+0x30);
- }
- yy = read_clock(0x8d); //读取年,只要有改变液晶显示也改变
- if(year_temp!=yy)
- {
- year_temp=yy;
- lcdWriteCommand(0x81);
- deal(yy);
- lcdWriteData(shi+0x30);
- lcdWriteData(ge+0x30);
- }
- xq = read_clock(0x8b); //读取星期,只要有改变液晶显示也改变
- if(day_temp!=xq)
- {
- day_temp=xq;
- switch(xq)
- {
- case 1: dispString(3, 2, 1, "一");break;
- case 2: dispString(3, 2, 1, "二");break;
- case 3: dispString(3, 2, 1, "三");break;
- case 4: dispString(3, 2, 1, "四");break;
- case 5: dispString(3, 2, 1, "五");break;
- case 6: dispString(3, 2, 1, "六");break;
- case 7: dispString(3, 2, 1, "日");break;
- default:break;
- }
- }
- temper=read_temp();//读取温度
- temper_ge=temper%10+0x30;
- temper_shi=temper%100/10+0x30;
- temper_bai=temper/100+0x30;
- //lcdWriteCommand(0x9b); //此处可以用来测试各种红外遥控的键值
- //lcdWriteData(workcode/10+0x30);
- //lcdWriteData(workcode%10+0x30);
- if(tflag==1)
- {
- dispString(3, 4, 1, " -");
- }
- else
- {
- dispString(3, 4, 1, " ");
- }
- if(temper_bai==0x30) temper_bai=0x20;
- lcdWriteCommand(0x9d);
- lcdWriteData(temper_bai);
- lcdWriteData(temper_shi);
- lcdWriteData('.');
- lcdWriteData(temper_ge);
- lcdWriteCommand(0x36);
-
- }
- /********************************************************************************************************
- 在12864上显示时间,大数字显示主界面2
- ********************************************************************************************************/
- void disp_sfm1()
- {
- uint temper;
- uchar temper_ge,temper_shi,temper_bai,day_temp,date_temp,month_temp,year_temp;
- lcdWriteCommand(0x36); //启动扩充指令集,启动绘图模式
- ss = read_clock(0x81); //更新数据
- if(sec_temp!=ss)//读取秒,只要有改变液晶显示也改变
- {
- sec_temp=ss;
- deal(sec_temp);
- if(secl!=shi)
- {
- secl=shi;
- display1(6,secl);
- }
- display1(7,ge);
- }
- mm = read_clock(0x83); //读取分,只要有改变液晶显示也改变
- if(min_temp!=mm)
- {
- min_temp=mm;
- deal(mm);
- display(3,shi);
- display(4,ge);
- }
- hh = read_clock(0x85); //读取小时,只要有改变液晶显示也改变
- if(hour_temp!=hh)
- {
- hour_temp=hh;
- deal(hh);
- display(0,shi);
- display(1,ge);
- }
- if(ge/1%2==0)
- {
- display(2,10);
- }
- else
- {
- display(2,11);
- }
- lcdWriteCommand(0x30);
- lcmnongli();
- yy = read_clock(0x8d); //读取年,只要有改变液晶显示也改变
- if(year_temp!=yy)
- {
- year_temp=yy;
- lcdWriteCommand(0x99);
- deal(yy);
- lcdWriteData(0x30);
- lcdWriteData(shi+0x30);
- lcdWriteData(ge+0x30);
- lcdWriteData(0x2d);
- }
- mo = read_clock(0x89); //读取月,只要有改变液晶显示也改变
- if(month_temp!=mo)
- {
- month_temp=mo;
- lcdWriteCommand(0x9b);
- deal(mo);
- lcdWriteData(shi+0x30);
- lcdWriteData(ge+0x30);
- }
- dd = read_clock(0x87); //读取日,只要有改变液晶显示也改变
- if(date_temp!=dd)
- {
- date_temp=dd;
- deal(dd);
- lcdWriteCommand(0x9c);
- lcdWriteData(0x2d);
- lcdWriteData(shi+0x30);
- lcdWriteData(ge+0x30);
- }
- xq = read_clock(0x8b); //读取星期,只要有改变液晶显示也改变
- if(day_temp!=xq)
- {
- day_temp=xq;
- switch(xq)
- {
- case 1: dispString(0, 7, 1, "一");break;
- case 2: dispString(0, 7, 1, "二");break;
- case 3: dispString(0, 7, 1, "三");break;
- case 4: dispString(0, 7, 1, "四");break;
- case 5: dispString(0, 7, 1, "五");break;
- case 6: dispString(0, 7, 1, "六");break;
- case 7: dispString(0, 7, 1, "日");break;
- default:break;
- }
- }
- temper=read_temp();//读取温度
- temper_ge=temper%10+0x30;
- temper_shi=temper%100/10+0x30;
- temper_bai=temper/100+0x30;
- //lcdWriteCommand(0x9b); //此处可以用来测试各种红外遥控的键值
- //lcdWriteData(workcode/10+0x30);
- //lcdWriteData(workcode%10+0x30);
- /*if(tflag==1)
- {
- dispString(1, 5, 1, " -");
- }
- else
- {
- dispString(1, 5, 1, " ");
- }*/
- if(temper_bai==0x30) temper_bai=0x20;
- lcdWriteCommand(0x95);
- lcdWriteData(temper_bai);
- lcdWriteData(temper_shi);
- lcdWriteData('.');
- lcdWriteData(temper_ge);
- lcdWriteCommand(0x36);
-
- }
- //*****************************Music******************************************************/
- //天空之城
- unsigned char code Music_wo[]={ 0x10,0x03, 0x11,0x03, 0x15,0x66, 0x11,0x03, 0x15,0x02,
- 0x17,0x02, 0x11,0x01, 0x0D,0x02, 0x0D,0x02, 0x10,0x66,
- 0x0F,0x03, 0x10,0x02, 0x15,0x02, 0x0F,0x15, 0x0D,0x03,
- 0x0D,0x03, 0x0E,0x66, 0x0D,0x03, 0x0E,0x03, 0x15,0x66,
- 0x0D,0x01, 0x15,0x02, 0x15,0x02, 0x15,0x02, 0x11,0x66,
- 0x0E,0x03, 0x0E,0x02, 0x11,0x02, 0x11,0x15, 0x10,0x03,
- 0x11,0x03, 0x15,0x66, 0x11,0x03, 0x15,0x02, 0x17,0x02,
- 0x11,0x15, 0x0D,0x03, 0x0D,0x03, 0x10,0x66, 0x0F,0x03,
- 0x10,0x02, 0x15,0x02, 0x0F,0x01, 0x0D,0x03, 0x0E,0x02,
- 0x15,0x03, 0x11,0x03, 0x11,0x02, 0x15,0x02, 0x16,0x03,
- 0x16,0x03, 0x17,0x03, 0x15,0x16, 0x15,0x02, 0x11,0x03,
- 0x10,0x03, 0x10,0x03, 0x11,0x02, 0x0F,0x02, 0x10,0x15,
- 0x15,0x03, 0x16,0x03, 0x17,0x66, 0x16,0x03, 0x17,0x02,
- 0x19,0x02, 0x16,0x15, 0x0F,0x03, 0x0F,0x03, 0x15,0x03,
- 0x11,0x03, 0x15,0x02, 0x17,0x02, 0x17,0x15, 0x10,0x03,
- 0x11,0x03, 0x15,0x02, 0x11,0x02, 0x16,0x03, 0x16,0x03,
- 0x15,0x66, 0x0F,0x03, 0x0F,0x16, 0x18,0x02, 0x17,0x02,
- 0x16,0x02, 0x15,0x02, 0x17,0x00, 0x17,0x02, 0x1A,0x01,
- 0x19,0x02, 0x19,0x02, 0x17,0x03, 0x16,0x03, 0x15,0x02,
- 0x15,0x02, 0x16,0x02, 0x15,0x03, 0x16,0x03, 0x16,0x03,
- 0x19,0x02, 0x17,0x15, 0x17,0x02, 0x1A,0x01, 0x19,0x01,
- 0x17,0x03, 0x16,0x03, 0x15,0x01, 0x15,0x03, 0x16,0x02,
- 0x15,0x03, 0x16,0x03, 0x16,0x03, 0x11,0x02, 0x10,0x01,
- 0x00,0x00 };
- /***********************************************************************************/
- /*------------------整屏写入数据:全亮,或者竖条-----------------------------*/
- void lcdfill(unsigned char disdata)
- { unsigned char x,y;
- for(y=0;y<32;y++)
- for(x=0;x<16;x++)
- { lcdWriteCommand(0x36);
- lcdWriteCommand(y+0x80); //行地址
- lcdWriteCommand(x+0x80); //列地址
- lcdWriteCommand(0x30);
- lcdWriteData(disdata);
- lcdWriteData(disdata);
- DelayM(2);
- }
- lcdWriteCommand(0x34);
- lcdWriteCommand(0x36);
- }
- /*------------------显示横-----------------------------*/
- void Disp_H_Line()
- { unsigned char x,y;
- unsigned char k=0x00;
- for(y=0;y<32;y++)
- { k=~k;
- for(x=0;x<16;x++)
- { lcdWriteCommand(0x36);
- lcdWriteCommand(y+0x80); //行地址
- lcdWriteCommand(x+0x80); //列地址
- lcdWriteCommand(0x30);
- lcdWriteData(k);
- lcdWriteData(k);
- DelayM(5);
- };
- }
- lcdWriteCommand(0x34);
- lcdWriteCommand(0x36);
- }
- /*------------------显示边框-------------------------------*/
- void Frame()
- {unsigned char x,y;
- lcdfill(0x00);
- for(x=0;x<9;x+=8)
- for(y=0;y<32;y++)
- { lcdWriteCommand(0x36);
- lcdWriteCommand(y+0x80); //行地址
- lcdWriteCommand(x+0x80); //列地址
- lcdWriteCommand(0x30);
- lcdWriteData(0x80);
- lcdWriteData(0x00);
-
- lcdWriteCommand(0x36);
- lcdWriteCommand(y+0x80); //行地址
- lcdWriteCommand(x+0x87); //列地址
- lcdWriteCommand(0x30);
- lcdWriteData(0x00);
- lcdWriteData(0x01);
- DelayM(5);
- }
- for(y=0;y<2;y++)
- for(x=0;x<8;x++)
- {lcdWriteCommand(0x36);
- lcdWriteCommand(y*31+0x80); //行地址
- lcdWriteCommand(x+0x80+8*y); //列地址
- lcdWriteCommand(0x30);
- lcdWriteData(0xff);
- lcdWriteData(0xff);
- DelayM(5);
- }
- lcdWriteCommand(0x34);
- lcdWriteCommand(0x36);
- }
- /*****************************************************************************/
- void zijian(void)
- {
- lcdClear();
- dispString(1, 0, 1, " V8.0版本 ");
- dispString(2, 0, 1, " 自检程序开始! ");
- DelayM(2000);
- lcdClear();
- displayPhoto(powerOnPhoto1, OFF);
- DelayM(2000);
- lcdfill(0xff); //显示全开
- DelayM(2000);
-
- Disp_H_Line(); //显示横条
- DelayM(2000);
-
-
- lcdfill(0xaa); //显示竖条
- DelayM(2000);
-
- Frame(); //显示边框
- DelayM(2000);
- clear_img();
- lcdClear();
- lcdWriteCommand(0x30); //选择8bit数据流
- lcdWriteCommand(0x0c); //开显示(无游标、不反白)
- lcdWriteCommand(0x01); //清除显示,并且设定地址指针为00H
- Beep_set();//确定按键音
- dispString(0, 0, 1, " 自检完成! ");
- dispString(2, 0, 1, " ==小东电子== ");
- dispString(3, 0, 1, " QQ:120985850 ");
- DelayM(2000);
- lcdInit ();
- }
- /*****************************************************************************/
- void naozhong()
- {
- lcdClear();
- dispString(0, 2, 1, "闹钟设置");
- dispString(2, 0, 1, "闹钟");
- n=Read24c02(0);
- if(n==0) {dispString(2, 7, 1, "关");} //
- if(n==1) {dispString(2, 7, 1, "开");} //
- if(n==2) {dispString(2, 7, 1, "开");} //
- if(n==3) {dispString(2, 7, 1, "开");} //
- n1=Read24c02(1);
- n2=Read24c02(2);
- lcdWriteCommand(0x8b);
- lcdWriteData((n1/10)+0x30);
- lcdWriteData(n1%10+0x30);
- dispString(2, 4, 1, "点");
- lcdWriteData((n2/10)+0x30);
- lcdWriteData(n2%10+0x30);
- while(1)
- {
- if (KEY_3 == 0||workcode==5) // 设置时间
- {
- DelayM(20); //去抖
- if(KEY_3 == 0 ||workcode==5)
- {
- Beep_key();//按键音
- workcode=0;
- n++;
- if (n >= 4 ){n = 0;}
- Write24c02(n,0);
- if(n==0) {dispString(2, 7, 1, "关");} //
- if(n==1) {dispString(2, 7, 1, "开");} //
- if(n==2) {dispString(2, 7, 1, "开");} //
- if(n==3) {dispString(2, 7, 1, "开");} //
- switch(n)
- {
- case 0: convertChar(1, 0, 0);
- break;
- case 1: convertChar(1, 0, 0);
- break;
- case 2: convertChar(2, 3, 2);
- break;
- case 3: convertChar(2, 5, 2);
- break;
- }
- while(KEY_3 == 0);//等待键松开
- }
- }
- if(KEY_4 == 0||KEY_2 == 0||workcode==3||workcode==7)
- {
- if ((KEY_2 == 0&&n==2)||(workcode==3&&n==2)) //
- {
- DelayM(20); //去抖
- if((KEY_2 == 0&&n==2)||(workcode==3&&n==2))
- {
- Beep_key();//按键音
- workcode=0;
- n1++;
- if (n1 >= 24 ){n1 = 0;}
- Write24c02(n1,1);
- while(KEY_2 == 0);//等待键松开
- }
- }
- if ((KEY_2 == 0&&n==3)||(workcode==3&&n==3)) //
- {
- DelayM(20); //去抖
- if((KEY_2 == 0&&n==3)||(workcode==3&&n==3))
- {
- Beep_key();//按键音
- workcode=0;
- n2++;
- if (n2>= 60 ){n2 = 0;}
- Write24c02(n2,2);
- while(KEY_2 == 0);//等待键松开
- }
- }
- if ((KEY_4 == 0&&n==2)||(workcode==7&&n==2)) //
- {
- DelayM(20); //去抖
- if((KEY_4 == 0&&n==2)||(workcode==7&&n==2))
- {
- Beep_key();//按键音
- workcode=0;
- n1--;
- if (n1<0 ){n1 = 23;}
- Write24c02(n1,1);
- while(KEY_4 == 0);//等待键松开
- }
- }
- if ((KEY_4 == 0&&n==3)||(workcode==7&&n==3)) //
- {
- DelayM(20); //去抖
- if((KEY_4 == 0&&n==3)||(workcode==7&&n==3))
- {
- Beep_key();//按键音
- workcode=0;
- n2--;
- if (n2<0 ){n2 = 59;}
- Write24c02(n2,2);
- while(KEY_4 == 0);//等待键松开
- }
- }
- n1=Read24c02(1);
- n2=Read24c02(2);
- lcdWriteCommand(0x8b);
- lcdWriteData((n1/10)+0x30);
- lcdWriteData(n1%10+0x30);
- dispString(2, 4, 1, "点");
- lcdWriteData((n2/10)+0x30);
- lcdWriteData(n2%10+0x30);
- }
- if(KEY_1 == 0 ||workcode==9)
- {
- Beep_key();//按键音
- workcode=0;
- k=0;
- while(KEY_1 == 0);//等待键松开
- lcdInit ();
- break;
- }
- }
- }
- /*****************************************************************************/
- void naozhongdao()
- {
- hh1=hh/16*10+hh%16;
- mm1=mm/16*10+mm%16;
- n1=Read24c02(1);
- n2=Read24c02(2);
- if(n1==hh1 && n2==mm1 && ss==0)
- {
- lcdWriteCommand(0x30); //选择8bit数据流
- lcdWriteCommand(0x0c); //开显示(无游标、不反白)
- lcdWriteCommand(0x01); //清除显示,并且设定地址指针为00H
- dispString(0, 1, 1, "闹钟时间到了! ");
- lcdWriteCommand(0x89);
- lcdWriteData((n1/10)+0x30);
- lcdWriteData(n1%10+0x30);
- dispString(2, 2, 1, "点");
- lcdWriteData((n2/10)+0x30);
- lcdWriteData(n2%10+0x30);
- dispString(2, 4, 1, "分");
- lcdWriteData(0x0e);
- Play(Music_wo,0,3,360);
- lcdInit ();
- }
- }
- /*****************************************************************************/
- void procKey (void)
- {
- uchar key1Times=1 ;
- lcdClear();
- dispString(0, 0, 1, " 功能菜单 ");
- dispString(1, 0, 1, "1:界面 2:设置");
- dispString(2, 0, 1, "3:闹钟 4:音乐");
- dispString(3, 0, 1, "5:自检 6:退出");
- convertChar(1, 0, 6);
- while(KEY_3 == 0);//等待键松开
- while(1)
- {
- if(KEY_4 == 0||KEY_2 == 0||workcode==4||workcode==6)
- {
- if (KEY_4 == 0||workcode==4) //
- {
- DelayM(20); //去抖
- if(KEY_4 == 0 ||workcode==4&& w == 0)
- {
- Beep_key();//按键音
- workcode=0;
- while(KEY_4 == 0);//等待键松开
- key1Times--;
- if (key1Times==0 ){key1Times = 6;}
- }
- }
- if (KEY_2 == 0||workcode==6) //
- {
- DelayM(20); //去抖
- if(KEY_2 == 0 ||workcode==6&& w == 0)
- {
- Beep_key();//按键音
- workcode=0;
- while(KEY_2 == 0);//等待键松开
- key1Times++;
- if (key1Times==7 ){key1Times = 1;}
- }
- }
- lcdClear();
- dispString(0, 0, 1, " 功能菜单 ");
- dispString(1, 0, 1, "1:界面 2:设置");
- dispString(2, 0, 1, "3:闹钟 4:音乐");
- dispString(3, 0, 1, "5:自检 6:退出");
- if (key1Times == 7)
- {
- key1Times = 1;
- }
- switch(key1Times)
- {
- case 1: convertChar(1, 0, 6);
- break;
- case 2: convertChar(1, 5, 6);
- break;
- case 3: convertChar(2, 0, 6);
- break;
- case 4: convertChar(2, 5, 6);
- break;
- case 5: convertChar(3, 0, 6);
- break;
- case 6: convertChar(3, 5, 6);
- break;
- }
- }
- if (KEY_3== 0||workcode==8||workcode==5) //
- {
- DelayM(20);
- if(KEY_3 == 0 ||workcode==8||workcode==5)
- {
- Beep_set();//确定按键音
- workcode=0;
- if (key1Times==1 )
- {if(k==0)
- {k=1;
- Write24c02(k,3);
- }
- else if(k==1)
- {
- k=2;
- Write24c02(k,3);
- }
- else if(k==2)
- {
- k=0;
- Write24c02(k,3);
- }
- lcdInit ();break;}
- if (key1Times==2 ){clear_img();lcdClear();w=1;k=2;Set_time(e);break;}
- if (key1Times==3 ){lcdClear();clear_img();k=3;break;}
- if (key1Times==4 ){clear_img();lcdClear();displayPhoto(powerOnPhoto, OFF);Play(Music_wo,0,3,360);lcdInit ();break;}
- if (key1Times==5 ){zijian(); break;}
- if (key1Times==6 ){lcdInit (); break;}
-
- }
- }
- }
- }
- /*****************************************************************************/
- //---主程序---//
- /*****************************************************************************/
- main()
- {
- 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_set();//确定按键音
- InitialSound();
- beep=1;
- Init_1302();
- lcdWriteCommand(0x30); //选择8bit数据流
- lcdWriteCommand(0x0c); //开显示(无游标、不反白)
- lcdWriteCommand(0x01); //清除显示,并且设定地址指针为00H
- lcdClear();
- displayPhoto(powerOnPhoto1, OFF); //此处为《小东电子》图片代码,可以更改为你喜欢的图片代码
- DelayM(2000); //显示等留4秒
- lcdClear();
- dispString(0, 0, 1, "┏━红外遥控━┓");
- dispString(1, 0, 1, "┃12864 LCD V8┃");
- dispString(2, 0, 1, "┃多功能万年历┃");
- dispString(3, 0, 1, "┗━━━━━━┛");
- DelayM(2000); //显示等留2秒
- lcdInit ();
- c_sun=0;
- n=Read24c02(0);
- k=Read24c02(3);
- if(k>2||k<0) k=0;
- EX0= 1; //使能 INT0 外部中断
- IT0 =1; //外中断0下降沿触发
- IR_GET=1; //I/O口初始化
- EA=1; //开总中断
-
- /*****************************************************************************/
- while(1)
- {//主循环
- if(k==2){updata ();}
- if(k==0){disp_sfm();}
- if(k==1){disp_sfm1();}
- if(k==3){naozhong();}
- if(n==1||n==2||n==3){naozhongdao();}
- //------------------------------------------------------------------
- if (KEY_3 == 0||workcode==5) // 设置时间
- {
- DelayM(10); //去抖
- if((KEY_3 == 0&& w == 1)||(workcode==5&& w == 1)) //当是调时状态 本键用于调整下一项
- {
- Beep_key();//按键音
- workcode=0;
- e++;
- if (e >= 7 ){e = 0;}
- Set_time(e);//调整
- }
- if((KEY_3 == 0&& w == 0)||(workcode==5&& w == 0)) //当是调时状态 本键用于调整下一项
- {
- workcode=0;
- lcdWriteCommand(0x30); //选择8bit数据流
- lcdWriteCommand(0x0c); //开显示(无游标、不反白)
- lcdWriteCommand(0x01); //清除显示,并且设定地址指针为00H
- Beep_key();//按键音
- procKey ();
- }
- while(KEY_3 == 0);//等待键松开
- }
- //------------------------------------------------------------------
- if ((KEY_1 == 0&& w == 1) ||(workcode==9&& w == 1))// 当在调时状态时就退出调时
- {
- DelayM(20);
- if((KEY_1 == 0&& w == 1) ||(workcode==9&& w == 1))
- {
- Beep_set();//确定按键音
- workcode=0;
- w = 0; //退出调时
- e = 0; //“下一项”计数器清0
- convertChar(0, 0, 0);
- lcdInit ();
- }
- }
- if ((KEY_1 == 0&& w == 0) ||(workcode==2&& w == 0))// 当在调时状态时就退出调时
- {
- DelayM(20);
- if((KEY_1 == 0&& w == 0) ||(workcode==2&& w == 0))
- {
- workcode=0;
- lcdWriteCommand(0x30); //选择8bit数据流
- lcdWriteCommand(0x0c); //开显示(无游标、不反白)
- lcdWriteCommand(0x01); //清除显示,并且设定地址指针为00H
- displayPhoto(powerOnPhoto, OFF);
- Play(Music_wo,0,3,360);
- lcdInit ();
- }
- while(KEY_1 == 0);//等待键松开
- }
- //------------------------------------------------------------------
- if ((KEY_2 == 0&& w == 1)||(workcode==3 && w == 1)) // 加减调整
- {
- DelayM(5);
- if((KEY_2 == 0&& w == 1)||(workcode==3 && w == 1))
- {
- Set_time(e);//调整
- workcode=0;
- Beep_key();//按键音
- }
- while(KEY_2 == 0);//等待键松开
- }
- //------------------------------------------------------------------
- if ((KEY_4 == 0&& w == 1)||(workcode==7&& w == 1))// 加减调整
- {
- DelayM(5);
- if((KEY_4 == 0&& w == 1)||(workcode==7&& w == 1))
- {
- Set_time(e);//调整
- workcode=0;
- Beep_key();//按键音
- }
- while(KEY_4 == 0);//等待键松开
- }
- //------------------------------------------------------------------
- if (workcode==1)// 加减调整
- {
- DelayM(5);
- if(workcode==1)
- {
- Beep_key();//按键音
- lcdWriteCommand(0x30); //选择8bit数据流
- lcdWriteCommand(0x0c); //开显示(无游标、不反白)
- lcdWriteCommand(0x01); //清除显示,并且设定地址指针为00H
- dispString(0, 0, 1, "┏━红外遥控━┓");
- dispString(1, 0, 1, "┃12864 LCD V7┃");
- dispString(2, 0, 1, "┃多功能万年历┃");
- dispString(3, 0, 1, "┗ 待机界面 ┛");
- workcode=10;
- }
- while(workcode==10);//等待键松开
- workcode=10;
- Beep_set();
- lcdInit ();
- }
- }
- }
- /*****************************************************************************/
- //外部中断0服务函数
- /*****************************************************************************/
- void intt_0() interrupt 0 //下降沿触发:接收不到红外时OUT高电平,接收到红外时OUT低电平。
- {
- uchar four,one,num=0;
- EX0 = 0; //关中断0使能,防止处理过程中再接收红外信号
- DelayM(2); //稍延时2ms,防干扰
- if (IR_GET) //再检测红外接收脚(9ms的前导低电平),为高电平说明是干扰
- {
- EX0 =1; //使能中断0
- return; //退出中断程序
- }
- while(!IR_GET); //等IR变为高电平,跳过9ms的前导低电平信号。
- while (IR_GET); //等 IR 变为低电平,跳过4.5ms的前导高电平信号。
- for (four=0;four<4;four++) //四组数据
- {
- for (one=0;one<8;one++) //每组数据8位
- {
- while (!IR_GET); //等 IR 变为高电平
- while (IR_GET) //计算IR高电平时长(低电平时长是一样的,不用计)
- {
- delay100us(1); //计时
- num++; //计时N次
- if (num>=20) //17*0.1ms=1.7ms
- { //数据“1”的时长最长也就1.685ms,计数超过则数据错误,退出中断
- EX0=1; //使能中断0
- return; //退出中断
- }
- } //高电平计数完毕
- RXDDATA[four]>>=1; //从低位读出,随着one的循环8次刚好读出一字节
- // if(num<6) //6*0.1ms=0.6ms, 0.565ms<0.6ms<1.685ms
- // RXDDATA[j]|=0x00; //数据“0”
- if(num>6&&num<20) // 17*0.1ms=1.7ms>1.685ms
- RXDDATA[four]|=0x80; //数据“1”
- num=0; //计时值清0,为下一位数据的计时做准备
- }//一组数据接收结束
- }//全部四组数据接收结束
- if(RXDDATA[0]!=0x00) //比较用户码(请根据自己的遥控板修改)
- {
- EX0=1; //使能中断0
- return; //退出中断
- }
- if(RXDDATA[1]!=0xff) //比较用户码(请根据自己的遥控板修改)
- {
- EX0=1; //使能中断0
- return; //退出中断
- }
- if (RXDDATA[2]!=~RXDDATA[3]) //检测接收到的数据是否正确
- { //不正确则
- EX0=1; //使能中断0
- return; //退出中断
- }
- workcode=workIRcode(RXDDATA); //处理红外编码,返回键值
- EX0 = 1; //处理完红外接收,使能中断0,退出中断0
- …………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
-
复制代码
所有资料51hei提供下载:
程序 PCB.rar
(12 MB, 下载次数: 290)
取模软件及元件资料.rar
(4.68 MB, 下载次数: 209)
相关算法及说明书,报表.rar
(29.77 KB, 下载次数: 214)
|