|
大侠帮忙看一下为什么这个程序下进msp430g2553中从超声波传感器接不到数据?串口调试工具接收部分无显示
#include"msp430g2553.h"
unsigned int a=0;
void UartRegCfg()
{
UCA0CTL1 |=UCSWRST; //reset UART module,as well as enable UART module
UCA0CTL1 |=UCSSEL_2; //UART clock is SMCLK
UCA0BR0 |=65; //Baud N=BCLK/rate,rate=9600,BCLK=SMCLK=8M
UCA0BR1 |=3;
UCA0MCTL = UCBRS1; //UCBRSx=2
UCA0CTL1 &=~UCSWRST; //UART reset end
}
void UartGpioCfg()
{P1DIR |= BIT6;
P1DIR |= BIT2; //P1.2 UART_TX
P1DIR &=~BIT1; //P1.1 UART_RX
P1SEL |= BIT1+BIT2; //select P1.1 and P1.2 as UART port
P1SEL2 |= BIT1+BIT2;
}
void UartInit()
{
UartRegCfg();
UartGpioCfg();
}
/************************************************************************
* Function Name : UARTPutChar
* Create Date : 2012/07/27
* Author :
*
* Description :send a character
*
* Param : cTX is willing to send character
************************************************************************/
void UARTPutChar(unsigned char cTX)
{
UCA0TXBUF=cTX;
while (!(IFG2&UCA0TXIFG)); //waiting UCA0TXBUF is empty
IFG2&=~UCA0TXIFG; //clear TX interrupt flag
}
/************************************************************************
* Function Name : UARTGetChar
* Create Date : 2012/07/27
* Author :
*
* Description :get a character
*
* Param : cRX is willing to get character
************************************************************************/
int UARTGetChar(void)
{
int GetChar=0;
while (!(IFG2&UCA0RXIFG)); //UCA1RXBUF has received a complete character
IFG2&=~UCA0RXIFG; //clear RX interrupt flag
UCA0TXBUF=UCA0RXBUF; //back to display
GetChar =UCA0RXBUF;
while (!(IFG2&UCA0TXIFG)); //waiting UCA0TXBUF is empty
IFG2&=~UCA0TXIFG; //clear TX interrupt flag
return GetChar;
}
/************************************************************************
* Function Name : UARTPutstring
* Create Date : 2012/07/27
* Author :
*
* Description :output string
*
* Param : char *str point send string
* return: the length of string
************************************************************************/
int UARTPutstring( char *str)
{
unsigned int uCount=0;
do
{
uCount++;
UARTPutChar(*str);
}
while(*++str!='\0');
UARTPutChar('\n');
return uCount;
}
void SysCtlClockInit()
{
DCOCTL=0;
BCSCTL1=CALBC1_16MHZ;
DCOCTL =CALDCO_16MHZ;
BCSCTL1|=DIVA_1; //ACLK =MCLK/2=8M
BCSCTL2|=DIVS_1; //SMCLK=MCLK/2=8M
}
void main()
{
WDTCTL = WDTPW + WDTHOLD;
SysCtlClockInit();
UartInit();
UARTGetChar();
while(1);
} |
阿莫论坛20周年了!感谢大家的支持与爱护!!
知道什么是神吗?其实神本来也是人,只不过神做了人做不到的事情 所以才成了神。 (头文字D, 杜汶泽)
|