STM32之GPIO端口位带操作

#ifndef __SYS_H
#define __SYS_H
#include "stm32f10x.h" //位带操作
//把“位带地址+位序号”转换别名地址宏
#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)) //GPIO输出输入地址映射
#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 //GPIO输入输出定义
#define PAOut(n) BIT_ADDR(GPIOA_ODR_Addr,n) //GPIOA的输出
#define PAIn(n) BIT_ADDR(GPIOA_IDR_Addr,n) //GPIOA的输入 #define PBOut(n) BIT_ADDR(GPIOB_ODR_Addr,n) //GPIOB的输出
#define PBIn(n) BIT_ADDR(GPIOB_IDR_Addr,n) //GPIOB的输入 #define PCOut(n) BIT_ADDR(GPIOC_ODR_Addr,n) //GPIOC的输出
#define PCIn(n) BIT_ADDR(GPIOC_IDR_Addr,n) //GPIOC的输入 #define PDOut(n) BIT_ADDR(GPIOD_ODR_Addr,n) //GPIOD的输出
#define PDIn(n) BIT_ADDR(GPIOD_IDR_Addr,n) //GPIOD的输入 #define PEOut(n) BIT_ADDR(GPIOE_ODR_Addr,n) //GPIOE的输出
#define PEIn(n) BIT_ADDR(GPIOE_IDR_Addr,n) //GPIOE的输入 #define PFOut(n) BIT_ADDR(GPIOF_ODR_Addr,n) //GPIOF的输出
#define PFIn(n) BIT_ADDR(GPIOF_IDR_Addr,n) //GPIOF的输入 #define PGOut(n) BIT_ADDR(GPIOG_ODR_Addr,n) //GPIOG的输出
#define PGIn(n) BIT_ADDR(GPIOG_IDR_Addr,n) //GPIOG的输入 /*
使用方法
#define TM1637_CLK PCOut(7) ---设置GPIOC的7口向TM1637的CLK通讯进行输出
#define TM1637_DIO PCOut(6) ---设置GPIOC的6口向TM1637的DIO通讯进行输出
#define TM1637_READ_DIO PCIn(6) ---设置GPIOC的6口读取TM1637的DIO数据
*/
上一篇:STM32F030系列实现仿位带操作


下一篇:玩转X-CTR100 | STM32F4 l GPIO位带操作