久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

標題: LCD12864紅外遙控萬年歷V8單片機源代碼 未改 [打印本頁]

作者: 電d子z    時間: 2018-12-5 14:07
標題: LCD12864紅外遙控萬年歷V8單片機源代碼 未改
公歷轉換農歷
公歷與農歷是我國目前并存的兩種歷法,各有其固有的規律,農歷與月球的運行相對應,其影響因素多,它的大小月和閏月與天體運行有關,計算十分復雜,且每年都不一致,因此要用單片機實現公歷與農歷的轉換用查表法是最方便實用的辦法。
計算公歷日對應的農歷日期的方法是先計算出公歷日離當年元旦的天數,然后查表取得當年的春節日期,計算出春節離元旦的天數,二者相減即可算出公歷日離春節的天數,以后只要根據大小月和閏月信息減一月天數,調整一月農歷月份,即可推算出公歷日所對應的農歷日期,如公歷日不到春節日期,農歷年要比公歷年小一年,農歷大小月取前一年的信息,農歷月從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、蜂鳴器請最好使用無源蜂鳴器或小喇叭,這樣音質會很好。





單片機源程序如下:
  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, 下載次數: 29)








歡迎光臨 (http://www.zg4o1577.cn/bbs/) Powered by Discuz! X3.1
主站蜘蛛池模板: 国产精品久久久久久久午夜片 | 国产视频三级 | 99爱在线观看 | 网站黄色在线免费观看 | 91一区二区 | 超碰97在线免费 | 久久综合影院 | 国产一级一片免费播放 | 亚洲a网| 日韩在线不卡视频 | 中文字幕一区在线观看视频 | 亚洲高清在线观看 | 欧美在线不卡 | 免费看啪啪网站 | 欧美久久久久 | 成人国产精品久久 | 久久久女女女女999久久 | 亚洲精品日韩综合观看成人91 | 精品福利在线 | 在线观看中文字幕亚洲 | 91亚洲国产成人久久精品网站 | 欧美精品欧美精品系列 | 日韩电影中文字幕 | 国产免费一区 | 国产精品美女久久久久久免费 | 国产综合久久 | 一级毛片免费完整视频 | 亚洲精品视频在线播放 | 男女污网站 | 麻豆国产一区二区三区四区 | 日韩国产欧美一区 | 2018国产精品 | 欧美色性| 欧美久久久网站 | 国产精品视频一区二区三区四蜜臂 | 成人中文字幕av | 美女久久久久 | 亚洲高清免费视频 | 日韩精品成人一区二区三区视频 | 色毛片 | 国产在线一区二 |