欢迎来到专业的辛易范文网平台! 工作总结 工作计划 心得体会 思想汇报 发言稿 述职报告 教案设计 申请书大全
当前位置:首页 > 范文大全 > 调查报告 > 正文

gpio实验报告stm32ze6篇

时间:2022-09-09 13:50:04 来源:网友投稿

gpio实验报告stm32ze6篇gpio实验报告stm32ze 山东科技大学《微控制器原理》实验指导书 STM32F103-GPIO基本输入输出实验1实验01STM32F103-GPIO基本输入输出下面是小编为大家整理的gpio实验报告stm32ze6篇,供大家参考。

gpio实验报告stm32ze6篇

篇一:gpio实验报告stm32ze

科技大学《微控制器原理》实验指导书

  STM32F103-GPIO 基本输入输出实验 1实验 01 STM32F103-GPIO 基本输入输出实验

 实验 01 STM32F103-GPIO 基本输入输出实验

 一、实验目的

 学习 STM32F103VCT6 单片机的通用 GPIO 的基本输出输入功能,主要了解 STM32 的GPIO 的原理和应用。

 二、实验设备 1) 装有 RV MDK 仿真软件的 Pentium 以上的计算机一套; 2) J-Link-ARM V8 仿真器一套; 3) STM32F103VCT 的神舟 II 号开发板一套。

 三、实验电路原理图及其说明 在神州Ⅱ号 STM32 开发板中,一共有 5 个 LED 指示灯,其中一个是电源指示灯LD5,其他的 4 个 LED (LD1、LD2、LD3 和 LD4)由 GPIO-PD 控制,4 个 LED 分别串了 470KΩ的电阻,起限流作用防止电流过大损坏 LED 和 GPIO 口。电路原理图如图 1 所示。

  图 1 STM32F103GPIO-LED 电路原理图图 当 GPIO 管脚输出高电平时,对应的 LED 灯亮;当 GPIO 管脚输出低电平时对应的LED 灯灭。GPIO 管脚与对应的 LED 灯的关系如下表所示:

 LED 灯 LED 灯对应的 GPIO LD1 PD08 LD2 PD09 LD3 PD10 LD4 PD11 蜂鸣器 DEEP PC8

 山东科技大学《微控制器原理》实验指导书

  STM32F103-GPIO 基本输入输出实验 2

 图 2 按键 KEY 硬件电路 GPIO 管脚与按键对应的关系 按键 GPIO 说明 确定 OK PD3 下拉电阻 上 UP PD4 下拉电阻 下 DOWN PA8 下拉电阻 左 LEFT PD0 下拉电阻 右 RIGHT PD1 下拉电阻 用户自定义 User PD2 上拉电阻 干预 Tamper PC13 上拉电阻 唤醒 Wakeup PA0 下拉电阻 四、实验内容 1. 使用单步运行实现 LD1、LD2、LD3、LD4 点亮和熄灭。

 2. 使用软件延时 1s 实现这四个灯交替闪烁的流水灯效果。

 3. 按下 UP、DOWN、LEFT、RIGHT 键分别让对应的 LD1、LD2、LD3、LD4 指示灯亮。

 4. 按下 LEFT 键让 LD1→LD2→LD3→LD4 自左向右流水显示;按下 RIGHT 键分别让LD4→LD3→LD2→LD1 自右向左流水显示。

 5. 按下 UP 键让 LD1→LD2→LD3→LD4 自左向右流水循环显示;按下 DOWN 键分别让LD4→LD3→LD2→LD1 自右向左流水循环显示。

 五、实验原理 流水灯的关键实际上就是如何控制 STM32 处理器的 GPIO 接口,作为 IO 口,输出指定的电平信号。

 STM32 的 IO 口可以由软件配置成 8 种模式:模拟输入、输入悬空、输入下拉、输入

 山东科技大学《微控制器原理》实验指导书

  STM32F103-GPIO 基本输入输出实验 3上拉、开漏输出、推挽输出、复用功能开漏输出和复用功能推挽输出等。STM32 每个 IO口可以自由编程,单 IO 口寄存器必须要按 32 位字被访问。STM32 的很多 IO 口都是 5V兼容的,这些 IO 口在与 5V 电平的外设连接的时候很有优势。

 STM32 的每个 IO 端口都有 7 个寄存器来控制:配置模式的 2 个 32 位的端口配置寄存器 CRL 和 CRH、2 个 32 位的数据寄存器 IDR 和 ODR、1 个 32 位的置位/复位寄存器 BSRR、一个 32 位的复位寄存器 BRR、1 个 32 位的锁存寄存器 LCKR 等。

 GPIO_CR 控制着每个 IO 口的模式及输出速率,STM32 的 IO 口位配置表如下表所示。

 配置模式 CNF1 CNF0 MODE1 MODE0 PxODR 寄存器 通用输出 推挽式 Push-Pull 0 0 01 10 11 见表 3.1.2 0 或 1 开漏 Open-Drain 1 0 或 1 复 用 功 能输出 推挽式 Push-Pull 1 0 不使用 开漏 Open-Drain 1 不使用 输入 模拟输入 0 0 00 不使用 浮空输入 1 不使用 下拉输入 1 0 0 上拉输入 1 STM32 输出模式配置如下表所示:

 MODE[1:0] 意义 00 保留 01 最大输出速度为 10MHz 10 最大输出速度为 2MHz 11 最大输出速度为 50MHz 六、实验现象 把程序下载到神州Ⅱ号 STM32 开发板后,可以根据实验设计看到四个 LED(LD1-4)单独或者轮流闪亮,实现流水灯的效果。

  七、实验报告书写要求 说明:七、实验报告书写要求 说明:

 实验报告均按以下格式书写

  1) 绘制程序流程图。

 2) 写出程序清单。

 3) 给出实验中用到的数据和实验结果。

 4) 通过实验,分析你的收获、不足、问题。

 山东科技大学《微控制器原理》实验指导书

  STM32F103-GPIO 基本输入输出实验 4八、参考程序 /* Includes ------------------------------------------------------------------*/ #include "stm32f10x.h" /* Private define ------------------------------------------------------------*/ #define RCC_GPIO_LED

 RCC_APB2Periph_GPIOD /*LED 使用的 GPIO 时钟*/ #define LEDn

 4

  /*神舟 II 号 LED 数量*/ #define GPIO_LED

  GPIOD

 /*LED 使用的 GPIO 组*/ #define LD1_PIN

  GPIO_Pin_8

  /*LD1 使用的 GPIO 管脚*/ #define LD2_PIN

  GPIO_Pin_9

 /*LD2 使用的 GPIO 管脚*/ #define LD3_PIN

  GPIO_Pin_10

  /*LD3 使用的 GPIO 管脚*/ #define LD4_PIN

  GPIO_Pin_11

 /*LD4 使用的 GPIO 管脚*/ /* Private variables ---------------------------------------------------------*/ u8 count=0; /* Private function prototypes -----------------------------------------------*/ void Delay(vu32 nCount); void Turn_On_LED(u8 LED_NUM); /* Private functions ---------------------------------------------------------*/ int main(void) { GPIO_InitTypeDef

 GPIO_InitStructure;

  //定义结构体变量

 /* 配置神舟 II 号 LED 灯使用的 GPIO 管脚模式*/

 RCC_APB2PeriphClockCmd(RCC_GPIO_LED, ENABLE); /*使能 LED 使用的 GPIO 时钟*/

 GPIO_InitStructure.GPIO_Pin = LD1_PIN|LD2_PIN|LD3_PIN|LD4_PIN;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

 GPIO_Init(GPIO_LED, &GPIO_InitStructure);

 /*LED 灯相关的 GPIO 口初始化*/

 GPIO_ResetBits(GPIO_LED,LD1_PIN|LD2_PIN|LD3_PIN|LD4_PIN);/*关闭所有 LED 灯*/

  while(1)

  {

 GPIO_ResetBits(GPIO_LED,LD1_PIN|LD2_PIN|LD3_PIN|LD4_PIN);/*关闭所有 LED 灯*/

  Turn_On_LED(count%4);

  //点亮一个 LED 灯

  count++;

  Delay(0x2FFFFF);

  } } /*点亮对应灯*/ void Turn_On_LED(u8 LED_NUM) {

 switch(LED_NUM)

 {

  case 0: GPIO_SetBits(GPIO_LED,LD1_PIN); break; /*点亮 LD1 灯*/

  case 1: GPIO_SetBits(GPIO_LED,LD2_PIN); break; /*点亮 LD2 灯*/

  case 2: GPIO_SetBits(GPIO_LED,LD3_PIN); break; /*点亮 LD3 灯*/

 山东科技大学《微控制器原理》实验指导书

  STM32F103-GPIO 基本输入输出实验 5

 case 3: GPIO_SetBits(GPIO_LED,LD4_PIN); break; /*点亮 LD4 灯*/

  default:

  GPIO_SetBits(GPIO_LED,LD1_PIN|LD2_PIN|LD3_PIN|LD4_PIN); break;/*点亮所有灯*/

 } } /******************************************************************************* * Function Name

 : Delay * Description

 : Inserts a delay time. * Input

 : nCount: specifies the delay time length. * Output

  : None * Return

  : None *******************************************************************************/ void Delay(vu32 nCount) {

  for(; nCount != 0; nCount--); } /******************* (C) COPYRIGHT 2008 STMicroelectronics *****END OF FILE****/ 说明:

 1) 为了降低STM32处理器的功耗,可以依据实际的需求,选择合适的时钟速率,GPIO口支持的最大时钟速率越低,它产生的功耗也越低。

 2) 在使用一个 GPIO 之前,一般需要对 GPIO 管脚的时钟、GPIO 管脚模式以及速率进行设定。

篇二:gpio实验报告stm32ze

Define to prevent recursive inclusion -------------------------------------*/ #ifndef __STM32F4xx_GPIO_H #define __STM32F4xx_GPIO_H

 #ifdef __cplusplus

 extern "C" { #endif

 /* Includes ------------------------------------------------------------------*/ #include "stm32f4xx.h"

 #define IS_GPIO_ALL_PERIPH(PERIPH) (((PERIPH) == GPIOA) || \

  ((PERIPH) == GPIOB) || \

  ((PERIPH) == GPIOC) || \

  ((PERIPH) == GPIOD) || \

  ((PERIPH) == GPIOE) || \

  ((PERIPH) == GPIOF) || \

  ((PERIPH) == GPIOG) || \

  ((PERIPH) == GPIOH) || \

  ((PERIPH) == GPIOI))

 /**

 * @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; #define IS_GPIO_MODE(MODE) (((MODE) == GPIO_Mode_IN)

 || ((MODE) == GPIO_Mode_OUT) || \

  ((MODE) == GPIO_Mode_AF)|| ((MODE) == GPIO_Mode_AN))

 /**

 * @brief

 GPIO Output type enumeration

 */

  typedef enum {

 GPIO_OType_PP = 0x00,

 GPIO_OType_OD = 0x01 }GPIOOType_TypeDef; #define IS_GPIO_OTYPE(OTYPE) (((OTYPE) == GPIO_OType_PP) || ((OTYPE) == GPIO_OType_OD))

  /**

 * @brief

 GPIO Output Maximum frequency enumeration

 */

  typedef enum {

 GPIO_Speed_2MHz

  = 0x00, /*!< Low speed */

  GPIO_Speed_25MHz

 = 0x01, /*!< Medium speed */

  GPIO_Speed_50MHz

 = 0x02, /*!< Fast speed */

  GPIO_Speed_100MHz = 0x03

 /*!< High speed on 30 pF (80 MHz Output max speed on 15 pF) */ }GPIOSpeed_TypeDef; #define IS_GPIO_SPEED(SPEED) (((SPEED) == GPIO_Speed_2MHz) || ((SPEED) == GPIO_Speed_25MHz) || \

  ((SPEED) == GPIO_Speed_50MHz)||

 ((SPEED) == GPIO_Speed_100MHz))

  /**

 * @brief

 GPIO Configuration PullUp PullDown enumeration

 */

 typedef enum {

 GPIO_PuPd_NOPULL = 0x00,

  GPIO_PuPd_UP

  = 0x01,

  GPIO_PuPd_DOWN

  = 0x02 }GPIOPuPd_TypeDef; #define IS_GPIO_PUPD(PUPD) (((PUPD) == GPIO_PuPd_NOPULL) || ((PUPD) == GPIO_PuPd_UP) || \

  ((PUPD) == GPIO_PuPd_DOWN))

 /**

 * @brief

 GPIO Bit SET and Bit RESET enumeration

 */

 typedef enum {

 Bit_RESET = 0,

  Bit_SET }BitAction; #define IS_GPIO_BIT_ACTION(ACTION) (((ACTION) == Bit_RESET) || ((ACTION) ==

 Bit_SET))

  /**

 * @brief

  GPIO Init structure definition

  */

 typedef struct {

  uint32_t 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 */

 GPIOOType_TypeDef GPIO_OType;

  /*!< Specifies the operating output type for the selected pins.

 This parameter can be a value of @ref GPIOOType_TypeDef */

 GPIOPuPd_TypeDef GPIO_PuPd;

  /*!< Specifies the operating Pull-up/Pull down for the selected pins.

 This parameter can be a value of @ref GPIOPuPd_TypeDef */ }GPIO_InitTypeDef;

 /* Exported constants --------------------------------------------------------*/

 /** @defgroup GPIO_Exported_Constants

  * @{

  */

  /** @defgroup GPIO_pins_define

 * @{

  */

 #define GPIO_Pin_0

  ((uint16_t)0x0001)

 /* Pin 0 selected */ #define GPIO_Pin_1

  ((uint16_t)0x0002)

 /* Pin 1 selected */ #define GPIO_Pin_2

  ((uint16_t)0x0004)

 /* Pin 2 selected */

 #define GPIO_Pin_3

  ((uint16_t)0x0008)

 /* Pin 3 selected */ #define GPIO_Pin_4

  ((uint16_t)0x0010)

 /* Pin 4 selected */ #define GPIO_Pin_5

  ((uint16_t)0x0020)

 /* Pin 5 selected */ #define GPIO_Pin_6

  ((uint16_t)0x0040)

 /* Pin 6 selected */ #define GPIO_Pin_7

  ((uint16_t)0x0080)

 /* Pin 7 selected */ #define GPIO_Pin_8

  ((uint16_t)0x0100)

 /* Pin 8 selected */ #define GPIO_Pin_9

  ((uint16_t)0x0200)

 /* Pin 9 selected */ #define GPIO_Pin_10

 ((uint16_t)0x0400)

 /* Pin 10 selected */ #define GPIO_Pin_11

 ((uint16_t)0x0800)

 /* Pin 11 selected */ #define GPIO_Pin_12

 ((uint16_t)0x1000)

 /* Pin 12 selected */ #define GPIO_Pin_13

 ((uint16_t)0x2000)

 /* Pin 13 selected */ #define GPIO_Pin_14

 ((uint16_t)0x4000)

 /* Pin 14 selected */ #define GPIO_Pin_15

 ((uint16_t)0x8000)

 /* Pin 15 selected */ #define GPIO_Pin_All

  ((uint16_t)0xFFFF)

 /* All pins selected */

 #define IS_GPIO_PIN(PIN) ((((PIN) & (uint16_t)0x00) == 0x00) && ((PIN) != (uint16_t)0x00)) #define IS_GET_GPIO_PIN(PIN) (((PIN) == GPIO_Pin_0) || \

  ((PIN) == GPIO_Pin_1) || \

  ((PIN) == GPIO_Pin_2) || \

  ((PIN) == GPIO_Pin_3) || \

  ((PIN) == GPIO_Pin_4) || \

  ((PIN) == GPIO_Pin_5) || \

  ((PIN) == GPIO_Pin_6) || \

  ((PIN) == GPIO_Pin_7) || \

  ((PIN) == GPIO_Pin_8) || \

  ((PIN) == GPIO_Pin_9) || \

  ((PIN) == GPIO_Pin_10) || \

  ((PIN) == GPIO_Pin_11) || \

  ((PIN) == GPIO_Pin_12) || \

  ((PIN) == GPIO_Pin_13) || \

  ((PIN) == GPIO_Pin_14) || \

  ((PIN) == GPIO_Pin_15)) /**

  * @}

  */

 /** @defgroup GPIO_Pin_sources

 * @{

  */

 #define GPIO_PinSource0

 ((uint8_t)0x00) #define GPIO_PinSource1

 ((uint8_t)0x01) #define GPIO_PinSource2

 ((uint8_t)0x02) #define GPIO_PinSource3

 ((uint8_t)0x03)

 #define GPIO_PinSource4

 ((uint8_t)0x04) #define GPIO_PinSource5

 ((uint8_t)0x05) #define GPIO_PinSource6

 ((uint8_t)0x06) #define GPIO_PinSource7

 ((uint8_t)0x07) #define GPIO_PinSource8

 ((uint8_t)0x08) #define GPIO_PinSource9

 ((uint8_t)0x09) #define GPIO_PinSource10

  ((uint8_t)0x0A) #define GPIO_PinSource11

  ((uint8_t)0x0B) #define GPIO_PinSource12

  ((uint8_t)0x0C) #define GPIO_PinSource13

  ((uint8_t)0x0D) #define GPIO_PinSource14

  ((uint8_t)0x0E) #define GPIO_PinSource15

  ((uint8_t)0x0F)

 #define IS_GPIO_PIN_SOURCE(PINSOURCE) (((PINSOURCE) == GPIO_PinSource0) || \

 ((PINSOURCE) == GPIO_PinSource1) || \

 ((PINSOURCE) == GPIO_PinSource2) || \

 ((PINSOURCE) == GPIO_PinSource3) || \

 ((PINSOURCE) == GPIO_PinSource4) || \

 ((PINSOURCE) == GPIO_PinSource5) || \

 ((PINSOURCE) == GPIO_PinSource6) || \

 ((PINSOURCE) == GPIO_PinSource7) || \

 ((PINSOURCE) == GPIO_PinSource8) || \

 ((PINSOURCE) == GPIO_PinSource9) || \

 ((PINSOURCE) == GPIO_PinSource10) || \

 ((PINSOURCE) == GPIO_PinSource11) || \

 ((PINSOURCE) == GPIO_PinSource12) || \

 ((PINSOURCE) == GPIO_PinSource13) || \

 ((PINSOURCE) == GPIO_PinSource14) || \

 ((PINSOURCE) == GPIO_PinSource15)) /**

  * @}

  */

  /** @defgroup GPIO_Alternat_function_selection_define

 * @{

  */

 /**

 * @brief

  AF 0 selection

  */

 #define GPIO_AF_RTC_50Hz

 ((uint8_t)0x00)

 /* RTC_50Hz Alternate Function mapping */ #define GPIO_AF_MCO

  ((uint8_t)0x00)

 /* MCO (MCO1 and MCO2) Alternate Function mapping */ #define GPIO_AF_TAMPER

 ((uint8_t)0x00)

 /* TAMPER (TAMPER_1 and

 TAMPER_2) Alternate Function mapping */ #define GPIO_AF_SWJ

  ((uint8_t)0x00)

 /* SWJ (SWD and JTAG) Alternate Function mapping */ #define GPIO_AF_TRACE

  ((uint8_t)0x00)

 /* TRACE Alternate Function mapping */

 /**

 * @brief

  AF 1 selection

  */

 #define GPIO_AF_TIM1

 ((uint8_t)0x01)

 /* TIM1 Alternate Function mapping */ #define GPIO_AF_TIM2

 ((uint8_t)0x01)

 /* TIM2 Alternate Function mapping */

 /**

 * @brief

  AF 2 selection

  */

 #define GPIO_AF_TIM3

 ((uint8_t)0x02)

 /* TIM3 Alternate Function mapping */ #define GPIO_AF_TIM4

 ((uint8_t)0x02)

 /* TIM4 Alternate Function mapping */ #define GPIO_AF_TIM5

 ((uint8_t)0x02)

 /* TIM5 Alternate Function mapping */

 /**

 * @brief

  AF 3 selection

  */

 #define GPIO_AF_TIM8

 ((uint8_t)0x03)

 /* TIM8 Alternate Function mapping */ #define GPIO_AF_TIM9

 ((uint8_t)0x03)

 /* TIM9 Alternate Function mapping */ #define GPIO_AF_TIM10

  ((uint8_t)0x03)

 /* TIM10 Alternate Function mapping */ #define GPIO_AF_TIM11

  ((uint8_t)0x03)

 /* TIM11 Alternate Function mapping */

 /**

 * @brief

  AF 4 selection

  */

 #define GPIO_AF_I2C1

 ((uint8_t)0x04)

 /* I2C1 Alternate Function mapping */ #define GPIO_AF_I2C2

 ((uint8_t)0x04)

 /* I2C2 Alternate Function mapping */ #define GPIO_AF_I2C3

 ((uint8_t)0x04)

 /* I2C3 Alternate Function mapping */

 /**

 * @brief

  AF 5 selection

  */

 #define GPIO_AF_SPI1

 ((uint8_t)0x05)

 /* SPI1 Altern...

篇三:gpio实验报告stm32ze

STM32开发板带您进入ARM世界

 STM32 GPIO 介绍

 普中STM32开发板带您进入ARM世界 本讲主要内容

 1.GPIO 是什么

 2.STM32 引脚分类

 3. 如何查找 GPIO 功能

 普中STM32开发板带您进入ARM世界 1.GPIO 是什么

 GPIO( general purpose intput output )是通用输入输 出端口的简称,可以通过软件来控制其输入和输出。STM32 芯片的GPIO引脚与外部设备连接起来,从而实现与外部通讯 、控制以及数据采集的功能。

 普中STM32开发板带您进入ARM世界 2.STM32 引脚分类

 电源管脚 晶振管脚 复位管脚 下载管脚 BOOT管脚 GPIO管脚

 普中STM32开发板带您进入ARM世界 3. 如何查找 GPIO 功能

 通过STM32F103ZET6芯片数据手册即可查找

 普中STM32开发板带您进入ARM世界

篇四:gpio实验报告stm32ze

Define to prevent recursive inclusion -------------------------------------*/ #ifndef __STM32F4xx_GPIO_H #define __STM32F4xx_GPIO_H

 #ifdef __cplusplus

 extern "C" { #endif

 /* Includes ------------------------------------------------------------------*/ #include "stm32f4xx.h"

 #define IS_GPIO_ALL_PERIPH(PERIPH) (((PERIPH) == GPIOA) || \

  ((PERIPH) == GPIOB) || \

  ((PERIPH) == GPIOC) || \

  ((PERIPH) == GPIOD) || \

  ((PERIPH) == GPIOE) || \

  ((PERIPH) == GPIOF) || \

  ((PERIPH) == GPIOG) || \

  ((PERIPH) == GPIOH) || \

  ((PERIPH) == GPIOI))

 /**

 * @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; #define IS_GPIO_MODE(MODE) (((MODE) == GPIO_Mode_IN)

 || ((MODE) == GPIO_Mode_OUT) || \

  ((MODE) == GPIO_Mode_AF)|| ((MODE) == GPIO_Mode_AN))

 /**

 * @brief

 GPIO Output type enumeration

 */

  typedef enum {

 GPIO_OType_PP = 0x00,

 GPIO_OType_OD = 0x01 }GPIOOType_TypeDef; #define IS_GPIO_OTYPE(OTYPE) (((OTYPE) == GPIO_OType_PP) || ((OTYPE) == GPIO_OType_OD))

  /**

 * @brief

 GPIO Output Maximum frequency enumeration

 */

  typedef enum {

 GPIO_Speed_2MHz

  = 0x00, /*!< Low speed */

  GPIO_Speed_25MHz

 = 0x01, /*!< Medium speed */

  GPIO_Speed_50MHz

 = 0x02, /*!< Fast speed */

  GPIO_Speed_100MHz = 0x03

 /*!< High speed on 30 pF (80 MHz Output max speed on 15 pF) */ }GPIOSpeed_TypeDef; #define IS_GPIO_SPEED(SPEED) (((SPEED) == GPIO_Speed_2MHz) || ((SPEED) == GPIO_Speed_25MHz) || \

  ((SPEED) == GPIO_Speed_50MHz)||

 ((SPEED) == GPIO_Speed_100MHz))

  /**

 * @brief

 GPIO Configuration PullUp PullDown enumeration

 */

 typedef enum {

 GPIO_PuPd_NOPULL = 0x00,

  GPIO_PuPd_UP

  = 0x01,

  GPIO_PuPd_DOWN

  = 0x02 }GPIOPuPd_TypeDef; #define IS_GPIO_PUPD(PUPD) (((PUPD) == GPIO_PuPd_NOPULL) || ((PUPD) == GPIO_PuPd_UP) || \

  ((PUPD) == GPIO_PuPd_DOWN))

 /**

 * @brief

 GPIO Bit SET and Bit RESET enumeration

 */

 typedef enum {

 Bit_RESET = 0,

  Bit_SET }BitAction; #define IS_GPIO_BIT_ACTION(ACTION) (((ACTION) == Bit_RESET) || ((ACTION) ==

 Bit_SET))

  /**

 * @brief

  GPIO Init structure definition

  */

 typedef struct {

  uint32_t 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 */

 GPIOOType_TypeDef GPIO_OType;

  /*!< Specifies the operating output type for the selected pins.

 This parameter can be a value of @ref GPIOOType_TypeDef */

 GPIOPuPd_TypeDef GPIO_PuPd;

  /*!< Specifies the operating Pull-up/Pull down for the selected pins.

 This parameter can be a value of @ref GPIOPuPd_TypeDef */ }GPIO_InitTypeDef;

 /* Exported constants --------------------------------------------------------*/

 /** @defgroup GPIO_Exported_Constants

  * @{

  */

  /** @defgroup GPIO_pins_define

 * @{

  */

 #define GPIO_Pin_0

  ((uint16_t)0x0001)

 /* Pin 0 selected */ #define GPIO_Pin_1

  ((uint16_t)0x0002)

 /* Pin 1 selected */ #define GPIO_Pin_2

  ((uint16_t)0x0004)

 /* Pin 2 selected */

 #define GPIO_Pin_3

  ((uint16_t)0x0008)

 /* Pin 3 selected */ #define GPIO_Pin_4

  ((uint16_t)0x0010)

 /* Pin 4 selected */ #define GPIO_Pin_5

  ((uint16_t)0x0020)

 /* Pin 5 selected */ #define GPIO_Pin_6

  ((uint16_t)0x0040)

 /* Pin 6 selected */ #define GPIO_Pin_7

  ((uint16_t)0x0080)

 /* Pin 7 selected */ #define GPIO_Pin_8

  ((uint16_t)0x0100)

 /* Pin 8 selected */ #define GPIO_Pin_9

  ((uint16_t)0x0200)

 /* Pin 9 selected */ #define GPIO_Pin_10

 ((uint16_t)0x0400)

 /* Pin 10 selected */ #define GPIO_Pin_11

 ((uint16_t)0x0800)

 /* Pin 11 selected */ #define GPIO_Pin_12

 ((uint16_t)0x1000)

 /* Pin 12 selected */ #define GPIO_Pin_13

 ((uint16_t)0x2000)

 /* Pin 13 selected */ #define GPIO_Pin_14

 ((uint16_t)0x4000)

 /* Pin 14 selected */ #define GPIO_Pin_15

 ((uint16_t)0x8000)

 /* Pin 15 selected */ #define GPIO_Pin_All

  ((uint16_t)0xFFFF)

 /* All pins selected */

 #define IS_GPIO_PIN(PIN) ((((PIN) & (uint16_t)0x00) == 0x00) && ((PIN) != (uint16_t)0x00)) #define IS_GET_GPIO_PIN(PIN) (((PIN) == GPIO_Pin_0) || \

  ((PIN) == GPIO_Pin_1) || \

  ((PIN) == GPIO_Pin_2) || \

  ((PIN) == GPIO_Pin_3) || \

  ((PIN) == GPIO_Pin_4) || \

  ((PIN) == GPIO_Pin_5) || \

  ((PIN) == GPIO_Pin_6) || \

  ((PIN) == GPIO_Pin_7) || \

  ((PIN) == GPIO_Pin_8) || \

  ((PIN) == GPIO_Pin_9) || \

  ((PIN) == GPIO_Pin_10) || \

  ((PIN) == GPIO_Pin_11) || \

  ((PIN) == GPIO_Pin_12) || \

  ((PIN) == GPIO_Pin_13) || \

  ((PIN) == GPIO_Pin_14) || \

  ((PIN) == GPIO_Pin_15)) /**

  * @}

  */

 /** @defgroup GPIO_Pin_sources

 * @{

  */

 #define GPIO_PinSource0

 ((uint8_t)0x00) #define GPIO_PinSource1

 ((uint8_t)0x01) #define GPIO_PinSource2

 ((uint8_t)0x02) #define GPIO_PinSource3

 ((uint8_t)0x03)

 #define GPIO_PinSource4

 ((uint8_t)0x04) #define GPIO_PinSource5

 ((uint8_t)0x05) #define GPIO_PinSource6

 ((uint8_t)0x06) #define GPIO_PinSource7

 ((uint8_t)0x07) #define GPIO_PinSource8

 ((uint8_t)0x08) #define GPIO_PinSource9

 ((uint8_t)0x09) #define GPIO_PinSource10

  ((uint8_t)0x0A) #define GPIO_PinSource11

  ((uint8_t)0x0B) #define GPIO_PinSource12

  ((uint8_t)0x0C) #define GPIO_PinSource13

  ((uint8_t)0x0D) #define GPIO_PinSource14

  ((uint8_t)0x0E) #define GPIO_PinSource15

  ((uint8_t)0x0F)

 #define IS_GPIO_PIN_SOURCE(PINSOURCE) (((PINSOURCE) == GPIO_PinSource0) || \

 ((PINSOURCE) == GPIO_PinSource1) || \

 ((PINSOURCE) == GPIO_PinSource2) || \

 ((PINSOURCE) == GPIO_PinSource3) || \

 ((PINSOURCE) == GPIO_PinSource4) || \

 ((PINSOURCE) == GPIO_PinSource5) || \

 ((PINSOURCE) == GPIO_PinSource6) || \

 ((PINSOURCE) == GPIO_PinSource7) || \

 ((PINSOURCE) == GPIO_PinSource8) || \

 ((PINSOURCE) == GPIO_PinSource9) || \

 ((PINSOURCE) == GPIO_PinSource10) || \

 ((PINSOURCE) == GPIO_PinSource11) || \

 ((PINSOURCE) == GPIO_PinSource12) || \

 ((PINSOURCE) == GPIO_PinSource13) || \

 ((PINSOURCE) == GPIO_PinSource14) || \

 ((PINSOURCE) == GPIO_PinSource15)) /**

  * @}

  */

  /** @defgroup GPIO_Alternat_function_selection_define

 * @{

  */

 /**

 * @brief

  AF 0 selection

  */

 #define GPIO_AF_RTC_50Hz

 ((uint8_t)0x00)

 /* RTC_50Hz Alternate Function mapping */ #define GPIO_AF_MCO

  ((uint8_t)0x00)

 /* MCO (MCO1 and MCO2) Alternate Function mapping */ #define GPIO_AF_TAMPER

 ((uint8_t)0x00)

 /* TAMPER (TAMPER_1 and

 TAMPER_2) Alternate Function mapping */ #define GPIO_AF_SWJ

  ((uint8_t)0x00)

 /* SWJ (SWD and JTAG) Alternate Function mapping */ #define GPIO_AF_TRACE

  ((uint8_t)0x00)

 /* TRACE Alternate Function mapping */

 /**

 * @brief

  AF 1 selection

  */

 #define GPIO_AF_TIM1

 ((uint8_t)0x01)

 /* TIM1 Alternate Function mapping */ #define GPIO_AF_TIM2

 ((uint8_t)0x01)

 /* TIM2 Alternate Function mapping */

 /**

 * @brief

  AF 2 selection

  */

 #define GPIO_AF_TIM3

 ((uint8_t)0x02)

 /* TIM3 Alternate Function mapping */ #define GPIO_AF_TIM4

 ((uint8_t)0x02)

 /* TIM4 Alternate Function mapping */ #define GPIO_AF_TIM5

 ((uint8_t)0x02)

 /* TIM5 Alternate Function mapping */

 /**

 * @brief

  AF 3 selection

  */

 #define GPIO_AF_TIM8

 ((uint8_t)0x03)

 /* TIM8 Alternate Function mapping */ #define GPIO_AF_TIM9

 ((uint8_t)0x03)

 /* TIM9 Alternate Function mapping */ #define GPIO_AF_TIM10

  ((uint8_t)0x03)

 /* TIM10 Alternate Function mapping */ #define GPIO_AF_TIM11

  ((uint8_t)0x03)

 /* TIM11 Alternate Function mapping */

 /**

 * @brief

  AF 4 selection

  */

 #define GPIO_AF_I2C1

 ((uint8_t)0x04)

 /* I2C1 Alternate Function mapping */ #define GPIO_AF_I2C2

 ((uint8_t)0x04)

 /* I2C2 Alternate Function mapping */ #define GPIO_AF_I2C3

 ((uint8_t)0x04)

 /* I2C3 Alternate Function mapping */

 /**

 * @brief

  AF 5 selection

  */

 #define GPIO_AF_SPI1

 ((uint8_t)0x05)

 /* SPI1 Altern...

篇五:gpio实验报告stm32ze

南理工大学 《嵌入式系统》课程实验报告 STM32 单片机外部中断程序开发

 实验概述

 【 实验目的及要求】

 1. 实验目的:

 (1)掌握 STM32 单片机外部中断程序开发 (2)掌握用寄存器开发 STM32 单片机程序 (3)掌握用库函数开发 STM32 单片机程序

 2. 实验要求:

 (1)学习 EXTRegister 和 EXT_INTLabbox 代码、编译和下载代码到实验箱,观察结果;在实验报告中说明其运行的结果。

 (2)完成按钮接口改为 PD7 后通过外部中断实现对 LED 控制的程序,完成代码并提交main.c 程序(注意:要包括中断处理程序)。同时对每行主要代码要进行注释,说明其功能。并需要在寄存器的配置上进行说明。

 (3)实验提交要求

 (1)按照实验模板完成实验报告,其中包括实验要求的所有内容。

 (2)提交电子版报告,撰写程序流程图,并且提交程序主要代码。

 (3)最终提交形式:制作成压缩 rar 格式文件,文件命名:组号_学号_姓名_实验二.rar

 【 实验环境】

 操作系统:Windows 10 1.TEB-CM5000 嵌入式单片机实验系统 2.MDK4.12 嵌入式软件开发环境

 实验内容

 1. 实验内容:

 (1)熟悉 TEB-CM5000 嵌入式单片机实验系统上的 LED 灯电路和外部中断接口。运行相关的程序实现一个按钮控制 LED 灯亮灭。

 其中,LD1(PF3)作为外接 LED 灯,具体电路如下:

 (2)

 按钮用连接引线通过连接独立按钮(如 USER2)连接到 PA3(TX2)引脚上,如下图。

  (3)分别学习 EXTRegister 和 EXT_INTLabbox 代码、编译和下载代码到实验箱,观察结果。

 (4)改变连接线连接方式,把 USER2 按钮保持不变和 PD7 连接起来,如下图:

  (5)编写程序,当按下 USER2 按钮时,LD1(PF3)灯会闪烁。

 二、实验过程:

 1.USER2 按钮按下时,LD1(PF3)灯闪烁。

 (1)寄存器位操作模式:

 a. 设置输入输出

  b. 连接外部中断通道 3

  c. 调用中断处理程序控制 LD1 亮灭

 (2)库函数 a. 设置输入输出

 b. 连接到外部中断通道 3

 c. 调用中断处理程序控制 LD1 亮灭

 小结

 1. 对于调用中断处理程序来控制灯的明灭有了更加深刻的理解和运用。

 2. 加深了对用寄存器开发 STM32 单片机程序和用库函数开发的区别的理解。

 指导教师评语及成绩

 评语:

 成绩:

  指导教师签名:

 批阅日期:

篇六:gpio实验报告stm32ze

一 搭建实验环境 一.实验简介 搭建嵌入式系统开发环境,建立第一个工程,流水灯实验 二.实验目的 掌握 STM32 开发环境,掌握从无到有的构建工程。

 三.实验内容 熟悉 MDK KEIL 开发环境,构建基于固件库的工程,编写代码实现流水灯工程。通过 ISP 下载代码到实验板,查看运行结果。下载代码到目标板,查看运行结果。

 四.实验设备 硬件部分:PC 计算机(宿主机)、STM32 实验板。

 软件部分:PC 机 WINDOWS 系统、MDK KEIL 软件、ISP 软件。

 五.实验步骤 1. 熟悉 MDK KEIL 开发环境 2. 熟悉串口编程软件 ISP 3. 查看固件库结构和文件 4. 建立工程目录,复制库文件 5. 建立和配置工程 6. 编写代码 7. 编译代码 8. 使用 ISP 下载到实验板 9. 测试运行结果 10. 记录实验过程,撰写实验报告 六.实验结果及测试 七.实验总结

 实验二 按键实验(查询方式)

 一.实验简介 在实验一的基础上,使用按键控制流水灯速度,及使用按键控制流水灯流水方向。

 二.实验目的 熟练使用库函数操作 GPIO,掌握利用查询方式控制按键的程序编写方法。

 三.实验内容 实现初始化 GPIO,并配置中断,在中断服务程序中通过修改全局变量,达到控制流水灯速度及方向。

 四.实验设备 硬件部分:PC 计算机(宿主机)、STM32 实验板。

 软件部分:PC 机 WINDOWS 系统、MDK KEIL 软件、ISP 软件。

 五.实验步骤 1 在实验一代码的基础上,编写按键控制部分代码 2 编写完成主程序 4 编译代码,下载到实验板 5.单步调试 6 记录实验过程,撰写实验报告 六.实验结果及测试 七.实验总结

 实验三 按键实验(中断方式)

 一.实验简介 在实验一的基础上,使用按键控制流水灯。

 二.实验目的 熟练使用库函数操作 GPIO,掌握中断配置和中断服务程序编写方法,掌握通过全局变量在中断服务程序和主程序间通信的方法。

 三.实验内容 实现初始化 GPIO,并配置中断,在中断服务程序中通过修改全局变量,达到控制流水灯速度及方向。

 下载代码到目标板,查看运行结果。

 四.实验设备 硬件部分:PC 计算机(宿主机)、STM32 实验板。

 软件部分:PC 机 WINDOWS 系统、MDK KEIL 软件、ISP 软件。

 五.实验步骤 1 在实验一代码的基础上,编写中断初始化代码 2 在主程序中声明全局变量,用于和中断服务程序通信,编写完成主程序 3 编写中断服务程序 4 编译代码,下载到实验板 5.单步调试 6 记录实验过程,撰写实验报告 六.实验结果及测试

 七.实验总结

 实验四 串口发送和接收实验 一.实验简介 编写代码实现串口发送和接收,将通过串口发送来的数据回送回去。

 二.实验目的 掌握 STM32 基本串口编程,进一步学习中断处理。

 三.实验内容 编写主程序,初始化串口 1,设置波特率为 115200,无校验,数据位 8 位,停止位 1 位。

 编写中断服务程序代码实现将发送过来的数据回送。

 四.实验设备 硬件部分:PC 计算机(宿主机)、STM32 实验板。

 软件部分:PC 机 WINDOWS 系统、MDK KEIL 软件、ISP 软件、串口调试助手。

 五.实验步骤 1 编写串口初始化代码 2 编写中断服务程序代码 3 编译代码,使用 ISP 下载到实验板 4 记录实验过程,撰写实验报告 六.实验结果及测试

 七.实验总结

 实验五 ADC 实验 一.实验简介 通过 ADC 将 STM32 系统将模拟量转换为数字量。

 二.实验目的 掌握 ADC 编程。

 三.实验内容 重新实现 C 库中的 printf()函数到串口 1。

 四.实验设备 硬件部分:PC 计算机(宿主机)、STM32 实验板。

 软件部分:PC 机 WINDOWS 系统、MDK KEIL 软件、ISP 软件、串口调试助手。

 五.实验步骤 1 编写主程序 2 编译代码,使用 ISP 下载到实验板,使用串口调试助手观察数据 3 记录实验过程,撰写实验报告 六.实验结果及测试

 七.实验总结

推荐访问:gpio实验报告stm32ze 实验 报告 gpio