找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 8754|回复: 2
打印 上一主题 下一主题
收起左侧

单片机遥控车电路和源程序

[复制链接]
跳转到指定楼层
楼主
做了一个单片机遥控车项目程序:
RX_01.rar (54.66 KB, 下载次数: 52)
TX.rar (9.25 KB, 下载次数: 43)
电路图:
多功能车接收电路.pdf (32.53 KB, 下载次数: 45)

这里把电路和源程序分享给51黑电子论坛的朋友们,希望对大家的设计能有所帮助。





tx部分程序预览:
  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. //函数名称:void DvrSmog(void)
  31. //输入参数:无
  32. //输出参数:无
  33. //函数功能:发射信号清除控制
  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. //函数名称:void NoSendSignel(void)
  87. //输入参数:无
  88. //输出参数:无
  89. //函数功能:连续无信号,停止发射
  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. //函数名称:void main(void)
  108. //输入参数:无
  109. //输出参数:无
  110. //函数功能:主程序段
  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();      //获得主推数据
  124.                 GetSendData();
  125.                 FNoSigEnb=1;        //填码禁止
  126.                 NoSendSignel();

  127.                 if(!FSendEnb0)  continue;
  128.                 SetLed(gb_key);
  129.                 sendRF();
  130.                 SoundCtrl();                //发声
  131.                DvrSmog();
  132.                 FNoSigEnb=0;        //填码允许               
  133.         }
  134. }
复制代码

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. /*__________________________  要修改参数  __________________________*/

  16. ICE_MODE        EQU     1        ;;当烧录时此项设为0,仿真时设为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. ;------------   调试选项 ---------------
  47. ;#define  Test_TlyEnb      1      ;禁止陀螺仪调整
  48. ;#define         Test_PrctEnb     1   ;禁止过流保护
  49. ;#define         Test_fireEnb     1   ;禁止对战
  50. ;------------   调试选项 ---------------
  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  ;参数=该芯片RAM大小
  63.                 _McrSetSTKP       ;初始化堆栈
  64.                 _Init_Port
  65.                 _Init_Ram
  66.                 _TC0_init_25us
  67.                 b0bset        FGIE

  68.         //=====测试模式?====================
  69. TestCheck:
  70.         call        PowerOnDelay        //延时稳定
  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        //清除保护标志

  88. /************* 系统主程序监控 ****************/
  89. MAIN:         
  90. //        _CLRWDT   
  91.         call        GetSysClk
  92.         call        ReciveRf
  93.         call        F_LargeChkCtrl        //大电流监测
  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        ;时钟发生位 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        ;进入正常模式标志

  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停止马达,使结构到位 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        ;退出模式延时标志 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刹车恢复 =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        ;正反脉冲交替,实现振动功能
  272.         b0bset        IOmot_Out2
  273.         jmp        $+3
  274.         b0bclr        IOmot_Out2
  275.         b0bset        IOmot_Out1
  276.         jmp        Adr_Int0
  277.         ;---------------------------正常模式
  278.    @@:       
  279.         b0bts1        Left                //左右转向
  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                ;主马达驱动
  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
复制代码






分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏5 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:51142 发表于 2017-4-22 16:19 | 只看该作者
这个好,编解码,学习资料!
回复

使用道具 举报

板凳
ID:249545 发表于 2018-4-18 09:48 | 只看该作者
感谢老师支持51黑
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表