📄 motor.s43
字号:
#include "msp430xW42x.h" ; standard definition include file
#include "global_vars.h" ; global variables include file
;********************************************************************/
; Main program
;********************************************************************/
ORG 0E000h
MAIN_T
MOV #WDTHOLD+WDTPW,&WDTCTL
mov.w #300h,SP
MOV.B #OSCCAP1+OSCCAP0,&FLL_CTL0
lo BIT.B #002h,&FLL_CTL0
JNZ lo
mov #0F000h,R5
osc_wait
dec R5
jnz osc_wait
clr R5
clr_ram_field
clr.b ram_start(R5)
inc R5
cmp #1000,R5
jnz clr_ram_field
init_port
mov.b #0FFh,&P1DIR
mov.b #0FFh,&P2DIR
mov.b #0FFh,&P3DIR
mov.b #0FFh,&P4DIR
mov.b #0FFh,&P5DIR
mov.b #0FFh,&P6DIR
clr.b &P6OUT
clr.b &P5OUT
clr.b &P4OUT
clr.b &P3OUT
clr.b &P2OUT
clr.b &P1OUT
bic.b #motor1_bit+motor2_bit,&P2OUT
bic.b #motor1_bit+motor2_bit,&P2DIR
mov.b #0AEh,&BTCTL
bic.b #BTIFG,&IFG2
bis.b #BTIE,&IE2
eint
main_loop
BIS #CPUOFF+SCG1+SCG0+GIE,SR
jmp main_loop
;;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
rtc_deal
bic.b #BTIFG,&IFG2
bit #time_motor_close_bit,&system_flag1
jnz close_sub
inc.w &second_word
cmp #60,&second_word ;60秒
jlo rtc_deal_end
clr &second_word
mov.b #8h,&motor_rotor_time ;开4秒
call #motor_status_open
bis #time_motor_close_bit,&system_flag1
rtc_deal_end
reti
close_sub
bic #time_motor_close_bit,&system_flag1
mov.b #8h,&motor_rotor_time ;关4秒
call #motor_status_close
reti
;;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;;------开电机
;;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
motor_status_open
dint
call #dc_motor_drive
bis.b #motor1_bit,&P2OUT
bic.b #motor2_bit,&P2OUT
call #com_motor_drive
bic.b #motor1_bit+motor2_bit,&P2OUT
clr &TACTL
bic.b #08h,&CACTL1
motor_status_open_end
bis #motor_status_open_bit,&system_flag1
bic #motor_status_close_bit,&system_flag1
eint
ret
;;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;;------关电机
;;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
motor_status_close
dint
call #dc_motor_drive
bis.b #motor2_bit,&P2OUT
bic.b #motor1_bit,&P2OUT
call #com_motor_drive
bic.b #motor1_bit+motor2_bit,&P2OUT
clr &TACTL
bic.b #08h,&CACTL1
bic #motor_status_open_bit,&system_flag1
bis #motor_status_close_bit,&system_flag1
eint
ret
;;--------------------------------------
;;-------用定时器来控制马达开关时间
;;--------------------------------------
dc_motor_drive
bic.b #motor1_bit+motor2_bit,&P2OUT
bis.b #motor1_bit+motor2_bit,&P2DIR
;;------打开比较器
mov.b #088h,&CACTL1
mov.b #0Eh,&CACTL2
clr &CCTL0
mov #124h,&TACTL
mov.w &TAR,&CCR0 ; Current state of TA Counter
add.w #04000h,&CCR0
clr.b &motor_time_counter
ret
;;--------------------------------------
;;马达旋转
;;--------------------------------------
com_motor_drive
bic #CCIFG1,&CCTL0
call #Delay
bic.b #01h,&CACTL1
;;----堵转电流
motor_rotor
bit.b #01h,&CACTL2
jnz motor_rotor_end
time_continue
bit #CCIFG1,&CCTL0
jz time_continue
clr &CCTL0
mov #124h,&TACTL
mov.w &TAR,&CCR0 ; Current state of TA Counter
add.w #04000h,&CCR0 ;0.5s
inc.b &motor_time_counter
cmp.b &motor_rotor_time,&motor_time_counter
jlo motor_rotor
;;------马达运转结束。
motor_rotor_end
bic.b #motor1_bit+motor2_bit,&P2OUT
clr &TACTL
clr &CCTL0
clr &CCR0
bic.b #08h,&CACTL1
ret
Delay
mov #04h,R5
DelayLoop
mov #0fffeh,R6
DelayLoop1
dec R6
jnz DelayLoop1
dec R5
jnz DelayLoop
ret
;************************************************************************************************
; Interrupt Vector Table
;************************************************************************************************
ORG 0FFE0h
DW rtc_deal ; 0FFE0h: Basic Timer1
DW MAIN_T ; 0FFE2h: I/O Port 2
DW MAIN_T ; 0FFE4h: not used
DW MAIN_T ; 0FFE6h: not used
DW MAIN_T ; 0FFE8h: I/O Port 1
DW MAIN_T ; 0FFEAh: Timer_A0 (CCIFG1\CCIFG2)
DW MAIN_T ; 0FFECh: Timer_A0 (CCIFG0)
DW MAIN_T ; 0FFEEh: not used
DW MAIN_T ; 0FFF0h: not used
DW MAIN_T ; 0FFF2h: Scan/IF
DW MAIN_T ; 0FFF4h: Watchdog Timer
DW MAIN_T ; 0FFF6h: Comparator_A
DW MAIN_T ; 0FFF8h: Timer_A1 (CCIFG1\CCIFG2\CCIFG3\CCIFG4)
DW MAIN_T ; 0FFFAh: Timer_A1 (CCIFG0)
DW MAIN_T ; 0FFFCh: NMI, Osc. Fault, Flash memory
DW MAIN_T ; 0FFFEh: Power-Up, ext. Reset, Watchdog,Flash mem.
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -