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

📄 ta_uart_32khz_9600.asm

📁 MSP 430 timer_uart,tmA3的片子可直接使用模块
💻 ASM
字号:
;*******************************************************************************
;   Code for application report - "Timer_A UART Library"
;*******************************************************************************
; 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.
;
;*******************************************************************************
;   TA UART Library
;
;   Description; Allows Timer_A to communicate through UART @ 9600 with 32kHz ACLK
;
;   L. Westlund
;   Version    1.1
;   Texas Instruments, Inc
;   August 2007
;   Built with Code Composer Essentials 2.0
;*******************************************************************************
;Change log
;
;1.0 - Inital version - L.Westlund
;1.1 - Misc. updates - A.Dannenberg
;      * Code now preserves registers used in callback function
;      * Fixed issue with callback function parameter
;      * Fixed issue with TAR capture
;*******************************************************************************
;*******************************************************************************
;   Timer_A UART Library - Assumes 32Khz xtal
;
;
;                   MSP430
;             -----------------
;         /|\|              XIN|-
;          | |                 | 32kHz
;          --|RST          XOUT|-
;            |                 |
;            |         P1.2/TA1|<----------
;            |                 | 9600 8N1
;            |         P1.3/TA2|---------->
;
;*******************************************************************************
 .cdecls C,LIST,    "msp430x11x1.h"

; The USE_C_CONTEXT_SAVE macro is used when C functions are called from the
; library. The macro preserves registers R11, R13 - R15 which may be destroyed
; during a C function call. If the calling function is in assembler the
; macro need not be used.
USE_C_CONTEXT_SAVE .set 1

RXD .set 004h           ; RXD on P1.2
TXD .set 008h           ; TXD on P1.3
TI_Bitime .set 003h
TI_Bitime_5 .set 001h


TI_TA_TX_READY .set 0x01
TI_TA_RX_RECEIVED .set 0x02

             ;Variables
            .def      TI_RXData
            .def      TI_FuncPtr
            .def      TI_TA_UART_StatusFlags
            ;Functions
            .def      TI_initTimer
            .def      TI_setCallbackFunction
            .def      TI_TX_Byte

            .bss      TI_FuncPtr,    2
            .bss      TI_TXData,     2
            .bss      TI_RXData,     1
            .bss      TI_TXBitCnt,   1
            .bss      TI_RXBitCnt,   1
            .bss      TI_TA_UART_StatusFlags, 1

            .text
;============================================================================
; TI_initTimer (func ptr)
;============================================================================
TI_initTimer   mov.w   #TASSEL_1+MC_2,&TACTL ; ACLK, continuous mode
            mov.w   #OUT,&TACCTL2           ; TXD Idle as Mark
SetupP1_2   bis.b   #TXD+RXD,&P1SEL         ; P1.2/3 Timer func
            bis.b   #TXD,&P1DIR             ; TXD output on P1
            bic.b   #RXD,&P1DIR             ; RXD input on P1
            mov.b   #TI_TA_TX_READY, &TI_TA_UART_StatusFlags
;-------------------------------FALL-THROUGH----------------------------------
TI_setCallbackFunction;    Subroutine that sets function to be called after RX
;-----------------------------------------------------------------------------
            mov.w   r12, &TI_FuncPtr        ; move function ptr, 1st param
;-------------------------------FALL-THROUGH----------------------------------
RX_Ready    ; Subroutine that Readies UART to RX Byte into RXData Buffer
;-----------------------------------------------------------------------------
            mov.w   #RX_Count,&TI_RXBitCnt  ; Load Bit Counter, 8 data bits
            mov.w   #CM1+SCS+OUT+CAP+CCIE,&TACCTL1 ; Sync, Neg Edge, Capture, Int
            ret                             ; Return from subroutine

;-----------------------------------------------------------------------------
TI_TX_Byte     ; Subroutine that Transmit One Byte from TXData Buffer
;-----------------------------------------------------------------------------
            bit.b   #TI_TA_TX_READY, &TI_TA_UART_StatusFlags
            jz      TX_Return
            bic.b   #TI_TA_TX_READY, &TI_TA_UART_StatusFlags
TX_CheckTAR mov.w   &TAR,&TACCR2            ; Current state of TA counter
            cmp.w   &TAR,&TACCR2            ; !!Prevent async capature!!
            jne     TX_CheckTAR             ;
            add.w   #TI_Bitime,&TACCR2      ; Some time till first bit
            mov.b   r12, &TI_TXData         ; put character into TXData
            mov.w   #TX_Count,&TI_TXBitCnt  ; Load Bit Counter Table Pointer
            mov.w   #OUTMOD2+OUTMOD0+CCIE,&TACCTL2    ; TXD = mark = idle
            bis.w   #GIE, SR                ; enable GIE, incase TX called in ISR
TX_Wait     bit.w   #CCIE,&TACCTL2          ; Wait for TX completion
            jnz     TX_Wait                 ;
TX_Return   ret                             ;

;------------------------------------------------------------------------------
TA1_ISR     ;  RXTXData Buffer holds UART Data for RX, R12 for TX
;------------------------------------------------------------------------------
            cmp.w   #0x04, &TAIV
            jl      TAIV_2
            jeq     TAIV_4
            jge     TAIV_10
TAIV_2      mov.w   &TI_RXBitCnt, PC        ; TAIV case 2: RX byte
TAIV_4      mov.w   &TI_TXBitCnt, PC        ; TAIV case 4: TX byte
TAIV_10     reti                            ; TAIV case 10: overflow

TX_Bit1     add.w   #01h,&TACCR2            ;
TX_Bit      rra.b   TI_TXData               ; LSB is shifted to carry
            jc      TX_Mark                 ; Jump if bit = 1
TX_Space    add.w   #TI_Bitime,&TACCR2      ; Bitime till next bit
            add.w   #0x02, &TI_TXBitCnt
            bis.w   #OUTMOD2,&TACCTL2       ; TX Space
            reti                            ;
TX_Comp     bic.w   #CCIE,&TACCTL2          ; All Bits TX, disable interrupt
            bis.b   #TI_TA_TX_READY, &TI_TA_UART_StatusFlags; All bits TX'ed set flag
TX_Mark     add.w   #TI_Bitime,&TACCR2      ; Bitime till next bit
            add.w   #0x02, &TI_TXBitCnt
            bic.w   #OUTMOD2,&TACCTL2       ; TX Mark
            reti                            ;

RX_Edge     bit.b   #TI_TA_RX_RECEIVED, &TI_TA_UART_StatusFlags
            jnz     RX_Next
            add.w   #0x02, &TI_RXBitCnt
            bic.w   #CAP,&TACCTL1           ; Switch to Compare mode
            add.w   #TI_Bitime_5+TI_Bitime,&TACCR1 ; First Databit 1.5 Bits from edge
            reti                            ;
RX_Bit1     add.w   #01h,&TACCR1            ;
RX_Bit      add.w   #0x02, &TI_RXBitCnt
            bit.w   #SCCI,&TACCTL1          ; Get bit waiting in SCCI
            rrc.b   TI_RXData               ; Store received bit
            add.w   #TI_Bitime,&TACCR1      ; Bitime till next bit
            reti                            ;
                                            ; Decode of Received Byte Here
RX_Comp     bic.w   #CCIE,&TACCTL1          ; All Bits RXed, Disable Interrupt
            bis.b   #TI_TA_RX_RECEIVED, &TI_TA_UART_StatusFlags
            call    #RX_Ready
            push.w  R12
            .if USE_C_CONTEXT_SAVE          ; Full context save?
            push.w  R11                     ;
            push.w  R13                     ; (needed as a C-callback function
            push.w  R14                     ; can be used. May be optimized
            push.w  R15                     ; in case of an ASM callback fn.)
            .endif
            mov.b   &TI_RXData, R12         ; Pass value to callback func
            call    &TI_FuncPtr
            tst.w   R12                     ; Exit LPMx?
            jz      RX_Comp2
            .if USE_C_CONTEXT_SAVE
            bic.w   #LPM4, 10(SP)           ; Exit LPMx
RX_Comp2    pop.w   R15                     ; Full context restore
            pop.w   R14
            pop.w   R13
            pop.w   R11
            .else
            bic.w   #LPM4, 2(SP)            ; Exit LPMx
RX_Comp2
            .endif
            pop.w   R12

RX_Next     reti

            .align
RX_Count    jmp     RX_Edge                 ; Special for TA
            jmp     RX_Bit                  ; RX First Data Bit
            jmp     RX_Bit1                 ;
            jmp     RX_Bit                  ;
            jmp     RX_Bit                  ;
            jmp     RX_Bit1                 ;
            jmp     RX_Bit                  ;
            jmp     RX_Bit1                 ;
            jmp     RX_Bit                  ;
            jmp     RX_Comp                 ; RX Complete, process RX data
TX_Count    jmp     TX_Bit                  ; TX First Data Bit
            jmp     TX_Bit1                 ;
            jmp     TX_Bit                  ;
            jmp     TX_Bit                  ;
            jmp     TX_Bit1                 ;
            jmp     TX_Bit                  ;
            jmp     TX_Bit1                 ;
            jmp     TX_Bit                  ;
            jmp     TX_Mark                 ; TX Stop Bit= Mark
TX_End      jmp     TX_Comp                 ; TX Complete and Complete

            .sect   ".int08"                ; Timer_A1 Vector
            .short  TA1_ISR                 ;
            .end

⌨️ 快捷键说明

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