像51一样操作STM32的IO
时间:11-23
来源:互联网
点击:
//-----------------------------------------------------------------------------------------------------
//别名区 ADDRESS=0x4200 0000 + (0x0001 100C*0x20) + (bitx*4) ;bitx:第x位
// 把“位段地址+位序号”转换别名地址宏
#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) )
#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 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 PA0 BIT_ADDR(GPIOA_ODR_Addr, 0) //输出
#define PA1 BIT_ADDR(GPIOA_ODR_Addr, 1) //输出
#define PA2 BIT_ADDR(GPIOA_ODR_Addr, 2) //输出
#define PA3 BIT_ADDR(GPIOA_ODR_Addr, 3) //输出
#define PA4 BIT_ADDR(GPIOA_ODR_Addr, 4) //输出
#define PA5 BIT_ADDR(GPIOA_ODR_Addr, 5) //输出
#define PA6 BIT_ADDR(GPIOA_ODR_Addr, 6) //输出
#define PA7 BIT_ADDR(GPIOA_ODR_Addr, 7) //输出
#define PA8 BIT_ADDR(GPIOA_ODR_Addr, 8) //输出
#define PA9 BIT_ADDR(GPIOA_ODR_Addr, 9) //输出
#define PA10 BIT_ADDR(GPIOA_ODR_Addr, 10) //输出
#define PA11 BIT_ADDR(GPIOA_ODR_Addr, 11) //输出
#define PA12 BIT_ADDR(GPIOA_ODR_Addr, 12) //输出
#define PA13 BIT_ADDR(GPIOA_ODR_Addr, 13) //输出
#define PA14 BIT_ADDR(GPIOA_ODR_Addr, 14) //输出
#define PA15 BIT_ADDR(GPIOA_ODR_Addr, 15) //输出
#define PA0in BIT_ADDR(GPIOA_IDR_Addr, 0) //输入
#define PA1in BIT_ADDR(GPIOA_IDR_Addr, 1) //输入
#define PA2in BIT_ADDR(GPIOA_IDR_Addr, 2) //输入
#define PA3in BIT_ADDR(GPIOA_IDR_Addr, 3) //输入
#define PA4in BIT_ADDR(GPIOA_IDR_Addr, 4) //输入
#define PA5in BIT_ADDR(GPIOA_IDR_Addr, 5) //输入
#define PA6in BIT_ADDR(GPIOA_IDR_Addr, 6) //输入
#define PA7in BIT_ADDR(GPIOA_IDR_Addr, 7) //输入
#define PA8in BIT_ADDR(GPIOA_IDR_Addr, 8) //输入
#define PA9in BIT_ADDR(GPIOA_IDR_Addr, 9) //输入
#define PA10in BIT_ADDR(GPIOA_IDR_Addr, 10) //输入
#define PA11in BIT_ADDR(GPIOA_IDR_Addr, 11) //输入
#define PA12in BIT_ADDR(GPIOA_IDR_Addr, 12) //输入
#define PA13in BIT_ADDR(GPIOA_IDR_Addr, 13) //输入
#define PA14in BIT_ADDR(GPIOA_IDR_Addr, 14) //输入
#define PA15in BIT_ADDR(GPIOA_IDR_Addr, 15) //输入
//-----------------------------------------------------
#define PB0 BIT_ADDR(GPIOB_ODR_Addr, 0) //输出
#define PB1 BIT_ADDR(GPIOB_ODR_Addr, 1) //输出
#define PB2 BIT_ADDR(GPIOB_ODR_Addr, 2) //输出
#define PB3 BIT_ADDR(GPIOB_ODR_Addr, 3) //输出
#define PB4 BIT_ADDR(GPIOB_ODR_Addr, 4) //输出
#define PB5 BIT_ADDR(GPIOB_ODR_Addr, 5) //输出
#define PB6 BIT_ADDR(GPIOB_ODR_Addr, 6) //输出
#define PB7 BIT_ADDR(GPIOB_ODR_Addr, 7) //输出
#define PB8 BIT_ADDR(GPIOB_ODR_Addr, 8) //输出
#define PB9 BIT_ADDR(GPIOB_ODR_Addr, 9) //输出
#define PB10 BIT_ADDR(GPIOB_ODR_Addr, 10) //输出
#define PB11 BIT_ADDR(GPIOB_ODR_Addr, 11) //输出
#define PB12 BIT_ADDR(GPIOB_ODR_Addr, 12) //输出
#define PB13 BIT_ADDR(GPIOB_ODR_Addr, 13) //输出
#define PB14 BIT_ADDR(GPIOB_ODR_Addr, 14) //输出
#define PB15 BIT_ADDR(GPIOB_ODR_Addr, 15) //输出
#define PB0in BIT_ADDR(GPIOB_IDR_Addr, 0) //输入
#define PB1in BIT_ADDR(GPIOB_IDR_Addr, 1) //输入
#define PB2in BIT_ADDR(GPIOB_IDR_Addr, 2) //输入
#define PB3in BIT_ADDR(GPIOB_IDR_Addr, 3) //输入
#define PB4in BIT_ADDR(GPIOB_IDR_Addr, 4) //输入
#define PB5in BIT_ADDR(GPIOB_IDR_Addr, 5) //输入
#define PB6in BIT_ADDR(GPIOB_IDR_Addr, 6) //输入
#define PB7in BIT_ADDR(GPIOB_IDR_Addr, 7) //输入
#define PB8in BIT_ADDR(GPIOB_IDR_Addr, 8) //输入
#define PB9in BIT_ADDR(GPIOB_IDR_Addr, 9) //输入
#define PB10in BIT_ADDR(GPIOB_IDR_Addr, 10) //输入
#define PB11in BIT_ADDR(GPIOB_IDR_Addr, 11) //输入
#define PB12in BIT_ADDR(GPIOB_IDR_Addr, 12) //输入
#define PB13in BIT_ADDR(GPIOB_IDR_Addr, 13) //输入
#define PB14in BIT_ADDR(GPIOB_IDR_Addr, 14) //输入
#define PB15in BIT_ADDR(GPIOB_IDR_Addr, 15) //输入
//----------------------------------------------------
#define PC0 BIT_ADDR(GPIOC_ODR_Addr, 0) //输出
#define PC1 BIT_ADDR(GPIOC_ODR_Addr, 1) //输出
#define PC2 BIT_ADDR(GPIOC_ODR_Addr, 2) //输出
#define PC3 BIT_ADDR(GPIOC_ODR_Addr, 3) //输出
#define PC4 BIT_ADDR(GPIOC_ODR_Addr, 4) //输出
#define PC5 BIT_ADDR(GPIOC_ODR_Addr, 5) //输出
#define PC6 BIT_ADDR(GPIOC_ODR_Addr, 6) //输出
#define PC7 BIT_ADDR(GPIOC_ODR_Addr, 7) //输出
#define PC8 BIT_ADDR(GPIOC_ODR_Addr, 8) //输出
#define PC9 BIT_ADDR(GPIOC_ODR_Addr, 9) //输出
#define PC10 BIT_ADDR(GPIOC_ODR_Addr, 10) //输出
#define PC11 BIT_ADDR(GPIOC_ODR_Addr, 11) //输出
#define PC12 BIT_ADDR(GPIOC_ODR_Addr, 12) //输出
#define PC13 BIT_ADDR(GPIOC_ODR_Addr, 13) //输出
#define PC14 BIT_ADDR(GPIOC_ODR_Addr, 14) //输出
#define PC15 BIT_ADDR(GPIOC_ODR_Addr, 15) //输出
#define PC0in BIT_ADDR(GPIOC_IDR_Addr, 0) //输入
#define PC1in BIT_ADDR(GPIOC_IDR_Addr, 1) //输入
#define PC2in BIT_ADDR(GPIOC_IDR_Addr, 2) //输入
#define PC3in BIT_ADDR(GPIOC_IDR_Addr, 3) //输入
#define PC4in BIT_ADDR(GPIOC_IDR_Addr, 4) //输入
#define PC5in BIT_ADDR(GPIOC_IDR_Addr, 5) //输入
#define PC6in BIT_ADDR(GPIOC_IDR_Addr, 6) //输入
#define PC7in BIT_ADDR(GPIOC_IDR_Addr, 7) //输入
#define PC8in BIT_ADDR(GPIOC_IDR_Addr, 8) //输入
#define PC9in BIT_ADDR(GPIOC_IDR_Addr, 9) //输入
#define PC10in BIT_ADDR(GPIOC_IDR_Addr, 10) //输入
#define PC11in BIT_ADDR(GPIOC_IDR_Addr, 11) //输入
#define PC12in BIT_ADDR(GPIOC_IDR_Addr, 12) //输入
#define PC13in BIT_ADDR(GPIOC_IDR_Addr, 13) //输入
#define PC14in BIT_ADDR(GPIOC_IDR_Addr, 14) //输入
#define PC15in BIT_ADDR(GPIOC_IDR_Addr, 15) //输入
//----------------------------------------------------
#define PD0 BIT_ADDR(GPIOD_ODR_Addr, 0) //输出
#define PD1 BIT_ADDR(GPIOD_ODR_Addr, 1) //输出
#define PD2 BIT_ADDR(GPIOD_ODR_Addr, 2) //输出
#define PD3 BIT_ADDR(GPIOD_ODR_Addr, 3) //输出
#define PD4 BIT_ADDR(GPIOD_ODR_Addr, 4) //输出
#define PD5 BIT_ADDR(GPIOD_ODR_Addr, 5) //输出
#define PD6 BIT_ADDR(GPIOD_ODR_Addr, 6) //输出
#define PD7 BIT_ADDR(GPIOD_ODR_Addr, 7) //输出
#define PD8 BIT_ADDR(GPIOD_ODR_Addr, 8) //输出
#define PD9 BIT_ADDR(GPIOD_ODR_Addr, 9) //输出
#define PD10 BIT_ADDR(GPIOD_ODR_Addr, 10) //输出
#define PD11 BIT_ADDR(GPIOD_ODR_Addr, 11) //输出
#define PD12 BIT_ADDR(GPIOD_ODR_Addr, 12) //输出
#define PD13 BIT_ADDR(GPIOD_ODR_Addr, 13) //输出
#define PD14 BIT_ADDR(GPIOD_ODR_Addr, 14) //输出
#define PD15 BIT_ADDR(GPIOD_ODR_Addr, 15) //输出
#define PD0in BIT_ADDR(GPIOD_IDR_Addr, 0) //输入
#define PD1in BIT_ADDR(GPIOD_IDR_Addr, 1) //输入
#define PD2in BIT_ADDR(GPIOD_IDR_Addr, 2) //输入
#define PD3in BIT_ADDR(GPIOD_IDR_Addr, 3) //输入
#define PD4in BIT_ADDR(GPIOD_IDR_Addr, 4) //输入
#define PD5in BIT_ADDR(GPIOD_IDR_Addr, 5) //输入
#define PD6in BIT_ADDR(GPIOD_IDR_Addr, 6) //输入
#define PD7in BIT_ADDR(GPIOD_IDR_Addr, 7) //输入
#define PD8in BIT_ADDR(GPIOD_IDR_Addr, 8) //输入
#define PD9in BIT_ADDR(GPIOD_IDR_Addr, 9) //输入
#define PD10in BIT_ADDR(GPIOD_IDR_Addr, 10) //输入
#define PD11in BIT_ADDR(GPIOD_IDR_Addr, 11) //输入
#define PD12in BIT_ADDR(GPIOD_IDR_Addr, 12) //输入
#define PD13in BIT_ADDR(GPIOD_IDR_Addr, 13) //输入
#define PD14in BIT_ADDR(GPIOD_IDR_Addr, 14) //输入
#define PD15in BIT_ADDR(GPIOD_IDR_Addr, 15) //输入
//----------------------------------------------------
#define PE0 BIT_ADDR(GPIOE_ODR_Addr, 0) //输出
#define PE1 BIT_ADDR(GPIOE_ODR_Addr, 1) //输出
#define PE2 BIT_ADDR(GPIOE_ODR_Addr, 2) //输出
#define PE3 BIT_ADDR(GPIOE_ODR_Addr, 3) //输出
#define PE4 BIT_ADDR(GPIOE_ODR_Addr, 4) //输出
#define PE5 BIT_ADDR(GPIOE_ODR_Addr, 5) //输出
#define PE6 BIT_ADDR(GPIOE_ODR_Addr, 6) //输出
#define PE7 BIT_ADDR(GPIOE_ODR_Addr, 7) //输出
#define PE8 BIT_ADDR(GPIOE_ODR_Addr, 8) //输出
#define PE9 BIT_ADDR(GPIOE_ODR_Addr, 9) //输出
#define PE10 BIT_ADDR(GPIOE_ODR_Addr, 10) //输出
#define PE11 BIT_ADDR(GPIOE_ODR_Addr, 11) //输出
#define PE12 BIT_ADDR(GPIOE_ODR_Addr, 12) //输出
#define PE13 BIT_ADDR(GPIOE_ODR_Addr, 13) //输出
#define PE14 BIT_ADDR(GPIOE_ODR_Addr, 14) //输出
#define PE15 BIT_ADDR(GPIOE_ODR_Addr, 15) //输出
#define PE0in BIT_ADDR(GPIOE_IDR_Addr, 0) //输入
#define PE1in BIT_ADDR(GPIOE_IDR_Addr, 1) //输入
#define PE2in BIT_ADDR(GPIOE_IDR_Addr, 2) //输入
#define PE3in BIT_ADDR(GPIOE_IDR_Addr, 3) //输入
#define PE4in BIT_ADDR(GPIOE_IDR_Addr, 4) //输入
#define PE5in BIT_ADDR(GPIOE_IDR_Addr, 5) //输入
#define PE6in BIT_ADDR(GPIOE_IDR_Addr, 6) //输入
#define PE7in BIT_ADDR(GPIOE_IDR_Addr, 7) //输入
#define PE8in BIT_ADDR(GPIOE_IDR_Addr, 8) //输入
#define PE9in BIT_ADDR(GPIOE_IDR_Addr, 9) //输入
#define PE10in BIT_ADDR(GPIOE_IDR_Addr, 10) //输入
#define PE11in BIT_ADDR(GPIOE_IDR_Addr, 11) //输入
#define PE12in BIT_ADDR(GPIOE_IDR_Addr, 12) //输入
#define PE13in BIT_ADDR(GPIOE_IDR_Addr, 13) //输入
#define PE14in BIT_ADDR(GPIOE_IDR_Addr, 14) //输入
#define PE15in BIT_ADDR(GPIOE_IDR_Addr, 15) //输入
//举例:
//输出
PA0=0;
PA1=1;
//输入
if(PB0==0)
;//检测到低电平
//别名区
// 把“位段地址+位序号”转换别名地址宏
#define BITBAND(addr, bitnum) ((addr & 0xF0000000)+0x2000000+((addr &0xFFFFF)<5)+(bitnum<2))
//把该地址转换成一个指针
#define MEM_ADDR(addr)
#define BIT_ADDR(addr, bitnum)
#define GPIOA_ODR_Addr
#define GPIOB_ODR_Addr
#define GPIOC_ODR_Addr
#define GPIOD_ODR_Addr
#define GPIOE_ODR_Addr
#define GPIOA_IDR_Addr
#define GPIOB_IDR_Addr
#define GPIOC_IDR_Addr
#define GPIOD_IDR_Addr
#define GPIOE_IDR_Addr
//-----------------------------------------------------
#define PA0
#define PA1
#define PA2
#define PA3
#define PA4
#define PA5
#define PA6
#define PA7
#define PA8
#define PA9
#define PA10
#define PA11
#define PA12
#define PA13
#define PA14
#define PA15
#define PA0in
#define PA1in
#define PA2in
#define PA3in
#define PA4in
#define PA5in
#define PA6in
#define PA7in
#define PA8in
#define PA9in
#define PA10in
#define PA11in
#define PA12in
#define PA13in
#define PA14in
#define PA15in
//-----------------------------------------------------
#define PB0
#define PB1
#define PB2
#define PB3
#define PB4
#define PB5
#define PB6
#define PB7
#define PB8
#define PB9
#define PB10
#define PB11
#define PB12
#define PB13
#define PB14
#define PB15
#define PB0in
#define PB1in
#define PB2in
#define PB3in
#define PB4in
#define PB5in
#define PB6in
#define PB7in
#define PB8in
#define PB9in
#define PB10in
#define PB11in
#define PB12in
#define PB13in
#define PB14in
#define PB15in
//----------------------------------------------------
#define PC0
#define PC1
#define PC2
#define PC3
#define PC4
#define PC5
#define PC6
#define PC7
#define PC8
#define PC9
#define PC10
#define PC11
#define PC12
#define PC13
#define PC14
#define PC15
#define PC0in
#define PC1in
#define PC2in
#define PC3in
#define PC4in
#define PC5in
#define PC6in
#define PC7in
#define PC8in
#define PC9in
#define PC10in
#define PC11in
#define PC12in
#define PC13in
#define PC14in
#define PC15in
//----------------------------------------------------
#define PD0
#define PD1
#define PD2
#define PD3
#define PD4
#define PD5
#define PD6
#define PD7
#define PD8
#define PD9
#define PD10
#define PD11
#define PD12
#define PD13
#define PD14
#define PD15
#define PD0in
#define PD1in
#define PD2in
#define PD3in
#define PD4in
#define PD5in
#define PD6in
#define PD7in
#define PD8in
#define PD9in
#define PD10in
#define PD11in
#define PD12in
#define PD13in
#define PD14in
#define PD15in
//----------------------------------------------------
#define PE0
#define PE1
#define PE2
#define PE3
#define PE4
#define PE5
#define PE6
#define PE7
#define PE8
#define PE9
#define PE10
#define PE11
#define PE12
#define PE13
#define PE14
#define PE15
#define PE0in
#define PE1in
#define PE2in
#define PE3in
#define PE4in
#define PE5in
#define PE6in
#define PE7in
#define PE8in
#define PE9in
#define PE10in
#define PE11in
#define PE12in
#define PE13in
#define PE14in
#define PE15in
//举例:
//输出
PA0=0;
PA1=1;
//输入
if(PB0==0)
51STM32I 相关文章:
- Windows CE 进程、线程和内存管理(11-09)
- RedHatLinux新手入门教程(5)(11-12)
- uClinux介绍(11-09)
- openwebmailV1.60安装教学(11-12)
- Linux嵌入式系统开发平台选型探讨(11-09)
- Windows CE 进程、线程和内存管理(二)(11-09)