zoukankan      html  css  js  c++  java
  • 常用的stm32库函数

    //初始化的方式:先定义初始化机构体、再打开时钟使能、在对每一组GPIO口进行初始化。  
      GPIO_InitTypeDef LED_GPIO; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB
    |RCC_APB2Periph_GPIOD, ENABLE); //ʹÄÜPB,PD¶Ë¿ÚʱÖÓ LED_GPIO.GPIO_Pin = GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6; //Ö¸¶¨Òý½Å PD3,4,5,6 LED_GPIO.GPIO_Mode = GPIO_Mode_Out_PP; //ÍÆÍìÊä³ö LED_GPIO.GPIO_Speed = GPIO_Speed_50MHz; //IO¿ÚËÙ¶ÈΪ50MHz GPIO_Init(GPIOD, &LED_GPIO); //¸ù¾ÝÉ趨²ÎÊý³õʼ»¯ //---------- PB8 ---------------------------- LED_GPIO.GPIO_Pin = GPIO_Pin_8; //Ö¸¶¨Òý½Å PB8 LED_GPIO.GPIO_Mode = GPIO_Mode_Out_PP; //ÍÆÍìÊä³ö LED_GPIO.GPIO_Speed = GPIO_Speed_50MHz; //IO¿ÚËÙ¶ÈΪ50MHz GPIO_Init(GPIOB, &LED_GPIO); //¸ù¾ÝÉ趨²ÎÊý³õʼ»¯
    • 点亮某个灯的代码
            GPIO_SetBits(GPIOD, GPIO_Pin_3|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6);
            GPIO_SetBits(GPIOB,GPIO_Pin_8);

    或者用宏定义

    #define LED_light(x) ( GPIOD_BSRR |= 0x0001<<x )
    #define LED_Close(x) ( GPIOD_BRR |= 0x0001<<x )
    #define LED_ALL_light ( GPIO_ODR |= 0x0078 )
    #define LED_ALL_close ( GPIO_ODR &= 0xff87 )
    •  在数码管上显示对应的数字的代码
    //单个来看:在PE8对应的数码管上显示数字0的代码
    case 1: { GPIOE->BSRR |= 0x0001<<8; //将PE8端口置高电平
                  GPIOE->BRR |= 0x3e00;//将其他的PE9,10,11都置为地电平
                  GPIOE->BRR |= 0x00ff; //将数码管对应的8段都置为0
                  GPIOE->BSRR |= Nixie_x[data]; //按数组里面的设置显示对应的字符
                   break;}
                            
        void Nixietube_light(u8 num, u8 data)
        {
    
            switch(num)
            {                            //       第几位                                                                                                                       数字0-9
                    case 1: { GPIOE->BSRR |= 0x0001<<8; GPIOE->BRR |= 0x3e00; GPIOE->BRR |= 0x00ff; GPIOE->BSRR |= Nixie_x[data];  break;}
                    case 2: { GPIOE->BSRR |= 0x0001<<9; GPIOE->BRR |= 0x3d00; GPIOE->BRR |= 0x00ff;GPIOE->BSRR |= Nixie_x[data];  break;}
                    case 3: { GPIOE->BSRR |= 0x0001<<10; GPIOE->BRR |= 0x3b00; GPIOE->BRR |= 0x00ff;GPIOE->BSRR |= Nixie_x[data];  break;}
                    case 4: { GPIOE->BSRR |= 0x0001<<11; GPIOE->BRR |= 0x3700; GPIOE->BRR |= 0x00ff;GPIOE->BSRR |= Nixie_x[data];  break;}
                    case 5: { GPIOE->BSRR |= 0x0001<<12; GPIOE->BRR |= 0x2f00; GPIOE->BRR |= 0x00ff;GPIOE->BSRR |= Nixie_x[data];  break;}
                    case 6: { GPIOE->BSRR |= 0x0001<<13; GPIOE->BRR |= 0x1f00; GPIOE->BRR |= 0x00ff;GPIOE->BSRR |= Nixie_x[data];  break;}
                
                  default: break;
            }
            
        }
  • 相关阅读:
    poj 1088 滑雪
    位运算与bitset
    hdu 4607 Park Visit
    树的直径
    codeforces 495D Sonya and Matrix
    German Collegiate Programming Contest 2015(第三场)
    BAPC 2014 Preliminary(第一场)
    Benelux Algorithm Programming Contest 2014 Final(第二场)
    E. Reachability from the Capital(tarjan+dfs)
    poj2104 K-th Number(划分树)
  • 原文地址:https://www.cnblogs.com/dadidelearning/p/10018257.html
Copyright © 2011-2022 走看看