寄存器使用结构体进行空间地址的映射

来源:互联网 发布:网络运维管理论坛 编辑:程序博客网 时间:2024/05/21 14:45

方式一:
typedef struct
{
  union {
  __I  uint8_t  RBR;    //RBR THR DLL 三个寄存器都占用空间 0x4001 0000
  __O  uint8_t  THR;
  __IO uint8_t  DLL;
       uint32_t RESERVED0;
  };
  union {
  __IO uint8_t  DLM;    //DLM  IER 都占用空间 0x4001 0004
  __IO uint32_t IER;
  };
  union {
  __I  uint32_t IIR;    //IIR  FCR 都占用空间 0x4001 0008
  __O  uint8_t  FCR;
  };
  __IO uint8_t  LCR;    //0x4001 000C
       uint8_t  RESERVED1[3];
  __IO uint8_t  MCR;     //0x4001 0010
       uint8_t  RESERVED2[3];
  __I  uint8_t  LSR;     // 0x4001 0014
       uint8_t  RESERVED3[3];
  __I  uint8_t  MSR;      //0x4001 0018
       uint8_t  RESERVED4[3];
  __IO uint8_t  SCR;        //0x4001 001C
       uint8_t  RESERVED5[3];
  __IO uint32_t ACR;      //0x4001 0020
       uint32_t RESERVED6;
  __IO uint32_t FDR;    //0x4001 0028
       uint32_t RESERVED7;
  __IO uint8_t  TER;      //0x4001 0030
       uint8_t  RESERVED8[27];
  __IO uint8_t  RS485CTRL;     //0x4001 004C
       uint8_t  RESERVED9[3];
  __IO uint8_t  ADRMATCH;     //0x4001 0050
       uint8_t  RESERVED10[3];
  __IO uint8_t  RS485DLY;     //0x4001 0054
       uint8_t  RESERVED11[3];
  __I  uint8_t  FIFOLVL;   //0x4001 0058
} LPC_UART1_TypeDef;

#define LPC_APB0_BASE         (0x40000000UL)
#define LPC_UART1_BASE        (LPC_APB0_BASE + 0x10000)
#define LPC_UART1             ((LPC_UART1_TypeDef     *) LPC_UART1_BASE    )

 

 

方式二:

/*********************************************************************************************************
**  UART1
*********************************************************************************************************/
#define U1RBRTHR                (*(volatile unsigned long *)0x40010000) /* U1DLL, U1RBR and U1THR       */
#define U1DLL                   U1RBRTHR                                /* share the same address       */
#define U1RBR                   U1RBRTHR
#define U1THR                   U1RBRTHR

#define U1IER                   (*(volatile unsigned long *)0x40010004) /* U1DLM and U1IER              */
#define U1DLM                   U1IER                                   /* share the same address       */


#define U1FCR                   (*(volatile unsigned long *)0x40010008) /* U1FCR and U1IIR              */
#define U1IIR                   U1FCR                                   /* share the same address       */

#define U1LCR                   (*(volatile unsigned long *)0x4001000C)
#define U1MCR                   (*(volatile unsigned long *)0x40010010)
#define U1LSR                   (*(volatile unsigned long *)0x40010014)
#define U1MSR                   (*(volatile unsigned long *)0x40010018)
#define U1SCR                   (*(volatile unsigned long *)0x4001001C)
#define U1ACR                   (*(volatile unsigned long *)0x40010020)
#define U1FDR                   (*(volatile unsigned long *)0x40010028)
#define U1TER                   (*(volatile unsigned long *)0x40010030)
#define U1RS485CTRL             (*(volatile unsigned long *)0x4001004C)
#define U1ADRMATCH              (*(volatile unsigned long *)0x40010050)
#define U1RS485DLY              (*(volatile unsigned long *)0x40010054)
#define U1FIFOLVL               (*(volatile unsigned long *)0x40010058)