|
做了一個單片機遙控車項目程序:
RX_01.rar
(54.66 KB, 下載次數(shù): 56)
2016-10-18 16:41 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
TX.rar
(9.25 KB, 下載次數(shù): 46)
2016-10-18 16:41 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
電路圖:
多功能車接收電路.pdf
(32.53 KB, 下載次數(shù): 48)
2016-10-18 16:41 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
這里把電路和源程序分享給51黑電子論壇的朋友們,希望對大家的設(shè)計能有所幫助。
0.png (123.86 KB, 下載次數(shù): 101)
下載附件
2016-10-18 16:37 上傳
0.png (311.58 KB, 下載次數(shù): 116)
下載附件
2016-10-18 16:36 上傳
0.png (192.8 KB, 下載次數(shù): 115)
下載附件
2016-10-18 16:36 上傳
tx部分程序預(yù)覽:
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)初版. |
- | |
- -----------------------------------------------------------*/
- /*__________________________ 要修改參數(shù) __________________________*/
- ICE_MODE EQU 1 ;;當(dāng)燒錄時此項設(shè)為0,仿真時設(shè)為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
- ;------------ 調(diào)試選項 ---------------
- ;#define Test_TlyEnb 1 ;禁止陀螺儀調(diào)整
- ;#define Test_PrctEnb 1 ;禁止過流保護
- ;#define Test_fireEnb 1 ;禁止對戰(zhàn)
- ;------------ 調(diào)試選項 ---------------
- .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 ;參數(shù)=該芯片RAM大小
- _McrSetSTKP ;初始化堆棧
- _Init_Port
- _Init_Ram
- _TC0_init_25us
- b0bset FGIE
- //=====測試模式?====================
- TestCheck:
- call PowerOnDelay //延時穩(wěn)定
- 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 //清除保護標(biāo)志
- /************* 系統(tǒng)主程序監(jiān)控 ****************/
- MAIN:
- // _CLRWDT
- call GetSysClk
- call ReciveRf
- call F_LargeChkCtrl //大電流監(jiān)測
- call GetMotorData
- call ledctrl
- call baidongctl
- call F_ModeOutDelay
- call DropNoSignal
- JMP MAIN
- ;--------------中---------斷-------------
- Interrupt:
- PUSH
- b0bclr FTC0IRQ
- _inf winTimer
- incms DTimerCont0 ;時鐘發(fā)生位 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 ;進入正常模式標(biāo)志
- 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停止馬達,使結(jié)構(gòu)到位 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 ;退出模式延時標(biāo)志 2011.3.17
- b0bclr FOutModekeep
- b0bset FOutModeOnce
- b0bclr IOmot_Out1
- b0bclr IOmot_Out2
- jmp Adr_Int0
- ;-------------------------
- @@:
- b0bclr IOmot_Out5
- ;-----------------------剎車模式
- b0bts0 shache_keep ;=0剎車恢復(fù) =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 ;正反脈沖交替,實現(xiàn)振動功能
- b0bset IOmot_Out2
- jmp $+3
- b0bclr IOmot_Out2
- b0bset IOmot_Out1
- jmp Adr_Int0
- ;---------------------------正常模式
- @@:
- b0bts1 Left //左右轉(zhuǎn)向
- 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 ;主馬達驅(qū)動
- _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
復(fù)制代碼
|
|