⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stm32f10x_gpio.lst

📁 STM32利用正交编码器实现电机的控制
💻 LST
📖 第 1 页 / 共 3 页
字号:
    176            if (GPIO_InitStruct->GPIO_Pin > 0x00FF)
    177            {
    178              tmpreg = GPIOx->CRH;
    179              for (pinpos = 0x00; pinpos < 0x08; pinpos++)
    180              {
    181                pos = (((u32)0x01) << (pinpos + 0x08));
    182                /* Get the port pins position */
    183                currentpin = ((GPIO_InitStruct->GPIO_Pin) & pos);
    184                if (currentpin == pos)
    185                {
    186                  pos = pinpos << 2;
    187                  /* Clear the corresponding high control register bits */
    188                  pinmask = ((u32)0x0F) << pos;
    189                  tmpreg &= ~pinmask;
    190          
    191                  /* Write the mode configuration in the corresponding bits */
    192                  tmpreg |= (currentmode << pos);
    193          
    194                  /* Reset the corresponding ODR bit */
    195                  if (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IPD)
    196                  {
    197                    GPIOx->BRR = (((u32)0x01) << (pinpos + 0x08));
    198                  }
    199                  /* Set the corresponding ODR bit */
    200                  if (GPIO_InitStruct->GPIO_Mode == GPIO_Mode_IPU)
    201                  {
    202                    GPIOx->BSRR = (((u32)0x01) << (pinpos + 0x08));
    203                  }
    204                }
    205              }
    206              GPIOx->CRH = tmpreg;
    207            }
    208          }
    209          
    210          /*******************************************************************************
    211          * Function Name  : GPIO_StructInit
    212          * Description    : Fills each GPIO_InitStruct member with its default value.
    213          * Input          : - GPIO_InitStruct : pointer to a GPIO_InitTypeDef structure
    214          *                    which will be initialized.
    215          * Output         : None
    216          * Return         : None
    217          *******************************************************************************/
    218          void GPIO_StructInit(GPIO_InitTypeDef* GPIO_InitStruct)
    219          {
    220            /* Reset GPIO init structure parameters values */
    221            GPIO_InitStruct->GPIO_Pin  = GPIO_Pin_All;
    222            GPIO_InitStruct->GPIO_Speed = GPIO_Speed_2MHz;
    223            GPIO_InitStruct->GPIO_Mode = GPIO_Mode_IN_FLOATING;
    224          }
    225          
    226          /*******************************************************************************
    227          * Function Name  : GPIO_ReadInputDataBit
    228          * Description    : Reads the specified input port pin.
    229          * Input          : - GPIOx: where x can be (A..E) to select the GPIO peripheral.
    230          *                : - GPIO_Pin:  specifies the port bit to read.
    231          *                    This parameter can be GPIO_Pin_x where x can be (0..15).
    232          * Output         : None
    233          * Return         : The input port pin value.
    234          *******************************************************************************/
    235          u8 GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, u16 GPIO_Pin)
    236          {
    237            u8 bitstatus = 0x00;
    238            
    239            /* Check the parameters */
    240            assert(IS_GET_GPIO_PIN(GPIO_Pin)); 
    241            
    242            if ((GPIOx->IDR & GPIO_Pin) != (u32)Bit_RESET)
    243            {
    244              bitstatus = (u8)Bit_SET;
    245            }
    246            else
    247            {
    248              bitstatus = (u8)Bit_RESET;
    249            }
    250            return bitstatus;
    251          }
    252          
    253          /*******************************************************************************
    254          * Function Name  : GPIO_ReadInputData
    255          * Description    : Reads the specified GPIO input data port.
    256          * Input          : - GPIOx: where x can be (A..E) to select the GPIO peripheral.
    257          * Output         : None
    258          * Return         : GPIO input data port value.
    259          *******************************************************************************/
    260          u16 GPIO_ReadInputData(GPIO_TypeDef* GPIOx)
    261          {
    262            return ((u16)GPIOx->IDR);
    263          }
    264          
    265          /*******************************************************************************
    266          * Function Name  : GPIO_ReadOutputDataBit
    267          * Description    : Reads the specified output data port bit.
    268          * Input          : - GPIOx: where x can be (A..E) to select the GPIO peripheral.
    269          *                : - GPIO_Pin:  specifies the port bit to read.
    270          *                    This parameter can be GPIO_Pin_x where x can be (0..15).
    271          * Output         : None
    272          * Return         : The output port pin value.
    273          *******************************************************************************/
    274          u8 GPIO_ReadOutputDataBit(GPIO_TypeDef* GPIOx, u16 GPIO_Pin)
    275          {
    276            u8 bitstatus = 0x00;
    277          
    278            /* Check the parameters */
    279            assert(IS_GET_GPIO_PIN(GPIO_Pin)); 
    280            
    281            if ((GPIOx->ODR & GPIO_Pin) != (u32)Bit_RESET)
    282            {
    283              bitstatus = (u8)Bit_SET;
    284            }
    285            else
    286            {
    287              bitstatus = (u8)Bit_RESET;
    288            }
    289            return bitstatus;
    290          }
    291          
    292          /*******************************************************************************
    293          * Function Name  : GPIO_ReadOutputData
    294          * Description    : Reads the specified GPIO output data port.
    295          * Input          : - GPIOx: where x can be (A..E) to select the GPIO peripheral.
    296          * Output         : None
    297          * Return         : GPIO output data port value.
    298          *******************************************************************************/
    299          u16 GPIO_ReadOutputData(GPIO_TypeDef* GPIOx)
    300          {
    301            return ((u16)GPIOx->ODR);
    302          }
    303          
    304          /*******************************************************************************
    305          * Function Name  : GPIO_SetBits
    306          * Description    : Sets the selected data port bits.
    307          * Input          : - GPIOx: where x can be (A..E) to select the GPIO peripheral.
    308          *                  - GPIO_Pin: specifies the port bits to be written.
    309          *                    This parameter can be any combination of GPIO_Pin_x where 
    310          *                    x can be (0..15).
    311          * Output         : None
    312          * Return         : None
    313          *******************************************************************************/
    314          void GPIO_SetBits(GPIO_TypeDef* GPIOx, u16 GPIO_Pin)
    315          {
    316            /* Check the parameters */
    317            assert(IS_GPIO_PIN(GPIO_Pin));
    318            GPIOx->BSRR = GPIO_Pin;
    319          }
    320          
    321          /*******************************************************************************
    322          * Function Name  : GPIO_ResetBits
    323          * Description    : Clears the selected data port bits.
    324          * Input          : - GPIOx: where x can be (A..E) to select the GPIO peripheral.
    325          *                  - GPIO_Pin: specifies the port bits to be written.
    326          *                    This parameter can be any combination of GPIO_Pin_x where 
    327          *                    x can be (0..15).
    328          * Output         : None
    329          * Return         : None
    330          *******************************************************************************/
    331          void GPIO_ResetBits(GPIO_TypeDef* GPIOx, u16 GPIO_Pin)
    332          {
    333            /* Check the parameters */
    334            assert(IS_GPIO_PIN(GPIO_Pin));
    335            GPIOx->BRR = GPIO_Pin;
    336          }
    337          
    338          /*******************************************************************************
    339          * Function Name  : GPIO_WriteBit
    340          * Description    : Sets or clears the selected data port bit.
    341          * Input          : - GPIOx: where x can be (A..E) to select the GPIO peripheral.
    342          *                  - GPIO_Pin: specifies the port bit to be written.
    343          *                    This parameter can be one of GPIO_Pin_x where x can be (0..15).
    344          *                  - BitVal: specifies the value to be written to the selected bit.
    345          *                    This parameter can be one of the BitAction enum values:
    346          *                       - Bit_RESET: to clear the port pin
    347          *                       - Bit_SET: to set the port pin
    348          * Output         : None
    349          * Return         : None
    350          *******************************************************************************/
    351          void GPIO_WriteBit(GPIO_TypeDef* GPIOx, u16 GPIO_Pin, BitAction BitVal)
    352          {
    353            /* Check the parameters */
    354            assert(IS_GET_GPIO_PIN(GPIO_Pin));
    355            assert(IS_GPIO_BIT_ACTION(BitVal)); 
    356            
    357            if (BitVal != Bit_RESET)
    358            {
    359              GPIOx->BSRR = GPIO_Pin;
    360            }
    361            else
    362            {
    363              GPIOx->BRR = GPIO_Pin;
    364            }
    365          }
    366          
    367          /*******************************************************************************
    368          * Function Name  : GPIO_Write
    369          * Description    : Writes data to the specified GPIO data port.
    370          * Input          : - GPIOx: where x can be (A..E) to select the GPIO peripheral.
    371          *                  - PortVal: specifies the value to be written to the port output
    372          *                    data register.
    373          * Output         : None
    374          * Return         : None
    375          *******************************************************************************/
    376          void GPIO_Write(GPIO_TypeDef* GPIOx, u16 PortVal)
    377          {
    378            GPIOx->ODR = PortVal;
    379          }
    380          
    381          /*******************************************************************************
    382          * Function Name  : GPIO_PinLockConfig
    383          * Description    : Locks GPIO Pins configuration registers.
    384          * Input          : - GPIOx: where x can be (A..E) to select the GPIO peripheral.
    385          *                  - GPIO_Pin: specifies the port bit to be written.
    386          *                    This parameter can be any combination of GPIO_Pin_x where 
    387          *                    x can be (0..15).
    388          * Output         : None
    389          * Return         : None
    390          *******************************************************************************/
    391          void GPIO_PinLockConfig(GPIO_TypeDef* GPIOx, u16 GPIO_Pin)
    392          {
    393            u32 tmp = 0x00010000;
    394            
    395            /* Check the parameters */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -