標(biāo)題: 帶片選LCD12864+RTC1302的時(shí)鐘單片機(jī)程序和Proteus仿真圖 [打印本頁(yè)]

作者: 3花木城    時(shí)間: 2021-12-28 13:35
標(biāo)題: 帶片選LCD12864+RTC1302的時(shí)鐘單片機(jī)程序和Proteus仿真圖
程序如圖,接下來(lái)改成可調(diào)12,24小時(shí)制。
程序和代碼在附近里,
仿真原理圖如下(proteus仿真工程文件可到本帖附件中下載)


單片機(jī)源程序如下:
  1. /****************************文件包含*************************************/
  2. #include < reg52.h >
  3. #include < character.h >
  4. #include < lcd.h >
  5. #include < clock.h >
  6. #include < sensor.h>
  7. #include < calendar.h >
  8. #include < key.h >

  9. /*****************************預(yù)定義**************************************/
  10. #define uchar unsigned char
  11. #define uint unsigned int
  12. /****************************************************************************/
  13. sbit bell = P3 ^ 6; //定義蜂鳴器端口
  14. /*****************************************************************************
  15. * 名稱: Timer0_Service() inturrupt 1
  16. * 功能: 中斷服務(wù)程序 整點(diǎn)報(bào)時(shí) 3聲嘟嘟的聲音
  17. * 入口參數(shù):
  18. * 出口參數(shù):
  19. *****************************************************************************/
  20. void Timer0_Service() interrupt 1
  21. {
  22.    static uchar count = 0;
  23.    static uchar flag = 0; //記錄鳴叫的次數(shù)
  24.    count = 0;
  25.    TR0 = 0;      //關(guān)閉Timer0
  26.    TH0 = 0x3c;
  27.    TL0 = 0XB0;   //延時(shí) 50 ms
  28.    TR0 = 1 ;     //啟動(dòng)Timer0
  29.    count ++;
  30.    if( count == 20 ) //鳴叫 1 秒
  31.    {
  32.       bell = ~ bell;
  33.       count = 0;
  34.       flag ++;
  35.    }
  36.    if( flag == 6 )
  37.    {
  38.       flag = 0;
  39.       TR0 = 0;   //關(guān)閉Timer0
  40.    }

  41. }
  42. /*****************************************************************************
  43. * 名稱: Timer2_Servie() interrupt 5
  44. * 功能: 中斷服務(wù)程序  整點(diǎn)報(bào)時(shí) 一分鐘
  45. * 入口參數(shù):
  46. * 出口參數(shù):
  47. *****************************************************************************/
  48. uchar HexNum_Convert(uchar HexNum)/*時(shí)間存儲(chǔ)個(gè)位和十位的方式與我們用的十進(jìn)制不一樣,你懂的,呵呵--BB車*/
  49. {
  50. uchar Numtemp;
  51. Numtemp=(HexNum>>4)*10+(HexNum&0X0F);
  52. return Numtemp;
  53. }
  54. /******************************************************************************
  55. * 函數(shù)名稱:main()
  56. * 功    能:
  57. * 入口參數(shù):
  58. * 出口參數(shù):
  59. ********************************************************************************/
  60. void main( void )
  61. {         
  62.     uchar clock_time[6] = {0X00,0X59,0X23,0X09,0X04,0X11};        //定義時(shí)間變量 秒  分 時(shí) 日 月 年
  63.         uchar alarm_time[2] = { 10, 06}; //鬧鐘設(shè)置  alarm_time[0]: 分鐘  alarm_time[1] :小時(shí)
  64.         uchar temperature[2];  //定義溫度變量   temperature[0]  低8位   temperature[1]  高8位
  65.     Lcd_Initial();     //LCD初始化
  66.         Clock_Fresh( clock_time ); //我把時(shí)間刷新放在這里,proteus會(huì)調(diào)用當(dāng)前系統(tǒng)時(shí)間,別問(wèn)為什么,經(jīng)驗(yàn),呵呵
  67.         Clock_Initial( clock_time ); //時(shí)鐘初試化
  68.    
  69.         /***********************中斷初始化***************************/
  70.     EA = 1; //開(kāi)總中斷
  71.     ET0 = 1;  //Timer0 開(kāi)中斷
  72.         ET2 = 1; //Timer2 開(kāi)中斷
  73.     TMOD = 0x01 ; //Timer0 工作方式 1
  74.         RCAP2H = 0x3c;
  75.     RCAP2L = 0xb0; //Timer2 延時(shí) 50 ms

  76.     while( 1 )
  77.         {
  78.            switch( Key_Scan() )
  79.        {
  80.           case up_array:  
  81.                                {
  82.                           Key_Idle();
  83.                        }
  84.                                break;     
  85.           case down_array:   
  86.                                  {
  87.                                                     Key_Idle();
  88.                                                  }
  89.                                  break;                  
  90.                   case clear_array:   
  91.                                   {   
  92.                                                      Key_Idle();
  93.                                               }
  94.                                                   break;
  95.                   case function_array:{
  96.                                  Key_Function( clock_time, alarm_time );
  97.                                       }
  98.                   case null:      
  99.                            {
  100.                                       Clock_Fresh( clock_time ); //時(shí)間刷新
  101.                               Lcd_Clock( clock_time );   //時(shí)間顯示
  102.                      
  103.                       Sensor_Fresh( temperature ); //溫度更新
  104.                                           Lcd_Temperture( temperature ); //溫度顯示

  105.                       Calendar_Convert( 0 , clock_time );
  106.                                           Week_Convert( 0, clock_time );

  107.                                           //整點(diǎn)報(bào)時(shí)
  108.                                         /*  if( ( * clock_time == 0x59 ) && ( * ( clock_time + 1 ) == 0x59 ) )
  109.                                           {
  110.                                              bell = 0;
  111.                                                  TR2 = 1; //啟動(dòng)Timer2
  112.                                           }        */
  113.                       //鬧鐘報(bào)警
  114.                       if( * alarm_time == HexNum_Convert(* ( clock_time + 1 ) )) //分鐘相吻合
  115.                                              if( * ( alarm_time + 1 ) == HexNum_Convert(*( clock_time + 2 )) ) //小時(shí)相吻合
  116.                                                  {
  117.                                                     bell = 0;
  118.                                                         TR2 = 1; //啟動(dòng)Timer2
  119.                                                  }
  120.                    }
  121.                                     break;
  122.          }
  123.         }
  124. }
復(fù)制代碼

Keil代碼與Proteus仿真下載:
4.0版 - 嘗試改界面-時(shí)分秒后移一位.7z (95.05 KB, 下載次數(shù): 25)





歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1