STM32F103C8T6 标准库,位段操作

标准库版本


//IO口操作宏定义
#define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<<5)+(bitnum<<2)) 
#define MEM_ADDR(addr)  *((volatile unsigned long  *)(addr)) 
#define BIT_ADDR(addr, bitnum)   MEM_ADDR(BITBAND(addr, bitnum)) 
//IO口地址映射
#define GPIOA_ODR_Addr    (GPIOA_BASE+12) //0x4001080C 
#define GPIOB_ODR_Addr    (GPIOB_BASE+12) //0x40010C0C 
#define GPIOC_ODR_Addr    (GPIOC_BASE+12) //0x4001100C 
#define GPIOD_ODR_Addr    (GPIOD_BASE+12) //0x4001140C 
#define GPIOE_ODR_Addr    (GPIOE_BASE+12) //0x4001180C 
#define GPIOF_ODR_Addr    (GPIOF_BASE+12) //0x40011A0C    
#define GPIOG_ODR_Addr    (GPIOG_BASE+12) //0x40011E0C    

#define GPIOA_IDR_Addr    (GPIOA_BASE+8) //0x40010808 
#define GPIOB_IDR_Addr    (GPIOB_BASE+8) //0x40010C08 
#define GPIOC_IDR_Addr    (GPIOC_BASE+8) //0x40011008 
#define GPIOD_IDR_Addr    (GPIOD_BASE+8) //0x40011408 
#define GPIOE_IDR_Addr    (GPIOE_BASE+8) //0x40011808 
#define GPIOF_IDR_Addr    (GPIOF_BASE+8) //0x40011A08 
#define GPIOG_IDR_Addr    (GPIOG_BASE+8) //0x40011E08 

直接寄存器操作

#define PAout(n)		*((volatile unsigned int*)(((0x40020000-0x40000000+0x14)*8+n)*4+0x42000000))
#define PBout(n)		*((volatile unsigned int*)(((0x40020400-0x40000000+0x14)*8+n)*4+0x42000000))
#define PCout(n)		*((volatile unsigned int*)(((0x40020800-0x40000000+0x14)*8+n)*4+0x42000000))
#define PDout(n)		*((volatile unsigned int*)(((0x40020C00-0x40000000+0x14)*8+n)*4+0x42000000))
#define PEout(n)		*((volatile unsigned int*)(((0x40021000-0x40000000+0x14)*8+n)*4+0x42000000))
#define PFout(n)		*((volatile unsigned int*)(((0x40021400-0x40000000+0x14)*8+n)*4+0x42000000))
#define PGout(n)		*((volatile unsigned int*)(((0x40021800-0x40000000+0x14)*8+n)*4+0x42000000))	

#define PAin(n)			*((volatile unsigned int*)(((0x40020000-0x40000000+0x10)*8+n)*4+0x42000000))
#define PBin(n)			*((volatile unsigned int*)(((0x40020400-0x40000000+0x10)*8+n)*4+0x42000000))
#define PCin(n)			*((volatile unsigned int*)(((0x40020800-0x40000000+0x10)*8+n)*4+0x42000000))
#define PDin(n)			*((volatile unsigned int*)(((0x40020C00-0x40000000+0x10)*8+n)*4+0x42000000))
#define PEin(n)			*((volatile unsigned int*)(((0x40021000-0x40000000+0x10)*8+n)*4+0x42000000))
#define PFin(n)			*((volatile unsigned int*)(((0x40021400-0x40000000+0x10)*8+n)*4+0x42000000))
#define PGin(n)			*((volatile unsigned int*)(((0x40021800-0x40000000+0x10)*8+n)*4+0x42000000))	

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值