各位大侠帮我看看这个程序为什么在串口调试助手上的手法不同步,即调试助手上的TX发送的与RX接收的数不同

#include"lpc17xx.h"#include"type.h"#include"uart.h"externvolatileuint8_tt;/**********... #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);
}
展开
 我来答
khlerc
2010-12-13 · TA获得超过420个赞
知道小有建树答主
回答量:485
采纳率:0%
帮助的人:303万
展开全部
#include "lpc17xx.h"
#include "type.h"
#include "uart.h"
头文件都是自定义的,没有他们没法编译啊。。。
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式