新手上路
- 积分
- 22
- 金钱
- 22
- 注册时间
- 2020-9-22
- 在线时间
- 5 小时
|
1金钱
- // 设置APB2总线的基地址
- #define APB2_BASE ((uint32)0x40010000)
- // 通过APB2总线基地址偏移量设置GPIOA~E的基地址
- #define GPIOA_BASE (APB2_BASE+0x0800)
- #define GPIOB_BASE (APB2_BASE+0x0C00)
- #define GPIOC_BASE (APB2_BASE+0x1000)
- #define GPIOD_BASE (APB2_BASE+0x1400)
- #define GPIOE_BASE (APB2_BASE+0x1800)
- typedef unsigned int uint32;
- typedef unsigned short uint16;
- typedef unsigned char uchar;
- // 定义一个结构体,前16位对应16个脚的输出
- typedef struct{
- uchar odr0:1;
- uchar odr1:1;
- uchar odr2:1;
- uchar odr3:1;
- uchar odr4:1;
- uchar odr5:1;
- uchar odr6:1;
- uchar odr7:1;
- uchar odr8:1;
- uchar odr9:1;
- uchar odr10:1;
- uchar odr11:1;
- uchar odr12:1;
- uchar odr13:1;
- uchar odr14:1;
- uchar odr15:1;
- uint16 size_a_seat;
- }GpioOut;
- #define GPIOA_OUT ((GpioOut*)GPIOA_BASE+0x0C)// 把odr寄存器的基地址强制类型转换成为结构体指针
- #define GPIOB_OUT ((GpioOut*)GPIOB_BASE+0x0C)
- #define GPIOC_OUT ((GpioOut*)GPIOC_BASE+0x0C)
- #define GPIOD_OUT ((GpioOut*)GPIOD_BASE+0x0C)
- #define GPIOE_OUT ((GpioOut*)GPIOE_BASE+0x0C)
复制代码 我实验了一下,这样的代码能编译通过但好像并没有成功操作到odr的每一位。
|
|