📄 motor2.asm
字号:
.mmregs
SPSA2 .set 0x0034
SPSD2 .set 0x0035
SPCR1 .set 0x0000
SPCR2 .set 0x0001
PCR .set 0x000e
.global _c_int00
.def _Motor_init
.def _STEP_CNRTL
.data
StepRun .word 0 ;stop/run
StepDir .word 0 ;p/n
StepLocal .word 0 ;local/rotate
StepHalf .word 1 ;All/Half
StepSpeed .word 20
StepSpeedSave .word 20
StepLong .word 48
StepLongSave .word 48
StepNumber .word 0
StepNumberSave .word 4
Step .word 0
StepDelay .word 0x1000
StepDelaySave .word 0x1000
pStep .word 0
STEP_M
STEP_M1 .word 0x3f08;0x3f04
STEP_M2 .word 0x3f02;0x3f01
STEP_M3 .word 0x3f04;0x3f08
STEP_M4 .word 0x3f01;0x3f02
STEP_MN
STEP_MN1 .word 0x3f08;0x3f04
STEP_MN2 .word 0x3f01;0x3f02
STEP_MN3 .word 0x3f04;0x3f08
STEP_MN4 .word 0x3f02;0x3f01
STEP_MH
STEP_MH1 .word 0x3f08;0x3f04
STEP_MH2 .word 0x3f0a
STEP_MH3 .word 0x3f02;0x3f01
SETP_MH4 .word 0x3f06
STEP_MH5 .word 0x3f04;0x3f08
SETP_MH6 .word 0x3f05
STEP_MH7 .word 0x3f01;0x3f02
SETP_MH8 .word 0x3f09
STEP_MHN
STEP_MHN1 .word 0x3f08;0x3f04
STEP_MHN2 .word 0x3f09
STEP_MHN3 .word 0x3f01;0x3f01
SETP_MHN4 .word 0x3f05
STEP_MHN5 .word 0x3f04;0x3f08
SETP_MHN6 .word 0x3f06
STEP_MHN7 .word 0x3f02;0x3f02
SETP_MHN8 .word 0x3f0a
.text
_STEP_CNRTL:
;运行/停止
LD *(StepRun),A
BC #_STEP_RET,AEQ
;步数,控制旋转/定位,不能初始化为0
LD *(StepLong),A
BC #_STEP_RET,AEQ
;半步/全步
CMPM *(StepHalf),#1
BC #_STEP_HALF,TC
;全步
ST #4,*(StepNumberSave)
;方向
CMPM *(StepDir),#1
BC #_STEP_DIR_N1,TC
ST #STEP_M,*(pStep)
B #_STEP_ALL
_STEP_DIR_N1:
ST #STEP_MN,*(pStep)
B #_STEP_ALL
_STEP_HALF:
;半步
ST #8,*(StepNumberSave)
;方向
CMPM *(StepDir),#1
BC #_STEP_DIR_N2,TC
ST #STEP_MH,*(pStep)
B #_STEP_ALL
_STEP_DIR_N2:
ST #STEP_MHN,*(pStep)
_STEP_ALL:
;读取当前的输出
LD *(StepNumber),A
ADD *(pStep),A
STLM A,AR1
NOP
NOP
LD *AR1,B
STL B,*(Step)
;通过延时控制速度
LD *(StepSpeed),A
SUB #1,A
STL A,*(StepSpeed)
BC #_STEP_RUN,AEQ
_STEP_DELAY:
LD *(StepDelay),B
SUB #1,B
STL B,*(StepDelay)
CMPM *(StepDelay),#0
BC #_STEP_DELAY,NTC
LD *(StepDelaySave),A
STL A,*(StepDelay)
B #_STEP_RET
_STEP_RUN:
LD *(StepSpeedSave),A
STL A,*(StepSpeed)
;向控制引脚发送信号
LD *(Step),B
STM #PCR,SPSA2
STLM B,SPSD2
LD *(StepNumber),A
ADD #1,A
STL A,*(StepNumber)
NOP
NOP
SUB *(StepNumberSave),A
BC #_STEP_LONG,ALT
ST #0,*(StepNumber)
_STEP_LONG:
;根据旋转/定位进行设置
LD *(StepLong),A
SUB #1,A
STL A,*(StepLong)
BC #_STEP_RET,AGT
CMPM *(StepLocal),#1
BC #_STEP_LOCAL,TC
LD *(StepLongSave),A
STL A,*(StepLong)
_STEP_LOCAL:
;ST #0,*(StepNumber)
_STEP_RET:
NOP
NOP
RET
;配置直流电机各种动作
_Motor_init:
LD #1,A
STL A,*(StepRun)
LD #1,A
XOR *(StepDir),A
STL A,*(StepDir)
LD #1,A
STL A,*(StepLocal)
LD #0,A
STL A,*(StepHalf)
LD #100h,A
STL A,*(StepSpeed)
STL A,*(StepSpeedSave)
LD #2,A
STL A,*(StepLongSave)
STL A,*(StepLong)
RET
.end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -