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

📄 msp430x24x_uscia1_irda_01.s43

📁 步进电机驱动程序msp430f247单片机
💻 S43
字号:
;*******************************************************************************
;   MSP430x24x Demo - USCI_A1 IrDA External Loopback Test, 8MHz SMCLK
;
;   Description: This example transmits bytes through the USCI module
;   configured for IrDA mode, and receives them using an external loopback
;   connection. The transfered sequence is 00h, 01h, 02h, ..., ffh. The
;   received bytes are also stored in memory starting at address RxData.
;   In the case of an RX error the LED is lighted and program execution stops.
;   An external loopback connection has been used as it allows for the
;   connection of a scope to monitor the communication, which is not possible
;   when using the internal loopback.
;   ACLK = n/a, MCLK = SMCLK = BRCLK = CALxxx_8MHZ = 8MHz
;
;               MSP430F249
;             -----------------
;         /|\|              XIN|-
;          | |                 |
;          --|RST          XOUT|-
;            |                 |
;            |     P3.7/UCA1RXD|--+   external
;            |     P3.6/UCA1TXD|--+   loopback connection
;            |                 |
;            |                 |
;            |             P1.0|--->  LED
;            |                 |
;
;   B. Nisarga
;   Texas Instruments Inc.
;   September 2007
;   Built with IAR Embedded Workbench Version: 3.42A
;*******************************************************************************
#include "msp430x24x.h"
;-------------------------------------------------------------------------------
            RSEG    CSTACK                  ; Define stack segment
;-------------------------------------------------------------------------------
            RSEG    DATA16_N                ; RAM
RxData      DS      256                     ; Allocate 256 byte of RAM
;-------------------------------------------------------------------------------
            RSEG    CODE                    ; Assemble to Flash memory
;-------------------------------------------------------------------------------
RESET       mov.w   #SFE(CSTACK),SP         ; Initialize stackpointer
StopWDT     mov.w   #WDTPW+WDTHOLD,&WDTCTL  ; Stop WDT
CheckCal    cmp.b   #0FFh,&CALBC1_8MHZ      ; Calibration constants erased?
            jeq     Trap
            cmp.b   #0FFh,&CALDCO_8MHZ
            jne     Load  
Trap        jmp     $                       ; Trap CPU!!
Load        mov.b   &CALBC1_8MHZ,&BCSCTL1   ; Set DCO to 8MHz
            mov.b   &CALDCO_8MHZ,&DCOCTL    ;
SetupP1     bic.b   #001h,&P1OUT            ; Clear P1.0
            bis.b   #001h,&P1DIR            ; P1.0 output
SetupP3     bis.b   #0C0h,&P3SEL            ; Use P3.6/P3.7 for USCI_A1
SetupUSCI0  bis.b   #UCSWRST,&UCA1CTL1      ; Set SW Reset
            mov.b   #UCSSEL_2+UCSWRST,&UCA1CTL1
                                            ; Use SMCLK, keep SW reset
            mov.b   #52,&UCA1BR0            ; 8MHz/52=153.8KHz
            mov.b   #0,&UCA1BR1             ;
            mov.b   #UCBRF_1+UCOS16,&UCA1MCTL
                                            ; Set 1st stage modulator to 1
                                            ; 16-times oversampling mode
            mov.b   #UCIRTXPL2+UCIRTXPL0+UCIRTXCLK+UCIREN,&UCA1IRTCTL
                                            ; Pulse length = 6 half clock cyc
                                            ; Enable BITCLK16, IrDA enc/dec
            bic.b   #UCSWRST,&UCA1CTL1      ; Resume operation
                                            ;
            clr.w   R4                      ; Init delay counter
            clr.b   R5                      ; TX data and pointer, 8-bit
                                            ;
Mainloop    inc.w   R4                      ; Small delay
            cmp.w   #1000,R4                ;
            jne     Mainloop                ;
            clr.w   R4                      ; Re-init delay counter
                                            ;
TX          bit.b   #UCA1TXIFG,&IFG2        ; USCI_A1 TX buffer ready?
            jnc     TX                      ; Loop if not
            mov.b   R5,&UCA1TXBUF           ; TX character
            dint                            ;
            bis.b   #UCA1RXIE,&UC1IE          ; Enable RX int
            bis.w   #CPUOFF+GIE,SR          ; Enter LPM0, interrupts enabled
            mov.b   &UCA1RXBUF,RxData(R5)   ; Store RXed character in RAM
            cmp.b   R5,&UCA1RXBUF           ; RX OK?
            jeq     RX_OK                   ;
                                            ;
RX_ERROR    bis.b   #001h,&P1OUT            ; LED P1.0 on
            jmp     $                       ; Trap PC here
                                            ;
RX_OK       inc.b   R5                      ; Next character to TX
            jmp     Mainloop                ; Again
                                            ;
;-------------------------------------------------------------------------------
USCIRX_ISR; Clear UCA1RXIFG interrupt flag and return active
;-------------------------------------------------------------------------------
            bic.b   #UCA1RXIFG,&UC1IFG      ; Clear RX int flag
            bic.b   #UCA1RXIE,&UC1IE        ; Disable RX int
            bic.w   #CPUOFF,0(SP)           ; Return active after receiption
            reti                            ; Return from ISR
;-------------------------------------------------------------------------------
            COMMON  INTVEC                  ; Interrupt Vectors
;-------------------------------------------------------------------------------
            ORG     USCIAB1RX_VECTOR        ; USCI A1/B1 Receive
            DW      USCIRX_ISR
            ORG     RESET_VECTOR            ; POR, ext. Reset
            DW      RESET
            END

⌨️ 快捷键说明

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