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

方式一:
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)

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值