⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uart.c

📁 Keil工程例子,NXP新出的芯片lpc2478的示例代码
💻 C
字号:
/*****************************************************************************
 *   uart.c:  UART API file for NXP LPC23xx/24xx Family Microprocessors
 *
 *   Copyright(C) 2006, NXP Semiconductor
 *   All rights reserved.
 *
 *   History
 *   2006.07.12  ver 1.00    Prelimnary version, first Release
 *
******************************************************************************/
#include "LPC24xx.H"  /* LPC23xx/24xx definitions */
#include "type.h"
#include "target.h"
#include "uart.h"

volatile BYTE UART0TxEmpty = 1;

/*****************************************************************************
** Function name:		UARTInit
**
** Descriptions:		Initialize UART0 port, setup pin select,
**						clock, parity, stop bits, FIFO, etc.
**
** parameters:			UART baudrate
** Returned value:		true or false, return false only if the 
**						interrupt handler can't be installed to the 
**						VIC table
** 
*****************************************************************************/
DWORD UARTInit( DWORD baudrate )
{
    DWORD Fdiv;
    PINSEL0 = 0x00000050;       /* RxD0 and TxD0 */

    U0LCR = 0x83;		/* 8 bits, no Parity, 1 Stop bit */
    Fdiv = ( Fpclk / 16 ) / baudrate ;	/*baud rate */
    U0DLM = Fdiv / 256;							
    U0DLL = Fdiv % 256;
    U0LCR = 0x03;		/* DLAB = 0 */
    U0FCR = 0x07;		/* Enable and reset TX and RX FIFO. */   
    U0IER = IER_RBR | IER_THRE | IER_RLS;	/* Enable UART0 interrupt */
    return (TRUE);
}


/*****************************************************************************
** Function name:		UARTSend
**
** Descriptions:		Send a block of data to the UART 0 port based
**				on the data length
**
** parameters:			buffer pointer, and data length
** Returned value:		None
** 
*****************************************************************************/
//void UARTSend(BYTE *BufferPtr, DWORD Length )
//{   int i;
//   while ( Length != 0 )
//    {
		/* THRE status, contain valid data */
	//	while ( !(UART0TxEmpty & 0x01) );	
	//	U0THR = *BufferPtr;
   //            for(i=10000;i>=0;i--);
	//BufferPtr++;
	//	Length--;
 //   }
//    return;
//}

void UARTSendChar(int x, int y)
{char a[8];
  int Length=8;
  int i,k=0;	
  if(x<=999&&y<=999)
   {
    a[0]=x/100+'0';
     a[1]=(x%100)/10+'0';
    a[2]=x%10+'0';
    a[3]=',';
     a[4]=y/100+'0';
      a[5]=(y%100)/10+'0';
      a[6]=y%10+'0';
      a[7]='\n';
   U0IER = IER_THRE | IER_RLS;			/* Disable RBR */   
   while ( Length != 0 )
    {
		/* THRE status, contain valid data */
		while ( !(UART0TxEmpty & 0x01) );	
		U0THR =a[k++];
               for(i=10000;i>=0;i--);
		Length--;
    }
   U0IER = IER_THRE | IER_RLS | IER_RBR;	/* Re-enable RBR */
   }
    return;
}


/******************************************************************************
**                            End Of File
******************************************************************************/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -