Skip to main content
hussien kazan
Associate II
July 14, 2018
Question

push button

  • July 14, 2018
  • 2 replies
  • 988 views
Posted on July 14, 2018 at 19:53

hello;

    I want to define the pinAO as a push button on keil v5 without using cubemx, i need its define and configuration function, can some one help? 

    This topic has been closed for replies.

    2 replies

    Tesla DeLorean
    Guru
    July 14, 2018
    Posted on July 14, 2018 at 20:37

    {

      GPIO_InitTypeDef GPIO_InitStructure;

      /* Enable GPIOA clock */

      __HAL_RCC_GPIOA_CLK_ENABLE();

      /* Configure PA0 pin as input pulled up (pressed button connects to ground) */

      GPIO_InitStructure.Mode = GPIO_MODE_INPUT;

      GPIO_InitStructure.Pull = GPIO_PULLUP;

      GPIO_InitStructure.Pin = GPIO_PIN_0;

      HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);

    //...

      if (HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0) == 0)

        puts('Button Depressed');

    }
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    hussien kazan
    Associate II
    July 14, 2018
    Posted on July 14, 2018 at 21:03

     ,

     ,

    This is the code that i wrote can u point it it compiling successfully, but its not working can u point out the errors , ?

    ♯ include 'stm32f4xx_hal.h'

     ,

    void GPIO_CONFIGER(void),

     ,

    void PUSHBUTTON(void),

     ,

    int main(void){

     ,

    HAL_Init(),

     ,

    GPIO_CONFIGER(),

     ,

    PUSHBUTTON(),

     ,

    while(1){

     ,

    GPIO_PinState MY_PUSHBUTTON,

     ,

     ,

    MY_PUSHBUTTON=HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0),

    if(MY_PUSHBUTTON){

     ,

    HAL_GPIO_WritePin(GPIOD,GPIO_PIN_12,MY_PUSHBUTTON),

     ,

    HAL_Delay(1000),

     ,

    HAL_GPIO_WritePin(GPIOD,GPIO_PIN_13,MY_PUSHBUTTON),

     ,

    HAL_Delay(1000),

     ,

    HAL_GPIO_WritePin(GPIOD,GPIO_PIN_14,MY_PUSHBUTTON),

     ,

    HAL_Delay(1000),

     ,

    HAL_GPIO_WritePin(GPIOD,GPIO_PIN_15,MY_PUSHBUTTON),

     ,

    HAL_Delay(1000),

     ,

     ,

    }

     ,

    }

     ,

     ,

    }

    void GPIO_CONFIGER(void){

     ,

    __HAL_RCC_GPIOD_CLK_ENABLE(),

     ,

     ,

    GPIO_InitTypeDef GPIOPIN,

     ,

    GPIOPIN.Mode= GPIO_MODE_OUTPUT_PP ,

     ,

    GPIOPIN.Pin= GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15 ,

     ,

    HAL_GPIO_Init(GPIOD, &,GPIOPIN),

    }

     ,

    void PUSHBUTTON(void){

     ,

    __HAL_RCC_GPIOA_CLK_ENABLE(),

     ,

    GPIO_InitTypeDef MYPUSHBUTTON,

     ,

    MYPUSHBUTTON.Pin=GPIO_PIN_0,

     ,

    MYPUSHBUTTON.Mode=GPIO_MODE_INPUT,

     ,

    MYPUSHBUTTON.Pull=GPIO_PULLUP,

     ,

    HAL_GPIO_Init(GPIOA,&,MYPUSHBUTTON),

     ,

    if(HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_0)==0){

     ,

    puts('Button Depressed'),

     ,

    }

     ,

    }

    void SYSTICK_CONGIR(){

     ,

    HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000),

     ,

    HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK),

     ,

    HAL_NVIC_SetPriority(SysTick_IRQn,0,0 ),

     ,

    HAL_NVIC_EnableIRQ(SysTick_IRQn),

    }

    void systick_handler(){

     ,

    HAL_IncTick(),

    }