鱼C论坛

 找回密码
 立即注册
查看: 1776|回复: 1

[已解决]c语言求助,急

[复制链接]
发表于 2022-12-16 22:36:12 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

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
};
最佳答案
2022-12-16 22:49:04
本帖最后由 lvk 于 2022-12-16 22:50 编辑

来自stm32标准库:
  1. /**
  2. * @brief  GPIO Configuration Mode enumeration
  3. */
  4. typedef enum
  5. {
  6.     GPIO_Mode_IN = 0x00,  /*!< GPIO Input Mode */
  7.     GPIO_Mode_OUT = 0x01, /*!< GPIO Output Mode */
  8.     GPIO_Mode_AF = 0x02,  /*!< GPIO Alternate function Mode */
  9.     GPIO_Mode_AN = 0x03   /*!< GPIO Analog Mode */
  10. } GPIOMode_TypeDef;

  11. /**
  12. * @brief  GPIO Output Maximum frequency enumeration
  13. */
  14. typedef enum
  15. {
  16.     GPIO_Low_Speed = 0x00,    /*!< Low speed    */
  17.     GPIO_Medium_Speed = 0x01, /*!< Medium speed */
  18.     GPIO_Fast_Speed = 0x02,   /*!< Fast speed   */
  19.     GPIO_High_Speed = 0x03    /*!< High speed   */
  20. } GPIOSpeed_TypeDef;

  21. /**
  22. * @brief   GPIO Init structure definition
  23. */
  24. typedef struct
  25. {
  26.     unsigned int GPIO_Pin; /*!< Specifies the GPIO pins to be configured.
  27.                           This parameter can be any value of @ref GPIO_pins_define */

  28.     GPIOMode_TypeDef GPIO_Mode; /*!< Specifies the operating mode for the selected pins.
  29.                                    This parameter can be a value of @ref GPIOMode_TypeDef */

  30.     GPIOSpeed_TypeDef GPIO_Speed; /*!< Specifies the speed for the selected pins.
  31.                                      This parameter can be a value of @ref GPIOSpeed_TypeDef */
  32. } GPIO_InitTypeDef;
复制代码

有些值和要求的不一样,照着改就行
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2022-12-16 22:49:04 | 显示全部楼层    本楼为最佳答案   
本帖最后由 lvk 于 2022-12-16 22:50 编辑

来自stm32标准库:
  1. /**
  2. * @brief  GPIO Configuration Mode enumeration
  3. */
  4. typedef enum
  5. {
  6.     GPIO_Mode_IN = 0x00,  /*!< GPIO Input Mode */
  7.     GPIO_Mode_OUT = 0x01, /*!< GPIO Output Mode */
  8.     GPIO_Mode_AF = 0x02,  /*!< GPIO Alternate function Mode */
  9.     GPIO_Mode_AN = 0x03   /*!< GPIO Analog Mode */
  10. } GPIOMode_TypeDef;

  11. /**
  12. * @brief  GPIO Output Maximum frequency enumeration
  13. */
  14. typedef enum
  15. {
  16.     GPIO_Low_Speed = 0x00,    /*!< Low speed    */
  17.     GPIO_Medium_Speed = 0x01, /*!< Medium speed */
  18.     GPIO_Fast_Speed = 0x02,   /*!< Fast speed   */
  19.     GPIO_High_Speed = 0x03    /*!< High speed   */
  20. } GPIOSpeed_TypeDef;

  21. /**
  22. * @brief   GPIO Init structure definition
  23. */
  24. typedef struct
  25. {
  26.     unsigned int GPIO_Pin; /*!< Specifies the GPIO pins to be configured.
  27.                           This parameter can be any value of @ref GPIO_pins_define */

  28.     GPIOMode_TypeDef GPIO_Mode; /*!< Specifies the operating mode for the selected pins.
  29.                                    This parameter can be a value of @ref GPIOMode_TypeDef */

  30.     GPIOSpeed_TypeDef GPIO_Speed; /*!< Specifies the speed for the selected pins.
  31.                                      This parameter can be a value of @ref GPIOSpeed_TypeDef */
  32. } GPIO_InitTypeDef;
复制代码

有些值和要求的不一样,照着改就行
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-4-30 19:49

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表