1、IO口配置
将IO口配置为开漏输出模式 GB6与GB7两个管脚
GPIO_InitStruct.Pin = GPIO_PIN_6|GPIO_PIN_7;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
2、软件模拟
2.1宏定义
//IO操作函数
/* Exported types ------------------------------------------------------------*/
typedef struct
{
unsigned short int b0 : 1;
unsigned short int b1 : 1;
unsigned short int b2 : 1;
unsigned short int b3 : 1;
unsigned short int b4 : 1;
unsigned short int b5 : 1;
unsigned short int b6 : 1;
unsigned short int b7 : 1;
unsigned short int b8 : 1;
unsigned short int b9 : 1;
unsigned short int b10 : 1;
unsigned short int b11 : 1;
unsigned short int b12 : 1;
unsigned short int b13 : 1;
unsigned short int b14 : 1;
unsigned short int b15 : 1;
} REG16_TypeDef;
/******************************************************************************
GPIO地址映射
基地址加上寄存器偏移地址组成
******************************************************************************/
#define GPIOA_ODR_Addr (GPIOA_BASE + 0x14) //0x48000014
#define GPIOB_ODR_Addr