uart_retarget.c
来自「i2s usb audio demo lpc2138」· C语言 代码 · 共 125 行
C
125 行
/*****************************************************************************
* uart_retarget.c: UART API file for Philips LPC23xx/24xx Family Microprocessors
*
* Copyright(C) 2006, Philips Semiconductor
* All rights reserved.
*
* History
* 2006.07.12 ver 1.00 Prelimnary version, first Release
*
******************************************************************************/
#include "LPC23xx.h" /* LPC23xx/24xx definitions */
#include "type.h"
#include "target.h"
#include "./inc/uart.h"
char UART_SendChar(DWORD PortNum, char chr); /* Write character to Serial Port 0 */
char UART_GetChar(DWORD PortNum); /* Read character from Serial Port 0 */
char UART_WaitChar(DWORD PortNum); /* Read character from Serial Port 0 */
/*****************************************************************************
** Function name: UART_SendChar
**
** Descriptions: Send a character of data to the selected UART port based
** for retarget.c (fputc)
**
** parameters: port Number and character
** Returned value: None
**
*****************************************************************************/
char UART_SendChar (DWORD PortNum, char chr) /* Write character to Serial Port 0 */
{
if (PortNum ==0 )
{
U0IER &= 0x0D; /* disable TX interrupt */
while (!(U0LSR & 0x20));
U0THR = chr;
return (0);
}
if (PortNum ==1 )
{
U1IER &= 0x0D; /* disable TX interrupt */
while (!(U1LSR & 0x20));
U1THR = chr;
return (0);
}
return(0);
}
/*****************************************************************************
** Function name: UART_GetChar
**
** Descriptions: Get a char of data from the selected UART port based
** for retarget.c fgetc (raw polled char)
**
** parameters: port Number and character
** Returned value: None
**
*****************************************************************************/
char UART_GetChar(DWORD PortNum) /* Read character from Serial Port 0 */
{ /* if character on port return value else return NULL */
if (PortNum ==0 )
{
if (!(U0LSR & 0x01))
return (0);
else
return (U0RBR);
}
if (PortNum ==1 )
{
if (!(U1LSR & 0x01))
return (0);
else
return (U1RBR);
}
return(0);
}
/*****************************************************************************
** Function name: UART_WaitChar
**
** Descriptions: Get a char of data from the selected UART port based
** for retarget.c fgetc (raw blocked char)
**
** parameters: port Number and character
** Returned value: always 0 will wait till success
**
*****************************************************************************/
char UART_WaitChar(DWORD PortNum) /* Read character from Serial Port 0 */
{ /* if character on port return value else return NULL */
if (PortNum ==0 )
{
while (!(U0LSR & 0x01));
return (U0RBR);
}
if (PortNum ==1 )
{
while (!(U1LSR & 0x01));
return (U1RBR);
}
return(0);
}
/******************************************************************************/
void sendstr (char *p) { /* Write string */
while (*p)
{
// sendchar (*p++);
UART_SendChar (0, *p++);
}
}
char hex2ascii(char temp)
{
char as[] = "0123456789ABCDEF";
return(as[temp]);
}
/******************************************************************************
** End Of File
******************************************************************************/
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?