各位大侠帮我看看这个程序为什么在串口调试助手上的手法不同步,即调试助手上的TX发送的与RX接收的数不同
#include "lpc17xx.h"#include "type.h"#include "uart.h"extern volatile uint8_t t;/******************************************************************************* Main Function main()This program has been test on Keil LPC1700 board.*****************************************************************************/int main (void){// uint32_t i; SystemInit(); UARTInit(1); /* baud rate setting 115200*/ while (1) /* Loop forever */ { t=UARTRecieve( 1 );// if(t==✀1✀) UARTSend( 1, t ); }}uint32_t UARTInit( uint32_t PortNum ){// uint32_t Fdiv;// uint32_t pclkdiv, pclk; if ( PortNum == 1 ) { LPC_PINCON->PINSEL4 &= ~0x0000000F; LPC_PINCON->PINSEL4 |= 0x0000000A; /* Enable RxD1 P2.1, TxD1 P2.0 */ /* By default, the PCLKSELx value is zero, thus, the PCLK for all the peripherals is 1/4 of the SystemFrequency. */ /* Bit 8,9 are for UART1 */// pclkdiv = (LPC_SC->PCLKSEL0 >> 8) & 0x03;// switch ( pclkdiv )// {// case 0x00:// default:// pclk = SystemFrequency/4;// break;// case 0x01:// pclk = SystemFrequency;// break; // case 0x02:// pclk = SystemFrequency/2;// break; // case 0x03:// pclk = SystemFrequency/8;// break;// } LPC_UART1->LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */// Fdiv = (( pclk / 16 ) / baudrate) ; /*baud rate */// LPC_UART1->DLM =Fdiv/256 ; // LPC_UART1->DLL = Fdiv%256; LPC_UART1->DLM =0 ; LPC_UART1->DLL =7 ; LPC_UART1->FDR =0x52 ; //小数除数锁存器值 LPC_UART1->LCR = 0x03; /* DLAB = 0 */ LPC_UART1->FCR = 0x07; /* Enable and reset TX and RX FIFO. */ return(TRUE); } return( FALSE ); }/* *********************************************** 发送函数(采用查询方式) *** ************************************************/void UARTSend( uint32_t portNum, uint8_t m ){ if(portNum==1) { if(LPC_UART1->LSR & 0x40) LPC_UART1->THR = m;// while ( (LPC_UART1->LSR & 0x40)==0 ); //等待数据发送完 }} /******************************************************* 接收函数(采用查询方式) ***********************************************************/uint8_t UARTRecieve(uint32_t portNum ){ uint8_t data;// uint32_t m; if(portNum==1) {// if((LPC_UART1->LSR & 0x01)==1) //如果FIFO不为空时,开始接收数据 /*注意:if能用,while不能用这是问什么 */ while((LPC_UART1->LSR & 0x01)==0); data=LPC_UART1->RBR; } return(data);}