找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 9652|回復(fù): 2
打印 上一主題 下一主題
收起左側(cè)

單片機遙控車電路和源程序

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:140725 發(fā)表于 2016-10-18 16:42 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式
做了一個單片機遙控車項目程序:
RX_01.rar (54.66 KB, 下載次數(shù): 56)
TX.rar (9.25 KB, 下載次數(shù): 46)
電路圖:
多功能車接收電路.pdf (32.53 KB, 下載次數(shù): 48)

這里把電路和源程序分享給51黑電子論壇的朋友們,希望對大家的設(shè)計能有所幫助。





tx部分程序預(yù)覽:
  1. /*****************************************************
  2. //項目名稱:興信多功能遙控車TX,27M/40M
  3. //項目編號:FC100515
  4. //項目日期:2010-6-3
  5. //初始編輯:##老魚探戈   V137_Studio
  6. ----------------------------------------

  7. //*****************************************************/
  8. #include"All.h"

  9. uchar Brakecnt=0,Swaycnt=0;
  10. uchar VibraCnt=0;        //振動10s
  11. uchar ShaCheCnt05;        //剎車延時0.5s
  12. //========================================//
  13. void InitAll(void)
  14. {       
  15.         WDTR=0x5A;
  16.         P2M=0x3f;
  17.         P0M=0x00;
  18.         P1M=0x0d;
  19.         FP54M=1;
  20.         P0UR=0x01;
  21. //        P1UR=0x00;
  22. //        P2UR=0x00;       
  23.         Init_TC0();
  24.         P2=0xc0;
  25.         PSoundCon=1;
  26.         PRSample=0;
  27.         PRMain=0;
  28. }
  29. //***************************************//
  30. //函數(shù)名稱:void DvrSmog(void)
  31. //輸入?yún)?shù):無
  32. //輸出參數(shù):無
  33. //函數(shù)功能:發(fā)射信號清除控制
  34. //**************************************//
  35. void DvrSmog(void)
  36. {       
  37.         if(Brake==1)
  38.         {
  39.                 Brakecnt++;
  40.                 if(Brakecnt>=7U)  
  41.                 { Brake=0; Brakecnt=0;}       
  42.         }       
  43.         else
  44.                 Brakecnt=0;
  45.         //-------------------------------------------
  46.         if(gb_key)       
  47.                 {Vibration=0;}               
  48.         //-------------------------------------------
  49.         if(Vibration==1)
  50.         {                       
  51.                 VibraCnt++;                        //  78/2=39ms
  52.                 if(VibraCnt>=250U)
  53.                 {
  54.                         VibraCnt=0;
  55.                         Vibration=0;
  56.                 }
  57.         }
  58.         else
  59.                 VibraCnt=0;
  60.         //-------------------------------------------       
  61.     if((SwayLeft==1||SwayRight==1)&&IntoMode==1)
  62.         {
  63.                 Swaycnt++;
  64.                 if(Swaycnt>=10U)
  65.                 {
  66.                         SwayRight=0;                //右擺
  67.                         SwayLeft=0;       
  68.                         Swaycnt=0;                       
  69.                 }               
  70.         }       
  71.         else  Swaycnt=0;   ///

  72.         //=========================================
  73.         if(ShaCheEnb&&gb_key==0)
  74.         {
  75.                 ShaCheCnt05++;
  76.                 if(ShaCheCnt05>=10U)
  77.                 {
  78.                         ShaCheCnt05=0;
  79.                         ShaCheEnb=0;
  80.                 //        ShaCheOver=1;
  81.                 }       
  82.         }
  83.         else ShaCheCnt05=0;
  84. }
  85. //***************************************//
  86. //函數(shù)名稱:void NoSendSignel(void)
  87. //輸入?yún)?shù):無
  88. //輸出參數(shù):無
  89. //函數(shù)功能:連續(xù)無信號,停止發(fā)射
  90. //**************************************//
  91. void NoSendSignel(void)
  92. {
  93.         static uchar NoSigcnt=0;
  94.         if((senddataH==0)&&(senddataL==0))
  95. //        if((senddataH|senddataL)==0)
  96.         {
  97.                 NoSigcnt++;
  98.                 if(NoSigcnt>=20U)
  99.                 {
  100.                         FSendEnb0=0;
  101.                         NoSigcnt=0;
  102.                 }
  103.         }
  104.         else {        NoSigcnt=0;        FSendEnb0=1;}
  105. }
  106. //***************************************//
  107. //函數(shù)名稱:void main(void)
  108. //輸入?yún)?shù):無
  109. //輸出參數(shù):無
  110. //函數(shù)功能:主程序段
  111. //**************************************//
  112. void main(void)
  113. {
  114.         InitAll();
  115.         while(1)
  116.         {                                       
  117.                 GetClock();
  118.                 GetSendTime();
  119.                 GetKey();
  120.                 PlaySdTimer();       
  121.                 GotoSleep();        //3min 睡眠       
  122.             if(!FSendEnb)  continue;
  123.                 Get_gb();      //獲得主推數(shù)據(jù)
  124.                 GetSendData();
  125.                 FNoSigEnb=1;        //填碼禁止
  126.                 NoSendSignel();

  127.                 if(!FSendEnb0)  continue;
  128.                 SetLed(gb_key);
  129.                 sendRF();
  130.                 SoundCtrl();                //發(fā)聲
  131.                DvrSmog();
  132.                 FNoSigEnb=0;        //填碼允許               
  133.         }
  134. }
復(fù)制代碼

rx程序:
  1.                 /*-----------------------------------------------------------
  2.                 |          Module Name: ------ MAIN.ASM                                  |
  3.                 |          Author:      ------ Tom                                     |       
  4.                 |          Version:     ------ Rev1.0                             |
  5.                 |          Create Date: ------ 2010/06/19                             |
  6.                 |          Remark:                                                   |
  7.                 |               1.None                                              |
  8.                 |          Description:                                         |
  9.                 |               1.None                                               |
  10.                 |                 2.None                                            |
  11.                 |          Revision History:                                     |
  12.                 |               1.Rev1.0(2010/07/01)初版.                     |
  13.                 |                                                                  |
  14.                  -----------------------------------------------------------*/


  15. /*__________________________  要修改參數(shù)  __________________________*/

  16. ICE_MODE        EQU     1        ;;當(dāng)燒錄時此項設(shè)為0,仿真時設(shè)為1
  17. CHIP                SN8P2501B        ; Select the CHIP
  18. //{{SONIX_CODE_OPTION
  19.         .Code_Option        LVD                LVD_L                ; 2.0V Reset
  20.         .Code_Option        Watch_Dog        Enable        ; Normal mode: Enable Watchdog Green and Sleep mode: Stop Watchdog
  21.         .Code_Option        High_Clk        IHRC_16M        ; Internal 16M RC Oscillator
  22.         .Code_Option        Fcpu                #2     ; Fcpu = Fosc/4
  23.         .Code_Option        Security        Enable
  24.         .Code_Option        Noise_Filter        Disable
  25.         .Code_Option        Reset_Pin        P11
  26. //}}SONIX_CODE_OPTION
  27. /*__________________________________________________________________*/
  28. .NOLIST
  29.         INCLUDE                SonixMac1.h
  30.         INCLUDE                SonixMac2.h
  31.         INCLUDE                SonixFun.h
  32.         INCLUDE                Math.h
  33.         INCLUDE                DefineRamPort.h
  34.         INCLUDE                Fmotor.h
  35.         INCLUDE                FSysClk.h
  36. .LIST
  37. .data
  38.          _Define_Port
  39.          _Define_Temp
  40.          _Define_IDData
  41.          _Define_ReciveData
  42.          _Define_GetMotData         

  43. ;         DComFlg         ds        1
  44. ;         FProtect         equ          DComFlg.0       
  45. ;         Fmot_ProctEnb        equ        DCOMFLG.4
  46. ;------------   調(diào)試選項 ---------------
  47. ;#define  Test_TlyEnb      1      ;禁止陀螺儀調(diào)整
  48. ;#define         Test_PrctEnb     1   ;禁止過流保護
  49. ;#define         Test_fireEnb     1   ;禁止對戰(zhàn)
  50. ;------------   調(diào)試選項 ---------------
  51. .CODE
  52.                 ORG         0000h
  53.                 JMP        RESET
  54.                     ORG         0008h
  55.                 jmp        Interrupt

  56. INCLUDE                GetID.ASM
  57. INCLUDE                ReciveRf.ASM
  58. INCLUDE                GetMotData.ASM
  59. INCLUDE                WuHua.ASM
  60. INCLUDE                TestMode.ASM
  61. //---------------------------------------
  62. RESET:            _CLRRAM      #64  ;參數(shù)=該芯片RAM大小
  63.                 _McrSetSTKP       ;初始化堆棧
  64.                 _Init_Port
  65.                 _Init_Ram
  66.                 _TC0_init_25us
  67.                 b0bset        FGIE

  68.         //=====測試模式?====================
  69. TestCheck:
  70.         call        PowerOnDelay        //延時穩(wěn)定
  71.         call        F_TestCheck
  72.         b0bts1        FTestPowerOn        //是否為測試模式?
  73.         jmp        MAIN               
  74.         b0bset        FLagProtect        //不進入中斷
  75.         //=========進入測試模式==============
  76. TestMain:
  77.         _CLRWDT   
  78.         call        GetSysClk       
  79.         call        F_PwerDelay3s
  80.         call        F_TestFBLRM        //測試左右前后模式馬達
  81.         call        F_TestLED
  82.         call        F_TestEndCnt5s         //延時5s       
  83.         //---------------------------
  84.         b0bts1        FTestAllEnd
  85.         jmp        TestMain
  86.         clr        R_TestWork0        //進入正常模式
  87.         b0bclr        FLagProtect        //清除保護標(biāo)志

  88. /************* 系統(tǒng)主程序監(jiān)控 ****************/
  89. MAIN:         
  90. //        _CLRWDT   
  91.         call        GetSysClk
  92.         call        ReciveRf
  93.         call        F_LargeChkCtrl        //大電流監(jiān)測
  94.         call         GetMotorData
  95.         call        ledctrl       
  96.         call        baidongctl
  97.         call        F_ModeOutDelay       
  98.         call        DropNoSignal
  99.         JMP     MAIN
  100. ;--------------中---------斷-------------
  101. Interrupt:   
  102.         PUSH
  103.         b0bclr        FTC0IRQ       
  104.         _inf        winTimer
  105.         incms        DTimerCont0        ;時鐘發(fā)生位 25us
  106.         b0bts0        FLagProtect
  107.         jmp        Adr_Int0
  108.         b0bts1        Mode1
  109.         jmp        Normal_mode
  110.         ;=======================大模式0
  111.         b0bts0        FInModeDelay        ;Go into Only one
  112.         jmp        @f

  113.         b0bts1        Motor_key1        ;擺動模式初始化        Motor_key1=0,完成,Motor_key1=1未完成
  114.         jmp        @f               

  115.         b0bset        IOmot_Out5
  116.         b0bclr        IOmot_Out1
  117.         b0bclr        IOmot_Out2
  118.         b0bclr        IOmot_Out3
  119.         b0bclr        IOmot_Out4
  120.         clr        modecntus
  121.         clr        modecntus1

  122.         b0bset        FInModeDelay        ;進來一次
  123.         b0bclr        FOutModeOnce        ;進入正常模式標(biāo)志

  124.         jmp        Adr_Int0
  125.         ;----------------------------
  126.     @@:                       
  127.         b0bts0        FlagModeDelay               
  128.         jmp        @f
  129.         b0bts0        Motor_key1        ;擺動模式初始化        Motor_key1=0,完成,Motor_key1=1未完成
  130.         jmp        Adr_Int0

  131.         incms        modecntus
  132.         _jge        modecntus,#100,$+2        ;2.5ms
  133.         jmp        Adr_Int0
  134.         clr        modecntus
  135.        
  136.         incms        modecntus1
  137.         _jge        modecntus1,#46,$+2        ;進入模式,延遲115ms停止馬達,使結(jié)構(gòu)到位 2011-3-17
  138.         jmp        Adr_Int0
  139.         clr        modecntus1
  140.                
  141.         b0bset        FlagModeDelay               
  142.         ;---------------------------
  143.   @@:                               
  144.         b0bclr        IOmot_Out5       
  145.         b0bts1        baidong_keep
  146.         jmp        $+2
  147.         jmp        Adr_Int0
  148.         clr        count0
  149.         clr        count1

  150.         b0bts0        Motor_key1        ;擺動模式初始化        Motor_key1=0,完成,Motor_key1=1未完成
  151.         jmp        Adr_Int0

  152.         b0bts1        zuobai                ;左擺動
  153.         jmp        @f
  154.         b0bset        baidong_mode
  155.         b0bset        baidong_keep
  156.         jmp        Adr_Int0
  157.    @@:
  158.         b0bts1        youbai                ;右擺動
  159.         jmp        @f
  160.         b0bclr        baidong_mode
  161.         b0bset        baidong_keep
  162.         jmp        Adr_Int0
  163.   @@:
  164.         b0bclr        IOmot_out1        ;無擺動
  165.         b0bclr        IOmot_out2
  166.         jmp        Adr_Int0
  167.         ;========================大模式1                       
  168.   Normal_mode:
  169.         b0bts1        Motor_key2        ;正常模式初始化 Motor_key2=1,完成,Motor_key2=0未完成
  170.         jmp        @f

  171.         b0bset        IOmot_Out5
  172.         b0bclr        IOmot_Out3       
  173.         b0bclr        IOmot_Out4
  174.         b0bclr        baidong_keep

  175.         b0bts0        FOutModeOnce
  176.         jmp        Adr_Int0       
  177.         b0bset        FOutModeDelay        ;退出模式延時標(biāo)志 2011.3.17
  178.         b0bclr        FOutModekeep
  179.         b0bset        FOutModeOnce
  180.         b0bclr        IOmot_Out1
  181.         b0bclr        IOmot_Out2

  182.         jmp        Adr_Int0
  183.         ;-------------------------
  184.     @@:       
  185.         b0bclr        IOmot_Out5
  186.         ;-----------------------剎車模式
  187.         b0bts0        shache_keep        ;=0剎車恢復(fù) =1剎車后保持
  188.         jmp        shache0
  189.         b0bts0        shache_do        ;=0沒有剎車 =1正在剎車
  190.         jmp        shache1       
  191.         b0bts1        shache               
  192.         jmp        @f
  193.         b0bset        shache_do
  194.         jmp        shache1
  195.   shache0:                        ;剎車后保持(前后馬達均輸出低電平)
  196.         b0bclr        IOmot_Out1
  197.         b0bclr        IOmot_Out2
  198.         b0bclr        IOmot_Out3
  199.         b0bclr        IOmot_Out4
  200.         jmp        Adr_Int0
  201.   shache1:                        ;剎車進行中(前后馬達正反控制均輸出高,并保持100ms)       
  202.         bts1    Fmot_Speed3Fx        ;制動方式2:反向制動
  203.           jmp        $+4
  204.         b0bclr        IOmot_Out2
  205.           b0bset        IOmot_Out1
  206.           jmp        $+3       
  207.         b0bclr  IOmot_Out1
  208.            b0bset        IOmot_Out2       


  209.         b0bclr        IOmot_Out3
  210.         b0bclr        IOmot_Out4
  211.         incms        count0        ;25us單位
  212.         jge        count0,#80,$+2       
  213.         jmp        Adr_Int0
  214.         clr        count0                ;2ms

  215.         incms        count2
  216.         jge        count2,#35,$+2        ;70ms 剎車時間太短,2011-03-07
  217.         jmp        Adr_Int0
  218.         clr        count2
  219.                                
  220.         incms        count1       
  221.         jge        count1,ShacheCnt,$+2
  222.         jmp        Adr_Int0
  223.         clr        count1                ;修改為剎車最長420ms

  224.         b0bclr        shache
  225.         b0bclr        shache_do
  226.         b0bset        shache_keep
  227.         b0bclr        IOmot_Out1
  228.         b0bclr  IOmot_Out2
  229.         jmp        Adr_Int0
  230.   @@:
  231.         ;---------------------------振動模式(以300ms做前后動作)       
  232.         mov        a,Dmot_Speed3
  233.         and        a,#7fh
  234.         bts1        FZ                ;主推有動作時,馬上停止振動
  235.         jmp        $+3
  236.         b0bts0        zhendong        //無振動信號時不振動
  237.         jmp        zhendongfirst
  238.         b0bclr        zhendong_keep       
  239.         clr        count0
  240.         clr        count1
  241.         clr        count2
  242.         jmp        @f
  243.   zhendongfirst:               
  244.         b0bts0        zhendong_keep               
  245.         jmp        do_zhendong       
  246.         b0bts1        zhendong
  247.         jmp        @f
  248.         b0bset        zhendong_keep       
  249.         clr        count0
  250.         clr        count1
  251.         clr        count2
  252.         b0bclr         IOmot_Out3
  253.         b0bclr         IOmot_Out4
  254.    do_zhendong:                       
  255.         incms        count0               
  256.         jge        count0,#40,$+2
  257.         jmp        Adr_Int0
  258.         clr        count0                ;1ms時間點

  259.         incms        count1
  260.         jge        count1,#18,$+2
  261.         jmp        Adr_Int0
  262.         b0bclr        IOmot_Out1               
  263.         b0bclr        IOmot_Out2               
  264.                
  265.         jge        count1,#90,$+2
  266.         jmp        Adr_Int0
  267.         clr        count1                ;60ms時間點

  268.             cpl        zhendong_flag                       
  269.         b0bts1        zhendong_flag
  270.         jmp        $+4       
  271.         b0bclr        IOmot_Out1        ;正反脈沖交替,實現(xiàn)振動功能
  272.         b0bset        IOmot_Out2
  273.         jmp        $+3
  274.         b0bclr        IOmot_Out2
  275.         b0bset        IOmot_Out1
  276.         jmp        Adr_Int0
  277.         ;---------------------------正常模式
  278.    @@:       
  279.         b0bts1        Left                //左右轉(zhuǎn)向
  280.         jmp        $+4
  281.         b0bclr        IOmot_Out3
  282.         b0bset        IOmot_Out4
  283.         jmp        @f
  284.         b0bts1        Right
  285.         jmp        $+4
  286.         b0bclr        IOmot_Out4
  287.         b0bset        IOmot_Out3
  288.         jmp        @f
  289.         b0bclr        IOmot_Out3
  290.         b0bclr  IOmot_Out4
  291.     @@:
  292.         incms        Dmot_SpdCnt                ;主馬達驅(qū)動
  293.         _je        Dmot_SpdCnt,#100,$+2
  294.         jmp        Amot_SP3
  295.         clr        Dmot_SpdCnt
  296.         mov        a,Dmot_Speed3
  297.         and        a,#7fh
  298.         bts1        FZ
  299.         jmp        @f
  300.         b0bclr        IOmot_Out1
  301.         b0bclr        IOmot_Out2
  302.         jmp        Adr_Int0
  303.     @@:
  304.         bts1    Fmot_Speed3Fx
  305.         b0bset  IOmot_Out1                //后退
  306.         bts0    Fmot_Speed3Fx
  307.         b0bset  IOmot_Out2                //前進
  308.         jmp        Adr_Int0
  309.   Amot_SP3:
  310.         mov        a,Dmot_Speed3
  311.         and        a,#7fh
  312.         je        a,Dmot_SpdCnt,$+2
  313.         jmp        Adr_Int0
  314.         b0bclr        IOmot_Out1
  315.         b0bclr        IOmot_Out2       
  316. Adr_Int0:
  317.                POP
  318.         RETI
  319. /*--------The end of the program-----------------*/
  320.         ENDP
復(fù)制代碼






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

使用道具 舉報

沙發(fā)
ID:51142 發(fā)表于 2017-4-22 16:19 | 只看該作者
這個好,編解碼,學(xué)習(xí)資料!
回復(fù)

使用道具 舉報

板凳
ID:249545 發(fā)表于 2018-4-18 09:48 | 只看該作者
感謝老師支持51黑
回復(fù)

使用道具 舉報

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

本版積分規(guī)則

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

Powered by 單片機教程網(wǎng)

快速回復(fù) 返回頂部 返回列表