LPC1114 UART收發(fā)實(shí)驗(yàn)
// 發(fā)送字符函數(shù)
本文引用地址:http://m.butianyuan.cn/article/201611/317367.htm/*****************************************************************************
** Function name:UARTSendByte
**
** Descriptions:Send a block of data to the UART 0 port based
**on the data Byte
**
** parameters:send data
** Returned value:None
**
*****************************************************************************/
void UARTSendByte(uint8_t dat)
{
while ( !(LPC_UART->LSR & LSR_THRE) )
{
; // 等待數(shù)據(jù)發(fā)送完畢
}
LPC_UART->THR = dat;
}
// 接受字符函數(shù)
/*****************************************************************************
** Function name:UARTReceiveByte
**
** Descriptions:Receive a block of data to the UART 0 port based
**on the data Byte
**
** parameters:None
** Returned value:Byte
**
*****************************************************************************/
uint8_t UARTReceiveByte(void)
{
uint8_t rcvData;
while (!(LPC_UART->LSR & LSR_RDR))
{
; // 查詢數(shù)據(jù)是否接收完畢
}
rcvData = LPC_UART->RBR; // 接收數(shù)據(jù)
return (rcvData);
}
// 接收字符串函數(shù)
/*****************************************************************************
** Function name:UARTReceive
**
** Descriptions:Receive a block of data to the UART 0 port based
**on the data Length
**
** parameters:buffer pointer, and data length
** Returned value:Note
**
*****************************************************************************/
void UARTReceive(uint8_t *BufferPtr, uint32_t Length)
{
while (Length--)
{
*BufferPtr++ = UARTReceiveByte(); // 把數(shù)據(jù)放入緩沖
}
}
// 主函數(shù)
int main(void) {
// TODO: insert code here
uint8_t ch = 0;
UARTInit(9600);
LPC_UART->IER = IER_THRE | IER_RLS; // 設(shè)置中斷使能寄存器
UARTSend((uint8_t *)Buffer, 10);
while (1)
{
ch = UARTReceiveByte(); // 接收字符
if (ch != 0x00)
{
UARTSendByte(ch); // 發(fā)送接收數(shù)據(jù)
}
}
// Enter an infinite loop, just incrementing a counter
volatile static int i = 0 ;
while(1) {
i++ ;
}
return 0 ;
}
2010-5-14 06:54
IMG_3381.JPG(76.79 KB)2010-5-14 06:54
IMG_3382.JPG(72.08 KB)2010-5-14 06:54
串口我用的是USB轉(zhuǎn)串口進(jìn)行調(diào)試的,如果先打開串口進(jìn)行,再連接實(shí)驗(yàn)板時(shí)會(huì)提示如下:
此時(shí)如果點(diǎn)擊"OK",將提示如下錯(cuò)誤:
此時(shí)應(yīng)該點(diǎn)擊如下圖紅圈的地方,LPC-Link,然后點(diǎn)擊“OK”即可正常連接。
2010-5-14 07:10
評論