www.pudn.com > slaa078a.zip > 11x1_uart3.s43


#include  "msp430x11x1.h" 
;***************************************************************************** 
;   MSP-FET430x110 Demo - 2400-baud UART using 32kHz Crystal 
; 
;   Description: This program demonstrates a half-duplex 2400-baud UART using  
;   Timer_A3 and a 32kHz crystal.  The program will wait in LPM3, echoing  
;   back a received character using 8N1 protocal. The 32768 crystal is used  
;   directly as the Timer_A clock and baud rate generator. 
; 
; 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. 
; 
;                MSP430F1121 
;             ----------------- 
;         /|\|              XIN|-   
;          | |                 | 32k 
;          --|RST          XOUT|- 
;            |                 | 
;            |                 | 2400 8N1  
;            |          TX/P1.1|-------->   
;            |          TX/P2.2|<-------- 
; 
RXD         equ    004h                ; RXD on P2.2 
TXD         equ    002h                ; TXD on P1.1 
;   RAM Registers Used 
RXTXData    equ    0200h               ; Register for RX or TX UART Data 
BitCnt      equ    0202h               ; Register used to count UART bits 
; 
;   Conditions for 2400 Baud SW UART, ACLK = 32768 
Bitime_5    equ    06                  ; .5 bit length + small adjustment  
Bitime      equ    014                 ; 427us bit length ~ 2341 baud 
; 
;   M.Buccini 
;   Texas Instruments, Inc 
;   March 2002  
;***************************************************************************** 
;-----------------------------------------------------------------------------  
            ORG     0F000h                  ; Program Start 
;-----------------------------------------------------------------------------  
RESET       mov.w   #300h,SP                ; Initialize Stackpointer 
            call    #Init_Sys               ; Initialize System Peripherals 
                                            ; 
Mainloop    call    #RX_Ready               ; UART ready to RX one Byte 
            bis.w   #LPM3,SR                ; Enter LPM3 Until Byte RXed 
            call    #TX_Byte                ; TX Back RXed Byte Received 
            jmp     Mainloop                ; 
                                            ; 
;-----------------------------------------------------------------------------  
Init_Sys    ; Subroutine to set-up peripherals   
;-----------------------------------------------------------------------------  
StopWDT     mov.w   #WDTPW+WDTHOLD,&WDTCTL  ; Stop WDT 
SetupTA     mov.w   #TASSEL0+MC1,&TACTL     ; ACLK, continous mode 
SetupC0     mov.w   #OUT,&CCTL0             ; TXD Idle as Mark  
SetupP1_2   bis.b   #TXD,&P1SEL             ; P1.1/TA0 for TXD function 
            bis.b   #TXD,&P1DIR             ; TXD output on P1 
            bis.b   #RXD,&P2SEL             ; P2.2/TA0 as RXD input 
            eint                            ; General Enable Interrupts 
            ret                             ; 
                                            ; 
;-----------------------------------------------------------------------------  
TX_Byte     ; Subroutine that Transmit One Byte from RXTXData Buffer. 
;-----------------------------------------------------------------------------  
            mov.w   &TAR,&CCR0              ; Current state of TA Counter 
            add.w   #Bitime,&CCR0           ; Some time till first bit 
            bis.w   #0100h, &RXTXData       ; Add mark stop bit to RXTXData  
            rla.w   &RXTXData               ; Add space start bit 
            mov.w   #10,&BitCnt             ; Load Bit Counter, 8 data + SP 
            mov.w   #OUTMOD0+CCIE,&CCTL0    ; TXD = mark = idle  
TX_Wait     bit.w   #CCIE,&CCTL0            ; Wait for TX completion 
            jnz     TX_Wait                 ;  
            ret                             ; 
                                            ; 
;-----------------------------------------------------------------------------  
RX_Ready  ; Subroutine that will Receive One Byte into RXTXData Buffer. 
;-----------------------------------------------------------------------------  
            mov.w   #08,&BitCnt              ; Load Bit Counter, 8 data bits 
SetupRX     mov.w   #SCS+CCIS0+OUTMOD0+CM1+CAP+CCIE,&CCTL0  ; Sync,Neg Edge,Cap           
            ret                             ; 
                                            ; 
;-----------------------------------------------------------------------------  
TA0_ISR  ;  CCR0/UART ISR:   RXTXData Buffer holds UART Data. 
;-----------------------------------------------------------------------------  
            add.w   #Bitime,&CCR0           ; Time to Next Bit 
            bit.w   #CCIS0,&CCTL0           ; RX on ISCCIB? 
            jnz     UART_RX                 ; Jump --> RX 
UART_TX     cmp.w   #00h,&BitCnt            ; 
            jne     TX_Next                 ; Next bit? 
            bic.w   #CCIE,&CCTL0            ; All Bits TX or RX, Disable Int. 
            reti                            ; 
TX_Next     bic.w   #OUTMOD2,&CCTL0         ; TX Mark  
            rra.w   &RXTXData               ; LSB is shifted to carry 
            jc      TX_Test                 ; Jump --> bit = 1 
TX_Space    bis.w   #OUTMOD2,&CCTL0         ; TX Space  
TX_Test     dec.w   &BitCnt                 ; All bits sent (or received)? 
            reti                            ; 
                                            ; 
UART_RX     bit.w   #CAP,&CCTL0             ; Compare mode for start bit edge 
            jz      RX_Bit                  ; Start bit edge? 
RX_Edge     bic.w   #CAP,&CCTL0             ; Switch to Compare mode 
            add.w   #Bitime_5,&CCR0         ; First databit 1.5 bits from edge 
            reti                            ; 
RX_Bit      bit.w   #SCCI,&CCTL0            ; Get bit waiting in receive latch 
            rrc.b   &RXTXData                ; Store received bit 
RX_Test     dec.w   &BitCnt                  ; All bits sent (or received)? 
            jnz     RX_Next                 ; Next bit? 
;>>>>>>>>>> Decode of Received Byte Here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 
RX_Comp     bic.w   #CCIE,&CCTL0            ; All Bits RXed, Disable Interrupt  
            mov.w   #GIE,0(SP)              ; Decode Byte= Active in Mainloop 
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< 
RX_Next     reti                            ; 
; 
;-----------------------------------------------------------------------------  
;           Interrupt Vectors Used MSP430x11x1           
;-----------------------------------------------------------------------------  
            ORG     0FFFEh                  ; MSP430 RESET Vector 
            DW      RESET                   ;  
            ORG     0FFF2h                  ; Timer_A0 Vector 
            DW      TA0_ISR                 ;  
            END