C语言访问存储器的方法
#define SDA_DIR_REG *(__IO uint32_t *)SDA_MOD_OFFSET
分析:
*(__IOuint16_t *) (((uint32_t)0x60020000) )
(((uint32_t)0x60020000))是32位的IO地址(物理地址,硬件上设定的,不可修改) *(__IO uint16_t*)是读取该地址的参数值,其值为16位参数。
将存储器定义为一种数据结构,然后定义一个指向结构体的指针。
typedef struct
{
__IO uint32_t MODER; /*!< GPIO port mode register, Address offset: 0x00 */
__IO uint32_t OTYPER; /*!< GPIO port output type register, Address offset: 0x04 */
__IO uint32_t OSPEEDR; /*!< GPIO port output speed register, Address offset: 0x08 */
__IO uint32_t PUPDR; /*!< GPIO port pull-up/pull-down register, Address offset: 0x0C */
__IO uint32_t IDR; /*!< GPIO port input data register, Address offset: 0x10 */
__IO uint32_t ODR; /*!< GPIO port output data register, Address offset: 0x14 */
__IO uint16_t BSRRL; /*!< GPIO port bit set/reset low register, Address offset: 0x18 */
__IO uint16_t BSRRH; /*!< GPIO port bit set/reset high register, Address offset: 0x1A */
__IO uint32_t LCKR; /*!< GPIO port configuration lock register, Address offset: 0x1C */
__IO uint32_t AFR[2]; /*!< GPIO alternate function registers, Address offset: 0x20-0x24 */
} GPIO_TypeDef;
#define PERIPH_BASE ((uint32_t)0x40000000)
#define AHB1PERIPH_BASE (PERIPH_BASE 0x00020000)
#define GPIOC_BASE (AHB1PERIPH_BASE 0x0800)
#define GPIOC ((GPIO_TypeDef *)GPIOC_BASE)
大家看着上面的代码应该很熟悉,这就是我在ST给的标准外设库中复制的,这也是CMSIS标准的驱动发方式。
typedef struct{ uint8 LCD_CMD;//用于LCD命令操作 uint8 LCD_DATA;//用于LCD数据操作} LCD_TypeDef;#define LCD_BASE ((uint32_t)(0x60000000 | 0x0000FFFF))#define LCD ((LCD_TypeDef *) LCD_BASE)
详解如下:
赞 (0)