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

📄 test44x_ta_uart2400.c

📁 AQ430 C Code,支持LSD-TEST430F44X
💻 C
字号:

#define RXD   0x04                      // RXD on P2.2
#define TXD   0x02                      // TXD on P1.1

//   Conditions for 2400 Baud SW UART, ACLK = 32768

#define Bitime_5  0x06                  // ~ 0.5 bit length + small adjustment 
#define Bitime  0x0E                    // 427us bit length ~ 2341 baud

unsigned int RXTXData;
unsigned char BitCnt;

void TX_Byte (void);
void RX_Ready (void);

//  M.Buccini
//  Texas Instruments, Inc
//  March 2002
//******************************************************************************

#include <msp430x11x1.h>

void main (void)
{
  WDTCTL = WDTPW + WDTHOLD;             // Stop watchdog timer
  CCTL0 = OUT;                          // TXD Idle as Mark 
  TACTL = TASSEL0+MC1;                  // ACLK, continous mode
  P1SEL = TXD;                          // P1.1/TA0 for TXD function
  P1DIR = TXD;                          // TXD output on P1
  P2SEL = RXD;                          // P2.2/TA0 as RXD input

// Mainloop
  for (;;)                              
  {
  RX_Ready();                           // UART ready to RX one Byte
  _BIS_SR(LPM3_bits+GIE);               // Enter LPM3 Until character RXed
  TX_Byte();                            // TX Back RXed Byte Received
  }
}


// Function Transmits Character from RXTXData Buffer
void TX_Byte (void)
{
  BitCnt = 0xA;                         // Load Bit counter, 8data + ST/SP
  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;             // Add space start bit
  CCTL0 = OUTMOD0+CCIE;                 // TXD = mark = idle 
  while ( CCTL0 & CCIE );               // Wait for TX completion
}


// Function Readies UART to Receive Character into RXTXData Buffer
void RX_Ready (void)
{
  BitCnt = 0x8;                         // Load Bit counter
  CCTL0 = SCS+CCIS0+OUTMOD0+CM1+CAP+CCIE;   // Sync, Neg Edge, Capture          
}


// Timer A0 interrupt service routine
interrupt[TIMERA0_VECTOR] void Timer_A (void)
{
  CCR0 += Bitime;                       // Add Offset to CCR0

// RX
  if (CCTL0 & CCIS0)                    // RX on CCI0B?
  {
    if( CCTL0 & CAP )                   // Capture mode = start bit edge
    {
    CCTL0 &= ~ CAP;                     // Switch from capture to compare mode 
    CCR0 += Bitime_5;
    }
    else
    {
    RXTXData = RXTXData >> 1;           
      if (CCTL0 & SCCI)                 // Get bit waiting in receive latch
      RXTXData |= 0x80;                 
      BitCnt --;                        // All bits RXed?
      if ( BitCnt == 0)
//>>>>>>>>>> Decode of Received Byte Here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
      {
      CCTL0 &= ~ CCIE;                  // All bits RXed, disable interrupt
      _BIC_SR_IRQ(LPM3_bits);           // Clear LPM3 bits from 0(SR)
      }
//>>>>>>>>>> Decode of Received Byte Here <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
    }
  }
// TX
  else
  {
    if ( BitCnt == 0)
    CCTL0 &= ~ CCIE;                    // All bits TXed, disable interrupt
    else
    {
      CCTL0 |=  OUTMOD2;                  // TX Space
      if (RXTXData & 0x01)                 
      CCTL0 &= ~ OUTMOD2;                 // TX Mark
      RXTXData = RXTXData >> 1;
      BitCnt --;
    }
  }
}

⌨️ 快捷键说明

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