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

📄 ma_uart1.c

📁 NXP LPC系列AMR7的开发程序源码(LCD
💻 C
📖 第 1 页 / 共 2 页
字号:

/*
*****************************************************************************
**
**      Project     : My project
**
**      Component   : LPC2106 (LPC2106)
**
**      Modulename  : UART1
**
**      Filename    : ma_uart1.c
**
**      Abstract    : This file implements a device driver for the UART1 
**                    module.
**
**      Compiler    : IAR C compiler
**
**      Date        : 2004-05-26 17:21:26
**
**      License no. : 9503-663-863-6224     Ivan
**
**      Warning     : This file has been automatically generated.
**                    Do not edit this file if you intend to regenerate it.
**
**      This device driver was created by IAR MakeApp version 
**      4.02A (NXP LPC210x: 4.00C) for the NXP LPC210x series of
**      microcontrollers.
**
**      (c)Copyright 2004 IAR Systems.
**      Your rights to this file are explained in the IAR MakeApp 
**      License Agreement. All other rights reserved.
**
*****************************************************************************
*/

/*
**===========================================================================
**  1       GENERAL
**  1.1     Revisions
**
**  Please read the IAR MakeApp for NXP LPC210x readme file 
**  
**
**===========================================================================
*/

/*
**===========================================================================
**  1.2     References
** 
**  No   Identification          Name or Description
**  ==   ===================     ================================
**
**  1    02/Oct/2003             NXP LPC210x Hardware Manual
** 
**===========================================================================
*/

/*
**===========================================================================
**  2.      INCLUDE FILES
**  2.1     Standard include files
**===========================================================================
*/

#include <inarm.h>

/*
**===========================================================================
**  2.2     Application include files
**===========================================================================
*/

#include "usercode.h"   /* Usercode macros (see <template.h>) */
#include "ma_tgt.h"     /* Target specific header file */
#include "ma_sfr.h"     /* Special function register bitfield macros */
#include "iolpc210x.h"  /* Defines Special function registers */

#include "ma_uart1.h"    /* Module driver header file */

/*
**===========================================================================
**  3.      DECLARATIONS
**  3.1     Internal constants
**===========================================================================
*/

#define MA_U1THR_UART1         0x00000000  /* UART1 Transmit Holding Register */
#define MA_U1THR_UART1_MASK    0x000000FF  /* Used bits */
#define MA_U1DLL_UART1         0x00000010  /* UART1 Divisor Latch LSB */
#define MA_U1DLL_UART1_MASK    0x000000FF  /* Used bits */
#define MA_U1DLM_UART1         0x00000000  /* UART1 Divisor Latch MSB */
#define MA_U1DLM_UART1_MASK    0x000000FF  /* Used bits */
#define MA_U1IER_UART1         0x00000000  /* UART1 Interrupt Enable Register */
#define MA_U1IER_UART1_MASK    0x0000000F  /* Used bits */
#define MA_U1FCR_UART1         0x00000000  /* UART1 FIFO Control Register */
#define MA_U1FCR_UART1_MASK    0x000000C7  /* Used bits */
#define MA_U1LCR_UART1         0x00000003  /* UART1 Line Control Register */
#define MA_U1LCR_UART1_MASK    0x000000FF  /* Used bits */
#define MA_U1MCR_UART1         0x00000000  /* UART1 Modem Control Register */
#define MA_U1MCR_UART1_MASK    0x00000013  /* Used bits */
#define MA_U1SCR_UART1         0x00000000  /* UART1 Scratch Pad Register */
#define MA_U1SCR_UART1_MASK    0x000000FF  /* Used bits */


/*
**===========================================================================
**  3.2     Internal macros
**===========================================================================
*/

#define U1IER_IEM              (U1IER_RXLSIE |\
                               U1IER_THREIE |\
                               U1IER_RDAIE)   /* Interrupt enable mask */
                               
#define U1LSR_ERR              (U1LSR_RXFE  |\
                               U1LSR_BI    |\
                               U1LSR_FE    |\
                               U1LSR_PE    |\
                               U1LSR_OE)      /* LSR Register Error Mask */                               

/*
**===========================================================================
**  3.3     Internal type definitions
**===========================================================================
*/

typedef struct
{
    /*--- General ---*/
    U8  EOS;

} UARTDataType;

/*
**===========================================================================
**  3.4     Global variables (declared as 'extern' in some header file)
**===========================================================================
*/

/*
**===========================================================================
**  3.5     Internal function prototypes (defined in Section 5)
**===========================================================================
*/

/*
**===========================================================================
**  3.6     Internal variables
**===========================================================================
*/

static volatile UARTDataType UART1;




/*
**===========================================================================
**  4.      GLOBAL FUNCTIONS (declared as 'extern' in some header file)
**===========================================================================
*/



void MA_Init_UART1( void ) 
/*
**---------------------------------------------------------------------------
**
**  Abstract:
**      Initializes the UART1 module. Only sets those registers with 
**      values not equal to the power-on reset values.
**
**  Parameters:
**      None
**
**  Returns:
**      None
**
**---------------------------------------------------------------------------
*/
{

    /*--- Handle user code on function entry ---*/
    ENTER_MA_INIT_UART1;

    /*
    **----------------------------
    **  Initialize UART channel 1
    **----------------------------
    */
    /*--- Disable interrupts ---*/
    U1IER = 0;              

    /*--- Initialize registers ---*/
    U1LCR    = ( U1LCR & ~MA_U1LCR_UART1_MASK ) | MA_U1LCR_UART1;

    /*--- Initialize baudrate ---*/
    U1LCR_bit.DLAB = 1;          /* Open the divisor register access */
    U1DLM = 0x0;
    U1DLL = 0x10;
    U1LCR_bit.DLAB = 0;         /* Close the divisor register access */

    /*--- Configure UART1 data block ---*/
    UART1.EOS = '\n';

    /*--- Handle user code on function exit ---*/
    EXIT_MA_INIT_UART1;

} /* MA_Init_UART1 */





void MA_Reset_UART1( void ) 
/*
**---------------------------------------------------------------------------
**
**  Abstract:
**      Resets the UART1 module. Sets all registers.
**
**  Parameters:
**      None
**
**  Returns:
**      None
**
**---------------------------------------------------------------------------
*/
{

    /*--- Handle user code on function entry ---*/
    ENTER_MA_RESET_UART1;

    /*
    **-----------------------
    **  Reset UART channel 1
    **-----------------------
    */
    /*--- Disable interrupts ---*/
    U1IER = 0;              

    /*--- Initialize registers ---*/
    U1LCR    = ( U1LCR & ~MA_U1LCR_UART1_MASK ) | MA_U1LCR_UART1;
    U1FCR    = ( U1FCR & ~MA_U1FCR_UART1_MASK ) | MA_U1FCR_UART1;

    /*--- Initialize baudrate ---*/
    U1LCR_bit.DLAB = 1;          /* Open the divisor register access */
    U1DLM = 0x0;
    U1DLL = 0x10;
    U1LCR_bit.DLAB = 0;          /* Close the divisor register access */

    /*--- Configure UART1 data block ---*/
    UART1.EOS = '\n';
    /*--- Handle user code on function exit ---*/
    EXIT_MA_RESET_UART1;

} /* MA_Reset_UART1 */





void MA_PutChar_UART1( U8 Data ) 
/*
**---------------------------------------------------------------------------
**
**  Abstract:
**      Send a character on the UART 1 channel. This function waits until
**      the transmit FIFO has space for the character to transmit.
**
**  Parameters:
**      Data        The character to transmit
**
**  Returns:
**      None
**
**---------------------------------------------------------------------------
*/
{
    /*--- Handle user code on function entry ---*/
    ENTER_MA_PUTCHAR_UART1;

    while(          U1LSR_bit.THRE           == U1LSR_THRE_VALID )
    {
        /*--- Wait for transmit holding register empty ---*/
        ;
    }

    /*--- Write character to transmit ---*/
    U1THR = Data;

    /*--- Handle user code on function exit ---*/
    EXIT_MA_PUTCHAR_UART1;
    
    return;

} /* MA_PutChar_UART1 */





void MA_PutString_UART1( C8 *pString ) 
/*
**---------------------------------------------------------------------------
**
**  Abstract:
**      Send a zero terminated string of characters to the UART 1 channel.
**      This function waits indefinitely until the string has been sent 
**      successfully.
**
**  Parameters:
**      pString     A pointer to the string to transmit
**
**  Returns:

⌨️ 快捷键说明

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