|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
请你定义一个GPIO结构体并给它赋值。
要求:1.结构体名称为GPIO_InitTypeDef
2.结构体变量有(1)GPIO_Pin;(2)GPIO_Speed;(3) GPIO_Mode;其中 GPIO_Pin为无符号短整形,GPIO_Speed和GPIO_Mode为枚举类型。GPIO_Speed的枚举有 GPIO_Speed_10MHz,GPIO_Speed_2MHz, GPIO_Speed_50MHz。GPIO_Mode的枚举有 GPIO_Mode_AIN=0x0,GPIO_Mode_IN_FLOATING=0x04,GPIO_Mode_IPD= 0x28,GPIO_Mode_IPU = 0x48,GPIO_Mode_Out_OD = 0x14, GPIO_Mode_Out_PP = 0x10,GPIO_Mode_AF_OD = 0x1C,GPIO_Mode_AF_PP = 0x18。
3.GPIO_Speed和GPIO_Mode为枚举类型。需要自己构造。
4.结构体变量的值可以是该变量的任意数据类型
例:enum GPIOSpeed_TypeDef
{
GPIO_Speed_10MHz = 1,
GPIO_Speed_2MHz,
GPIO_Speed_50MHz
};
本帖最后由 lvk 于 2022-12-16 22:50 编辑
来自stm32标准库:
- /**
- * @brief GPIO Configuration Mode enumeration
- */
- typedef enum
- {
- GPIO_Mode_IN = 0x00, /*!< GPIO Input Mode */
- GPIO_Mode_OUT = 0x01, /*!< GPIO Output Mode */
- GPIO_Mode_AF = 0x02, /*!< GPIO Alternate function Mode */
- GPIO_Mode_AN = 0x03 /*!< GPIO Analog Mode */
- } GPIOMode_TypeDef;
- /**
- * @brief GPIO Output Maximum frequency enumeration
- */
- typedef enum
- {
- GPIO_Low_Speed = 0x00, /*!< Low speed */
- GPIO_Medium_Speed = 0x01, /*!< Medium speed */
- GPIO_Fast_Speed = 0x02, /*!< Fast speed */
- GPIO_High_Speed = 0x03 /*!< High speed */
- } GPIOSpeed_TypeDef;
- /**
- * @brief GPIO Init structure definition
- */
- typedef struct
- {
- unsigned int GPIO_Pin; /*!< Specifies the GPIO pins to be configured.
- This parameter can be any value of @ref GPIO_pins_define */
- GPIOMode_TypeDef GPIO_Mode; /*!< Specifies the operating mode for the selected pins.
- This parameter can be a value of @ref GPIOMode_TypeDef */
- GPIOSpeed_TypeDef GPIO_Speed; /*!< Specifies the speed for the selected pins.
- This parameter can be a value of @ref GPIOSpeed_TypeDef */
- } GPIO_InitTypeDef;
复制代码
有些值和要求的不一样,照着改就行
|
|