微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > MSP430G2553测试程序(串口程序,定时器模式)

MSP430G2553测试程序(串口程序,定时器模式)

时间:11-28 来源:互联网 点击:

//------------------------------------------------------------------------------
// Prints a string over using the Timer_A UART
//------------------------------------------------------------------------------
void TimerA_UART_print(char *string)
{
while (*string) {
TimerA_UART_tx(*string++);
}
}
//------------------------------------------------------------------------------
// Timer_A UART - Transmit Interrupt Handler
//------------------------------------------------------------------------------
#pragma vector = TIMER0_A0_VECTOR
__interrupt void Timer_A0_ISR(void)
{
static unsigned char txBitCnt = 10;

TACCR0 += UART_TBIT;// Add Offset to CCRx
if (txBitCnt == 0) {// All bits TXed?
TACCTL0 &= ~CCIE;// All bits TXed, disable interrupt
txBitCnt = 10;// Re-load bit counter
}
else {
if (txData & 0x01) {
TACCTL0 &= ~OUTMOD2;// TX Mark 1
}
else {
TACCTL0 |= OUTMOD2;// TX Space 0
}
txData >>= 1;
txBitCnt--;
}
}
//------------------------------------------------------------------------------
// Timer_A UART - Receive Interrupt Handler
//------------------------------------------------------------------------------
#pragma vector = TIMER0_A1_VECTOR
__interrupt void Timer_A1_ISR(void)
{
static unsigned char rxBitCnt = 8;
static unsigned char rxData = 0;

switch (__even_in_range(TA0IV, TA0IV_TAIFG)) { // Use calculated branching
case TA0IV_TACCR1:// TACCR1 CCIFG - UART RX
TACCR1 += UART_TBIT;// Add Offset to CCRx
if (TACCTL1 & CAP) {// Capture mode = start bit edge
TACCTL1 &= ~CAP;// Switch capture to compare mode
TACCR1 += UART_TBIT_div_2;// Point CCRx to middle of D0
}
else {
rxData >>= 1;
if (TACCTL1 & SCCI) {// Get bit waiting in receive latch
rxData |= 0x80;
}
rxBitCnt--;
if (rxBitCnt == 0) {// All bits RXed?
rxBuffer = rxData;// Store in global variable
rxBitCnt = 8;// Re-load bit counter
TACCTL1 |= CAP;// Switch compare to capture mode
__bic_SR_register_on_exit(LPM0_bits);// Clear LPM0 bits from 0(SR)
}
}
break;
}
}

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top