Advertisement
daskalot

Untitled

Nov 16th, 2018
1,683
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 1.43 KB | None | 0 0
  1. /* Includes ------------------------------------------------------------------*/
  2. #include "stm32f4_discovery.h"
  3.  
  4. /**
  5.   * @brief   Main program
  6.   * @param  None
  7.   * @retval None
  8.   */
  9.  
  10. int main(void){
  11.   //Start the device clock
  12.   RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
  13.   //Init the Device Structure
  14.   GPIO_InitTypeDef leds;
  15.   leds.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
  16.   leds.GPIO_Mode = GPIO_Mode_OUT;
  17.   leds.GPIO_Speed = GPIO_Speed_2MHz;
  18.   leds.GPIO_OType = GPIO_OType_PP;
  19.   leds.GPIO_PuPd = GPIO_PuPd_NOPULL;
  20.   GPIO_Init(GPIOD, &leds);
  21.  
  22.   //Start the device(= button) clock
  23.   RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
  24.   //Init the device(=button) structure
  25.   GPIO_InitTypeDef button;
  26.   button.GPIO_Pin = GPIO_Pin_0;
  27.   button.GPIO_Mode = GPIO_Mode_IN;
  28.   button.GPIO_Speed = GPIO_Speed_2MHz;
  29.   button.GPIO_OType = GPIO_OType_PP;
  30.   button.GPIO_PuPd = GPIO_PuPd_NOPULL;
  31.   GPIO_Init(GPIOD, &button);  
  32.  
  33.   //Delay util
  34.   volatile uint32_t d = 0x01000000;
  35.   //Temper calc
  36.   volatile uint16_t calc = (uint16_t)1;
  37.   while (1){
  38.       if(calc&1) GPIO_SetBits(GPIOD, GPIO_Pin_12);
  39.       if(calc&2) GPIO_SetBits(GPIOD, GPIO_Pin_13);
  40.       if(calc&4) GPIO_SetBits(GPIOD, GPIO_Pin_14);
  41.       if(calc&8) GPIO_SetBits(GPIOD, GPIO_Pin_15);
  42.       while(d--);
  43.       d = 0x01000000;
  44.       GPIO_ResetBits(GPIOD, 0xF000);  
  45.       calc++;
  46.     if(calc>15) calc = 1;
  47.   }
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement