1. Trang chủ
  2. » Kỹ Thuật - Công Nghệ

msp430g2xx1 ta uart2400

3 106 0

Đang tải... (xem toàn văn)

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 3
Dung lượng 4,87 KB

Nội dung

//****************************************************************************** // MSP430G2xx1 Demo - Timer_A, Ultra-Low Pwr UART 2400 Echo, 32kHz ACLK // // Description: Use Timer_A CCR0 hardware output modes and SCCI data latch // to implement UART function @ 2400 baud Software does not directly read and // write to RX and TX pins, instead proper use of output modes and SCCI data // latch are demonstrated Use of these hardware features eliminates ISR // latency effects as hardware insures that output and input bit latching and // timing are perfectly synchronised with Timer_A regardless of other // software activity In the Mainloop the UART function readies the UART to // receive one character and waits in LPM3 with all activity interrupt driven // After a character has been received, the UART receive function forces exit // from LPM3 in the Mainloop which echo's back the received character // ACLK = TACLK = LFXT1 = 32768Hz, MCLK = SMCLK = default DCO // //* An external watch crystal is required on XIN XOUT for ACLK *// // // MSP430G2xx1 // // /|\| XIN|// | | | 32kHz // |RST XOUT|// | | // | CCI0B/TXD/P1.5| > // | | 2400 8N1 // | CCI0A/RXD/P1.1|< -// #define RXD 0x02 // RXD on P1.1 #define TXD 0x20 // TXD on P1.5 // Conditions for 2400 Baud SW UART, ACLK = 32768 #define Bitime_5 adjustment #define Bitime 0x06 // ~ 0.5 bit length + small 0x0E // 427us bit length ~ 2341 baud unsigned int RXTXData; unsigned char BitCnt; void TX_Byte (void); void RX_Ready (void); // D Dang // Texas Instruments Inc // October 2010 // Built with CCS Version 4.2.0 and IAR Embedded Workbench Version: 5.10 //****************************************************************************** #include void main (void) { WDTCTL = WDTPW + WDTHOLD; CCTL0 = OUT; TACTL = TASSEL_1 + MC_2; P1SEL = TXD + RXD; P1DIR = TXD; // Stop watchdog timer // TXD Idle as Mark // ACLK, continuous mode // // // Mainloop for (;;) { RX_Ready(); // UART ready to RX one Byte _BIS_SR(LPM3_bits + GIE); RXed TX_Byte(); } } // Enter LPM3 w/ interr until char // TX Back RXed Byte Received // Function Transmits Character from RXTXData Buffer void TX_Byte (void) { BitCnt = 0xA; // Load Bit counter, 8data + ST/SP while (CCR0 != TAR) // Prevent async capture CCR0 = TAR; // Current state of TA counter CCR0 += Bitime; // Some time till first bit RXTXData |= 0x100; // Add mark stop bit to RXTXData RXTXData = RXTXData > 1; BitCnt ; } } // RX else { if( CCTL0 & CAP ) { CCTL0 &= ~ CAP; mode CCR0 += Bitime_5; } else { RXTXData = RXTXData >> 1; if (CCTL0 & SCCI) RXTXData |= 0x80; // Add Offset to CCR0 // TX on CCI0B? // All bits TXed, disable interrupt // TX Space // TX Mark // Capture mode = start bit edge // Switch from capture to compare // Get bit waiting in receive latch BitCnt ; // All bits RXed? if ( BitCnt == 0) //>>>>>>>>>> Decode of Received Byte Here

Ngày đăng: 25/12/2017, 12:23

TÀI LIỆU CÙNG NGƯỜI DÙNG

  • Đang cập nhật ...

TÀI LIỆU LIÊN QUAN

w