⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dcmotor.s43

📁 msp430单片机部分代码,,,msp430单片机部分代码
💻 S43
字号:
;******************************************************************************
;
; THIS PROGRAM IS PROVIDED "AS IS". TI MAKES NO WARRANTIES OR
; REPRESENTATIONS, EITHER EXPRESS, IMPLIED OR STATUTORY, 
; INCLUDING ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS 
; FOR A PARTICULAR PURPOSE, LACK OF VIRUSES, ACCURACY OR 
; COMPLETENESS OF RESPONSES, RESULTS AND LACK OF NEGLIGENCE. 
; TI DISCLAIMS ANY WARRANTY OF TITLE, QUIET ENJOYMENT, QUIET 
; POSSESSION, AND NON-INFRINGEMENT OF ANY THIRD PARTY 
; INTELLECTUAL PROPERTY RIGHTS WITH REGARD TO THE PROGRAM OR 
; YOUR USE OF THE PROGRAM.
;
; IN NO EVENT SHALL TI BE LIABLE FOR ANY SPECIAL, INCIDENTAL, 
; CONSEQUENTIAL OR INDIRECT DAMAGES, HOWEVER CAUSED, ON ANY 
; THEORY OF LIABILITY AND WHETHER OR NOT TI HAS BEEN ADVISED 
; OF THE POSSIBILITY OF SUCH DAMAGES, ARISING IN ANY WAY OUT 
; OF THIS AGREEMENT, THE PROGRAM, OR YOUR USE OF THE PROGRAM. 
; EXCLUDED DAMAGES INCLUDE, BUT ARE NOT LIMITED TO, COST OF 
; REMOVAL OR REINSTALLATION, COMPUTER TIME, LABOR COSTS, LOSS 
; OF GOODWILL, LOSS OF PROFITS, LOSS OF SAVINGS, OR LOSS OF 
; USE OR INTERRUPTION OF BUSINESS. IN NO EVENT WILL TI'S 
; AGGREGATE LIABILITY UNDER THIS AGREEMENT OR ARISING OUT OF 
; YOUR USE OF THE PROGRAM EXCEED FIVE HUNDRED DOLLARS 
; (U.S.$500).
;
; Unless otherwise stated, the Program written and copyrighted 
; by Texas Instruments is distributed as "freeware".  You may, 
; only under TI's copyright in the Program, use and modify the 
; Program without any charge or restriction.  You may 
; distribute to third parties, provided that you transfer a 
; copy of this license to the third party and the third party 
; agrees to these terms by its first use of the Program. You 
; must reproduce the copyright notice and any other legend of 
; ownership on each copy or partial copy, of the Program.
;
; You acknowledge and agree that the Program contains 
; copyrighted material, trade secrets and other TI proprietary 
; information and is protected by copyright laws, 
; international copyright treaties, and trade secret laws, as 
; well as other intellectual property laws.  To protect TI's 
; rights in the Program, you agree not to decompile, reverse 
; engineer, disassemble or otherwise translate any object code 
; versions of the Program to a human-readable form.  You agree 
; that in no event will you alter, remove or destroy any 
; copyright notice included in the Program.  TI reserves all 
; rights not specifically granted under this license. Except 
; as specifically provided herein, nothing in this agreement 
; shall be construed as conferring by implication, estoppel, 
; or otherwise, upon you, any license or other right under any 
; TI patents, copyrights or trade secrets.
;
; You may not use the Program in non-TI devices.
;
;
#include          "msp430x11x1.h" ; Standard Equations

NAME  DCmotorspeedcontroller
;******************************************************************************
;    
;    Murugavel Raju
;    Texas Instruments, Inc
;    
;******************************************************************************
;CPU registers used
;******************************************************************************

#define    Duty_cycle   R6                

;******************************************************************************
;Constants
;******************************************************************************
PWM_OUT    equ    004h                    ; bit2 of Port1 / TA1  
Period     equ    0ffh                    ; Counts for D/A, 8bits = 256 
;******************************************************************************
;
;******************************************************************************
           RSEG  CSTACK
           DS    0           
;****************************************************************************** 
           RSEG CODE
;****************************************************************************** 

RESET      mov     #SFE(CSTACK),SP         ; define stackpointer
           call    #Init_Sys               ; Initialize            

Mainloop   bit.b   #BIT0,&P2IN             ; check if 'decrease' button pressed      
           jz      Next1
           
           bit.b   #BIT1,&P2IN             ; check if 'increase' button pressed
           jz      Next2
           
           jmp     Mainloop                ; loop if no button pressed 

Next1      cmp     #0,Duty_cycle           ; check if PWM = 0
           jz      Mainloop                ; repeat loop
           dec     Duty_cycle              ; increment the PWM by one step           
           jmp     SendPWM         
           
Next2      cmp     #0ffh,Duty_cycle        ; check if 256 steps are done
           jz      Mainloop                ; Repeat for next cycle
           inc     Duty_cycle              ; increment the PWM by one step
                      
SendPWM    mov     Duty_cycle,&CCR1        ; Send value to PWM output
           call    #Delay                  ; insert a small delay between key polling
           jmp     Mainloop                ; repeat loop
                                            
;******************************************************************************
Init_Sys;  Modules and Controls Registers set-up subroutine
;******************************************************************************
StopWDT    mov     #WDTPW+WDTHOLD,&WDTCTL  ; Stop Watchdog Timer

SetupBC    mov.b   #XTOFF+RSEL2+RSEL1+RSEL0,&BCSCTL1   
                                           ; RSEL=7
           mov.b   #0ffh,&DCOCTL           ; DCO selected for highest freq.                                            
                                                                                                           
SetupP1    mov.b   #0,&P1OUT               ; P1OUT reset
           bis.b   #PWM_OUT,&P1SEL         ; P1.2/TA1 for PWM OUT                
           bis.b   #0ffh,P1DIR             ; P1.2 output for PWM OUT and remaining unused

SetupP2    mov.b   #03ch,&P2DIR            ; P2.0,P2.1 as inputs,P2.2 to P2.5 outputs(unused) 
           
           mov     #Period,&CCR0           ; Set Period length for PWM output  
           mov     #0,&CCR1                ; Initial PWM value for output
           mov     #OUTMOD_7,&CCTL1        ; Set output mode 7 for TA1
SetupTA    mov     #TASSEL1+MC0,&TACTL     ; Set TimerA Up mode, SMCLK as TACLK
           
           mov     #0,Duty_cycle           ; reset Duty_cycle buffer
           ret                             ; Return from subroutine
                                            

;******************************************************************************
Delay;     Software delay
;******************************************************************************
           push    #03FFFh                 ; Delay to TOS
L1         dec     0(SP)                   ; Decrement TOS
           jnz     L1                      ; Delay over?
           incd    SP                      ; Clean TOS
           ret                             ; Return from subroutine
                                                     

;****************************************************************************** 
             COMMON  INTVEC                 ; MSP430F1xx Interrupt vectors             
;******************************************************************************               
             ORG     RESET_VECTOR
RESET_VEC    DW      RESET                  ; POR, ext. Reset, Watchdog

             END

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -