標題: 單片機用PT2262/2272帶解碼模塊無線電遙控LED源程序 [打印本頁]

作者: 51黑電子happy    時間: 2017-3-30 02:14
標題: 單片機用PT2262/2272帶解碼模塊無線電遙控LED源程序
PT2262/2272是臺灣普城公司生產(chǎn)的一種CMOS工藝制造的低功耗低價位通用編解碼電路,本例采用這種模塊,來遙控led


無線芯片的資料詳見:http://www.torrancerestoration.com/bbs/dpj-44384-1.html

單片機源程序:

  1. //---------------------------------------------------------------------------------------------------------
  2. // 程序名:  WX6-5.c
  3. // 程序功能: 無線電遙控LED
  4. //---------------------------------------------------------------------------------------------------------
  5. #include <reg51.h>                            //頭文件
  6. #define uchar unsigned char
  7. #define uint unsigned int
  8. #define IN P0                                 //接收數(shù)據(jù)端口
  9. #define A P1
  10. sbit VT=P0^4;                                 //接收控制信號位
  11. sbit SPK=P2^7;                                //蜂鳴器信號輸入位定義

  12. //---------------------------------------- 延時函數(shù) ------------------------------------------------        

  13.   void delay(uint k)                               //總延時時間:1ms k
  14.    {
  15.      uint i,j;                                 //定義局部變量i、j  
  16.      for(i=0;i<k;i++){                                //外層循環(huán)
  17.      for(j=0;j<121;j++)                             //內層循環(huán)
  18.     {;}}
  19.    }

  20. //----------------------------------------- 發(fā)聲函數(shù) ----------------------------------------------

  21.   void  fs_d ()                                         
  22.     {   
  23.       unsigned int j,y;                        //聲明無符號整型變量j, y        
  24.        {                    
  25.          for(y=0;y<1000;y++)                   //循環(huán)1000次,嘀響0.5s
  26.           {  
  27.             SPK=~SPK;                          //反相輸出
  28.                 for(j=0;j<50;j++);                 //延時約500μs
  29.            }  
  30.         delay(200);                                       
  31.       }                                          
  32.    }
  33.   
  34. //------------------------------------------ 主函數(shù) ----------------------------------------------

  35. void  main()
  36.   {
  37.     while(1)                                    //循環(huán)檢測
  38.      {
  39.       if(VT==1)                                 //遙控有信號輸出
  40.        {
  41.          delay(100);                            //等待,消除干擾信號
  42.          if(VT==1)                              //依然有遙控信號
  43.            {           
  44.                      A=(IN & 0x0f);                     //將接收到的信號作與運算后賦予A            
  45.                          P1=~A;                             //由P1端口反向輸出
  46.                      fs_d ();                           //鳴響1聲
  47.                    }
  48.            }
  49.          }           
  50.   }                  
  51.                         
  52. //-----------------------------------------------------------------------------------------------------


復制代碼


該系列源碼包含有很多非常經(jīng)典,代碼風格十分規(guī)范,而且注釋詳細的單片機例程,還帶仿真,對于MCU學習特別是初學者是很有幫助的,全部源碼下載(共25個項目)www.torrancerestoration.com/bbs/dpj-79328-1.html

本例程下載(含proteus仿真工程文件與源碼):
無線電遙控LED.rar (18.73 KB, 下載次數(shù): 61)






作者: Chandler1983    時間: 2017-3-30 14:47
謝謝樓主,學習了!。




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