无法在LPC2148中将串行数据发布到主机PC

时间:2015-04-07 02:30:16

标签: arm lpc

我正在尝试将数据发送到LP2148中的UART1。以下是代码。 但是终端软件上显示的数据只是一些垃圾(主要是????)。我无法解决问题。 终端软件配置为9600波特。 pclk是15 MHz。

#include  <lpc214x.h>        //Includes LPC2148 register definitions


#define Fosc            12000000                    
#define Fcclk           (Fosc * 5)                  
#define Fcco            (Fcclk * 4)                 
#define Fpclk           (Fcclk / 4)            

#define  UART_BPS   9600     //Set Baud Rate here

const unsigned char SEND_STRING[] = "Hello, Testing LPC214x Development Board\nCommunication Test\nSend any character to continue\n";
const unsigned char SEND_STRING1[] = "Test Passed\n";


void  Init_UART1(void)                 //This function setups UART1
{  
   unsigned int Baud16;
   U1LCR = 0x83;                    // DLAB = 1
   Baud16 = (Fpclk / 16) / UART_BPS;  
   U1DLM = Baud16 / 256;                            
   U1DLL = Baud16 % 256;                        
   U1LCR = 0x03;
}


void  UART1_SendByte(unsigned char data)          //A function to send a byte on UART1
{  
   U1THR = data;                    
   while( (U1LSR&0x40)==0 );        
}


void  UART1_SendStr(const unsigned char *str)          //A function to send a string on UART1
{  
   while(1)
   {  
      if( *str == '\0' ) break;
      UART1_SendByte(*str++);       
   }
}


int  main(void)
{  
   PINSEL0 = 0x00050000;            // Enable UART1 Rx and Tx pins
   PINSEL1 = 0x00000000;
   PINSEL2 = 0x00000000;

   Init_UART1();
   UART1_SendStr(SEND_STRING);
   while((U1LSR&0x01)==0);
   UART1_SendStr(SEND_STRING1);
   while(1) 
   {  

   }
  // return(0);
}

0 个答案:

没有答案