主程序 main写的规范一点,如:
;=========================================
;==========IO Port Define=================
;=========================================
#define PModeKey T_PA,0
#define PPressKey T_PA,1
#define PMotForward T_PA,2
#define PMotBackward T_PA,3
;=========================================
;===========Registers Defines=============
;=========================================
RSysWork0 EQU 0x10
#define FSleepIn RSysWork0,0 ;睡眠
#define FPistiveSoundChose RSysWork0,1 ;正转声音选择允许
#define FKey10sTimeOut RSysWork0,2 ;10s未松手,马达继续反转
#define FMotTimeDownFirst RSysWork0,3 ;倒计时时间判断
FTableWork0 EQu 0x11
#define FTabInverTimeEnb FTableWork0,0 ;Tab_InverTimeSpd
#define FTabInverSpdEnb FTableWork0,1 ;Tab_InverSpd
#define FTabMotSpdEnb FTableWork0,2 ;Tab_MotSpd
#define FTabFindEnb FTableWork0,3 ;Find Table Enable
;===============================================
;=========声音播放选择==========================
;===============================================
RSoundMode0 EQU 0X12
#define FPlayVoice RSoundMode0,0 ;声音播放
#define FPlayEnb RSoundMode0,1 ;声音播放允许
#define FInvertSoundChose RSoundMode0,2 ;反转声音切换
#define FSoundEngine RSoundMode0,3 ;待机声
RSoundMode2 EQU 0X13
#define FSoundLand1 RSoundMode2,0 ;跑地声1
#define FSoundLand2 RSoundMode2,1 ;跑地声2
#define FSoundLand3 RSoundMode2,2 ;跑地声3
#define FSoundLand4 RSoundMode2,3 ;跑地声4
RSoundMode1 EQU 0X14
#define FSpeedUp1 RSoundMode1,0 ;加速声1
#define FSpeedUp2 RSoundMode1,1 ;加速声2
#define FSpeedUp3 RSoundMode1,2 ;加速声3
#define FSpeedUp4 RSoundMode1,3 ;加速声4
FKeyWork0 EQU 0x15
#define FDoorKeyDown FKeyWork0,0 ;车门按下标志
#define FDoorKeyEnb FKeyWork0,1 ;按键允许
#define FModeKeyDown FKeyWork0,2 ;模式按下标志
#define FModeKeyEnb FKeyWork0,3 ;模式开关允许
RPressTCnt0 EQU 0x16 ;按压基准
RPressTime EQU 0x17 ;按压时间
;------------------------------------
FMotCtrl EQU 0x18 ;马达控制标志
#define FMotInvert FMotCtrl,0 ;反转标志
; #define FMotInvertRunEnb FMotCtrl,1 ;转停控制
#define FMotPositive FMotCtrl,2 ;正转标志
#define FMotTimeDown FMotCtrl,3 ;倒计时标志
DMotspd EQU 0x19
DMotCnt EQU 0x1a
TMotDown0 EQU 0x1b
TMotDown1 EQU 0x1c ;倒计时秒单位
KeyLastA1 EQU 0x1d
KeyLastA0 EQU 0x1e
;----------------------------
RTabInverCnt EQU 0x20 ;反转查表PCL计数
RMotInverCnt EQU 0x21 ;级数级数
RMotInverTime EQU 0x22 ;反转转停时间
;----------------------------
;-------睡眠计数10s
;----------------------------
R_SleepCnt0 EQU 0X30
R_SleepCnt1 EQU 0X31
R_SleepCnt2 EQU 0X32
;============================
;=====系统时间标志位
;============================
DBaseClk0 EQU 0x38
DBaseClk1 EQU 0x39
DBaseClk2 EQU 0x3a
Sysbank0 EQU 0x3b
SysFlag0 EQU 0x3c
#define FClk_25ms SysFlag0,0
#define FClk_50ms SysFlag0,1
#define FClk_100ms SysFlag0,2
#define FClk_200ms SysFlag0,3
;----------------------------
Temp0 EQU 0x3d
Temp1 EQU 0x3e
;=============================================
;=============头文件包含======================
;=============================================
#include"INH\NY4P_SFR.H"
#include"INH\NY4P_MACRO.M"
#include"INH\NY4P_MACRO1.M"
#include"INH\NY4_MATH.M"
;----------------------------
ORG 0X000000
JMP RESET
ORG 0X000800
;----------------------------
#include"module\keyscanA.asm"
#include"module\GetTabDataA.asm"
#include"module\MotorDrvA.asm"
#include"module\InitA.asm"
;=============================================
;=============初始化程序段====================
;=============================================
RESET:
_CLEAR_RAM
Cwdt ;清看门狗
_MOVL 0x2,T_BT ;1ms
_MOVL 0X3,T_PAIO
_MOVL 0X3,T_PA
_MOVL 0Xf,T_PBIO
_MOVL 0Xf,T_PB
mvma t_sfr
orl 0x4
mvam t_sfr
mvla 0x1
mvam KeyLastA0
mvla 0x2
mvam KeyLastA1
;-------------------------
M_LoadVoiceDataAddress Start,0x7,0xC ;8K 启动
play
L_PowerStartA:
CWDT ;清看门狗
MVMA T_SFR
ANDL fRP**
CPAL 0
JMP L_PowerStartA
;--------------------------------
M_LoadVoiceDataAddress Playup,0x6,0x3 ;10K 加油声
play
L_PowerPlayUpA0:
CWDT ;清看门狗
MVMA T_SFR
ANDL fRP**
CPAL 0
JMP L_PowerPlayUpA0
;--------------------------------
M_StopVoiceDataRate ;声音停止
;--------------------------------------
;上电就按下车门,认为是触发。
;--------------------------------------
_BTSS_BIT PPressKey,L_PowerOnSleep
;--------------------------------------
_setbit FDoorKeyDown ;按键按下
_setbit FTabFindEnb ;查表允许
_setbit FTabInverTimeEnb ;反转查表
_setbit FMotInvert ;允许反转
_setbit FModeKeyEnb ;模式按键允许
JMP F_MainA
L_PowerOnSleep:
_setbit FSoundEngine ;待机声
_setbit FPlayVoice
_setbit FPlayEnb
;=============================================
;=============主程序段========================
;=============================================
F_MainA:
call Systime_ctrl
call Get_systime
jmp F_GetModeA ;传感器
After_GetModeA:
call GetPresKeyA ;车门按制
jmp F_GetTabDataA ;查表
After_GetMotDataA:
call MotorDrv_NegA
call MotorDrvA ;马达驱动
JMP MotTimerDownA
After_MotTimerDownA:
call F_GetInvertSoundA
jmp VoiceActionA
After_VoiceActionA:
JMP F_CheckSleep
After_CheckSleep:
;----------------------------
_btsc_bit FSleepIn,F_MainA
MVMA T_SFR
ANDL fRP**
CPAL 0
JMP F_MainA
_MOVM T_PA,T_PA
_MOVM T_PB,T_PB
_clrbit FSleepIn
;------------清寄存器------------
L_FallInSleep:
nop
nop
nop
nop
_SLEEP
nop
nop
nop
nop
_btss_bit PModeKey,L_WakePressKey
_btsc_bit FModeKeyEnb,L_FallInSleep
jmp L_SystemWakeup
L_WakePressKey:
_btss_bit PPressKey,L_FallInSleep
_btss_bit FModeKeyEnb,L_FallInSleep
L_SystemWakeup:
mvla 0x1
mvam KeyLastA0
mvla 0x2
mvam KeyLastA1
; JMP RESET
JMP F_MainA
;=============================================
;=============表格定义========================
;=============================================
org 0x000D20
Tab_MotSpd: ;正转,满级10级
dw 0x0
dw 0x1 ;10%
dw 0x2
dw 0x3
dw 0x4 ;40%
dw 0x5
dw 0x6
dw 0x7 ;70%
dw 0x8
dw 0x9
dw 0xa ;100%
;---------------------------
;---------------------------
;反转转停时间控制,满级12级
;---------------------------
;最高位:转停控制
;次高位:马达转停时间控制
;最低位:反转马达级数
;===========================
org 0x000D30
Tab_InverTimeSpd:
dw 0x183 ;0.8s Run
dw 0x080 ;0.5s Stop
;-------------
dw 0x186 ;0.8s Run
dw 0x050 ;0.5s Stop
;-------------
dw 0x186 ;0.8s Run
dw 0x040 ;0.4s Stop
;-------------
dw 0x189 ;0.8s Run
dw 0x030 ;0.3s Stop
;-------------
dw 0x189 ;0.8s Run
dw 0x020 ;0.2s Stop
;-------------
dw 0x189 ;0.8s Run
dw 0x010 ;0.1s Stop
;-------------
dw 0x1bc ;1.5s Run
dw 0x1ac ;1.4s Run
dw 0x18c ;1.5s Run
;---------------------------
;=============================================
;=============声音文件包含====================
;最后修改:3/14/2011 11:47:38 AM
;=============================================
Start:
#includata"sound\MainswitchOnA.v4x"
;----------------------------
Playup:
#includata"sound\MainswitchOnB.v4x"
;----------------------------
Enginestart:
#includata"sound\Idlingsound.v4x"
;----------------------------
Speedup:
#includata"sound\GripswitchON.v4x"
;----------------------------
SpeedOnLand:
#includata"sound\StartswitchON.v4x"
;======================================
END |