做了一个单片机遥控车项目程序:
RX_01.rar
(54.66 KB, 下载次数: 52)
TX.rar
(9.25 KB, 下载次数: 43)
电路图:
多功能车接收电路.pdf
(32.53 KB, 下载次数: 45)
这里把电路和源程序分享给51黑电子论坛的朋友们,希望对大家的设计能有所帮助。
tx部分程序预览:
rx程序:
- /*-----------------------------------------------------------
- | Module Name: ------ MAIN.ASM |
- | Author: ------ Tom |
- | Version: ------ Rev1.0 |
- | Create Date: ------ 2010/06/19 |
- | Remark: |
- | 1.None |
- | Description: |
- | 1.None |
- | 2.None |
- | Revision History: |
- | 1.Rev1.0(2010/07/01)初版. |
- | |
- -----------------------------------------------------------*/
- /*__________________________ 要修改参数 __________________________*/
- ICE_MODE EQU 1 ;;当烧录时此项设为0,仿真时设为1
- CHIP SN8P2501B ; Select the CHIP
- //{{SONIX_CODE_OPTION
- .Code_Option LVD LVD_L ; 2.0V Reset
- .Code_Option Watch_Dog Enable ; Normal mode: Enable Watchdog Green and Sleep mode: Stop Watchdog
- .Code_Option High_Clk IHRC_16M ; Internal 16M RC Oscillator
- .Code_Option Fcpu #2 ; Fcpu = Fosc/4
- .Code_Option Security Enable
- .Code_Option Noise_Filter Disable
- .Code_Option Reset_Pin P11
- //}}SONIX_CODE_OPTION
- /*__________________________________________________________________*/
- .NOLIST
- INCLUDE SonixMac1.h
- INCLUDE SonixMac2.h
- INCLUDE SonixFun.h
- INCLUDE Math.h
- INCLUDE DefineRamPort.h
- INCLUDE Fmotor.h
- INCLUDE FSysClk.h
- .LIST
- .data
- _Define_Port
- _Define_Temp
- _Define_IDData
- _Define_ReciveData
- _Define_GetMotData
- ; DComFlg ds 1
- ; FProtect equ DComFlg.0
- ; Fmot_ProctEnb equ DCOMFLG.4
- ;------------ 调试选项 ---------------
- ;#define Test_TlyEnb 1 ;禁止陀螺仪调整
- ;#define Test_PrctEnb 1 ;禁止过流保护
- ;#define Test_fireEnb 1 ;禁止对战
- ;------------ 调试选项 ---------------
- .CODE
- ORG 0000h
- JMP RESET
- ORG 0008h
- jmp Interrupt
- INCLUDE GetID.ASM
- INCLUDE ReciveRf.ASM
- INCLUDE GetMotData.ASM
- INCLUDE WuHua.ASM
- INCLUDE TestMode.ASM
- //---------------------------------------
- RESET: _CLRRAM #64 ;参数=该芯片RAM大小
- _McrSetSTKP ;初始化堆栈
- _Init_Port
- _Init_Ram
- _TC0_init_25us
- b0bset FGIE
- //=====测试模式?====================
- TestCheck:
- call PowerOnDelay //延时稳定
- call F_TestCheck
- b0bts1 FTestPowerOn //是否为测试模式?
- jmp MAIN
- b0bset FLagProtect //不进入中断
- //=========进入测试模式==============
- TestMain:
- _CLRWDT
- call GetSysClk
- call F_PwerDelay3s
- call F_TestFBLRM //测试左右前后模式马达
- call F_TestLED
- call F_TestEndCnt5s //延时5s
- //---------------------------
- b0bts1 FTestAllEnd
- jmp TestMain
- clr R_TestWork0 //进入正常模式
- b0bclr FLagProtect //清除保护标志
- /************* 系统主程序监控 ****************/
- MAIN:
- // _CLRWDT
- call GetSysClk
- call ReciveRf
- call F_LargeChkCtrl //大电流监测
- call GetMotorData
- call ledctrl
- call baidongctl
- call F_ModeOutDelay
- call DropNoSignal
- JMP MAIN
- ;--------------中---------断-------------
- Interrupt:
- PUSH
- b0bclr FTC0IRQ
- _inf winTimer
- incms DTimerCont0 ;时钟发生位 25us
- b0bts0 FLagProtect
- jmp Adr_Int0
- b0bts1 Mode1
- jmp Normal_mode
- ;=======================大模式0
- b0bts0 FInModeDelay ;Go into Only one
- jmp @f
- b0bts1 Motor_key1 ;摆动模式初始化 Motor_key1=0,完成,Motor_key1=1未完成
- jmp @f
- b0bset IOmot_Out5
- b0bclr IOmot_Out1
- b0bclr IOmot_Out2
- b0bclr IOmot_Out3
- b0bclr IOmot_Out4
- clr modecntus
- clr modecntus1
- b0bset FInModeDelay ;进来一次
- b0bclr FOutModeOnce ;进入正常模式标志
- jmp Adr_Int0
- ;----------------------------
- @@:
- b0bts0 FlagModeDelay
- jmp @f
- b0bts0 Motor_key1 ;摆动模式初始化 Motor_key1=0,完成,Motor_key1=1未完成
- jmp Adr_Int0
- incms modecntus
- _jge modecntus,#100,$+2 ;2.5ms
- jmp Adr_Int0
- clr modecntus
-
- incms modecntus1
- _jge modecntus1,#46,$+2 ;进入模式,延迟115ms停止马达,使结构到位 2011-3-17
- jmp Adr_Int0
- clr modecntus1
-
- b0bset FlagModeDelay
- ;---------------------------
- @@:
- b0bclr IOmot_Out5
- b0bts1 baidong_keep
- jmp $+2
- jmp Adr_Int0
- clr count0
- clr count1
- b0bts0 Motor_key1 ;摆动模式初始化 Motor_key1=0,完成,Motor_key1=1未完成
- jmp Adr_Int0
- b0bts1 zuobai ;左摆动
- jmp @f
- b0bset baidong_mode
- b0bset baidong_keep
- jmp Adr_Int0
- @@:
- b0bts1 youbai ;右摆动
- jmp @f
- b0bclr baidong_mode
- b0bset baidong_keep
- jmp Adr_Int0
- @@:
- b0bclr IOmot_out1 ;无摆动
- b0bclr IOmot_out2
- jmp Adr_Int0
- ;========================大模式1
- Normal_mode:
- b0bts1 Motor_key2 ;正常模式初始化 Motor_key2=1,完成,Motor_key2=0未完成
- jmp @f
- b0bset IOmot_Out5
- b0bclr IOmot_Out3
- b0bclr IOmot_Out4
- b0bclr baidong_keep
- b0bts0 FOutModeOnce
- jmp Adr_Int0
- b0bset FOutModeDelay ;退出模式延时标志 2011.3.17
- b0bclr FOutModekeep
- b0bset FOutModeOnce
- b0bclr IOmot_Out1
- b0bclr IOmot_Out2
- jmp Adr_Int0
- ;-------------------------
- @@:
- b0bclr IOmot_Out5
- ;-----------------------刹车模式
- b0bts0 shache_keep ;=0刹车恢复 =1刹车后保持
- jmp shache0
- b0bts0 shache_do ;=0没有刹车 =1正在刹车
- jmp shache1
- b0bts1 shache
- jmp @f
- b0bset shache_do
- jmp shache1
- shache0: ;刹车后保持(前后马达均输出低电平)
- b0bclr IOmot_Out1
- b0bclr IOmot_Out2
- b0bclr IOmot_Out3
- b0bclr IOmot_Out4
- jmp Adr_Int0
- shache1: ;刹车进行中(前后马达正反控制均输出高,并保持100ms)
- bts1 Fmot_Speed3Fx ;制动方式2:反向制动
- jmp $+4
- b0bclr IOmot_Out2
- b0bset IOmot_Out1
- jmp $+3
- b0bclr IOmot_Out1
- b0bset IOmot_Out2
- b0bclr IOmot_Out3
- b0bclr IOmot_Out4
- incms count0 ;25us单位
- jge count0,#80,$+2
- jmp Adr_Int0
- clr count0 ;2ms
- incms count2
- jge count2,#35,$+2 ;70ms 刹车时间太短,2011-03-07
- jmp Adr_Int0
- clr count2
-
- incms count1
- jge count1,ShacheCnt,$+2
- jmp Adr_Int0
- clr count1 ;修改为刹车最长420ms
- b0bclr shache
- b0bclr shache_do
- b0bset shache_keep
- b0bclr IOmot_Out1
- b0bclr IOmot_Out2
- jmp Adr_Int0
- @@:
- ;---------------------------振动模式(以300ms做前后动作)
- mov a,Dmot_Speed3
- and a,#7fh
- bts1 FZ ;主推有动作时,马上停止振动
- jmp $+3
- b0bts0 zhendong //无振动信号时不振动
- jmp zhendongfirst
- b0bclr zhendong_keep
- clr count0
- clr count1
- clr count2
- jmp @f
- zhendongfirst:
- b0bts0 zhendong_keep
- jmp do_zhendong
- b0bts1 zhendong
- jmp @f
- b0bset zhendong_keep
- clr count0
- clr count1
- clr count2
- b0bclr IOmot_Out3
- b0bclr IOmot_Out4
- do_zhendong:
- incms count0
- jge count0,#40,$+2
- jmp Adr_Int0
- clr count0 ;1ms时间点
- incms count1
- jge count1,#18,$+2
- jmp Adr_Int0
- b0bclr IOmot_Out1
- b0bclr IOmot_Out2
-
- jge count1,#90,$+2
- jmp Adr_Int0
- clr count1 ;60ms时间点
- cpl zhendong_flag
- b0bts1 zhendong_flag
- jmp $+4
- b0bclr IOmot_Out1 ;正反脉冲交替,实现振动功能
- b0bset IOmot_Out2
- jmp $+3
- b0bclr IOmot_Out2
- b0bset IOmot_Out1
- jmp Adr_Int0
- ;---------------------------正常模式
- @@:
- b0bts1 Left //左右转向
- jmp $+4
- b0bclr IOmot_Out3
- b0bset IOmot_Out4
- jmp @f
- b0bts1 Right
- jmp $+4
- b0bclr IOmot_Out4
- b0bset IOmot_Out3
- jmp @f
- b0bclr IOmot_Out3
- b0bclr IOmot_Out4
- @@:
- incms Dmot_SpdCnt ;主马达驱动
- _je Dmot_SpdCnt,#100,$+2
- jmp Amot_SP3
- clr Dmot_SpdCnt
- mov a,Dmot_Speed3
- and a,#7fh
- bts1 FZ
- jmp @f
- b0bclr IOmot_Out1
- b0bclr IOmot_Out2
- jmp Adr_Int0
- @@:
- bts1 Fmot_Speed3Fx
- b0bset IOmot_Out1 //后退
- bts0 Fmot_Speed3Fx
- b0bset IOmot_Out2 //前进
- jmp Adr_Int0
- Amot_SP3:
- mov a,Dmot_Speed3
- and a,#7fh
- je a,Dmot_SpdCnt,$+2
- jmp Adr_Int0
- b0bclr IOmot_Out1
- b0bclr IOmot_Out2
- Adr_Int0:
- POP
- RETI
- /*--------The end of the program-----------------*/
- ENDP
复制代码
|