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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 8588|回復: 12
打印 上一主題 下一主題
收起左側

DIY集MP3、電子時鐘、電子音樂于一體的夢幻十字旋轉屏

  [復制鏈接]
跳轉到指定樓層
樓主
今天比較空閑,發個最近的作品到51hei論壇。先再看總體介紹圖

但是,我這個DIY作品為了能跟大家分享,讓更多的愛好者看到,我還是決定要發到這個版塊來哈
當然,十字旋轉屏不是我原創的了,這個東西很早以前就有了,但是本著弘揚DIY精神的態度,
我可不局限于只是讓旋轉屏滾動顯示文字就罷了……所以全新的DIY開始了……
由于這個東西是今年4月份左右弄的,弄好后送給MM了,現在也拿不回來了哈~~
所以下面介紹的圖片是以前留下的,所以要詳細說制作過程比較難了…
剛傳了視頻,也先讓大家看看以下留下的視頻效果……看完視頻后我再用保留下來的圖片和原理圖、程序等盡可能的向大家
介紹以前的制作過程!
其實,我最想向大家分享的是這個顯示屏的程序,我寫這個程序的時候,由于網上資料不全,我自己弄了幾天才終于搞墊了哈
!


看完視頻,我將開始介紹DIY過程……
1、主旋轉屏底盒及電路等
我也去網上看過不少DIY高手用身邊的材料做的旋轉屏(有十字立體的,也有平面的),我也很是佩服。但是看來看去,他們說的材料我都不太有,而且我這個東西做出來后需要有一定的耐用性和美觀性(因為要送MM嘛),所以最后主旋轉屏是買了網上的套件來焊接組裝。


,
買回到的套件是這樣子的






這是原理圖。
具體的安裝方法等等我就不多做介紹了,因為那是別人的東西了,我再說出來,只能說我剽竊別人的,具體參考這賣套件的這個鏈接吧,他們上面有說明http://item.taobao點com/item.htm?spm=0.0.0.33.yS9Nym&;id=12577599101
而我下面主要說我對這個套件進行改裝DIY的部分:
2、電源
電源我原來是用5V手機直充供電的,但由于是無線供電,最后到達頂部旋轉屏的電壓供不上(其實主要不是電壓供不到,而是旋轉屏點亮后,整體功率增強,就會導致輸出的有效電壓迅速下降,從而低于單片機的正常工作電壓),導致單片機無**常工作,所以為了提高輸出功率,只能提高電壓。我試過用9V的開關電源,可以正常工作,但電壓太高就會導致互初正反饋振蕩電路(在底盒內部)的三極管溫度很高,所以最終我去二手市場花了4塊錢買了一個諾基亞的直充,上面標稱是輸出5.7V,我用萬用表量過,也差不多,剛好合適哈,我再在次級線圈上多繞了幾圈,次級感應出來的電壓就更大,更合適了。
3、頂部旋轉屏DIY
原來的套件使用的是STC89C51RC的單片機,我為了能多寫點程序和添加功能,我換成了52的單片機




看上面的圖片,大家會發現,我自己用洞洞板加了一個DS1302的時鐘模塊進去,同時還添加了一體化紅外接收頭用于調時間和控制顯示。特別說明一下,一般51單片機有4個IO口,而這個旋轉屏套件是兩個(紅色和綠色)16路流水燈直接加限流電阻后連到單片機的32個IO口,所以按理來說單片機的IO口已全部占用。但是這個單片機不是一般的51單片機,它還有4個P4的IO口。這多出來的4個IO口,一個我用于普通紅外接收(用于編程時控制顯示的),一個用于一體化紅外接收頭,另外兩個用于接DS1302,但DS1302一共要接三根線,另外一個IO口哪里來呢?實際上另一根線我接到了其中一個綠色LED上,所以,時間的顯示只能顯示紅色,而且看視頻你會發現顯示時間時上面有一綠色的燈環在亮,這是DS1302控制線控制綠色LED發出來的。具體的,各位高手看我程序就懂了。對于P4口的定義等等,可以參考我的C程序哈~~




還有,我用到的遙控器是這種常用車載MP3的遙控器,估計現在很多開發板也是附帶這種紅外遙控器,可以對時間和顯示進行控制。



4、底盒內部電路介紹
底部的DIY才是我自己的核心哈。








下面從左到右給大家介紹一下:
(1)最左邊是一些開關和接口,主要有MP3耳機接口、電源輸入接口,開關主要有MP3獨立總開關、旋轉屏總開關、電機開關、電子音樂開關。
(2)MP3模塊
MP3模塊是買網上的夾子MP3


就是這種,大概10塊錢左右。里面主要就是一個MP3解碼芯片,把外殼去掉,在底盒合適位置鑿個洞就裝上去了哈,MP3模塊的供電也是直接接電源接口(5.7v)。因為電源是接到MP3模塊的USB接口上,本應5V供電,現在電壓過高了,因此為了保險起見,串聯了一個1N4007二極管才按到MP3模塊的USB接口的,這樣1N4007降了0.6-0.7V左右,MP3模塊就可以工作了。但是實際卻發現,有時給MP3供電卻沒反應,后面想到,平時MP3模塊不工作時,兩條電源線呈高阻狀態,而1N4007要導通工作時,兩端要有0.2V左右的壓降,因此,在1N4007輸出端我加了一個20K的下拉電阻哈,電路就像下面這樣子


,這樣就保證每次都可以上電啟動MP3了。
還有耳機的接口啊什么的,在底盒左側我都重新單獨弄出來,接法就不說了,大家都懂的。
MP3我弄有單獨的總開關,在左上角位置,同時MP3的五個按鍵我也全部引出來了,那幾個按鍵大家參考一下插卡MP3的原理圖就會發現,那是模擬按鍵,而不是數字按鍵。因此,好像五個按鍵我一共引出了八條線出來,有三條是公共的,還是五條是分別控制五個按鍵。而且節省體積,我引出的引線是用爛耳機里面的漆包線作為導線的,同時上面連DS1302模塊也是用那種線。下面是最終安裝好的MP3效果圖






(3)無線供電模塊
這個就不用多做介紹了,我是用洞洞板做的,電路圖參考上面主旋轉屏的原理圖,我加了散熱,并固定好,同時,在該模塊下面還是一個紅外發射LED,是配合頂部旋轉屏編程顯示的。
(4)電子音樂
我使用的是普通的固化了語音內容的音樂IC,增加了一點電子韻味哈,這個模塊也是在51電子淘寶來的,


,參考電路也是上面這個,但是我沒用揚聲器,節省體積我用了有源蜂鳴器代替(注意一定要用有源的蜂鳴器,無源的聲音很。瑫r該模塊工作電壓比較小,我直接加了100歐左右的電阻分壓就可以了。這個模塊我也加了獨立的開關,因為電機的工作有很大的干擾,因此在這個音樂IC的電源輸入端我加了100UF的濾波電容。
(5)MP3外揚電路
為實現MP3外揚,有使用了TDA2822功放芯片,并加大了輸入電源的濾波(220UF,盡量大,因為電機干擾),出來的聲音勉強可以了哈。如果從MP3音頻插口直接輸入到TDA2822的聲音過大失真嚴重的話,可以在輸入線按一個10-20K左右的電阻下拉到地線,這樣聲音就柔和適合多了。電路原理圖參考下面



同時,剛才的耳機接口要用那種五個腳帶開關的音頻插座,這樣就可以實現插入耳機后斷開送入TDA2822的音源。在該模塊下面有一個0.5W的小喇叭,通過上面的紅外說明上面的洞洞發出聲音。如下



(6)電機調速
按照原來的套件,電機是直接接到一個1N4007的兩端通過1N4007兩端的壓降供電的(大概0.6-0.7V),但這樣的供電在實際中,電機會轉得很慢。又因為我在頂部加了時鐘模塊和其它的,不加大電機電壓,轉速跟不上,顯示時會非常閃爍的,所以我用了CW317可調穩壓IC對電機進行調壓?赡苡行┡笥丫驼f了,干嘛不直接串聯一個電阻到電機就可以了,干嘛那么麻煩。首先,電阻串聯是可以的,但電阻阻值會隨著產熱發生改變,加上直流電機本身的阻值不是很高,要串聯的電阻是也是比較低的,電阻產熱會很高,就導致到電機的電壓不穩定,即影響轉速,又不穩定了。所以最后還是用CW317進行穩壓調速。其電路很簡單,大家參考CW317芯片的經典接法就是了。
(7)其他
還買了個七彩LED,在底盒頂部用電鉆打了一些小洞組成一個“心”形,在心形中間把這個七彩LED裝上,這些小洞既可以來給底盒的互初正反饋振蕩電路散熱,又有其他的意思哈




~~還有其他的旋轉屏顯示效果,只是真正見識到了我這人DIY作品才能感受得到的哈。
到現在,DIY過程也介紹得差不多了,因為制作過程中沒留有相片,只能靠現在的口述了……
感興趣的朋友,制作過程中有什么問題的都可以向我交流探討哈
最后,分享我的程序,這個程序可是原創的哦,有什么建議或問題再交流了哈…………
程序發下: 十字旋轉LED紅外時鐘程序.rar (69.28 KB, 下載次數: 36)

,
最后,算算我這個東西大概一共花了七八十塊錢左右哈,但功能很多,也夠炫了哈~~
最后還有一點相片分享哈~~









分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏1 分享淘帖 頂 踩
回復

使用道具 舉報

沙發
ID:1 發表于 2014-12-20 01:16 | 只看該作者
作品很牛,以下是主程序方便大家預覽:
  1. #include <reg52.h>
  2. #include <intrins.h>
  3. #include "LED_STRING.h"
  4. #include "DS1302.h"

  5. sfr XICON=0xc0;                                 //定義STC89C52中斷特殊功能寄存器

  6. sbit PX3=XICON^7;
  7. sbit EX3=XICON^6;
  8. sbit IE3=XICON^5;
  9. sbit IT3=XICON^4;
  10. sbit PX2=XICON^3;
  11. sbit EX2=XICON^2;
  12. sbit IE2=XICON^1;
  13. sbit IT2=XICON^0;

  14. sbit IR=P4^2;                        //紅外
  15. uchar a[4];                         //存儲紅外解出來的廠家編碼和鍵碼值及它們的反碼
  16. uint LowTime,HighTime;         //存儲高低電平寬度的變量
  17. uchar L_OnTime,display_flag,time_count,time_count0,time_count1,effect;
  18. uchar led_0,led_1,display_n,KeyVal;
  19. bit IR_Flag,display_time_flag,set_second_flag;
  20. uchar set_count,set_year,set_month,set_day,set_week;
  21. char set_hour,set_minute,set_second;
  22. uchar set_year_tmp,set_month_tmp,set_day_tmp,set_week_tmp,set_hour_tmp,set_minute_tmp;

  23. /*延遲機器周期級的短延遲*/
  24. void delay(uchar z)
  25. {
  26.         while (z--)
  27.         _nop_();
  28. }

  29. /*開機初始畫面*/
  30. void open_display()
  31. {
  32.         uchar i;
  33.         uint led_0,led_1,count,num;
  34. L_OnTime++;
  35. num++;
  36. count=num;
  37. if(num>(16*15))
  38. {
  39. display_flag=1;
  40. TR1=1;
  41. }
  42.         if(L_OnTime>65) L_OnTime=65;

  43.         for(i=0;i<L_OnTime;i++)
  44.                 {
  45.                 count--;
  46.                 led_0=count*2+1;
  47.                 led_1=count*2;
  48.                 delay(60);
  49.                 P3=tab_open[led_0];
  50.                 P1=tab_open[led_1];
  51.                 P0=tab_open[led_0];
  52.                 P2=tab_open[led_1];
  53.                 delay(30);
  54.                 P1=0xff;
  55.                 P3=0xff;
  56.                 P0=0xff;
  57.                 P2=0xff;
  58.                 delay(3);
  59.                 }
  60. }


  61. /*LOVE畫面*/
  62. void love_display()
  63. {
  64.         uchar i;
  65.         uint led_0,led_1,count,num;

  66. L_OnTime++;
  67. num++;
  68. count=num;
  69. if(num>(16*13)) num=0;
  70.         if(effect==0)
  71.         {
  72.                 if(L_OnTime>65) L_OnTime=65;
  73.         }
  74.         else
  75.         {
  76.                 if(L_OnTime>125) L_OnTime=125;
  77.         }

  78.         for(i=0;i<L_OnTime;i++)
  79.                 {
  80.                 count--;
  81.                 led_0=count*2+1;
  82.                 led_1=count*2;
  83.                 delay(60);
  84.                         if(effect==0)
  85.                         {
  86.                         P3=tab_love[led_0];
  87.                         P1=tab_love[led_1];
  88.                         P0=tab_love[led_0];
  89.                         P2=tab_love[led_1];
  90.                         }
  91.                         else if(effect==1)
  92.                         {
  93.                         P0=tab_love[led_0];
  94.                         P2=tab_love[led_1];
  95.                         }
  96.                         else
  97.                         {
  98.                         P3=tab_love[led_0];
  99.                         P1=tab_love[led_1];
  100.                         }
  101.                 delay(30);
  102.                 P1=0xff;
  103.                 P3=0xff;
  104.                 P0=0xff;
  105.                 P2=0xff;
  106.                 delay(3);               
  107.                 }
  108. }

  109. /*顯示“年、月、日、星期”*/
  110. void time0_display()
  111. {
  112. uchar time_count0=8;
  113. uchar time_count1=16;
  114. int time_count=159;
  115. uchar i;
  116. uchar L_0=159;
  117.         for(i=0;i<L_0;i++)
  118.         {
  119.                 if(time_count>143&&time_count<160)                                        //星期值
  120.                 {
  121.                 led_0=((ReadSet1302(0x8b)&0x0f)-1)*32+(time_count1*2)-1;
  122.                 led_1=((ReadSet1302(0x8b)&0x0f)-1)*32+(time_count1*2)-2;
  123.                 P3=tab_xingqi[led_0];
  124.                 P1=tab_xingqi[led_1];
  125.                 if(--time_count1<1) time_count1=16;
  126.                 }
  127.                 else if(time_count>127&&time_count<144)                                        //“期“
  128.                 {                                                                       
  129.                 led_0=3*32+(time_count1*2)-1;
  130.                 led_1=3*32+(time_count1*2)-2;
  131.                 P3=tab_time[led_0];
  132.                 P1=tab_time[led_1];
  133.                 delay(65);
  134.                 if(--time_count1<1) time_count1=16;
  135.                 }

  136.                 else if(time_count>111&&time_count<128)                                        //“星“
  137.                 {                                                                       
  138.                 led_0=2*32+(time_count1*2)-1;
  139.                 led_1=2*32+(time_count1*2)-2;
  140.                 P3=tab_time[led_0];
  141.                 P1=tab_time[led_1];
  142.                 delay(65);
  143.                 if(--time_count1<1) time_count1=16;
  144.                 }


  145.                 else if(time_count>95&&time_count<112)                                        //“日“
  146.                 {                                                                       
  147.                 led_0=6*32+(time_count1*2)-1;
  148.                 led_1=6*32+(time_count1*2)-2;
  149.                 P3=tab_xingqi[led_0];
  150.                 P1=tab_xingqi[led_1];
  151.                 delay(65);
  152.                 if(--time_count1<1) time_count1=16;
  153.                 }

  154.                 else if(time_count>87&&time_count<96)                                                                  //”日“ 個位
  155.                 {
  156.                 led_0=((ReadSet1302(0x87)&0x0f)*16)+(time_count0*2)-1;
  157.                 led_1=((ReadSet1302(0x87)&0x0f)*16)+(time_count0*2)-2;
  158.                 P3=tab_num[led_0];
  159.                 P1=tab_num[led_1];
  160.                 if(--time_count0<1) time_count0=8;
  161.                 }
  162.                 else if(time_count>79&&time_count<88)                                                                 //”日“ 十位
  163.                 {
  164.                 led_0=((ReadSet1302(0x87)>>4)*16)+(time_count0*2)-1;
  165.                 led_1=((ReadSet1302(0x87)>>4)*16)+(time_count0*2)-2;
  166.                 P3=tab_num[led_0];
  167.                 P1=tab_num[led_1];
  168.                 if(--time_count0<1) time_count0=8;
  169.                 }
  170.                                
  171.                 else if(time_count>63&&time_count<80)                                        //“月“       
  172.                 {                                                               
  173.                 led_0=1*32+(time_count1*2)-1;
  174.                 led_1=1*32+(time_count1*2)-2;
  175.                 P3=tab_time[led_0];
  176.                 P1=tab_time[led_1];
  177.                 delay(65);
  178.                 if(--time_count1<1) time_count1=16;
  179.                 }
  180.                                                                                                                                        
  181.                 else if(time_count>55&&time_count<64)                                                                  //”月“ 個位
  182.                 {
  183.                 led_0=((ReadSet1302(0x89)&0x0f)*16)+(time_count0*2)-1;
  184.                 led_1=((ReadSet1302(0x89)&0x0f)*16)+(time_count0*2)-2;
  185.                 P3=tab_num[led_0];
  186.                 P1=tab_num[led_1];
  187.                 if(--time_count0<1) time_count0=8;
  188.                 }
  189.                 else if(time_count>47&&time_count<56)                                                                 //”月“ 十位
  190.                 {
  191.                 led_0=((ReadSet1302(0x89)>>4)*16)+(time_count0*2)-1;
  192.                 led_1=((ReadSet1302(0x89)>>4)*16)+(time_count0*2)-2;
  193.                 P3=tab_num[led_0];
  194.                 P1=tab_num[led_1];
  195.                 if(--time_count0<1) time_count0=8;                                                                                                                        
  196.                 }

  197.                 else if(time_count>31&&time_count<48)                                        //“年“       
  198.                 {                                                               
  199.                 led_0=0*32+(time_count1*2)-1;
  200.                 led_1=0*32+(time_count1*2)-2;
  201.                 P3=tab_time[led_0];
  202.                 P1=tab_time[led_1];
  203.                 delay(65);
  204.                 if(--time_count1<1) time_count1=16;
  205.                 }

  206.                 else if(time_count>23&&time_count<32)                                                                  //”年“ 個位
  207.                 {
  208.                 led_0=((ReadSet1302(0x8d)&0x0f)*16)+(time_count0*2)-1;
  209.                 led_1=((ReadSet1302(0x8d)&0x0f)*16)+(time_count0*2)-2;
  210.                 P3=tab_num[led_0];
  211.                 P1=tab_num[led_1];
  212.                 if(--time_count0<1) time_count0=8;
  213.                 }
  214.                 else if(time_count>15&&time_count<24)                                                                 //”年“ 十位
  215.                 {
  216.                 led_0=((ReadSet1302(0x8d)>>4)*16)+(time_count0*2)-1;
  217.                 led_1=((ReadSet1302(0x8d)>>4)*16)+(time_count0*2)-2;
  218.                 P3=tab_num[led_0];
  219.                 P1=tab_num[led_1];
  220.                 if(--time_count0<1) time_count0=8;                                                                                                                        
  221.                 }
  222.                 else if(time_count>7&&time_count<16)                                                                 //"0"
  223.                 {
  224.                 led_0=(0*16)+(time_count0*2)-1;
  225.                 led_1=(0*16)+(time_count0*2)-2;
  226.                 P3=tab_num[led_0];
  227.                 P1=tab_num[led_1];
  228.                 delay(70);                                                                                                                                //延遲,使得在這里處理的時間與處理1302的時間相同
  229.                 if(--time_count0<1) time_count0=8;
  230.                 }
  231.                 else if(time_count>=0&&time_count<8)                                                                 //"2"
  232.                 {
  233.                 led_0=(2*16)+(time_count0*2)-1;
  234.                 led_1=(2*16)+(time_count0*2)-2;
  235.                 P3=tab_num[led_0];
  236.                 P1=tab_num[led_1];
  237.                 delay(70);                                                                                                                                //延遲,使得在這里處理的時間與處理1302的時間相同
  238.                 if(--time_count0<1) time_count0=8;
  239.                 }

  240.         if(--time_count<0)
  241.         {
  242.         time_count=159;
  243.         time_count0=8;
  244.         time_count1=16;
  245.         }

  246.         }
  247.                 delay(95);
  248.                 P3=0xff;
  249.                 P1=0xff;
  250.                 delay(5);
  251. }

  252. /*顯示“時、分、秒”*/
  253. void time1_display()
  254. {
  255. uchar time_count1=8;
  256. char time_count=79;
  257. uchar i;
  258. uchar L_0=79;
  259.         for(i=0;i<L_0;i++)
  260.         {
  261.                 if(time_count>63)
  262.                 {
  263.                 delay(123);                                                                  //整屏左移
  264.                 }
  265.                 else if(time_count>55&&time_count<64)                                                                                                         //秒個位
  266.                 {
  267.                 led_0=((ReadSet1302(0x81)&0x0f)*16)+(time_count1*2)-1;
  268.                 led_1=((ReadSet1302(0x81)&0x0f)*16)+(time_count1*2)-2;
  269.                 P3=tab_num[led_0];
  270.                 P1=tab_num[led_1];
  271.                 }
  272.                 else if(time_count>47&&time_count<56)                                                                  //秒十位
  273.                 {
  274.                 led_0=((ReadSet1302(0x81)>>4)*16)+(time_count1*2)-1;
  275.                 led_1=((ReadSet1302(0x81)>>4)*16)+(time_count1*2)-2;
  276.                 P3=tab_num[led_0];
  277.                 P1=tab_num[led_1];
  278.                 }
  279.                 else if(time_count>39&&time_count<48)                                                                   //冒號
  280.                 {
  281.                 led_0=(10*16)+(time_count1*2)-1;
  282.                 led_1=(10*16)+(time_count1*2)-2;
  283.                 P3=tab_num[led_0];
  284.                 P1=tab_num[led_1];
  285.                 delay(70);                                                                                                                                //延遲,使得在這里處理的時間與處理1302的時間相同
  286.                 }
  287.                 else if(time_count>31&&time_count<40)                                                                   //分個位
  288.                 {
  289.                 led_0=((ReadSet1302(0x83)&0x0f)*16)+(time_count1*2)-1;
  290.                 led_1=((ReadSet1302(0x83)&0x0f)*16)+(time_count1*2)-2;
  291.                 P3=tab_num[led_0];
  292.                 P1=tab_num[led_1];
  293.                 }
  294.                 else if(time_count>23&&time_count<32)                                                                   //分十位
  295.                 {
  296.                 led_0=((ReadSet1302(0x83)>>4)*16)+(time_count1*2)-1;
  297.                 led_1=((ReadSet1302(0x83)>>4)*16)+(time_count1*2)-2;
  298.                 P3=tab_num[led_0];
  299.                 P1=tab_num[led_1];
  300.                 }
  301.                 else if(time_count>15&&time_count<24)                                                                   //冒號
  302.                 {
  303.                 led_0=(10*16)+(time_count1*2)-1;
  304.                 led_1=(10*16)+(time_count1*2)-2;
  305.                 P3=tab_num[led_0];
  306.                 P1=tab_num[led_1];
  307.                 delay(70);
  308.                 }
  309.                 else if(time_count>7&&time_count<16)                                                                   //時個位
  310.                 {
  311.                 led_0=((ReadSet1302(0x85)&0x0f)*16)+(time_count1*2)-1;
  312.                 led_1=((ReadSet1302(0x85)&0x0f)*16)+(time_count1*2)-2;
  313.                 P3=tab_num[led_0];
  314.                 P1=tab_num[led_1];
  315.                 }
  316.                 else if(time_count>=0&&time_count<8)                                                                   //時十位
  317.                 {
  318.                 led_0=((ReadSet1302(0x85)>>4)*16)+(time_count1*2)-1;
  319.                 led_1=((ReadSet1302(0x85)>>4)*16)+(time_count1*2)-2;
  320.                 P3=tab_num[led_0];
  321.                 P1=tab_num[led_1];
  322.                 }
  323.         if(--time_count1<1) time_count1=8;
  324.         if(--time_count<0)
  325.         {
  326.         time_count=79;
  327.         time_count1=8;
  328.         }

  329.         }
  330.                 delay(95);
  331.                 P3=0xff;
  332.                 P1=0xff;
  333.                 delay(5);


  334. }


  335. /*調“年、月、日、星期、時、分、秒”*/

  336. void set_time_display()
  337. {

  338. uchar time_count0=8;
  339. uchar time_count1=16;
  340. int time_count=71;
  341. uchar i;
  342. uchar L_0=71;
  343.                 switch(set_count)
  344.                 {
  345.                         case 1:
  346.                         {
  347.                         for(i=0;i<L_0;i++)
  348.                         {
  349.                                 if(time_count>55)
  350.                                 {
  351.                                 delay(85);                                                                  //整屏左移
  352.                                 }
  353.                                 else if(time_count>47&&time_count<56)
  354.                                 {
  355.                                 led_0=(set_year%10)*16+(time_count0*2)-1;
  356.                                 led_1=(set_year%10)*16+(time_count0*2)-2;
  357.                                 P3=tab_num[led_0];
  358.                                 P1=tab_num[led_1];
  359.                                 if(--time_count0<1) time_count0=8;
  360.                                 }
  361.                                 else if(time_count>39&&time_count<48)
  362.                                 {
  363.                                 led_0=(set_year/10)*16+(time_count0*2)-1;
  364.                                 led_1=(set_year/10)*16+(time_count0*2)-2;
  365.                                 P3=tab_num[led_0];
  366.                                 P1=tab_num[led_1];
  367.                                 if(--time_count0<1) time_count0=8;
  368.                                 }
  369.                                 else if(time_count>31&&time_count<40)                           //冒號
  370.                                 {
  371.                                 led_0=(10*16)+(time_count0*2)-1;
  372.                                 led_1=(10*16)+(time_count0*2)-2;
  373.                                 P3=tab_num[led_0];
  374.                                 P1=tab_num[led_1];
  375.                                 if(--time_count0<1) time_count0=8;               
  376.                                 }
  377.                                 else if(time_count>15&&time_count<32)                           //“年”
  378.                                 {
  379.                                 led_0=0*32+(time_count1*2)-1;
  380.                                 led_1=0*32+(time_count1*2)-2;
  381.                                 P3=tab_time[led_0];
  382.                                 P1=tab_time[led_1];
  383.                                 if(--time_count1<1) time_count1=16;
  384.                                 }
  385.                                 else if(time_count>=0&&time_count<16)                           //“調”
  386.                                 {
  387.                                 led_0=4*32+(time_count1*2)-1;
  388.                                 led_1=4*32+(time_count1*2)-2;
  389.                                 P3=tab_time[led_0];
  390.                                 P1=tab_time[led_1];
  391.                                 if(--time_count1<1) time_count1=16;
  392.                                 }                                               
  393.                                  delay(70);
  394.                                 if(--time_count<0)
  395.                                 {
  396.                                 time_count=71;
  397.                                 time_count0=8;
  398.                                 time_count1=16;
  399.                                 }
  400.                         }
  401.                 }
  402.                 break;
  403.                 case 2:
  404.                 {
  405.                         for(i=0;i<L_0;i++)
  406.                         {
  407.                                 if(time_count>55)
  408.                                 {
  409.                                 delay(85);                                                                  //整屏左移
  410.                                 }
  411.                                 else if(time_count>47&&time_count<56)
  412.                                 {
  413.                                 led_0=(set_month%10)*16+(time_count0*2)-1;
  414.                                 led_1=(set_month%10)*16+(time_count0*2)-2;
  415.                                 P3=tab_num[led_0];
  416.                                 P1=tab_num[led_1];
  417.                                 if(--time_count0<1) time_count0=8;
  418.                                 }
  419.                                 else if(time_count>39&&time_count<48)
  420.                                 {
  421.                                 led_0=(set_month/10)*16+(time_count0*2)-1;
  422.                                 led_1=(set_month/10)*16+(time_count0*2)-2;
  423.                                 P3=tab_num[led_0];
  424.                                 P1=tab_num[led_1];
  425.                                 if(--time_count0<1) time_count0=8;
  426.                                 }
  427.                                 else if(time_count>31&&time_count<40)                           //冒號
  428.                                 {
  429.                                 led_0=(10*16)+(time_count0*2)-1;
  430.                                 led_1=(10*16)+(time_count0*2)-2;
  431.                                 P3=tab_num[led_0];
  432.                                 P1=tab_num[led_1];
  433.                                 if(--time_count0<1) time_count0=8;               
  434.                                 }
  435.                                 else if(time_count>15&&time_count<32)                           //“月”
  436.                                 {
  437.                                 led_0=1*32+(time_count1*2)-1;
  438.                                 led_1=1*32+(time_count1*2)-2;
  439.                                 P3=tab_time[led_0];
  440.                                 P1=tab_time[led_1];
  441.                                 if(--time_count1<1) time_count1=16;
  442.                                 }
  443.                                 else if(time_count>=0&&time_count<16)                           //“調”
  444.                                 {
  445.                                 led_0=4*32+(time_count1*2)-1;
  446.                                 led_1=4*32+(time_count1*2)-2;
  447.                                 P3=tab_time[led_0];
  448.                                 P1=tab_time[led_1];
  449.                                 if(--time_count1<1) time_count1=16;
  450.                                 }                                               
  451.                                  delay(70);
  452.                                 if(--time_count<0)
  453.                                 {
  454.                                 time_count=71;
  455.                                 time_count0=8;
  456.                                 time_count1=16;
  457.                                 }
  458.                         }
  459.                 }
  460.                 break;
  461.                 case 3:
  462.                 {
  463.                         for(i=0;i<L_0;i++)
  464.                         {
  465.                                 if(time_count>55)
  466.                                 {
  467.                                 delay(85);                                                                  //整屏左移
  468.                                 }
  469.                                 else if(time_count>47&&time_count<56)
  470.                                 {
  471.                                 led_0=(set_day%10)*16+(time_count0*2)-1;
  472.                                 led_1=(set_day%10)*16+(time_count0*2)-2;
  473.                                 P3=tab_num[led_0];
  474.                                 P1=tab_num[led_1];
  475.                                 if(--time_count0<1) time_count0=8;
  476.                                 }
  477.                                 else if(time_count>39&&time_count<48)
  478.                                 {
  479.                                 led_0=(set_day/10)*16+(time_count0*2)-1;
  480.                                 led_1=(set_day/10)*16+(time_count0*2)-2;
  481.                                 P3=tab_num[led_0];
  482.                                 P1=tab_num[led_1];
  483.                                 if(--time_count0<1) time_count0=8;
  484.                                 }
  485.                                 else if(time_count>31&&time_count<40)                           //冒號
  486.                                 {
  487.                                 led_0=(10*16)+(time_count0*2)-1;
  488.                                 led_1=(10*16)+(time_count0*2)-2;
  489.                                 P3=tab_num[led_0];
  490.                                 P1=tab_num[led_1];
  491.                                 if(--time_count0<1) time_count0=8;               
  492.                                 }
  493.                                 else if(time_count>15&&time_count<32)                           //“日”
  494.                                 {
  495.                                 led_0=6*32+(time_count1*2)-1;
  496.                                 led_1=6*32+(time_count1*2)-2;
  497.                                 P3=tab_xingqi[led_0];
  498.                                 P1=tab_xingqi[led_1];
  499.                                 if(--time_count1<1) time_count1=16;
  500.                                 }
  501.                                 else if(time_count>=0&&time_count<16)                           //“調”
  502.                                 {
  503.                                 led_0=4*32+(time_count1*2)-1;
  504.                                 led_1=4*32+(time_count1*2)-2;
  505.                                 P3=tab_time[led_0];
  506.                                 P1=tab_time[led_1];
  507.                                 if(--time_count1<1) time_count1=16;
  508.                                 }                                               
  509.                                  delay(70);

  510.                                 if(--time_count<0)
  511.                                 {
  512.                                 time_count=71;
  513.                                 time_count0=8;
  514.                                 time_count1=16;
  515.                                 }
  516.                         }

  517.                 }
  518.                 break;
  519.                 case 4:
  520.                 {
  521.                 for(i=0;i<L_0;i++)
  522.                         {
  523.                                 if(time_count>55)
  524.                                 {
  525.                                 delay(85);                                                                  //整屏左移
  526.                                 }
  527.                                 else if(time_count>39&&time_count<56)                                         //設置星期的值
  528.                                 {
  529.                                 led_0=(set_week-1)*32+(time_count1*2)-1;
  530.                                 led_1=(set_week-1)*32+(time_count1*2)-2;
  531.                                 P3=tab_xingqi[led_0];
  532.                                 P1=tab_xingqi[led_1];
  533.                                 if(--time_count1<1) time_count1=16;
  534.                                 }
  535.                                 else if(time_count>31&&time_count<40)                                  //冒號
  536.                                 {
  537.                                 led_0=(10*16)+(time_count0*2)-1;
  538.                                 led_1=(10*16)+(time_count0*2)-2;
  539.                                 P3=tab_num[led_0];
  540.                                 P1=tab_num[led_1];
  541.                                 if(--time_count0<1) time_count0=8;
  542.                                 }

  543.                                 else if(time_count>15&&time_count<32)                           //“星”
  544.                                 {
  545.                                 led_0=2*32+(time_count1*2)-1;
  546.                                 led_1=2*32+(time_count1*2)-2;
  547.                                 P3=tab_time[led_0];
  548.                                 P1=tab_time[led_1];
  549.                                 if(--time_count1<1) time_count1=16;
  550.                                 }
  551.                                 else if(time_count>=0&&time_count<16)                           //“調”
  552.                                 {
  553.                                 led_0=4*32+(time_count1*2)-1;
  554.                                 led_1=4*32+(time_count1*2)-2;
  555.                                 P3=tab_time[led_0];
  556.                                 P1=tab_time[led_1];
  557.                                 if(--time_count1<1) time_count1=16;
  558.                                 }                                               
  559.                                  delay(70);

  560.                                 if(--time_count<0)
  561.                                 {
  562.                                 time_count=71;
  563.                                 time_count0=8;
  564.                                 time_count1=16;
  565.                                 }
  566.                         }
  567.                 }
  568.                 break;
  569.                 case 5:
  570.                 {
  571.                         for(i=0;i<L_0;i++)
  572.                         {
  573.                                 if(time_count>55)
  574.                                 {
  575.                                 delay(85);                                                                  //整屏左移
  576.                                 }
  577.                                 else if(time_count>47&&time_count<56)
  578.                                 {
  579.                                 led_0=(set_hour%10)*16+(time_count0*2)-1;
  580.                                 led_1=(set_hour%10)*16+(time_count0*2)-2;
  581.                                 P3=tab_num[led_0];
  582.                                 P1=tab_num[led_1];
  583.                                 if(--time_count0<1) time_count0=8;
  584.                                 }
  585.                                 else if(time_count>39&&time_count<48)
  586.                                 {
  587.                                 led_0=(set_hour/10)*16+(time_count0*2)-1;
  588.                                 led_1=(set_hour/10)*16+(time_count0*2)-2;
  589.                                 P3=tab_num[led_0];
  590.                                 P1=tab_num[led_1];
  591.                                 if(--time_count0<1) time_count0=8;
  592.                                 }
  593.                                 else if(time_count>31&&time_count<40)                           //冒號
  594.                                 {
  595.                                 led_0=(10*16)+(time_count0*2)-1;
  596.                                 led_1=(10*16)+(time_count0*2)-2;
  597.                                 P3=tab_num[led_0];
  598.                                 P1=tab_num[led_1];
  599.                                 if(--time_count0<1) time_count0=8;               
  600.                                 }
  601.                                 else if(time_count>15&&time_count<32)                           //“時”
  602.                                 {
  603.                                 led_0=5*32+(time_count1*2)-1;
  604.                                 led_1=5*32+(time_count1*2)-2;
  605.                                 P3=tab_time[led_0];
  606.                                 P1=tab_time[led_1];
  607.                                 if(--time_count1<1) time_count1=16;
  608.                                 }
  609.                                 else if(time_count>=0&&time_count<16)                           //“調”
  610.                                 {
  611.                                 led_0=4*32+(time_count1*2)-1;
  612.                                 led_1=4*32+(time_count1*2)-2;
  613.                                 P3=tab_time[led_0];
  614.                                 P1=tab_time[led_1];
  615.                                 if(--time_count1<1) time_count1=16;
  616.                                 }                                               
  617.                                  delay(70);

  618.                                 if(--time_count<0)
  619.                                 {
  620.                                 time_count=71;
  621.                                 time_count0=8;
  622.                                 time_count1=16;
  623.                                 }
  624.                         }

  625.                 }
  626.                 break;
  627.                 case 6:
  628.                 {
  629.                         for(i=0;i<L_0;i++)
  630.                         {
  631.                                 if(time_count>55)
  632.                                 {
  633.                                 delay(85);                                                                  //整屏左移
  634.                                 }
  635.                                 else if(time_count>47&&time_count<56)
  636.                                 {
  637.                                 led_0=(set_minute%10)*16+(time_count0*2)-1;
  638.                                 led_1=(set_minute%10)*16+(time_count0*2)-2;
  639.                                 P3=tab_num[led_0];
  640.                                 P1=tab_num[led_1];
  641.                                 if(--time_count0<1) time_count0=8;
  642.                                 }
  643.                                 else if(time_count>39&&time_count<48)
  644.                                 {
  645.                                 led_0=(set_minute/10)*16+(time_count0*2)-1;
  646.                                 led_1=(set_minute/10)*16+(time_count0*2)-2;
  647.                                 P3=tab_num[led_0];
  648.                                 P1=tab_num[led_1];
  649.                                 if(--time_count0<1) time_count0=8;
  650.                                 }
  651.                                 else if(time_count>31&&time_count<40)                           //冒號
  652.                                 {
  653.                                 led_0=(10*16)+(time_count0*2)-1;
  654.                                 led_1=(10*16)+(time_count0*2)-2;
  655.                                 P3=tab_num[led_0];
  656.                                 P1=tab_num[led_1];
  657.                                 if(--time_count0<1) time_count0=8;               
  658.                                 }
  659.                                 else if(time_count>15&&time_count<32)                           //“分”
  660.                                 {
  661.                                 led_0=6*32+(time_count1*2)-1;
  662.                                 led_1=6*32+(time_count1*2)-2;
  663.                                 P3=tab_time[led_0];
  664.                                 P1=tab_time[led_1];
  665.                                 if(--time_count1<1) time_count1=16;
  666.                                 }
  667.                                 else if(time_count>=0&&time_count<16)                           //“調”
  668.                                 {
  669.                                 led_0=4*32+(time_count1*2)-1;
  670.                                 led_1=4*32+(time_count1*2)-2;
  671.                                 P3=tab_time[led_0];
  672.                                 P1=tab_time[led_1];
  673.                                 if(--time_count1<1) time_count1=16;
  674.                                 }                                               
  675.                                  delay(70);

  676.                                 if(--time_count<0)
  677.                                 {
  678.                                 time_count=71;
  679.                                 time_count0=8;
  680.                                 time_count1=16;
  681.                                 }
  682.                         }

  683.                 }
  684.                 break;
  685.                 case 7:
  686.                 {
  687.                         for(i=0;i<L_0;i++)
  688.                         {
  689.                                 if(time_count>55)
  690.                                 {
  691.                                 delay(85);                                                                  //整屏左移
  692.                                 }
  693.                                 else if(time_count>47&&time_count<56)
  694.                                 {
  695.                                 led_0=(set_second%10)*16+(time_count0*2)-1;
  696.                                 led_1=(set_second%10)*16+(time_count0*2)-2;
  697.                                 P3=tab_num[led_0];
  698.                                 P1=tab_num[led_1];
  699.                                 if(--time_count0<1) time_count0=8;
  700.                                 }
  701.                                 else if(time_count>39&&time_count<48)
  702.                                 {
  703.                                 led_0=(set_second/10)*16+(time_count0*2)-1;
  704.                                 led_1=(set_second/10)*16+(time_count0*2)-2;
  705.                                 P3=tab_num[led_0];
  706.                                 P1=tab_num[led_1];
  707.                                 if(--time_count0<1) time_count0=8;
  708.                                 }
  709.                                 else if(time_count>31&&time_count<40)                           //冒號
  710.                                 {
  711.                                 led_0=(10*16)+(time_count0*2)-1;
  712.                                 led_1=(10*16)+(time_count0*2)-2;
  713.                                 P3=tab_num[led_0];
  714.                                 P1=tab_num[led_1];
  715.                                 if(--time_count0<1) time_count0=8;               
  716.                                 }
  717.                                 else if(time_count>15&&time_count<32)                           //“秒”
  718.                                 {
  719.                                 led_0=7*32+(time_count1*2)-1;
  720.                                 led_1=7*32+(time_count1*2)-2;
  721.                                 P3=tab_time[led_0];
  722.                                 P1=tab_time[led_1];
  723.                                 if(--time_count1<1) time_count1=16;
  724.                                 }
  725.                                 else if(time_count>=0&&time_count<16)                           //“調”
  726.                                 {
  727.                                 led_0=4*32+(time_count1*2)-1;
  728.                                 led_1=4*32+(time_count1*2)-2;
  729.                                 P3=tab_time[led_0];
  730.                                 P1=tab_time[led_1];
  731.                                 if(--time_count1<1) time_count1=16;
  732.                                 }                                               
  733.                                  delay(70);

  734.                                 if(--time_count<0)
  735.                                 {
  736.                                 time_count=71;
  737.                                 time_count0=8;
  738.                                 time_count1=16;
  739.                                 }
  740.                         }

  741.                 }
  742.         }

  743.                 P3=0xff;
  744.                 P1=0xff;
  745.                 delay(5);

  746. }


  747. /*紅外解碼過程函數*/
  748. bit IRWork()
  749. {
  750. uchar i,j;
  751. uchar dat;
  752. for(j=0;j<4;j++)                                                         //共四個編碼
  753. {
  754. for(i=0;i<8;i++)                                                         //每個編碼八位
  755.         {
  756. dat>>=1;                                                                                //先移位
  757. TH0=0;
  758. TL0=0;
  759. TR0=1;
  760. while(!IR);                                                                                //低電平等待
  761. TR0=0;
  762. LowTime=TH0*256+TL0;                                                        //將低電平寬度保存
  763. TH0=0;
  764. TL0=0;
  765. TR0=1;
  766. while(IR);                                                                                 //高電平等待
  767. TR0=0;
  768. HighTime=TH0*256+TL0;                                                         //將高電平寬度保存
  769.             if(LowTime<380||LowTime>750) return 0;           //檢測得到的低電平是否在560us左右,如果不是,則返回0;說明解碼失敗

  770.                    if((HighTime>1500)&&(HighTime<1900)) //如果高電平時間在1690微秒左右,(1690-200=1490,1690+200=1890),則該位是1;
  771.                                    dat=dat|0x80;       //是0的情況可判斷,也可以不判斷了,因為不判斷的話上面開始移位后高位已自動清0,在這一行不在高位置1,已說明是0
  772.         }
  773. a[j]=dat;                                                                                                          //將每次解出的編碼存到a[]中
  774. }
  775. if(a[2]=~a[3]) return 1;                                                                        //再次判斷鍵碼值,如果一致,返回1,解碼正確
  776. }

  777. void IR_Scan(uchar dat00)
  778. {
  779.         switch(dat00)
  780.     {
  781.           case 0x46:KeyVal=7;break;                                           //MODE
  782.           case 0x07:KeyVal=8;break;                                           //EQ
  783.           case 0x15:KeyVal=9;break;                                           //--
  784.           case 0x09:KeyVal=10;break;                                           //+
  785.           case 0x19:KeyVal=11;break;                                           //REP
  786.           case 0x0d:KeyVal=12;break;                                        //SCAN
  787.           default:break;
  788.           }                                                  
  789. }


  790. /*設置時間入口*/
  791. void KeyScan()
  792. {
  793.         if(IR_Flag&&(KeyVal==7))                                                  //切換顯示時間和日期
  794.         {
  795.         IR_Flag=0;                                                                           //標志位清零,每次只進入一遍這個函數,即每按一次鍵加1或減1
  796.                 display_time_flag=!display_time_flag;
  797.                 TR1=1;
  798.                 TH1=(65536-50000)/256;
  799.                 TL1=(65536-50000)%256;
  800.                 time_count=0;
  801.                 time_count0=0;
  802.                 time_count1=0;
  803.                 if(display_flag!=1)
  804.                 {
  805.                  display_flag=1;
  806.                  display_time_flag=0;
  807.                 }
  808.                 if(display_time_flag==1)        time_count1=28;
  809.                         if(set_count!=0)
  810.                         {
  811.                         if(set_count==7)
  812.                         {
  813.                         WriteSet1302(0x80,(((set_second/10)<<4)|(set_second%10)));
  814.                         set_second_flag=0;
  815.                         }
  816.                         WriteSet1302(0x8e,0x80);
  817.                         display_time_flag=!display_time_flag;
  818.                         set_count=0;
  819.                         }

  820.         }

  821.         else if(IR_Flag&&(KeyVal==8))                                                  //設置時間
  822.         {
  823.         IR_Flag=0;
  824.         display_flag=1;
  825.                 if(++set_count>8) set_count=0;
  826.                 switch(set_count)
  827.                 {
  828.                         case 1:                                                                                                                          //設置年
  829.                         {
  830.                         WriteSet1302(0x8e,0x00);                                                   //去掉保護
  831.                         set_year_tmp=(ReadSet1302(0x8d)>>4)*10+((ReadSet1302(0x8d))&0x0f);                         //在當前值設置
  832.                         set_year=set_year_tmp;
  833.                         }
  834.                         break;
  835.                         case 2:                                                                                                                                  //設置月
  836.                         {
  837.                         set_month_tmp=(ReadSet1302(0x89)>>4)*10+((ReadSet1302(0x89))&0x0f);
  838.                         set_month=set_month_tmp;
  839.                         }
  840.                         break;
  841.                         case 3:                                                                                                                                         //設置日
  842.                         {
  843.                         set_day_tmp=(ReadSet1302(0x87)>>4)*10+((ReadSet1302(0x87))&0x0f);
  844.                         set_day=set_day_tmp;
  845.                         }
  846.                         break;
  847.                         case 4:                                                                                                                                         //設置星期
  848.                         {
  849.                         set_week_tmp=ReadSet1302(0x8b);
  850.                         set_week=set_week_tmp;
  851.                         }
  852.                         break;
  853.                         case 5:                                                                                                                                         //設置時
  854.                         {
  855.                         set_hour_tmp=(ReadSet1302(0x85)>>4)*10+((ReadSet1302(0x85))&0x0f);
  856.                         set_hour=set_hour_tmp;
  857.                         }
  858.                         break;
  859.                         case 6:                                                                                                                                         //設置分
  860.                         {
  861.                         set_minute_tmp=(ReadSet1302(0x83)>>4)*10+((ReadSet1302(0x83))&0x0f);
  862.                         set_minute=set_minute_tmp;
  863.                         }
  864.                         break;
  865.                         case 8:
  866.                         {
  867.                         WriteSet1302(0x80,(((set_second/10)<<4)|(set_second%10)));
  868.                         WriteSet1302(0x8e,0x80);                                                        //寫保護
  869.                         set_second_flag=0;
  870.                         set_count=0;
  871.                         time_count1=0;
  872.                         }
  873.                         break;
  874.                 }
  875.         }

  876.         else if(IR_Flag&&(KeyVal==10))                                                                           //+
  877.         {       
  878.                 IR_Flag=0;
  879.                 switch(set_count)
  880.                 {
  881.                 case 1:
  882.                 {
  883.                         if(++set_year>50) set_year=10;
  884.                 }
  885.                 break;
  886.                 case 2:
  887.                 {
  888.                         if(++set_month>12) set_month=1;
  889.                 }
  890.                 break;
  891.                 case 3:
  892.                 {
  893.                         if(++set_day>31) set_day=1;
  894.                 }
  895.                 break;
  896.                 case 4:
  897.                 {
  898.                         if(++set_week>7) set_week=1;
  899.                 }
  900.                 break;
  901.                 case 5:
  902.                 {
  903.                         if(++set_hour>23) set_hour=0;
  904.                 }
  905.                 break;
  906.                 case 6:
  907.                 {
  908.                         if(++set_minute>59) set_minute=0;
  909.                 }
  910.                 break;
  911.                 case 7:
  912.                 {
  913.                         set_second_flag=1;
  914.                         if(++set_second>59) set_second=0;
  915.                 }
  916.                 break;
  917.                 }
  918.         }

  919.         else if(IR_Flag&&(KeyVal==9))                                                                 //-
  920.         {
  921.                 IR_Flag=0;
  922.                 switch(set_count)
  923.                 {
  924.                 case 1:
  925.                 {
  926.                         if(--set_year<10) set_year=50;
  927.                 }
  928.                 break;
  929.                 case 2:
  930.                 {
  931.                         if(--set_month<1) set_month=12;
  932.                 }
  933.                 break;
  934.                 case 3:
  935.                 {
  936.                         if(--set_day<1) set_day=31;
  937.                 }
  938.                 break;
  939.                 case 4:
  940.                 {
  941.                         if(--set_week<1) set_week=7;
  942.                 }
  943.                 break;
  944.                 case 5:
  945.                 {
  946.                         if(--set_hour<0) set_hour=23;
  947.                 }
  948.                 break;
  949.                 case 6:
  950.                 {
  951.                         if(--set_minute<0) set_minute=59;
  952.                 }
  953.                 break;
  954.                 case 7:
  955.                 {
  956.                         set_second_flag=1;
  957.                         if(--set_second<0) set_second=59;
  958.                 }
  959.                 }
  960.         }
  961.         else if(IR_Flag&&(KeyVal==11))                                                                 //-
  962.         {
  963.                 IR_Flag=0;
  964.                 display_flag=2;
  965.                 TH1=(65536-50000)/256;
  966.                 TL1=(65536-50000)%256;
  967.                 time_count=0;
  968.                 time_count0=0;
  969.         }
  970.         else if(IR_Flag&&(KeyVal==12))                                                                 //-
  971.         {
  972.                 IR_Flag=0;
  973.                 if(++effect>2)        effect=0;
  974.         }


  975. }


  976. void set_time()
  977. {
  978. switch(set_count)
  979. {
  980.         case 1:
  981.         {
  982.         if(set_year!=set_year_tmp) WriteSet1302(0x8c,((set_year/10)<<4)|(set_year%10));                                                 //將上個設置數據寫入1302
  983.         } break;
  984.         case 2:
  985.         {
  986.         if(set_month!=set_month_tmp)  WriteSet1302(0x88,((set_month/10)<<4)|(set_month%10));
  987.         } break;
  988.         case 3:
  989.         {
  990.         if(set_day!=set_day_tmp) WriteSet1302(0x86,((set_day/10)<<4)|(set_day%10));
  991.         } break;
  992.         case 4:
  993.         {
  994.         if(set_week!=set_week_tmp) WriteSet1302(0x8a,set_week);
  995.         } break;
  996.         case 5:
  997.         {
  998.         if(set_hour!=set_hour_tmp) WriteSet1302(0x84,((set_hour/10)<<4)|(set_hour%10));
  999.         } break;
  1000.         case 6:
  1001.         {
  1002.         if(set_minute!=set_minute_tmp) WriteSet1302(0x82,((set_minute/10)<<4)|(set_minute%10));
  1003.         } break;
  1004.         case 7:
  1005.         {
  1006.                 if(set_second_flag==0)
  1007.                 {        
  1008.                 set_second=(ReadSet1302(0x81)>>4)*10+((ReadSet1302(0x81))&0x0f);
  1009.                 }
  1010.                 else
  1011.                 {
  1012.                 WriteSet1302(0x80,((((set_second/10)<<4)|(set_second%10))|0x80));                                           //秒默認為00分,且先不啟動時鐘
  1013.                 }

  1014.         } break;


  1015. }
  1016. }

  1017. void main()
  1018. {
  1019. //set_count=1;
  1020. P1=0xff;
  1021. P3=0xff;
  1022. EA=1;
  1023. EX2=1;
  1024. EX3=1;
  1025. ET1=1;
  1026. IT2=0;
  1027. IT3=1;        //下降沿觸發
  1028. PX2=0;
  1029. PX3=1;        //最高優先級
  1030. PT1=1;
  1031. TMOD=0x11;
  1032. TH1=(65536-50000)/256;
  1033. TL1=(65536-50000)%256;
  1034. Init1302();
  1035.         while(1)
  1036.         {
  1037.                    KeyScan();
  1038.                  set_time();
  1039.                  EX2=1;

  1040.                  
  1041.         }

  1042. }



  1043. void time1() interrupt 3
  1044. {
  1045. TH1=(65536-50000)/256;
  1046. TL1=(65536-50000)%256;
  1047.         if(++time_count>=20)
  1048.         {
  1049.         time_count=0;
  1050.         if(set_count==0)
  1051.         {
  1052.                 if(++time_count0>40)
  1053.                 {
  1054.                 time_count0=0;
  1055.                 time_count1=0;
  1056.                                 if(++display_flag>2) display_flag=1;
  1057.                 }
  1058.                 time_count1++;
  1059.                 if(time_count1<28) display_time_flag=0;
  1060.                 else if(time_count1>27)
  1061.                 {
  1062.                 display_time_flag=1;
  1063.                         if(time_count1>40) time_count1=0;
  1064.                 }

  1065.         }

  1066.         }
  1067. }

  1068. void int2_led()        interrupt 6
  1069. {
  1070. EX2=0;
  1071. switch(display_flag)
  1072. {
  1073. case 0:open_display();break;
  1074. case 1:
  1075. {

  1076.         if(set_count==0)
  1077.         {
  1078.         if(display_time_flag==0)         time1_display();                                                //顯示時間
  1079.         else   time0_display();                                                                                                //顯示日期
  1080.         }
  1081. else set_time_display();                                                                                                 //顯示設置狀態
  1082. } break;
  1083. case 2:love_display();break;
  1084. }
  1085.         EX3=1;                                                                                                                                //再開外中斷INT3

  1086.        
  1087. }

  1088. /*紅外接收外中斷INT0*/
  1089. void int3() interrupt 7
  1090. {
  1091. EX3=0;
  1092. //delay(10);
  1093. if(IR) return;                                                          //防止長按時無效尾碼的干擾,這個很關鍵!!。                                                                 //暫關T1中斷
  1094. TL0=0x00;
  1095. TH0=0x00;
  1096. TR0=1;
  1097. while(!IR);                                                  //低電平引導碼等待
  1098. TR0=0;
  1099. LowTime=TH0*256+TL0;
  1100. TL0=0x00;
  1101. TH0=0x00;
  1102. TR0=1;
  1103. while(IR);                                                     //高電平引導碼等待
  1104. TR0=0;
  1105. HighTime=TH0*256+TL0;

  1106. if((LowTime>8250)&&(LowTime<9350)&&(HighTime>3950)&&(HighTime<5050))           //判斷是否在合理的范圍內
  1107.         {
  1108.                 if(IRWork()&&(a[0]==0x00))                                                                   //如果解碼正確,且廠家編碼為0x04(我的遙控器)才執行子語句,防其它遙控器干擾
  1109.                 {
  1110.                 IR_Flag=1;               
  1111.                 IR_Scan(a[2]);               
  1112.                 }
  1113.         }
  1114. }
復制代碼
回復

使用道具 舉報

板凳
ID:72901 發表于 2015-1-28 12:33 | 只看該作者
不錯,值得學習
回復

使用道具 舉報

地板
ID:72995 發表于 2015-1-31 12:02 | 只看該作者
樓主,好厲害啊,贊贊贊贊贊
回復

使用道具 舉報

5#
ID:72611 發表于 2015-4-4 17:31 | 只看該作者
高手呀
回復

使用道具 舉報

6#
ID:76142 發表于 2015-4-4 23:13 | 只看該作者
謝謝分享
回復

使用道具 舉報

7#
ID:76142 發表于 2015-4-4 23:13 | 只看該作者
謝謝分享
回復

使用道具 舉報

8#
ID:111276 發表于 2016-7-4 10:00 來自手機 | 只看該作者
厲害,我也要學習做一個當生日禮物送
回復

使用道具 舉報

9#
ID:140943 發表于 2016-9-30 00:39 來自手機 | 只看該作者
樓主可以發下完整的教程和說明嗎。。新手想嘗試下
回復

使用道具 舉報

10#
ID:190426 發表于 2017-4-17 14:25 | 只看該作者
今天剛剛來到51黑電子論壇 希望 能夠和大家相處的愉快
回復

使用道具 舉報

11#
ID:81140 發表于 2017-9-16 16:31 | 只看該作者
太棒了                     
回復

使用道具 舉報

12#
ID:81140 發表于 2017-9-16 16:31 | 只看該作者
太棒了。。。。。。。。。。!
回復

使用道具 舉報

13#
ID:251422 發表于 2017-11-27 14:03 | 只看該作者
小白學習
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 男女久久久 | 91九色在线观看 | 射久久| 亚洲国产成人精品女人 | 中文字幕亚洲欧美日韩在线不卡 | 91精品国产91久久久久久吃药 | 久夜精品 | 韩日视频在线观看 | 日产精品久久久一区二区福利 | 国产乱码精品1区2区3区 | 成人网av | 看羞羞视频免费 | 国产电影一区二区在线观看 | 日本免费一区二区三区四区 | 中文字幕一区二区三区在线观看 | 日韩视频观看 | 在线成人 | 欧美一区两区 | 国产精品亚洲综合 | 欧美三级成人理伦 | 久久久久久免费毛片精品 | 久久久美女 | av色在线| 一区二区三区四区不卡视频 | 九九九久久国产免费 | 成人免费大片黄在线播放 | 每日在线更新av | 午夜影院在线观看 | 在线国产一区 | 亚洲国产精品成人无久久精品 | 日韩视频在线一区 | 日韩中文字幕免费在线观看 | 欧美一级片在线观看 | 日日碰狠狠躁久久躁96avv | 国产一区二区久久久 | 四季久久免费一区二区三区四区 | 精品免费国产 | 久久国产精品免费一区二区三区 | 亚洲视频在线观看免费 | 99精品视频在线观看免费播放 | 日韩在线免费电影 |