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

📄 usbh_uart.c

📁 基于LPC2468处理器的源代码
💻 C
字号:
/*
**************************************************************************************************************
*                                                 USB Host Stack
*
*                                     (c) Copyright 2008, OnChip  Technologies LLC
*                                                 All Rights Reserved
*
*                                               www.onchiptech.com
*
* File           : usbh_uart.c
* Programmer(s)  : Prasad.K.R.S.V
* Version        :
*
**************************************************************************************************************
*/

/*
**************************************************************************************************************
*                                           INCLUDE HEADER FILES
**************************************************************************************************************
*/

#include <app_cfg.h>
#include <usbh_uart.h>

/*
**************************************************************************************************************
*                                         INITIALIZE UART
*
* Description: This function initializes UART port, setup pin select, clock, parity, stopbits, FIFO etc
*
* Arguments  : baud_rate    UART baud rate (115200)
*
* Returns    : None
*
**************************************************************************************************************
*/

void  UART_Init(CPU_INT32U baudrate)
{
    CPU_INT32U  Fdiv;
    CPU_INT32U  pin_sel;
          
#if (USBH_CFG_UART_SEL == USBH_CFG_UART_KEIL_MCB2300)
    pin_sel  = PINSEL0;	                      /* P0.15 TXD1, P0.16 RXD1                                     */
    pin_sel &= 0x3FFFFFFF;
    pin_sel |= 0x40000000;
    PINSEL0  = pin_sel;

    pin_sel  = PINSEL1;
    pin_sel &= 0xFFFFFFFC;
    pin_sel |= 0x00000001;
    PINSEL1  = pin_sel;

#elif(USBH_CFG_UART_SEL == USBH_CFG_UART_EA_OEM_LPC2468)

    pin_sel  = PINSEL7;
    pin_sel &= 0xFFFFFFF0;
    pin_sel |= 0x0000000F;
    PINSEL7  = pin_sel;

#endif

   	U1LCR    = 0x83;		                  /* 8 bits, no Parity, 1 Stop bit                              */
    Fdiv     = ( Fpclk / 16 ) / baudrate ;	  /*baud rate                                                   */
    U1DLM    = Fdiv / 256;							                                                        
    U1DLL    = Fdiv % 256;
	U1LCR    = 0x03;		                  /* DLAB = 0                                                   */
    U1FCR    = 0x07;		                  /* Enable and reset TX and RX FIFO                            */

}

/*
**************************************************************************************************************
*                                         PRINT CHARECTER
*
* Description: This function is used to print a single charecter through UART1.
*
* Arguments  : ch    charecter to be printed
*
* Returns    : None
*
**************************************************************************************************************
*/

void  UART_PrintChar (CPU_INT08U ch)
{

   while (!(U1LSR & 0x20));
   U1THR  = ch;
}

/*
**************************************************************************************************************
*                                         PRINT STRING
*
* Description: This function is used to print a string
*
* Arguments  : str    Pointer to the string
*
* Returns    : None
*
**************************************************************************************************************
*/

void  UART_PrintStr (const CPU_INT08U * str)
{

   while ((*str) != 0) {
      if (*str == '\n') {
         UART_PrintChar(*str++);
         UART_PrintChar('\r');
      } else {
         UART_PrintChar(*str++);
      }    
   }
}

/*
**************************************************************************************************************
*                                        PRINT FORMATTED STRING
*
* Description: This function is used to print formatted string. This function takes variable length arguments
*
* Arguments  : variable length arguments
*
* Returns    : None
*
**************************************************************************************************************
*/

void  UART_Printf (const  CPU_INT08U *format, ...)
{
    static  CPU_INT08U  buffer[512 + 1];
            va_list     vArgs;


    va_start(vArgs, format);
    vsprintf((char *)buffer, (char const *)format, vArgs);
    va_end(vArgs);
    UART_PrintStr((CPU_INT08U*) buffer);
}

⌨️ 快捷键说明

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