找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1565|回复: 1
收起左侧

LCD12864红外遥控万年历V8单片机源代码 未改

[复制链接]
ID:440009 发表于 2018-12-5 14:07 | 显示全部楼层 |阅读模式
公历转换农历
公历与农历是我国目前并存的两种历法,各有其固有的规律,农历与月球的运行相对应,其影响因素多,它的大小月和闰月与天体运行有关,计算十分复杂,且每年都不一致,因此要用单片机实现公历与农历的转换用查表法是最方便实用的办法。
计算公历日对应的农历日期的方法是先计算出公历日离当年元旦的天数,然后查表取得当年的春节日期,计算出春节离元旦的天数,二者相减即可算出公历日离春节的天数,以后只要根据大小月和闰月信息减一月天数,调整一月农历月份,即可推算出公历日所对应的农历日期,如公历日不到春节日期,农历年要比公历年小一年,农历大小月取前一年的信息,农历月从12 月向前推算。
本文介绍的公历转换农历C语言程序实现从1901 年到2099 年199 年的公历日到农历转换,如果到2099年后则要添加农历表,但我相信199年对我们现代人已经足够了。在功能函数入口输入BCD公历数据函数出口直接输出BCD农历数据。农历显示按照人为习惯都是用大写显示,比如:“1号”应该显示为’初一“;“21”应该显示为“廿一”;“12月”应该显示为“腊月”等。
二十四节气和生肖
二十四节气是我国劳动人民创造的辉煌文化,它能反映季节的变化,指导农事活动,影响着千家万户的衣食住行。有人认为二十四节气从属农历,其实,它是根据阳历划定的。即根据太阳在黄道上的位置,把一年划分为24个彼此相等的段落。也就是把黄道分成24个等份,每等份各占黄经15°。由于太阳通过每等份所需的时间几乎相等,二十四节气的公历日期每年大致相同:上半年在6日、21日前后,下半年在8日、23日前后。
二十四节气没有固定规律,也需要存表。如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,每月用一个字节存放,高位存放第一个节气数据,低位存放第二个节气的数据,根据以上规律便可编写出节气表,最后通过表计算出每月节气。
   生肖计算相对就简单多了。12生肖按以下排列:
0鼠    1牛  2虎 3兔  4龙  5蛇  6马  7羊 8猴  9鸡   10狗  11猪
    用当前年数减去1900,然后除以12取余,余数就代表属相数。
  1. 例如:1951年
        (1982-1900)/12=余10
          即1982年生的人的属相为狗年
  2.2009年
         (2009-1900/12=余7
         即2009年生的人属相为牛年
万年历使用说明

V6.1以上版本12864万年历PCB增加了24CXX接口和TL1838红外接口,其他接口电路跟老版本一样,程序可以通用,这样此万年历便成了一个简单实用的单片机开发实验板。

一、电源电压4.8V—12V,可以直接用电脑USB供电。(如高于5V供电,请将 J3 短路帽拔掉
二、程序修改说明
1、如果你编译通不过,就是你用的KEIL库文件不全,请换个完整版本的KEIL,或到我店铺购买,本程序是完全编译通过,且没有1个警告;
2、本程序由于农历,节气等数据很占空间,编译后有22K,请使用程序存储器25K以上的51单片机,比如STC89C58STC89C516等;
3、如果你的汉字显示不全或乱码,比如“三“显示不了,那是你的KEIL没有打补丁,并不是程序问题,至于什么补丁你可以网上搜或向我索要;
4、在修改位定义的时候需要将Soundplay.h文件下的sbit    BeepIO  = P3^7;  sbit KEY_1 = P2^7;一起修改;
5、蜂鸣器请最好使用无源蜂鸣器或小喇叭,这样音质会很好。



电路图_00.jpg

单片机源程序如下:
  1. /*****************************************************************************************************************/
  2. //12864液晶万年历 时钟2010年最新 V8版本

  3. //增加了24C02接口,具有开机界面记忆功能、闹钟时间可以掉电保存功能
  4. //V8.0版本主要特点为三种风格界面显示,功能更强大
  5. /****************************************************************************************************************/
  6. //头文件
  7. #include <AT89X52.h>
  8. #include <string.h>
  9. #include <intrins.h> //包含_nop_()延时函数
  10. #ifndef uchar
  11. #define uchar unsigned char
  12. #endif

  13. #ifndef uint
  14. #define uint  unsigned int
  15. #endif

  16. #include "SoundPlay.h"
  17. #include "ds1302.h"
  18. #include "ds18b20.h"
  19. #include "24c02.h"
  20. #include "lcd12864.h"
  21. #include "tl1838.h"

  22. /*****************************************************************************/
  23. //键盘引脚定义
  24. //sbit KEY_1 = P2^7;  //左上,在音乐文件SoundPlay.h中已定义
  25. sbit KEY_2 = P2^6;         //左下
  26. sbit KEY_3 = P2^5;         //右上
  27. sbit KEY_4 = P2^4;         //右下
  28. /****************************************************************************/
  29. //定义全局变量
  30. unsigned char yy,mo,dd,xq,hh,year,year1;//定义时间映射全局变量(专用寄存器)
  31. unsigned char shi,ge,sec_temp,min_temp,hour_temp,secl,selx,e=0,hh1,mm1,mm,ss,n,t;
  32. char xdata n1,n2;
  33. bit w = 0; //调时标志位
  34. uchar c_sun,year_sun,month_sun,day_sun; //农历
  35. /******************************************************************************/
  36. /*--  一幅图像 KISS- 正向取模,字节正序*/     
  37. /*--  宽度x高度=128x64  --*/
  38. /******************************************************************************/
  39. uchar code powerOnPhoto []={
  40.   
  41. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  42. …………
  43. …………
  44. …………限于本文篇幅 余下代码请从51黑下载附件…………
  45. 0x2d,0x92,0xB5, //2099
  46. };
  47. ///月份数据表
  48. code uchar day_code1[9]={0x0,0x1f,0x3b,0x5a,0x78,0x97,0xb5,0xd4,0xf3};
  49. code uint day_code2[3]={0x111,0x130,0x14e};
  50. /*
  51. 函数功能:输入BCD阳历数据,输出BCD阴历数据(只允许1901-2099年)
  52. 调用函数示例:Conversion(c_sun,year_sun,month_sun,day_sun)
  53. 如:计算2004年10月16日Conversion(0,0x4,0x10,0x16);
  54. c_sun,year_sun,month_sun,day_sun均为BCD数据,c_sun为世纪标志位,c_sun=0为21世
  55. 纪,c_sun=1为19世纪
  56. 调用函数后,原有数据不变,读c_moon,year_moon,month_moon,day_moon得出阴历BCD数据
  57. */
  58. bit c_moon;
  59. data uchar year_moon,month_moon,day_moon,week;
  60. /*子函数,用于读取数据表中农历月的大月或小月,如果该月为大返回1,为小返回0*/
  61. bit get_moon_day(uchar month_p,uint table_addr)
  62. {
  63. uchar temp;
  64. switch (month_p)
  65. {
  66. case 1:{temp=year_code[table_addr]&0x08;
  67. if (temp==0)return(0);else return(1);}
  68. case 2:{temp=year_code[table_addr]&0x04;
  69. if (temp==0)return(0);else return(1);}
  70. case 3:{temp=year_code[table_addr]&0x02;
  71. if (temp==0)return(0);else return(1);}
  72. case 4:{temp=year_code[table_addr]&0x01;
  73. if (temp==0)return(0);else return(1);}
  74. case 5:{temp=year_code[table_addr+1]&0x80;
  75. if (temp==0) return(0);else return(1);}
  76. case 6:{temp=year_code[table_addr+1]&0x40;
  77. if (temp==0)return(0);else return(1);}
  78. case 7:{temp=year_code[table_addr+1]&0x20;
  79. if (temp==0)return(0);else return(1);}
  80. case 8:{temp=year_code[table_addr+1]&0x10;
  81. if (temp==0)return(0);else return(1);}
  82. case 9:{temp=year_code[table_addr+1]&0x08;
  83. if (temp==0)return(0);else return(1);}
  84. case 10:{temp=year_code[table_addr+1]&0x04;
  85. if (temp==0)return(0);else return(1);}
  86. case 11:{temp=year_code[table_addr+1]&0x02;
  87. if (temp==0)return(0);else return(1);}
  88. case 12:{temp=year_code[table_addr+1]&0x01;
  89. if (temp==0)return(0);else return(1);}
  90. case 13:{temp=year_code[table_addr+2]&0x80;
  91. if (temp==0)return(0);else return(1);}
  92. }
  93. }
  94. /*
  95. 函数功能:输入BCD阳历数据,输出BCD阴历数据(只允许1901-2099年)
  96. 调用函数示例:Conversion(c_sun,year_sun,month_sun,day_sun)
  97. 如:计算2004年10月16日Conversion(0,0x4,0x10,0x16);
  98. c_sun,year_sun,month_sun,day_sun均为BCD数据,c_sun为世纪标志位,c_sun=0为21世
  99. 纪,c_sun=1为19世纪
  100. 调用函数后,原有数据不变,读c_moon,year_moon,month_moon,day_moon得出阴历BCD数据
  101. */
  102. void Conversion(bit c,uchar year,uchar month,uchar day)
  103. { //c=0 为21世纪,c=1 为19世纪 输入输出数据均为BCD数据
  104. uchar temp1,temp2,temp3,month_p;
  105. uint temp4,table_addr;
  106. bit flag2,flag_y;
  107. temp1=year/16; //BCD->hex 先把数据转换为十六进制
  108. temp2=year%16;
  109. year=temp1*10+temp2;
  110. temp1=month/16;
  111. temp2=month%16;
  112. month=temp1*10+temp2;
  113. temp1=day/16;
  114. temp2=day%16;
  115. day=temp1*10+temp2;
  116. //定位数据表地址
  117. if(c==0)
  118. {
  119. table_addr=(year)*0x3;
  120. }
  121. //else
  122. //{
  123. //table_addr=(year-1)*0x3;
  124. //}
  125. //定位数据表地址完成
  126. //取当年春节所在的公历月份
  127. temp1=year_code[table_addr+2]&0x60;
  128. temp1=_cror_(temp1,5);
  129. //取当年春节所在的公历月份完成
  130. //取当年春节所在的公历日
  131. temp2=year_code[table_addr+2]&0x1f;
  132. //取当年春节所在的公历日完成
  133. // 计算当年春年离当年元旦的天数,春节只会在公历1月或2月
  134. if(temp1==0x1)
  135. {
  136. temp3=temp2-1;
  137. }
  138. else
  139. {
  140. temp3=temp2+0x1f-1;
  141. }
  142. // 计算当年春年离当年元旦的天数完成
  143. //计算公历日离当年元旦的天数,为了减少运算,用了两个表
  144. //day_code1[9],day_code2[3]
  145. //如果公历月在九月或前,天数会少于0xff,用表day_code1[9],
  146. //在九月后,天数大于0xff,用表day_code2[3]
  147. //如输入公历日为8月10日,则公历日离元旦天数为day_code1[8-1]+10-1
  148. //如输入公历日为11月10日,则公历日离元旦天数为day_code2[11-10]+10-1
  149. if (month<10)
  150. {
  151. temp4=day_code1[month-1]+day-1;
  152. }
  153. else
  154. {
  155. temp4=day_code2[month-10]+day-1;
  156. }
  157. if ((month>0x2)&&(year%0x4==0))
  158. { //如果公历月大于2月并且该年的2月为闰月,天数加1
  159. temp4+=1;
  160. }
  161. //计算公历日离当年元旦的天数完成
  162. //判断公历日在春节前还是春节后
  163. if (temp4>=temp3)
  164. { //公历日在春节后或就是春节当日使用下面代码进行运算
  165. temp4-=temp3;
  166. month=0x1;
  167. month_p=0x1; //month_p为月份指向,公历日在春节前或就是春节当日month_p指向首月
  168. flag2=get_moon_day(month_p,table_addr);
  169. //检查该农历月为大小还是小月,大月返回1,小月返回0
  170. flag_y=0;
  171. if(flag2==0)temp1=0x1d; //小月29天
  172. else temp1=0x1e; //大小30天
  173. temp2=year_code[table_addr]&0xf0;
  174. temp2=_cror_(temp2,4); //从数据表中取该年的闰月月份,如为0则该年无闰月
  175. while(temp4>=temp1)
  176. {
  177. temp4-=temp1;
  178. month_p+=1;
  179. if(month==temp2)
  180. {
  181. flag_y=~flag_y;
  182. if(flag_y==0)
  183. month+=1;
  184. }
  185. else month+=1;
  186. flag2=get_moon_day(month_p,table_addr);
  187. if(flag2==0)temp1=0x1d;
  188. else temp1=0x1e;
  189. }
  190. day=temp4+1;
  191. }
  192. else
  193. { //公历日在春节前使用下面代码进行运算
  194. temp3-=temp4;
  195. if (year==0x0)
  196. {
  197. year=0x63;c=1;
  198. }
  199. else year-=1;
  200. table_addr-=0x3;
  201. month=0xc;
  202. temp2=year_code[table_addr]&0xf0;
  203. temp2=_cror_(temp2,4);
  204. if (temp2==0)
  205. month_p=0xc;
  206. else
  207. month_p=0xd; //
  208. /*month_p为月份指向,如果当年有闰月,一年有十三个月,月指向13,无闰月指向12*/
  209. flag_y=0;
  210. flag2=get_moon_day(month_p,table_addr);
  211. if(flag2==0)temp1=0x1d;
  212. else temp1=0x1e;
  213. while(temp3>temp1)
  214. {
  215. temp3-=temp1;
  216. month_p-=1;
  217. if(flag_y==0)month-=1;
  218. if(month==temp2)flag_y=~flag_y;
  219. flag2=get_moon_day(month_p,table_addr);
  220. if(flag2==0)temp1=0x1d;
  221. else temp1=0x1e;
  222. }
  223. day=temp1-temp3+1;
  224. }
  225. c_moon=c; //HEX->BCD ,运算结束后,把数据转换为BCD数据
  226. temp1=year/10;
  227. temp1=_crol_(temp1,4);
  228. temp2=year%10;
  229. year_moon=temp1|temp2;
  230. temp1=month/10;
  231. temp1=_crol_(temp1,4);
  232. temp2=month%10;
  233. month_moon=temp1|temp2;
  234. temp1=day/10;
  235. temp1=_crol_(temp1,4);
  236. temp2=day%10;
  237. day_moon=temp1|temp2;
  238. }
  239. /*函数功能:输入BCD阳历数据,输出BCD星期数据(只允许1901-2099年)
  240. 调用函数示例:Conver_week(c_sun,year_sun,month_sun,day_sun)
  241. 如:计算2004年10月16日Conversion(0,0x4,0x10,0x16);
  242. c_sun,year_sun,month_sun,day_sun均为BCD数据,c_sun为世纪标志位,c_sun=0为21世
  243. 纪,c_sun=1为19世纪
  244. 调用函数后,原有数据不变,读week得出阴历BCD数据
  245. */
  246. code uchar table_week[12]={0,3,3,6,1,4,6,2,5,0,3,5}; //月修正数据表
  247. /*
  248. 算法:日期+年份+所过闰年数+月较正数之和除7 的余数就是星期但如果是在
  249. 闰年又不到3 月份上述之和要减一天再除7
  250. 星期数为0
  251. */
  252. /*void Conver_week(bit c,uchar year,uchar month,uchar day)
  253. {//c=0 为21世纪,c=1 为19世纪 输入输出数据均为BCD数据
  254. uchar temp1,temp2;
  255. temp1=year/16; //BCD->hex 先把数据转换为十六进制
  256. temp2=year%16;
  257. year=temp1*10+temp2;
  258. temp1=month/16;
  259. temp2=month%16;
  260. month=temp1*10+temp2;
  261. temp1=day/16;
  262. temp2=day%16;
  263. day=temp1*10+temp2;
  264. if (c==0){year+=0x64;} //如果为21世纪,年份数加100
  265. temp1=year/0x4; //所过闰年数只算1900年之后的
  266. temp2=year+temp1;
  267. temp2=temp2%0x7; //为节省资源,先进行一次取余,避免数大于0xff,避免使用整型数据
  268. temp2=temp2+day+table_week[month-1];
  269. if (year%0x4==0&&month<3)temp2-=1;
  270. week=temp2%0x7;
  271. }*/
  272. //test
  273. /****************************************************************************************************************************
  274. 函数功能: 二十四节气数据库
  275. 入口参数: unsigned char(yy,mo,dd) 对应 年月日
  276. 出口参数: unsigned char(0-24) 1-24对应二十四节气
  277. 作者    : TOTOP
  278. 二十四节气数据库(1901--2050)
  279. 数据格式说明:   
  280. 如1901年的节气为   
  281.      1月    2月     3月     4月       5月      6月    7月     8月      9月    10月   11月    12月   
  282. [ 6,21][ 4,19][ 6,21][ 5,21][ 6,22][ 6,22][ 8,23][ 8,24][ 8,24][ 8,24][ 8,23][ 8,22]   
  283. [ 9, 6][11, 4][ 9, 6][10, 6][ 9, 7][ 9, 7][ 7, 8][ 7, 9][ 7, 9][ 7, 9][ 7, 8][ 7,15]   
  284. 上面第一行数据为每月节气对应公历日期,15减去每月第一个节气,每月第二个节气减去15得第二
  285. 行,这样每月两个节气对应数据都小于16,每月用一个字节存放,高位存放第一个节气数据,低位存
  286. 放第二个节气的数据,可得下表   
  287. ****************************************************************************************************************************/
  288. uchar code jieqi_code[]=
  289. {
  290.        0x96,0xB4,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x88,0x78,0x87,0x86,     //2000   
  291. …………
  292. …………
  293. …………限于本文篇幅 余下代码请从51黑下载附件…………
  294.        0xA5,0xC3,0xA5,0xB5,0xA6,0xA6,0x87,0x88,0x78,0x78,0x87,0x87,     //2050
  295.     };
  296. uchar jieqi (uchar y2,m2,d2)
  297. {
  298. uchar temp,d,y,y1,m;
  299. uint addr;
  300. d=d2/16*10+d2%16;
  301. m=m2/16*10+m2%16;
  302. y1=y2/16*10+y2%16+2000;
  303. y=y1-2000;
  304. addr=y*12+m-1;
  305. if(d<15)
  306. {
  307. temp=15-d;
  308. if((jieqi_code[addr]>>4)==temp) return (m*2-1);
  309. else return (0);
  310. }
  311. if(d==15) return (0);
  312. if(d>15)
  313. {
  314. temp=d-15;
  315. if((jieqi_code[addr]&0x0f)==temp) return (m*2);
  316. else return (0);
  317. }
  318. }

  319. /******************************************************************************/
  320. //公历节日数据库表
  321. /******************************************************************************/
  322. void days ()  //公历节日数据库
  323.        {         
  324.         uchar j;
  325.         j=jieqi(yy,mo,dd);
  326.                 if(t/2%2==0)//设置变化的时间,默认是2秒
  327.                 {           //以下自己添加生日、节日信息
  328.                 if ( month_moon== 0x06 && day_moon== 0x02 ){dispString(3, 0, 1, "后天是    的生日");}
  329.    else if ( month_moon== 0x06 && day_moon== 0x03 ){dispString(3, 0, 1, "明天是    的生日");}


  330.                 //农历节日
  331.    else     if ( month_moon== 0x12 && day_moon== 0x29 ){dispString(3, 0, 1, "    明天大年    ");}
  332.    else            if ( month_moon== 0x12 && day_moon== 0x30 ){dispString(3, 0, 1, "    大年三十    ");}
  333.    else            if ( month_moon== 0x05 && day_moon== 0x05 ){dispString(3, 0, 1, "  今天是端午节  ");}
  334.    else                if ( month_moon== 0x08 && day_moon== 0x15 ){dispString(3, 0, 1, "  今天是中秋节  ");}
  335.    else                if ( month_moon== 0x01 && day_moon== 0x15 ){dispString(3, 0, 1, "  今天是元宵节  ");}
  336.    else                if ( month_moon== 0x02 && day_moon== 0x02 ){dispString(3, 0, 1, "  今天是龙抬头  ");}
  337.    else                if ( month_moon== 0x07 && day_moon== 0x07 ){dispString(3, 0, 1, "  今天是七夕!   ");}
  338.    else                if ( month_moon== 0x07 && day_moon== 0x15 ){dispString(3, 0, 1, "  今天是鬼节!   ");}
  339.    else                if ( month_moon== 0x09 && day_moon== 0x09 ){dispString(3, 0, 1, "  今天是重阳节  ");}
  340.    else                if ( month_moon== 0x12 && day_moon== 0x08 ){dispString(3, 0, 1, "  今天是腊八节  ");}
  341.                 //国立节日                                                               
  342.    else     if ( mo == 0x01 && dd == 0x01 ){dispString(3, 0, 1, "    元旦快乐!   ");}//1月
  343.    else                if ( mo == 0x01 && dd == 0x28 ){dispString(3, 0, 1, "今天是世界麻风日");}
  344.                
  345.    else                if ( mo == 0x02 && dd == 0x02 ){dispString(3, 0, 1, "今天是世界湿地日");}//2月
  346.    else                if ( mo == 0x02 && dd == 0x13 ){dispString(3, 0, 1, "  明天情人节了  ");}               
  347.    else                if ( mo == 0x02 && dd == 0x14 ){dispString(3, 0, 1, "  今天是情人节  ");}
  348.                                 
  349.    else                if ( mo == 0x03 && dd == 0x01 ){dispString(3, 0, 1, "今天是国际海豹日");}//3月               
  350.    else                if ( mo == 0x03 && dd == 0x03 ){dispString(3, 0, 1, "今天是全国爱耳日");}               
  351.    else                if ( mo == 0x03 && dd == 0x08 ){dispString(3, 0, 1, "今天是3.8 妇女节");}               
  352.    else                if ( mo == 0x03 && dd == 0x12 ){dispString(3, 0, 1, "  今天是植树节  ");}               
  353.    else                if ( mo == 0x03 && dd == 0x14 ){dispString(3, 0, 1, "今天是国际警察日");}               
  354.    else                if ( mo == 0x03 && dd == 0x15 ){dispString(3, 0, 1, "今天消费者权益日");}               
  355.    else                if ( mo == 0x03 && dd == 0x17 ){dispString(3, 0, 1, "今天是国际航海日");}               
  356.    else                if ( mo == 0x03 && dd == 0x21 ){dispString(3, 0, 1, "今天是世界森林日");}               
  357.    else                if ( mo == 0x03 && dd == 0x22 ){dispString(3, 0, 1, "今天是世界水日!");}               
  358.    else                if ( mo == 0x03 && dd == 0x23 ){dispString(3, 0, 1, "今天是世界气象日");}               
  359.    else                if ( mo == 0x03 && dd == 0x24 ){dispString(3, 0, 1, "世界防治结核病日");}
  360.                                 
  361.    else                if ( mo == 0x04 && dd == 0x01 ){dispString(3, 0, 1, "愚人节,小心上当");}//4               
  362.    else                if ( mo == 0x04 && dd == 0x07 ){dispString(3, 0, 1, "今天是世界卫生日");}               
  363.    else                if ( mo == 0x04 && dd == 0x08 ){dispString(3, 0, 1, "  今天复活节!   ");}               
  364.    else                if ( mo == 0x04 && dd == 0x13 ){dispString(3, 0, 1, "  黑色星期五!   ");}
  365.                                 
  366.    else                if ( mo == 0x05 && dd == 0x01 ){dispString(3, 0, 1, "  今天是劳动节  ");}//5               
  367.    else                if ( mo == 0x05 && dd == 0x04 ){dispString(3, 0, 1, "今天是五四青年节");}               
  368.    else                if ( mo == 0x05 && dd == 0x08 ){dispString(3, 0, 1, "今天世界红十字日");}               
  369.    else                if ( mo == 0x05 && dd == 0x12 ){dispString(3, 0, 1, "今天是国际护士节");}               
  370.    else                if ( mo == 0x05 && dd == 0x05 ){dispString(3, 0, 1, "近日注意母亲节! ");}               
  371.    else                if ( mo == 0x05 && dd == 0x15 ){dispString(3, 0, 1, "今天是国际家庭日");}
  372.    else                if ( mo == 0x05 && dd == 0x31 ){dispString(3, 0, 1, "今天是世界无烟日");}               
  373.                                 
  374.    else                if ( mo == 0x06 && dd == 0x01 ){dispString(3, 0, 1, "今天是国际儿童节");}//6
  375.    else                if ( mo == 0x06 && dd == 0x05 ){dispString(3, 0, 1, "今天是世界环境日");}               
  376.    else                if ( mo == 0x06 && dd == 0x26 ){dispString(3, 0, 1, "今天是国际禁毒日");}               
  377.    else                if ( mo == 0x06 && dd == 0x06 ){dispString(3, 0, 1, "今天是全国爱眼日");}               
  378.    else                if ( mo == 0x06 && dd == 0x13 ){dispString(3, 0, 1, "近日注意父亲节! ");}
  379.    else                if ( mo == 0x06 && dd == 0x15 ){dispString(3, 0, 1, "近日注意父亲节! ");}
  380.                                 
  381.    else                if ( mo == 0x07 && dd == 0x01 ){dispString(3, 0, 1, "香港回归记念日! ");}//7
  382.    else                if ( mo == 0x07 && dd == 0x07 ){dispString(3, 0, 1, "抗日战争记念日! ");}
  383.    else                if ( mo == 0x07 && dd == 0x11 ){dispString(3, 0, 1, "今天是世界人口日");}

  384.    else                if ( mo == 0x08 && dd == 0x01 ){dispString(3, 0, 1, "今天是八一建军节");}//8
  385.    else                if ( mo == 0x08 && dd == 0x08 ){dispString(3, 0, 1, "今天是中国男子节");}
  386.    else                if ( mo == 0x08 && dd == 0x15 ){dispString(3, 0, 1, "抗战胜利记念日!");}

  387.    else                if ( mo == 0x09 && dd == 0x10 ){dispString(3, 0, 1, "  今天是教师节  ");}//9
  388.    else                if ( mo == 0x09 && dd == 0x18 ){dispString(3, 0, 1, "九·一八事变记念");}
  389.    else                if ( mo == 0x09 && dd == 0x20 ){dispString(3, 0, 1, "今天是国际爱牙日");}
  390.    else                if ( mo == 0x09 && dd == 0x27 ){dispString(3, 0, 1, "今天是世界旅游日");}

  391.    else                if ( mo == 0x10 && dd == 0x01 ){dispString(3, 0, 1, "  今天是国庆节  ");}//10
  392.    else                if ( mo == 0x10 && dd == 0x04 ){dispString(3, 0, 1, "今天是世界动物日");}
  393.    else                if ( mo == 0x10 && dd == 0x24 ){dispString(3, 0, 1, "今天是联合国日! ");}
  394.    else                if ( mo == 0x10 && dd == 0x12 ){dispString(3, 0, 1, "明天国际教师节! ");}
  395.    else                if ( mo == 0x10 && dd == 0x13 ){dispString(3, 0, 1, "今天是国际教师节");}

  396.    else                if ( mo == 0x11 && dd == 0x10 ){dispString(3, 0, 1, "今天是世界青年节");}//11
  397.    else                if ( mo == 0x11 && dd == 0x17 ){dispString(3, 0, 1, "今天是世界学生节");}

  398.    else                if ( mo == 0x12 && dd == 0x01 ){dispString(3, 0, 1, "今天世界艾滋病日");}//12
  399.    else                if ( mo == 0x12 && dd == 0x23 ){dispString(3, 0, 1, "  明晚平安夜!   ");}
  400.    else                if ( mo == 0x12 && dd == 0x24 ){dispString(3, 0, 1, "  今晚平安夜!   ");}
  401.    else                if ( mo == 0x12 && dd == 0x25 ){dispString(3, 0, 1, "    圣诞快乐    ");}
  402.    else                if ( mo == 0x12 && dd == 0x31 ){dispString(3, 0, 1, "    明日元旦    ");}
  403.                   }
  404.                 else{
  405.                         //二十四节气
  406.                if (j==1){dispString(3, 0, 1, "    今天小寒    ");}
  407.    else        if (j==2){dispString(3, 0, 1, "    今天大寒    ");}
  408.    else        if (j==3){dispString(3, 0, 1, "    今天立春    ");}
  409.    else        if (j==4){dispString(3, 0, 1, "    今天雨水    ");}
  410.    else        if (j==5){dispString(3, 0, 1, "    今天惊蛰    ");}
  411.    else        if (j==6){dispString(3, 0, 1, "    今天春分    ");}
  412.    else        if (j==7){dispString(3, 0, 1, "    今天清明    ");}
  413.    else        if (j==8){dispString(3, 0, 1, "    今天谷雨    ");}
  414.    else        if (j==9){dispString(3, 0, 1, "    今天立夏    ");}
  415.    else        if (j==10){dispString(3, 0, 1, "    今天小满    ");}
  416.    else        if (j==11){dispString(3, 0, 1, "    今天芒种    ");}
  417.    else        if (j==12){dispString(3, 0, 1, "    今天夏至    ");}
  418.    else        if (j==13){dispString(3, 0, 1, "    今天小暑    ");}
  419.    else        if (j==14){dispString(3, 0, 1, "    今天大暑    ");}
  420.    else        if (j==15){dispString(3, 0, 1, "    今天立秋    ");}
  421.    else        if (j==16){dispString(3, 0, 1, "    今天处暑    ");}
  422.    else        if (j==17){dispString(3, 0, 1, "    今天白露    ");}
  423.    else        if (j==18){dispString(3, 0, 1, "    今天秋分    ");}
  424.    else        if (j==19){dispString(3, 0, 1, "    今天寒露    ");}
  425.    else        if (j==20){dispString(3, 0, 1, "    今天霜降    ");}
  426.    else        if (j==21){dispString(3, 0, 1, "    今天立冬    ");}
  427.    else        if (j==22){dispString(3, 0, 1, "    今天小雪    ");}
  428.    else        if (j==23){dispString(3, 0, 1, "    今天大雪    ");}
  429.    else        if (j==24){dispString(3, 0, 1, "    今天冬至    ");}

  430.    //非节日时显示时晨信息
  431.    else {   if ( hh >= 0x04 && hh <  0x06 ){dispString(3, 0, 1, "  凌晨  点  分  ");
  432.                         lcdWriteCommand(0x9b);
  433.                         if(hh1/10 != 0){lcdWriteData((hh1/10)+0x30);}        //十位消隐
  434.                         else{lcdWriteData(0x20);}//同上        
  435.                     lcdWriteData(hh1%10+0x30);
  436.                     lcdWriteCommand(0x9d);          //":"
  437.                     if(mm/16 != 0){lcdWriteData((mm/16)+0x30);}        //十位消隐
  438.                         else{lcdWriteData(0x20);}//同上        
  439.                 lcdWriteData(mm%16+0x30); }
  440.                         if ( hh >= 0x06 && hh <  0x08 ){dispString(3, 0, 1, "  早晨  点  分  ");
  441.                         lcdWriteCommand(0x9b);
  442.                         if(hh1/10 != 0){lcdWriteData((hh1/10)+0x30);}        //十位消隐
  443.                         else{lcdWriteData(0x20);}//同上        
  444.                     lcdWriteData(hh1%10+0x30);
  445.                     lcdWriteCommand(0x9d);          //":"
  446.                     if(mm/16 != 0){lcdWriteData((mm/16)+0x30);}        //十位消隐
  447.                         else{lcdWriteData(0x20);}//同上        
  448.                 lcdWriteData(mm%16+0x30); }
  449.                         if ( hh >= 0x08 && hh <  0x12 ){dispString(3, 0, 1, "  上午  点  分  ");
  450.                         lcdWriteCommand(0x9b);
  451.                         if(hh1/10 != 0){lcdWriteData((hh1/10)+0x30);}        //十位消隐
  452.                         else{lcdWriteData(0x20);}//同上        
  453.                     lcdWriteData(hh1%10+0x30);
  454.                     lcdWriteCommand(0x9d);          //":"
  455.                     if(mm/16 != 0){lcdWriteData((mm/16)+0x30);}        //十位消隐
  456.                         else{lcdWriteData(0x20);}//同上        
  457.                 lcdWriteData(mm%16+0x30); }
  458.                         if ( hh == 0x12)               {dispString(3, 0, 1, "  中午  点  分  ");
  459.                         lcdWriteCommand(0x9b);
  460.                         if(hh1/10 != 0){lcdWriteData((hh1/10)+0x30);}        //十位消隐
  461.                         else{lcdWriteData(0x20);}//同上        
  462.                     lcdWriteData(hh1%10+0x30);
  463.                     lcdWriteCommand(0x9d);          //":"
  464.                     if(mm/16 != 0){lcdWriteData((mm/16)+0x30);}        //十位消隐
  465.                         else{lcdWriteData(0x20);}//同上        
  466.                 lcdWriteData(mm%16+0x30); }
  467.                         if ( hh >= 0x13 && hh <  0x18 ){dispString(3, 0, 1, "  下午  点  分  ");
  468.                         lcdWriteCommand(0x9b);
  469.                         if(hh1/10 != 0){lcdWriteData((hh1/10)+0x30);}        //十位消隐
  470.                         else{lcdWriteData(0x20);}//同上        
  471.                     lcdWriteData(hh1%10+0x30);
  472.                     lcdWriteCommand(0x9d);          //":"
  473.                     if(mm/16 != 0){lcdWriteData((mm/16)+0x30);}        //十位消隐
  474.                         else{lcdWriteData(0x20);}//同上        
  475.                 lcdWriteData(mm%16+0x30); }
  476.                         if ( hh >= 0x18 && hh <  0x22 ){dispString(3, 0, 1, "  晚上  点  分  ");
  477.                         lcdWriteCommand(0x9b);
  478.                         if(hh1/10 != 0){lcdWriteData((hh1/10)+0x30);}        //十位消隐
  479.                         else{lcdWriteData(0x20);}//同上        
  480.                     lcdWriteData(hh1%10+0x30);
  481.                     lcdWriteCommand(0x9d);          //":"
  482.                     if(mm/16 != 0){lcdWriteData((mm/16)+0x30);}        //十位消隐
  483.                         else{lcdWriteData(0x20);}//同上        
  484.                 lcdWriteData(mm%16+0x30); }
  485.                         if ( hh >= 0x22 && hh <= 0x23 ){dispString(3, 0, 1, "  夜里  点  分  ");
  486.                         lcdWriteCommand(0x9b);
  487.                         if(hh1/10 != 0){lcdWriteData((hh1/10)+0x30);}        //十位消隐
  488.                         else{lcdWriteData(0x20);}//同上        
  489.                     lcdWriteData(hh1%10+0x30);
  490.                     lcdWriteCommand(0x9d);          //":"
  491.                     if(mm/16 != 0){lcdWriteData((mm/16)+0x30);}        //十位消隐
  492.                         else{lcdWriteData(0x20);}//同上        
  493.                 lcdWriteData(mm%16+0x30); }
  494.                         if ( hh >= 0x00 && hh <  0x04 ){dispString(3, 0, 1, "  深夜  点  分  ");
  495.                         lcdWriteCommand(0x9b);
  496.                         if(hh1/10 != 0){lcdWriteData((hh1/10)+0x30);}        //十位消隐
  497.                         else{lcdWriteData(0x20);}//同上        
  498.                     lcdWriteData(hh1%10+0x30);
  499.                     lcdWriteCommand(0x9d);          //":"
  500.                     if(mm/16 != 0){lcdWriteData((mm/16)+0x30);}        //十位消隐
  501.                         else{lcdWriteData(0x20);}//同上        
  502.                 lcdWriteData(mm%16+0x30); }
  503.                         }

  504.                 }
  505. }
  506. /*****************************************************************************/        
  507. //农历显示
  508. /******************************************************************************/
  509. void lcmnongli()
  510. {
  511. uchar yue,ri;
  512. year_sun=yy;
  513. month_sun=mo;
  514. day_sun=dd;
  515. Conversion(c_sun,year_sun,month_sun,day_sun);
  516. yue=(month_moon/16)*10+month_moon%16;
  517. year1=yue;

  518. if(k==2)
  519. {
  520. ri=(day_moon/16)*10+day_moon%16;  //显示农历月
  521.   if(yue==1){dispString(1, 0, 1, "正"); }
  522.   if(yue==2){dispString(1, 0, 1, "二"); }
  523.   if(yue==3){dispString(1, 0, 1, "三"); }
  524.   if(yue==4){dispString(1, 0, 1, "四"); }
  525.   if(yue==5){dispString(1, 0, 1, "五"); }
  526.   if(yue==6){dispString(1, 0, 1, "六"); }
  527.   if(yue==7){dispString(1, 0, 1, "七"); }
  528.   if(yue==8){dispString(1, 0, 1, "八"); }
  529.   if(yue==9){dispString(1, 0, 1, "九"); }
  530.   if(yue==10){dispString(1, 0, 1, "十"); }
  531.   if(yue==11){dispString(1, 0, 1, "冬"); }
  532.   if(yue==12){dispString(1, 0, 1, "腊"); }
  533.   dispString(1, 1, 1, "月");
  534.   if(ri<=10)
  535.    {
  536.     if(ri==1){  dispString(1, 2, 1, "初一"); }
  537.     if(ri==2){  dispString(1, 2, 1, "初二"); }
  538.     if(ri==3){  dispString(1, 2, 1, "初三"); }
  539.     if(ri==4){  dispString(1, 2, 1, "初四");}
  540.     if(ri==5){  dispString(1, 2, 1, "初五"); }
  541.     if(ri==6){  dispString(1, 2, 1, "初六"); }
  542.     if(ri==7){  dispString(1, 2, 1, "初七"); }
  543.     if(ri==8){  dispString(1, 2, 1, "初八"); }
  544.     if(ri==9){  dispString(1, 2, 1, "初九");  }
  545.     if(ri==10){  dispString(1, 2, 1, "初十"); }
  546.    }
  547.   else
  548.    {
  549.     if(ri==11){  dispString(1, 2, 1, "十一");}
  550.     if(ri==12){  dispString(1, 2, 1, "十二");}
  551.     if(ri==13){  dispString(1, 2, 1, "十三"); }
  552.     if(ri==14){  dispString(1, 2, 1, "十四"); }
  553.     if(ri==15){  dispString(1, 2, 1, "十五"); }
  554.     if(ri==16){  dispString(1, 2, 1, "十六"); }
  555.     if(ri==17){  dispString(1, 2, 1, "十七"); }
  556.     if(ri==18){  dispString(1, 2, 1, "十八"); }
  557.     if(ri==19){  dispString(1, 2, 1, "十九"); }
  558.     if(ri==20){  dispString(1, 2, 1, "二十");}
  559.     if(ri==21){  dispString(1, 2, 1, "廿一");  }
  560.     if(ri==22){  dispString(1, 2, 1, "廿二");}
  561.     if(ri==23){  dispString(1, 2, 1, "廿三"); }
  562.     if(ri==24){  dispString(1, 2, 1, "廿四"); }
  563.     if(ri==25){  dispString(1, 2, 1, "廿五"); }
  564.     if(ri==26){  dispString(1, 2, 1, "廿六");}
  565.     if(ri==27){  dispString(1, 2, 1, "廿七"); }
  566.     if(ri==28){  dispString(1, 2, 1, "廿八"); }
  567.     if(ri==29){  dispString(1, 2, 1, "廿九");}
  568.     if(ri==30){  dispString(1, 2, 1, "三十"); }
  569.    }

  570.    }
  571.    else
  572.    {
  573.         ri=(day_moon/16)*10+day_moon%16;  //显示农历月
  574.   if(yue==1){dispString(2, 1, 1, "正"); }
  575.   if(yue==2){dispString(2, 1, 1, "二"); }
  576.   if(yue==3){dispString(2, 1, 1, "三"); }
  577.   if(yue==4){dispString(2, 1, 1, "四"); }
  578.   if(yue==5){dispString(2, 1, 1, "五"); }
  579.   if(yue==6){dispString(2, 1, 1, "六"); }
  580.   if(yue==7){dispString(2, 1, 1, "七"); }
  581.   if(yue==8){dispString(2, 1, 1, "八"); }
  582.   if(yue==9){dispString(2, 1, 1, "九"); }
  583.   if(yue==10){dispString(2, 1, 1, "十"); }
  584.   if(yue==11){dispString(2, 1, 1, "冬"); }
  585.   if(yue==12){dispString(2, 1, 1, "腊"); }
  586.   dispString(2, 2, 1, "月");
  587.   if(ri<=10)
  588.    {
  589.     if(ri==1){  dispString(2, 3, 1, "初一"); }
  590.     if(ri==2){  dispString(2, 3, 1, "初二"); }
  591.     if(ri==3){  dispString(2, 3, 1, "初三"); }
  592.     if(ri==4){  dispString(2, 3, 1, "初四");}
  593.     if(ri==5){  dispString(2, 3, 1, "初五"); }
  594.     if(ri==6){  dispString(2, 3, 1, "初六"); }
  595.     if(ri==7){  dispString(2, 3, 1, "初七"); }
  596.     if(ri==8){  dispString(2, 3, 1, "初八"); }
  597.     if(ri==9){  dispString(2, 3, 1, "初九");  }
  598.     if(ri==10){  dispString(2, 3, 1, "初十"); }
  599.    }
  600.   else
  601.    {
  602.     if(ri==11){  dispString(2, 3, 1, "十一");}
  603.     if(ri==12){  dispString(2, 3, 1, "十二");}
  604.     if(ri==13){  dispString(2, 3, 1, "十三"); }
  605.     if(ri==14){  dispString(2, 3, 1, "十四"); }
  606.     if(ri==15){  dispString(2, 3, 1, "十五"); }
  607.     if(ri==16){  dispString(2, 3, 1, "十六"); }
  608.     if(ri==17){  dispString(2, 3, 1, "十七"); }
  609.     if(ri==18){  dispString(2, 3, 1, "十八"); }
  610.     if(ri==19){  dispString(2, 3, 1, "十九"); }
  611.     if(ri==20){  dispString(2, 3, 1, "二十");}
  612.     if(ri==21){  dispString(2, 3, 1, "廿一");  }
  613.     if(ri==22){  dispString(2, 3, 1, "廿二");}
  614.     if(ri==23){  dispString(2, 3, 1, "廿三"); }
  615.     if(ri==24){  dispString(2, 3, 1, "廿四"); }
  616.     if(ri==25){  dispString(2, 3, 1, "廿五"); }
  617.     if(ri==26){  dispString(2, 3, 1, "廿六");}
  618.     if(ri==27){  dispString(2, 3, 1, "廿七"); }
  619.     if(ri==28){  dispString(2, 3, 1, "廿八"); }
  620.     if(ri==29){  dispString(2, 3, 1, "廿九");}
  621.     if(ri==30){  dispString(2, 3, 1, "三十"); }
  622.    }
  623.    }
  624. }
  625. /******************************************************************************/
  626. //十二生肖显示
  627. /******************************************************************************/
  628. void lcmshengxiao()
  629. {
  630. uint y3;
  631. y3=(yy/16*10+yy%16+2000-1900)%12;
  632. if(year<6 & year1>6) y3--;
  633. switch(y3)
  634. {
  635.   case 0: dispString(0, 6, 1, "子鼠");
  636.           break;
  637.   case 1:  dispString(0, 6, 1, "丑牛");
  638.           break;
  639.   case 2:  dispString(0, 6, 1, "寅虎");
  640.           break;
  641.   case 3:  dispString(0, 6, 1, "卯兔");
  642.           break;
  643.   case 4:  dispString(0, 6, 1, "辰龙");
  644.           break;
  645.   case 5: dispString(0, 6, 1, "巳蛇");
  646.           break;
  647.   case 6: dispString(0, 6, 1, "午马");
  648.           break;
  649.   case 7: dispString(0, 6, 1, "未羊");
  650.           break;
  651.   case 8:  dispString(0, 6, 1, "申猴");
  652.           break;
  653.   case 9:  dispString(0, 6, 1, "酉鸡");
  654.           break;
  655.   case 10:  dispString(0, 6, 1, "戌狗");
  656.           break;
  657.   case 11: dispString(0, 6, 1, "亥猪");
  658.           break;
  659. }
  660. }
  661. /*****************************************************************************/
  662. //调时用加1程序
  663. void Set_time(unsigned char sel)//根据选择调整的相应项目加1并写入DS1302
  664. {
  665.   signed char address,item;
  666.   signed char max,mini;
  667.   dispString(3, 2, 1, "设置");
  668.   if(sel==6)  {dispString(3, 4, 1, "秒钟");address=0x80; max=59;mini=0;}     //秒7
  669.   if(sel==5)  {dispString(3, 4, 1, "分钟");address=0x82; max=59;mini=0;}    //分钟6
  670.   if(sel==4)  {dispString(3, 4, 1, "小时");address=0x84; max=23;mini=0;}    //小时5
  671.   if(sel==3)  {dispString(3, 4, 1, "星期");address=0x8a; max=7;mini=1;}    //星期4  
  672.   if(sel==2)  {dispString(3, 4, 1, "日期");address=0x86; max=31;mini=1;}    //日3
  673.   if(sel==1)  {dispString(3, 4, 1, "月份");address=0x88; max=12;mini=1;}    //月2
  674.   if(sel==0)  {dispString(3, 4, 1, "年份");address=0x8c; max=99; mini=0;}    //年1
  675.   switch(sel)
  676.         {
  677.             case 0: convertChar(0, 1, 2);
  678.                                 break;
  679.                 case 1: convertChar(0, 2, 3);
  680.                                 break;
  681.                 case 2:        convertChar(0, 4, 2);
  682.                                 break;
  683.                 case 3: convertChar(1, 7, 2);
  684.                                 break;
  685.                 case 4: convertChar(2, 0, 2);
  686.                                 break;
  687.                 case 5: convertChar(2, 1, 3);
  688.                                 break;
  689.                 case 6: convertChar(2, 3, 2);
  690.                                 break;
  691.         }
  692.   //读取1302某地址上的数值转换成10进制赋给item
  693.   item=((read_clock(address+1))/16)*10 + (read_clock(address+1))%16;
  694.   if(KEY_2 == 0||workcode==3)
  695.   {
  696.           item++;//数加 1
  697.         workcode=0;  
  698.   }
  699.   if(KEY_4 == 0||workcode==7)
  700.   {
  701.           item--;//数减 1
  702.         workcode=0;
  703.   }
  704.   if(item>max) item=mini;//查看数值有效范围   
  705.   if(item<mini) item=max;           
  706.   write_clock(0x8e,0x00);//允许写操作
  707.   write_clock(address,(item/10)*16+item%10);//转换成16进制写入1302
  708.   write_clock(0x8e,0x80);//写保护,禁止写操作
  709.   
  710. }

  711. /*****************************************************************************/

  712. /*****************************************************************************/
  713. //扬声器驱动程序(闹钟音乐)
  714. /*****************************************************************************/        
  715. void Beep(void)
  716. {//BELL-扬声器--整点报时
  717.         unsigned char a;//定义变量用于发声的长度设置
  718.         for(a=60;a>0;a--){//第一个声音的长度
  719.                 beep = ~beep;//取反扬声器驱动口,以产生音频
  720.                 Delay(100);//音调设置延时
  721.         }
  722.         for(a=100;a>0;a--){//同上
  723.                 beep = ~beep;
  724.                 Delay(80);//
  725.         }
  726.         for(a=100;a>0;a--){//同上
  727.                 beep = ~beep;
  728.                 Delay(30);//
  729.         }
  730.         beep = 1;//音乐结束后扬声器拉高关闭
  731. }
  732. /*****************************************************************************/
  733. void Beep_set(void){//BELL -扬声器--确定设置
  734.         unsigned char a;//定义变量用于发声的长度设置
  735.         for(a=50;a>0;a--){//第一个声音的长度
  736.                 beep = ~beep;//取反扬声器驱动口,以产生音频
  737.                 Delay(100);//音调设置延时
  738.         }
  739.         for(a=100;a>0;a--){//同上
  740.                 beep = ~beep;
  741.                 Delay(50);//
  742.         }
  743.         for(a=50;a>0;a--){//同上
  744.                 beep = ~beep;
  745.                 Delay(100);//
  746.         }
  747.         beep = 1;//音乐结束后扬声器拉高关闭
  748. }
  749. /*****************************************************************************/
  750. void Beep_key(void){//-扬声器--按键音
  751.         unsigned char a;//定义变量用于发声的长度设置
  752.         for(a=100;a>0;a--){//声音的长度
  753.                 beep = ~beep;
  754.                 Delay(50);//音调设置延时
  755.         }
  756.         beep = 1;//音乐结束后扬声器拉高关闭
  757. }               
  758. /*****************************************************************************/

  759. /*****************************************************************************/
  760. //电子钟应用层程序设计
  761. /*****************************************************************************/
  762. //向LCM中填写 年 数据
  763. void lcm_w_yy(void){
  764.         //if(read_clock(0x8d) != yy){
  765.                 yy = read_clock(0x8d);
  766.                 dispString(0, 0, 1, "20");
  767.                 lcdWriteCommand(0x81);
  768.                 lcdWriteData((yy/16)+0x30);        
  769.                 lcdWriteData(yy%16+0x30);
  770. }        //}
  771. /*****************************************************************************/
  772. //向LCM中填写 月 数据
  773. void lcm_w_mo(void){
  774.         //if(read_clock(0x89) != mo){
  775.                 mo = read_clock(0x89);
  776.                     lcdWriteCommand(0x82);
  777.                         lcdWriteData(0x2d);
  778.                         lcdWriteData((mo/16)+0x30);        //十位消隐               
  779.                     lcdWriteData(mo%16+0x30);
  780.                         lcdWriteData(0x2d);
  781.                         year=(mo/16*10)+mo%16;
  782. }        //}
  783. /*****************************************************************************/
  784. //星期处理并送入LCM的指定区域
  785. void lcm_w_xq(void){
  786.         //if(read_clock(0x8b) != xq){
  787.         xq = read_clock(0x8b);
  788.         selx = (read_clock(0x8b))%16; //字节低4位的BCD码放入selx
  789.                 if(selx==7)  {dispString(1, 7, 1, "日");}    //
  790.                   if(selx==6)  {dispString(1, 7, 1, "六");}    //
  791.                   if(selx==5)  {dispString(1, 7, 1, "五");}    //
  792.                   if(selx==4)  {dispString(1, 7, 1, "四");}    //
  793.                   if(selx==3)  {dispString(1, 7, 1, "三");}    //
  794.                   if(selx==2)  {dispString(1, 7, 1, "二");}    //
  795.                   if(selx==1)  {dispString(1, 7, 1, "一");}    //星期一
  796.         dispString(1, 5, 1, "星期");
  797. }        //}
  798. /*****************************************************************************/
  799. //向LCM中填写 日 数据
  800. void lcm_w_dd(void){
  801. //        if(read_clock(0x87) != dd){
  802.                 dd = read_clock(0x87);
  803.                 lcdWriteCommand(0x84);
  804.                 lcdWriteData((dd/16)+0x30);        //十位消隐        
  805.                 lcdWriteData(dd%16+0x30);
  806. }        //}
  807. /*****************************************************************************/
  808. //向LCM中填写 小时 数据
  809. void lcm_w_hh(void){
  810.         if(read_clock(0x85) != hh){
  811.                 hh = read_clock(0x85);
  812.                         if (hh > 0x07 && hh < 0x22 && w == 0){
  813.                                 Beep();//整点报时音
  814.                         }
  815.                 }
  816.                 lcdWriteCommand(0x88);
  817.                 lcdWriteData((hh/16)+0x30);
  818.                 lcdWriteData(hh%16+0x30);
  819.                 hh1=hh/16*10+hh%16;
  820.                 if(hh1>12) hh1=(hh1-12);
  821.                                 
  822. }
  823. /*****************************************************************************/
  824. //向LCM中填写 分钟 数据
  825. void lcm_w_mm(void){
  826.         if(read_clock(0x83) != mm)
  827.             {               
  828.                 mm = read_clock(0x83);
  829.             }
  830.                 lcdWriteCommand(0x89);
  831.                 if(t/1%2==0)lcdWriteData(0x3a);          //":"
  832.                 else{lcdWriteData(0x20);}
  833.                 lcdWriteData((mm/16)+0x30);
  834.                 lcdWriteData(mm%16+0x30);
  835.                 if(t/1%2==0) lcdWriteData(0x3a);          //":"
  836.                 else{lcdWriteData(0x20);}        
  837. }
  838. /*****************************************************************************/
  839. //向LCM中填写 秒 数据
  840. void lcm_w_ss(void)
  841. {
  842.         unsigned int i=0;
  843.         unsigned char a=0,b=0,c=0;
  844.         if(read_clock(0x81) != ss){        //判断是否需要更新
  845.                 ss = read_clock(0x81);        //更新数据
  846.                 if(w==1&&e==6)
  847.                 {
  848.                  if(t/1%2==0)
  849.                  {
  850.                 lcdWriteCommand(0x8b);                //秒值在LCM上的写入位置
  851.                 lcdWriteData((ss/16)+0x30);        //写十位               
  852.                 lcdWriteData(ss%16+0x30);        //写个位
  853.                  }
  854.                  else
  855.                  {
  856.                 lcdWriteCommand(0x8b);                //秒值在LCM上的写入位置
  857.                 lcdWriteData(0x20);        //写十位               
  858.                 lcdWriteData(0x20);        //写个位
  859.                  }
  860.                 }
  861.                 else
  862.                 {
  863.                 lcdWriteCommand(0x8b);                //秒值在LCM上的写入位置
  864.                 lcdWriteData((ss/16)+0x30);        //写十位               
  865.                 lcdWriteData(ss%16+0x30);        //写个
  866.                 }
  867.     }
  868. }
  869. /*****************************************************************************/
  870. void disp_temper()//温度值显示
  871. {
  872.     uint temper;
  873.         uchar temper_ge,temper_shi,temper_bai;
  874.         temper=read_temp();//读取温度
  875.         temper_ge=temper%10+0x30;
  876.         temper_shi=temper%100/10+0x30;
  877.         temper_bai=temper/100+0x30;
  878.         if(tflag==1)
  879.         {
  880.                 dispString(2, 4, 1, " -");
  881.         }
  882.         else
  883.         {
  884.          dispString(2, 4, 1, "  ");
  885.         }
  886.         if(temper_bai==0x30) temper_bai=0x20;
  887.         lcdWriteCommand(0x8d);
  888. lcdWriteData(temper_bai);
  889.         lcdWriteData(temper_shi);
  890. lcdWriteData('.');
  891. lcdWriteData(temper_ge);

  892.         dispString(2, 7, 1, "℃");        
  893.    }
  894.    /*****************************************************************************/
  895. //刷新数据
  896. void updata (void){
  897.         lcm_w_ss();//刷新 秒
  898.                 lcm_w_mm();//刷新 分
  899.                 lcm_w_hh();//刷新 小时
  900.                 lcm_w_dd();//刷新 日
  901.                 lcm_w_xq();//更新星期值        
  902.                 lcm_w_mo();//刷新 月
  903.                 lcm_w_yy();//刷新 年
  904.                 ss = read_clock(0x81);        //更新数据
  905.                 t=ss/16*10+ss%16;
  906.                 lcmnongli();
  907.             lcmshengxiao();
  908.             disp_temper();
  909.                 if(w == 0)
  910.                 {                                
  911.                         days ();//节日显示
  912.                 }
  913.                 if (n==1||n==2||n==3)
  914.                     {
  915.                         lcdWriteCommand(0x85);                //秒值在LCM上的写入位置
  916.                         lcdWriteData(0x20);
  917.                     lcdWriteData(0x0e);        
  918.                         }
  919.                 else{
  920.                      lcdWriteCommand(0x85);                //秒值在LCM上的写入位置
  921.                          lcdWriteData(0x20);
  922.                      lcdWriteData(0x20);        
  923.                      }                                
  924. }
  925. /*********************************************************************************************************
  926. 处理显示函数(被调用层)                                       
  927. *********************************************************************************************************/
  928. void deal(uchar sfm)
  929. {
  930.         shi=sfm/16;
  931.         ge=sfm%16;
  932. }
  933. /********************************************************************************************************
  934. 12864显示时分秒函数(被调用层)
  935. ********************************************************************************************************/
  936. void display(uchar add,uchar dat)
  937. {
  938.         uchar i,j=0;
  939.         if(k==0)
  940.         {
  941.         for(i=16;i<32;i++)
  942.         {                        
  943.                 lcdWriteCommand(0x80+i);                                                        
  944.                 lcdWriteCommand(0x90+add);                                                
  945.                 lcdWriteData(tab[dat][j++]);
  946.                 lcdWriteData(tab[dat][j++]);
  947.         }
  948.         for(i=0;i<16;i++)
  949.         {
  950.                 lcdWriteCommand(0x80+i);
  951.                 lcdWriteCommand(0x88+add);
  952.                 lcdWriteData(tab[dat][j++]);
  953.                 lcdWriteData(tab[dat][j++]);
  954.         }
  955.         }
  956.         else
  957.         {
  958.         for(i=0;i<16;i++)
  959.         {
  960.                 lcdWriteCommand(0x80+i);
  961.                 lcdWriteCommand(0x80+add);
  962.                 lcdWriteData(tab1[dat][j++]);
  963.                 lcdWriteData(tab1[dat][j++]);
  964.         }
  965.         for(i=16;i<32;i++)
  966.         {                        
  967.                 lcdWriteCommand(0x80+i);                                                        
  968.                 lcdWriteCommand(0x90+add);                                                
  969.                 lcdWriteData(tab1[dat][j++]);
  970.                 lcdWriteData(tab1[dat][j++]);
  971.         }
  972.         }
  973. }
  974. /********************************************************************************************************
  975. 12864显示时分秒函数(被调用层)2
  976. ********************************************************************************************************/
  977. void display1(uchar add,uchar dat)
  978. {
  979.         uchar i,j=0;
  980.         for(i=0;i<16;i++)
  981.         {
  982.                 lcdWriteCommand(0x80+i);
  983.                 lcdWriteCommand(0x88+add);
  984.                 lcdWriteData(tab1[dat][j++]);
  985.                 lcdWriteData(tab1[dat][j++]);
  986.         }
  987.         for(i=16;i<32;i++)
  988.         {                        
  989.                 lcdWriteCommand(0x80+i);                                                        
  990.                 lcdWriteCommand(0x98+add);                                                
  991.                 lcdWriteData(tab1[dat][j++]);
  992.                 lcdWriteData(tab1[dat][j++]);
  993.         }
  994. }
  995. /*********************************************************************************************************
  996. 初始化函数(被调用层)                                       
  997. *********************************************************************************************************/
  998. void init_dz()
  999. {
  1000.         lcdWriteCommand(0x30);                                                        //选择8bit数据流,基本指令集
  1001.         lcdWriteCommand(0x0c);                                                      //开显示(无游标、不反白)
  1002.         lcdWriteCommand(0x01);                                                       //清除显示,并且设定地址指针为00H
  1003.         if(k==0)
  1004.         {
  1005.         dispString(0, 2, 1, "年  月  日");        
  1006.         dispString(3, 0, 1, "星期");        
  1007.         lcdWriteCommand(0x81);                                                         //处理年,并显示
  1008.         yy = read_clock(0x8d);                                
  1009.         deal(yy);
  1010.         lcdWriteData(shi+0x30);
  1011.         lcdWriteData(ge+0x30);
  1012.                                                                                                  //处理月,并显示
  1013.         lcdWriteCommand(0x83);
  1014.         mo = read_clock(0x89);
  1015.         deal(mo);
  1016.         lcdWriteData(shi+0x30);
  1017.         lcdWriteData(ge+0x30);

  1018.         lcdWriteCommand(0x85);                                                         //处理日,并显示
  1019.         dd = read_clock(0x87);
  1020.         deal(dd);
  1021.         lcdWriteData(shi+0x30);
  1022.         lcdWriteData(ge+0x30);
  1023.                                                                                                                                   //处理星期,并显示
  1024.         xq = read_clock(0x8b);
  1025.         switch(xq)
  1026.         {
  1027.                 case 1:        dispString(3, 2, 1, "一");break;
  1028.                 case 2:        dispString(3, 2, 1, "二");break;
  1029.                 case 3:        dispString(3, 2, 1, "三");break;
  1030.                 case 4:        dispString(3, 2, 1, "四");break;
  1031.                 case 5:        dispString(3, 2, 1, "五");break;
  1032.                 case 6:        dispString(3, 2, 1, "六");break;
  1033.                 case 7:        dispString(3, 2, 1, "日");break;
  1034.                 default:break;
  1035.         }
  1036.         dispString(3, 7, 1, "℃");
  1037.         lcdWriteCommand(0x36);                                                         //启动扩充指令集,启动绘图模式
  1038.     clear_img();                                                                //清理图片缓冲区
  1039.         lcmnongli();
  1040.         hh = read_clock(0x85);                                                         //处理小时,并显示
  1041.         deal(hh);
  1042.         display(0,shi);
  1043.         display(1,ge);
  1044.         display(2,10);
  1045.         mm = read_clock(0x83);                                                         //处理分钟,并显示
  1046.         deal(mm);
  1047.         display(3,shi);
  1048.         display(4,ge);
  1049.         display(5,10);
  1050.         ss = read_clock(0x81);                                                         //处理秒,并显示
  1051.         deal(ss);
  1052.         display(6,shi);
  1053.         display(7,ge);
  1054.         }
  1055.         else
  1056.         {

  1057.         dispString(0, 5, 1, "星期");
  1058.         dispString(3, 0, 1, " 20");        
  1059.         lcdWriteCommand(0x99);                                                         //处理年,并显示
  1060.         yy = read_clock(0x8d);                                
  1061.         deal(yy);
  1062.         lcdWriteData(0x20);
  1063.         lcdWriteData(shi+0x30);
  1064.         lcdWriteData(ge+0x30);
  1065.         lcdWriteData(0x2d);
  1066.                                                                                                  //处理月,并显示
  1067.         //lcdWriteCommand(0x9a);
  1068.         mo = read_clock(0x89);
  1069.         deal(mo);
  1070.         lcdWriteData(shi+0x30);
  1071.         lcdWriteData(ge+0x30);

  1072.         //lcdWriteCommand(0x9c);                                                         //处理日,并显示
  1073.         dd = read_clock(0x87);
  1074.         deal(dd);
  1075.         lcdWriteData(0x2d);
  1076.         lcdWriteData(shi+0x30);
  1077.         lcdWriteData(ge+0x30);
  1078.                                                                                                                                   //处理星期,并显示
  1079.         xq = read_clock(0x8b);
  1080.         switch(xq)
  1081.         {
  1082.                 case 1:        dispString(0, 7, 1, "一");break;
  1083.                 case 2:        dispString(0, 7, 1, "二");break;
  1084.                 case 3:        dispString(0, 7, 1, "三");break;
  1085.                 case 4:        dispString(0, 7, 1, "四");break;
  1086.                 case 5:        dispString(0, 7, 1, "五");break;
  1087.                 case 6:        dispString(0, 7, 1, "六");break;
  1088.                 case 7:        dispString(0, 7, 1, "日");break;
  1089.                 default:break;
  1090.         }
  1091.         dispString(1, 7, 1, "℃");



  1092.         lcdWriteCommand(0x36);                                                         //启动扩充指令集,启动绘图模式
  1093.         clear_img();                                                                //清理图片缓冲区
  1094.         hh = read_clock(0x85);                                                         //处理小时,并显示
  1095.         deal(hh);
  1096.         display(0,shi);
  1097.         display(1,ge);
  1098.         display(2,10);
  1099.         mm = read_clock(0x83);                                                         //处理分钟,并显示
  1100.         deal(mm);
  1101.         display(3,shi);
  1102.         display(4,ge);
  1103.         ss = read_clock(0x81);                                                         //处理秒,并显示
  1104.         deal(ss);
  1105.         display1(6,shi);
  1106.         display1(7,ge);
  1107.         }
  1108. }
  1109. /********************************************************************************************************
  1110. 在12864上显示时间,大数字显示主界面1
  1111. ********************************************************************************************************/
  1112. void disp_sfm()
  1113. {
  1114.         uint temper;
  1115.         uchar temper_ge,temper_shi,temper_bai,day_temp,date_temp,month_temp,year_temp;
  1116.         lcdWriteCommand(0x36);                                                         //启动扩充指令集,启动绘图模式
  1117.     ss = read_clock(0x81);        //更新数据                                                
  1118.         if(sec_temp!=ss)//读取秒,只要有改变液晶显示也改变
  1119.         {
  1120.                 sec_temp=ss;
  1121.                 deal(sec_temp);
  1122.                 if(secl!=shi)
  1123.                 {
  1124.                         secl=shi;
  1125.                         display(6,secl);
  1126.                 }
  1127.                 display(7,ge);        
  1128.         }
  1129.         mm = read_clock(0x83);                                                         //读取分,只要有改变液晶显示也改变
  1130.         if(min_temp!=mm)
  1131.         {
  1132.                 min_temp=mm;
  1133.                 deal(mm);
  1134.                 display(3,shi);
  1135.                 display(4,ge);
  1136.         }
  1137.         hh = read_clock(0x85);                                                        //读取小时,只要有改变液晶显示也改变
  1138.         if(hour_temp!=hh)
  1139.         {
  1140.                 hour_temp=hh;
  1141.                 deal(hh);
  1142.                 display(0,shi);
  1143.                 display(1,ge);
  1144.         }

  1145.         if(ge/1%2==0)
  1146.         {
  1147.         display(2,10);
  1148.         display(5,10);
  1149.         }
  1150.         else
  1151.         {
  1152.         display(2,11);
  1153.         display(5,11);
  1154.         }
  1155.          
  1156.         lcdWriteCommand(0x30);
  1157.         dd = read_clock(0x87);                                                //读取日,只要有改变液晶显示也改变
  1158.         if(date_temp!=dd)
  1159.         {        
  1160.                 date_temp=dd;
  1161.                 deal(dd);
  1162.                 lcdWriteCommand(0x85);
  1163.                 lcdWriteData(shi+0x30);
  1164.                 lcdWriteData(ge+0x30);
  1165.         }
  1166.         mo = read_clock(0x89);                                                //读取月,只要有改变液晶显示也改变
  1167.         if(month_temp!=mo)
  1168.         {
  1169.                 month_temp=mo;
  1170.                 lcdWriteCommand(0x83);
  1171.                 deal(mo);
  1172.                 lcdWriteData(shi+0x30);
  1173.                 lcdWriteData(ge+0x30);
  1174.         }
  1175.         yy = read_clock(0x8d);                                                        //读取年,只要有改变液晶显示也改变
  1176.         if(year_temp!=yy)
  1177.         {
  1178.                 year_temp=yy;
  1179.                 lcdWriteCommand(0x81);
  1180.                 deal(yy);
  1181.                 lcdWriteData(shi+0x30);
  1182.                 lcdWriteData(ge+0x30);
  1183.         }
  1184.                 xq = read_clock(0x8b);                                                         //读取星期,只要有改变液晶显示也改变
  1185.         if(day_temp!=xq)
  1186.         {        
  1187.                 day_temp=xq;
  1188.                 switch(xq)
  1189.         {
  1190.                 case 1:        dispString(3, 2, 1, "一");break;
  1191.                 case 2:        dispString(3, 2, 1, "二");break;
  1192.                 case 3:        dispString(3, 2, 1, "三");break;
  1193.                 case 4:        dispString(3, 2, 1, "四");break;
  1194.                 case 5:        dispString(3, 2, 1, "五");break;
  1195.                 case 6:        dispString(3, 2, 1, "六");break;
  1196.                 case 7:        dispString(3, 2, 1, "日");break;
  1197.                 default:break;
  1198.                 }
  1199.         }
  1200.         temper=read_temp();//读取温度
  1201.         temper_ge=temper%10+0x30;
  1202.         temper_shi=temper%100/10+0x30;
  1203.         temper_bai=temper/100+0x30;

  1204.         //lcdWriteCommand(0x9b); //此处可以用来测试各种红外遥控的键值
  1205.         //lcdWriteData(workcode/10+0x30);
  1206.         //lcdWriteData(workcode%10+0x30);

  1207.         if(tflag==1)
  1208.         {

  1209.                         dispString(3, 4, 1, " -");
  1210.         }
  1211.         else
  1212.         {
  1213.          dispString(3, 4, 1, "  ");
  1214.         }
  1215.         if(temper_bai==0x30) temper_bai=0x20;
  1216.         lcdWriteCommand(0x9d);
  1217.         lcdWriteData(temper_bai);
  1218.         lcdWriteData(temper_shi);
  1219.         lcdWriteData('.');
  1220.         lcdWriteData(temper_ge);

  1221.         lcdWriteCommand(0x36);        

  1222. }
  1223. /********************************************************************************************************
  1224. 在12864上显示时间,大数字显示主界面2
  1225. ********************************************************************************************************/
  1226. void disp_sfm1()
  1227. {
  1228.         uint temper;
  1229.         uchar temper_ge,temper_shi,temper_bai,day_temp,date_temp,month_temp,year_temp;
  1230.         lcdWriteCommand(0x36);                                                         //启动扩充指令集,启动绘图模式
  1231.     ss = read_clock(0x81);        //更新数据                                                
  1232.         if(sec_temp!=ss)//读取秒,只要有改变液晶显示也改变
  1233.         {
  1234.                 sec_temp=ss;
  1235.                 deal(sec_temp);
  1236.                 if(secl!=shi)
  1237.                 {
  1238.                         secl=shi;
  1239.                         display1(6,secl);
  1240.                 }
  1241.                 display1(7,ge);        
  1242.         }
  1243.         mm = read_clock(0x83);                                                         //读取分,只要有改变液晶显示也改变
  1244.         if(min_temp!=mm)
  1245.         {
  1246.                 min_temp=mm;
  1247.                 deal(mm);
  1248.                 display(3,shi);
  1249.                 display(4,ge);
  1250.         }
  1251.         hh = read_clock(0x85);                                                        //读取小时,只要有改变液晶显示也改变
  1252.         if(hour_temp!=hh)
  1253.         {
  1254.                 hour_temp=hh;
  1255.                 deal(hh);
  1256.                 display(0,shi);
  1257.                 display(1,ge);
  1258.         }

  1259.         if(ge/1%2==0)
  1260.         {
  1261.         display(2,10);
  1262.         }
  1263.         else
  1264.         {
  1265.         display(2,11);
  1266.         }
  1267.                 lcdWriteCommand(0x30);
  1268.         lcmnongli();
  1269.         yy = read_clock(0x8d);                                                        //读取年,只要有改变液晶显示也改变
  1270.         if(year_temp!=yy)
  1271.         {
  1272.                 year_temp=yy;
  1273.                 lcdWriteCommand(0x99);
  1274.                 deal(yy);
  1275.                 lcdWriteData(0x30);
  1276.                 lcdWriteData(shi+0x30);
  1277.                 lcdWriteData(ge+0x30);
  1278.                 lcdWriteData(0x2d);
  1279.         }
  1280.         mo = read_clock(0x89);                                                //读取月,只要有改变液晶显示也改变
  1281.         if(month_temp!=mo)
  1282.         {
  1283.                 month_temp=mo;
  1284.                 lcdWriteCommand(0x9b);
  1285.                 deal(mo);
  1286.                 lcdWriteData(shi+0x30);
  1287.                 lcdWriteData(ge+0x30);
  1288.         }
  1289.         dd = read_clock(0x87);                                                //读取日,只要有改变液晶显示也改变
  1290.         if(date_temp!=dd)
  1291.         {        
  1292.                 date_temp=dd;
  1293.                 deal(dd);
  1294.                 lcdWriteCommand(0x9c);
  1295.                 lcdWriteData(0x2d);
  1296.                 lcdWriteData(shi+0x30);
  1297.                 lcdWriteData(ge+0x30);
  1298.         }
  1299.                 xq = read_clock(0x8b);                                                         //读取星期,只要有改变液晶显示也改变
  1300.         if(day_temp!=xq)
  1301.         {        
  1302.                 day_temp=xq;
  1303.                 switch(xq)
  1304.         {
  1305.                 case 1:        dispString(0, 7, 1, "一");break;
  1306.                 case 2:        dispString(0, 7, 1, "二");break;
  1307.                 case 3:        dispString(0, 7, 1, "三");break;
  1308.                 case 4:        dispString(0, 7, 1, "四");break;
  1309.                 case 5:        dispString(0, 7, 1, "五");break;
  1310.                 case 6:        dispString(0, 7, 1, "六");break;
  1311.                 case 7:        dispString(0, 7, 1, "日");break;
  1312.                 default:break;
  1313.                 }
  1314.         }
  1315.         temper=read_temp();//读取温度
  1316.         temper_ge=temper%10+0x30;
  1317.         temper_shi=temper%100/10+0x30;
  1318.         temper_bai=temper/100+0x30;

  1319.         //lcdWriteCommand(0x9b); //此处可以用来测试各种红外遥控的键值
  1320.         //lcdWriteData(workcode/10+0x30);
  1321.         //lcdWriteData(workcode%10+0x30);

  1322.         /*if(tflag==1)
  1323.         {

  1324.                         dispString(1, 5, 1, " -");
  1325.         }
  1326.         else
  1327.         {
  1328.          dispString(1, 5, 1, "  ");
  1329.         }*/
  1330.         if(temper_bai==0x30) temper_bai=0x20;
  1331.         lcdWriteCommand(0x95);
  1332.         lcdWriteData(temper_bai);
  1333.         lcdWriteData(temper_shi);
  1334.         lcdWriteData('.');
  1335.         lcdWriteData(temper_ge);

  1336.         lcdWriteCommand(0x36);        

  1337. }
  1338. //*****************************Music******************************************************/
  1339. //天空之城
  1340. unsigned char code Music_wo[]={  0x10,0x03, 0x11,0x03, 0x15,0x66, 0x11,0x03, 0x15,0x02,
  1341.                                   0x17,0x02, 0x11,0x01, 0x0D,0x02, 0x0D,0x02, 0x10,0x66,
  1342.                                   0x0F,0x03, 0x10,0x02, 0x15,0x02, 0x0F,0x15, 0x0D,0x03,
  1343.                                   0x0D,0x03, 0x0E,0x66, 0x0D,0x03, 0x0E,0x03, 0x15,0x66,
  1344.                                   0x0D,0x01, 0x15,0x02, 0x15,0x02, 0x15,0x02, 0x11,0x66,
  1345.                                   0x0E,0x03, 0x0E,0x02, 0x11,0x02, 0x11,0x15, 0x10,0x03,
  1346.                                   0x11,0x03, 0x15,0x66, 0x11,0x03, 0x15,0x02, 0x17,0x02,
  1347.                                   0x11,0x15, 0x0D,0x03, 0x0D,0x03, 0x10,0x66, 0x0F,0x03,
  1348.                                   0x10,0x02, 0x15,0x02, 0x0F,0x01, 0x0D,0x03, 0x0E,0x02,
  1349.                                   0x15,0x03, 0x11,0x03, 0x11,0x02, 0x15,0x02, 0x16,0x03,
  1350.                                   0x16,0x03, 0x17,0x03, 0x15,0x16, 0x15,0x02, 0x11,0x03,
  1351.                                   0x10,0x03, 0x10,0x03, 0x11,0x02, 0x0F,0x02, 0x10,0x15,
  1352.                                   0x15,0x03, 0x16,0x03, 0x17,0x66, 0x16,0x03, 0x17,0x02,
  1353.                                   0x19,0x02, 0x16,0x15, 0x0F,0x03, 0x0F,0x03, 0x15,0x03,
  1354.                                   0x11,0x03, 0x15,0x02, 0x17,0x02, 0x17,0x15, 0x10,0x03,
  1355.                                   0x11,0x03, 0x15,0x02, 0x11,0x02, 0x16,0x03, 0x16,0x03,
  1356.                                   0x15,0x66, 0x0F,0x03, 0x0F,0x16, 0x18,0x02, 0x17,0x02,
  1357.                                   0x16,0x02, 0x15,0x02, 0x17,0x00, 0x17,0x02, 0x1A,0x01,
  1358.                                   0x19,0x02, 0x19,0x02, 0x17,0x03, 0x16,0x03, 0x15,0x02,
  1359.                                   0x15,0x02, 0x16,0x02, 0x15,0x03, 0x16,0x03, 0x16,0x03,
  1360.                                   0x19,0x02, 0x17,0x15, 0x17,0x02, 0x1A,0x01, 0x19,0x01,
  1361.                                   0x17,0x03, 0x16,0x03, 0x15,0x01, 0x15,0x03, 0x16,0x02,
  1362.                                   0x15,0x03, 0x16,0x03, 0x16,0x03, 0x11,0x02, 0x10,0x01,
  1363.                                   0x00,0x00 };
  1364. /***********************************************************************************/
  1365. /*------------------整屏写入数据:全亮,或者竖条-----------------------------*/
  1366. void lcdfill(unsigned char disdata)
  1367. { unsigned char x,y;
  1368.         for(y=0;y<32;y++)
  1369.          for(x=0;x<16;x++)
  1370.          { lcdWriteCommand(0x36);
  1371.             lcdWriteCommand(y+0x80);        //行地址
  1372.             lcdWriteCommand(x+0x80);     //列地址
  1373.             lcdWriteCommand(0x30);
  1374.             lcdWriteData(disdata);
  1375.             lcdWriteData(disdata);
  1376.                         DelayM(2);
  1377.             }
  1378.    lcdWriteCommand(0x34);                           
  1379.    lcdWriteCommand(0x36);
  1380.    }
  1381. /*------------------显示横-----------------------------*/
  1382. void Disp_H_Line()
  1383. { unsigned char x,y;
  1384.    unsigned char k=0x00;
  1385.        for(y=0;y<32;y++)
  1386.          { k=~k;
  1387.            for(x=0;x<16;x++)
  1388.          { lcdWriteCommand(0x36);
  1389.             lcdWriteCommand(y+0x80);      //行地址
  1390.             lcdWriteCommand(x+0x80);     //列地址
  1391.             lcdWriteCommand(0x30);
  1392.             lcdWriteData(k);
  1393.             lcdWriteData(k);
  1394.                         DelayM(5);
  1395.            };
  1396.          }
  1397.      lcdWriteCommand(0x34);                          
  1398.    lcdWriteCommand(0x36);
  1399. }
  1400. /*------------------显示边框-------------------------------*/
  1401. void Frame()
  1402. {unsigned char x,y;
  1403.           lcdfill(0x00);
  1404.         for(x=0;x<9;x+=8)
  1405.           for(y=0;y<32;y++)
  1406.            { lcdWriteCommand(0x36);
  1407.             lcdWriteCommand(y+0x80);      //行地址
  1408.             lcdWriteCommand(x+0x80);        //列地址
  1409.             lcdWriteCommand(0x30);
  1410.             lcdWriteData(0x80);
  1411.             lcdWriteData(0x00);
  1412.            
  1413.             lcdWriteCommand(0x36);
  1414.             lcdWriteCommand(y+0x80);      //行地址
  1415.             lcdWriteCommand(x+0x87);        //列地址
  1416.             lcdWriteCommand(0x30);
  1417.             lcdWriteData(0x00);
  1418.             lcdWriteData(0x01);
  1419.             DelayM(5);
  1420.             }
  1421.       for(y=0;y<2;y++)
  1422.          for(x=0;x<8;x++)
  1423.            {lcdWriteCommand(0x36);
  1424.             lcdWriteCommand(y*31+0x80);      //行地址
  1425.             lcdWriteCommand(x+0x80+8*y);        //列地址
  1426.             lcdWriteCommand(0x30);
  1427.             lcdWriteData(0xff);
  1428.             lcdWriteData(0xff);
  1429.                         DelayM(5);
  1430.            }
  1431.          lcdWriteCommand(0x34);
  1432.          lcdWriteCommand(0x36);
  1433.                     }
  1434. /*****************************************************************************/
  1435. void zijian(void)
  1436. {
  1437. lcdClear();
  1438. dispString(1, 0, 1, "    V8.0版本    ");
  1439. dispString(2, 0, 1, "  自检程序开始! ");
  1440. DelayM(2000);
  1441. lcdClear();
  1442. displayPhoto(powerOnPhoto1, OFF);
  1443.                                                    DelayM(2000);
  1444. lcdfill(0xff);               //显示全开
  1445.       DelayM(2000);            
  1446.    
  1447.      Disp_H_Line();                //显示横条
  1448.        DelayM(2000);
  1449.       
  1450.       
  1451.        lcdfill(0xaa);               //显示竖条
  1452.       DelayM(2000);
  1453.      
  1454.       Frame();                     //显示边框
  1455.       DelayM(2000);
  1456.           clear_img();
  1457.           lcdClear();
  1458.           lcdWriteCommand(0x30);       //选择8bit数据流
  1459.       lcdWriteCommand(0x0c);       //开显示(无游标、不反白)
  1460.       lcdWriteCommand(0x01);       //清除显示,并且设定地址指针为00H
  1461.           Beep_set();//确定按键音
  1462.           dispString(0, 0, 1, "    自检完成!  ");
  1463.           dispString(2, 0, 1, "  ==小东电子==  ");
  1464.           dispString(3, 0, 1, "  QQ:120985850  ");
  1465.           DelayM(2000);
  1466.           lcdInit ();
  1467. }
  1468. /*****************************************************************************/
  1469. void naozhong()
  1470. {
  1471.                 lcdClear();
  1472.                   dispString(0, 2, 1, "闹钟设置");
  1473.                   dispString(2, 0, 1, "闹钟");
  1474.                 n=Read24c02(0);
  1475.                   if(n==0)  {dispString(2, 7, 1, "关");}    //
  1476.                   if(n==1)  {dispString(2, 7, 1, "开");}    //
  1477.                 if(n==2)  {dispString(2, 7, 1, "开");}    //
  1478.                 if(n==3)  {dispString(2, 7, 1, "开");}    //
  1479.                 n1=Read24c02(1);
  1480.             n2=Read24c02(2);
  1481.                 lcdWriteCommand(0x8b);
  1482.         lcdWriteData((n1/10)+0x30);
  1483.             lcdWriteData(n1%10+0x30);
  1484.             dispString(2, 4, 1, "点");
  1485.             lcdWriteData((n2/10)+0x30);
  1486.         lcdWriteData(n2%10+0x30);
  1487.                    while(1)
  1488.                    {
  1489.                    if (KEY_3 == 0||workcode==5) // 设置时间
  1490.               {
  1491.                 DelayM(20);           //去抖
  1492.                 if(KEY_3 == 0 ||workcode==5)
  1493.                   {
  1494.                    Beep_key();//按键音
  1495.                    workcode=0;
  1496.                    n++;
  1497.                    if (n >= 4 ){n = 0;}
  1498.                    Write24c02(n,0);
  1499.                if(n==0)  {dispString(2, 7, 1, "关");}    //
  1500.                  if(n==1)  {dispString(2, 7, 1, "开");}    //
  1501.                    if(n==2)  {dispString(2, 7, 1, "开");}    //
  1502.                    if(n==3)  {dispString(2, 7, 1, "开");}    //
  1503.                    switch(n)
  1504.         {
  1505.               case 0:        convertChar(1, 0, 0);
  1506.                                 break;
  1507.                 case 1: convertChar(1, 0, 0);
  1508.                                 break;
  1509.                 case 2:        convertChar(2, 3, 2);
  1510.                                 break;
  1511.                 case 3: convertChar(2, 5, 2);
  1512.                                 break;
  1513.         }
  1514.                   while(KEY_3 == 0);//等待键松开
  1515.                   }
  1516.                 }
  1517.         if(KEY_4 == 0||KEY_2 == 0||workcode==3||workcode==7)
  1518.         {
  1519.         if ((KEY_2 == 0&&n==2)||(workcode==3&&n==2)) //
  1520.               {
  1521.                  DelayM(20);           //去抖
  1522.                  if((KEY_2 == 0&&n==2)||(workcode==3&&n==2))
  1523.                         {
  1524.                         Beep_key();//按键音
  1525.                         workcode=0;
  1526.                         n1++;
  1527.                         if (n1 >= 24 ){n1 = 0;}
  1528.                         Write24c02(n1,1);
  1529.                         while(KEY_2 == 0);//等待键松开
  1530.                         }
  1531.                 }
  1532.         if ((KEY_2 == 0&&n==3)||(workcode==3&&n==3)) //
  1533.               {
  1534.                  DelayM(20);           //去抖
  1535.                  if((KEY_2 == 0&&n==3)||(workcode==3&&n==3))
  1536.                         {
  1537.                         Beep_key();//按键音
  1538.                         workcode=0;
  1539.                         n2++;
  1540.                         if (n2>= 60 ){n2 = 0;}
  1541.                         Write24c02(n2,2);
  1542.                         while(KEY_2 == 0);//等待键松开
  1543.                         }
  1544.                 }
  1545.                 if ((KEY_4 == 0&&n==2)||(workcode==7&&n==2)) //
  1546.               {
  1547.                  DelayM(20);           //去抖
  1548.                  if((KEY_4 == 0&&n==2)||(workcode==7&&n==2))
  1549.                         {
  1550.                         Beep_key();//按键音
  1551.                         workcode=0;
  1552.                         n1--;
  1553.                         if (n1<0 ){n1 = 23;}
  1554.                         Write24c02(n1,1);
  1555.                         while(KEY_4 == 0);//等待键松开
  1556.                         }
  1557.                 }
  1558.         if ((KEY_4 == 0&&n==3)||(workcode==7&&n==3)) //
  1559.               {
  1560.                  DelayM(20);           //去抖
  1561.                  if((KEY_4 == 0&&n==3)||(workcode==7&&n==3))
  1562.                         {
  1563.                         Beep_key();//按键音
  1564.                         workcode=0;
  1565.                         n2--;
  1566.                         if (n2<0 ){n2 = 59;}
  1567.                         Write24c02(n2,2);
  1568.                         while(KEY_4 == 0);//等待键松开
  1569.                         }
  1570.                 }
  1571.                 n1=Read24c02(1);
  1572.             n2=Read24c02(2);
  1573.                 lcdWriteCommand(0x8b);
  1574.         lcdWriteData((n1/10)+0x30);
  1575.             lcdWriteData(n1%10+0x30);
  1576.             dispString(2, 4, 1, "点");
  1577.             lcdWriteData((n2/10)+0x30);
  1578.         lcdWriteData(n2%10+0x30);
  1579.         }
  1580.            if(KEY_1 == 0 ||workcode==9)
  1581.                                             {
  1582.                                                   Beep_key();//按键音
  1583.                                                   workcode=0;
  1584.                                                   k=0;
  1585.                                                   while(KEY_1 == 0);//等待键松开
  1586.                                           lcdInit ();
  1587.                               break;
  1588.                                     }
  1589.    }

  1590. }
  1591. /*****************************************************************************/
  1592. void naozhongdao()
  1593. {
  1594.         hh1=hh/16*10+hh%16;
  1595.         mm1=mm/16*10+mm%16;
  1596.         n1=Read24c02(1);
  1597.     n2=Read24c02(2);
  1598.         if(n1==hh1 && n2==mm1 && ss==0)
  1599.                    {
  1600.                     lcdWriteCommand(0x30);       //选择8bit数据流
  1601.             lcdWriteCommand(0x0c);       //开显示(无游标、不反白)
  1602.             lcdWriteCommand(0x01);       //清除显示,并且设定地址指针为00H
  1603.                    dispString(0, 1, 1, "闹钟时间到了! ");
  1604.                    lcdWriteCommand(0x89);
  1605.            lcdWriteData((n1/10)+0x30);
  1606.                lcdWriteData(n1%10+0x30);
  1607.                    dispString(2, 2, 1, "点");
  1608.                lcdWriteData((n2/10)+0x30);
  1609.            lcdWriteData(n2%10+0x30);
  1610.                    dispString(2, 4, 1, "分");
  1611.                    lcdWriteData(0x0e);
  1612.                    Play(Music_wo,0,3,360);
  1613.                    lcdInit ();
  1614.                  }
  1615. }
  1616. /*****************************************************************************/
  1617. void procKey (void)
  1618. {
  1619. uchar key1Times=1 ;
  1620. lcdClear();
  1621. dispString(0, 0, 1, "    功能菜单    ");
  1622. dispString(1, 0, 1, "1:界面    2:设置");
  1623. dispString(2, 0, 1, "3:闹钟    4:音乐");
  1624. dispString(3, 0, 1, "5:自检    6:退出");
  1625. convertChar(1, 0, 6);
  1626. while(KEY_3 == 0);//等待键松开
  1627. while(1)
  1628. {
  1629. if(KEY_4 == 0||KEY_2 == 0||workcode==4||workcode==6)
  1630.                         {
  1631. if (KEY_4 == 0||workcode==4) //
  1632.               {
  1633.                  DelayM(20);           //去抖
  1634.                  if(KEY_4 == 0 ||workcode==4&& w == 0)
  1635.                         {
  1636.                         Beep_key();//按键音
  1637.                         workcode=0;
  1638.                         while(KEY_4 == 0);//等待键松开
  1639.                         key1Times--;
  1640.                         if (key1Times==0 ){key1Times = 6;}
  1641.                         }
  1642.                 }
  1643.                 if (KEY_2 == 0||workcode==6) //
  1644.               {
  1645.                  DelayM(20);           //去抖
  1646.                  if(KEY_2 == 0 ||workcode==6&& w == 0)
  1647.                         {
  1648.                         Beep_key();//按键音
  1649.                         workcode=0;
  1650.                         while(KEY_2 == 0);//等待键松开
  1651.                         key1Times++;
  1652.                         if (key1Times==7 ){key1Times = 1;}
  1653.                         }
  1654.                 }
  1655.         lcdClear();
  1656.         dispString(0, 0, 1, "    功能菜单    ");
  1657.         dispString(1, 0, 1, "1:界面    2:设置");
  1658.         dispString(2, 0, 1, "3:闹钟    4:音乐");
  1659.         dispString(3, 0, 1, "5:自检    6:退出");
  1660.         if (key1Times == 7)
  1661.         {
  1662.                 key1Times = 1;
  1663.         }

  1664.         switch(key1Times)
  1665.         {
  1666.                 case 1: convertChar(1, 0, 6);
  1667.                                 break;
  1668.                 case 2:        convertChar(1, 5, 6);
  1669.                                 break;
  1670.                 case 3: convertChar(2, 0, 6);
  1671.                                 break;
  1672.                 case 4: convertChar(2, 5, 6);
  1673.                                 break;
  1674.                 case 5: convertChar(3, 0, 6);
  1675.                                 break;
  1676.                 case 6: convertChar(3, 5, 6);
  1677.                                 break;
  1678.         }
  1679. }
  1680. if (KEY_3== 0||workcode==8||workcode==5) //
  1681.                          {
  1682.                                DelayM(20);
  1683.                                if(KEY_3 == 0 ||workcode==8||workcode==5)
  1684.                                              {                                
  1685.                                           Beep_set();//确定按键音
  1686.                                                   workcode=0;
  1687.                                                   if (key1Times==1 )
  1688.                                                   {if(k==0)
  1689.                                                   {k=1;
  1690.                                                   Write24c02(k,3);
  1691.                                                   }
  1692.                                                   else if(k==1)
  1693.                                                   {
  1694.                                                   k=2;
  1695.                                                   Write24c02(k,3);
  1696.                                                   }
  1697.                                                   else if(k==2)
  1698.                                                   {
  1699.                                                   k=0;
  1700.                                                   Write24c02(k,3);
  1701.                                                   }
  1702.                                                   lcdInit ();break;}
  1703.                                                   if (key1Times==2 ){clear_img();lcdClear();w=1;k=2;Set_time(e);break;}
  1704.                                                   if (key1Times==3 ){lcdClear();clear_img();k=3;break;}
  1705.                                                   if (key1Times==4 ){clear_img();lcdClear();displayPhoto(powerOnPhoto, OFF);Play(Music_wo,0,3,360);lcdInit ();break;}
  1706.                                                   if (key1Times==5 ){zijian(); break;}
  1707.                                                   if (key1Times==6 ){lcdInit (); break;}
  1708.                                                   
  1709.                                                   }
  1710.                                         }
  1711.   }
  1712. }
  1713. /*****************************************************************************/
  1714. //---主程序---//
  1715. /*****************************************************************************/
  1716. main()
  1717. {
  1718.     KEY_1 = 1;KEY_2 = 1;KEY_3 = 1;KEY_4 = 1;//初始键盘
  1719.         yy=0xff;mo=0xff;dd=0xff;xq=0xff;hh=0xff;mm=0xff;ss=0xff; //各数据刷新
  1720.         Beep_set();//确定按键音        
  1721.     InitialSound();
  1722.         beep=1;
  1723.         Init_1302();
  1724.         lcdWriteCommand(0x30);       //选择8bit数据流
  1725.     lcdWriteCommand(0x0c);       //开显示(无游标、不反白)
  1726.     lcdWriteCommand(0x01);       //清除显示,并且设定地址指针为00H
  1727.         lcdClear();
  1728.     displayPhoto(powerOnPhoto1, OFF); //此处为《小东电子》图片代码,可以更改为你喜欢的图片代码
  1729.         DelayM(2000); //显示等留4秒
  1730.         lcdClear();
  1731.         dispString(0, 0, 1, "┏━红外遥控━┓");
  1732.         dispString(1, 0, 1, "┃12864 LCD V8┃");
  1733.         dispString(2, 0, 1, "┃多功能万年历┃");
  1734.         dispString(3, 0, 1, "┗━━━━━━┛");
  1735.         DelayM(2000); //显示等留2秒
  1736.         lcdInit ();
  1737.         c_sun=0;
  1738.         n=Read24c02(0);
  1739.         k=Read24c02(3);
  1740.         if(k>2||k<0) k=0;
  1741.         EX0= 1;                //使能 INT0 外部中断
  1742.         IT0 =1;      //外中断0下降沿触发
  1743.         IR_GET=1;         //I/O口初始化
  1744.         EA=1;                //开总中断
  1745.          
  1746. /*****************************************************************************/
  1747.         while(1)
  1748.                 {//主循环
  1749.         if(k==2){updata ();}
  1750.                 if(k==0){disp_sfm();}
  1751.                 if(k==1){disp_sfm1();}
  1752.                 if(k==3){naozhong();}
  1753.                 if(n==1||n==2||n==3){naozhongdao();}                                
  1754.                 //------------------------------------------------------------------

  1755.                 if (KEY_3 == 0||workcode==5) // 设置时间
  1756.                                       {
  1757.                                     DelayM(10);           //去抖
  1758.                                         if((KEY_3 == 0&& w == 1)||(workcode==5&& w == 1)) //当是调时状态 本键用于调整下一项
  1759.                                                 {
  1760.                                                 Beep_key();//按键音
  1761.                                                 workcode=0;
  1762.                                                 e++;
  1763.                                                 if (e >= 7 ){e = 0;}
  1764.                                                 Set_time(e);//调整                                
  1765.                                     }
  1766.                                         if((KEY_3 == 0&& w == 0)||(workcode==5&& w == 0))  //当是调时状态 本键用于调整下一项
  1767.                                                 {
  1768.                                                 workcode=0;
  1769.                                                 lcdWriteCommand(0x30);       //选择8bit数据流
  1770.                         lcdWriteCommand(0x0c);       //开显示(无游标、不反白)
  1771.                         lcdWriteCommand(0x01);       //清除显示,并且设定地址指针为00H
  1772.                                                 Beep_key();//按键音
  1773.                                                 procKey ();                                
  1774.                                     }
  1775.                                                 while(KEY_3 == 0);//等待键松开
  1776.                          }
  1777.                 //------------------------------------------------------------------
  1778.                 if ((KEY_1 == 0&& w == 1) ||(workcode==9&& w == 1))// 当在调时状态时就退出调时
  1779.                          {
  1780.                                DelayM(20);
  1781.                                if((KEY_1 == 0&& w == 1) ||(workcode==9&& w == 1))
  1782.                                              {                                
  1783.                                           Beep_set();//确定按键音
  1784.                                                   workcode=0;
  1785.                                           w = 0;          //退出调时
  1786.                                           e = 0;                //“下一项”计数器清0
  1787.                                                   convertChar(0, 0, 0);
  1788.                                                   lcdInit ();                                                               
  1789.                                      }
  1790.                                         }
  1791.                 if ((KEY_1 == 0&& w == 0) ||(workcode==2&& w == 0))// 当在调时状态时就退出调时
  1792.                          {
  1793.                                DelayM(20);
  1794.                                if((KEY_1 == 0&& w == 0) ||(workcode==2&& w == 0))
  1795.                                              {
  1796.                                                  workcode=0;                                
  1797.                                                  lcdWriteCommand(0x30);       //选择8bit数据流
  1798.                          lcdWriteCommand(0x0c);       //开显示(无游标、不反白)
  1799.                          lcdWriteCommand(0x01);       //清除显示,并且设定地址指针为00H
  1800.                                                  displayPhoto(powerOnPhoto, OFF);
  1801.                                                  Play(Music_wo,0,3,360);
  1802.                                                  lcdInit ();
  1803.                                                  }
  1804.                                  while(KEY_1 == 0);//等待键松开
  1805.                         }
  1806.                 //------------------------------------------------------------------
  1807.                 if ((KEY_2 == 0&& w == 1)||(workcode==3 && w == 1)) // 加减调整
  1808.                          {
  1809.                              DelayM(5);
  1810.                              if((KEY_2 == 0&& w == 1)||(workcode==3 && w == 1))
  1811.                                   {                                
  1812.                                        Set_time(e);//调整
  1813.                                            workcode=0;
  1814.                                            Beep_key();//按键音
  1815.                                   }
  1816.                             while(KEY_2 == 0);//等待键松开
  1817.                        }
  1818.                 //------------------------------------------------------------------
  1819.                 if ((KEY_4 == 0&& w == 1)||(workcode==7&& w == 1))// 加减调整
  1820.                         {               
  1821.                                 DelayM(5);
  1822.                              if((KEY_4 == 0&& w == 1)||(workcode==7&& w == 1))
  1823.                                      {                                
  1824.                                        Set_time(e);//调整
  1825.                                            workcode=0;
  1826.                                            Beep_key();//按键音
  1827.                                  }
  1828.                              while(KEY_4 == 0);//等待键松开
  1829.                       }
  1830.                         //------------------------------------------------------------------
  1831.                 if (workcode==1)// 加减调整
  1832.                         {               
  1833.                                 DelayM(5);
  1834.                              if(workcode==1)
  1835.                                      {                                
  1836.                                            Beep_key();//按键音
  1837.                                             lcdWriteCommand(0x30);       //选择8bit数据流
  1838.                         lcdWriteCommand(0x0c);       //开显示(无游标、不反白)
  1839.                         lcdWriteCommand(0x01);       //清除显示,并且设定地址指针为00H
  1840.                                                 dispString(0, 0, 1, "┏━红外遥控━┓");
  1841.                             dispString(1, 0, 1, "┃12864 LCD V7┃");
  1842.                             dispString(2, 0, 1, "┃多功能万年历┃");
  1843.                             dispString(3, 0, 1, "┗  待机界面  ┛");
  1844.                                                 workcode=10;
  1845.                                  }
  1846.                              while(workcode==10);//等待键松开
  1847.                                   workcode=10;
  1848.                                   Beep_set();
  1849.                                   lcdInit ();
  1850.                       }
  1851.   }
  1852. }

  1853. /*****************************************************************************/
  1854.                                   //外部中断0服务函数
  1855. /*****************************************************************************/


  1856. void intt_0() interrupt 0 //下降沿触发:接收不到红外时OUT高电平,接收到红外时OUT低电平。
  1857. {
  1858.         uchar four,one,num=0;
  1859.         EX0 = 0;   //关中断0使能,防止处理过程中再接收红外信号
  1860.         DelayM(2);          //稍延时2ms,防干扰
  1861.         if (IR_GET) //再检测红外接收脚(9ms的前导低电平),为高电平说明是干扰
  1862.         {
  1863.                 EX0 =1;         //使能中断0
  1864.                 return;         //退出中断程序
  1865.         }
  1866.         while(!IR_GET);     //等IR变为高电平,跳过9ms的前导低电平信号。
  1867.         while (IR_GET);    //等 IR 变为低电平,跳过4.5ms的前导高电平信号。
  1868.         for (four=0;four<4;four++)  //四组数据
  1869.         {
  1870.                 for (one=0;one<8;one++)   //每组数据8位
  1871.                 {
  1872.                         while (!IR_GET);  //等 IR 变为高电平
  1873.                         while (IR_GET)    //计算IR高电平时长(低电平时长是一样的,不用计)
  1874.                         {
  1875.                                 delay100us(1);  //计时
  1876.                                 num++;      //计时N次     
  1877.                                 if (num>=20)        //17*0.1ms=1.7ms
  1878.                                 {                 //数据“1”的时长最长也就1.685ms,计数超过则数据错误,退出中断
  1879.                                         EX0=1;        //使能中断0
  1880.                                         return;        //退出中断
  1881.                                 }                  
  1882.                         }    //高电平计数完毕     
  1883.                         RXDDATA[four]>>=1;          //从低位读出,随着one的循环8次刚好读出一字节
  1884. //                        if(num<6)  //6*0.1ms=0.6ms, 0.565ms<0.6ms<1.685ms
  1885. //                                RXDDATA[j]|=0x00;   //数据“0”
  1886.                         if(num>6&&num<20)         // 17*0.1ms=1.7ms>1.685ms
  1887.                                 RXDDATA[four]|=0x80;  //数据“1”
  1888.                         num=0; //计时值清0,为下一位数据的计时做准备
  1889.                 }//一组数据接收结束
  1890.         }//全部四组数据接收结束
  1891.         if(RXDDATA[0]!=0x00)  //比较用户码(请根据自己的遥控板修改)
  1892.         {
  1893.                 EX0=1;         //使能中断0
  1894.                 return;   //退出中断
  1895.         }
  1896.         if(RXDDATA[1]!=0xff)  //比较用户码(请根据自己的遥控板修改)
  1897.         {
  1898.                 EX0=1;         //使能中断0
  1899.                 return;   //退出中断
  1900.         }
  1901.         if (RXDDATA[2]!=~RXDDATA[3])  //检测接收到的数据是否正确
  1902.         {                           //不正确则
  1903.                 EX0=1;           //使能中断0
  1904.                 return;   //退出中断
  1905.         }

  1906.         workcode=workIRcode(RXDDATA);        //处理红外编码,返回键值

  1907.         EX0 = 1;         //处理完红外接收,使能中断0,退出中断0
  1908. }
  1909.         
复制代码

所有资料51hei提供下载:
12864红外遥控万年历V8源代码 未改.7z (149.67 KB, 下载次数: 28)

评分

参与人数 1黑币 +5 收起 理由
清风兑酒 + 5 很给力!要是有全套资料就完美了

查看全部评分

回复

使用道具 举报

ID:312128 发表于 2019-3-24 21:56 | 显示全部楼层
此帖仅作者可见

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表