Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.40 KB | None | 0 0
  1. #include <stm32l1xx.h>
  2. #include <stm32l1xx_conf.h>
  3. #include <stm32l1xx_gpio.h>
  4. #include <stm32l1xx_rcc.h>
  5.  
  6. void delay(int B); /*Прототип функции delay()*/
  7. void led3(void); /*Прототип функции led3()*/
  8. void led4(void); /*Прототип функции led4()*/
  9. void led34(void); /*Прототип функции led4()*/
  10.  
  11. int main(void)
  12. {
  13.     /*Объявление переменных типа uint32_t*/
  14.     uint32_t i,j;
  15.  
  16.     /*Объявление структуры GPIO_InitStructure*/
  17.     GPIO_InitTypeDef GPIO_InitStructure;
  18.  
  19.     /*Включение тактирования*/
  20.     RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE);
  21.     GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_6 ;
  22.     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  23.     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
  24.     GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  25.    
  26.     /*Инициализация структуры*/
  27.     GPIO_Init(GPIOB, &GPIO_InitStructure);
  28.    
  29.  
  30.     while (1)
  31.     {
  32.         for (int j=0;j<17;j++)
  33.         {
  34.             if (j == 4 || j == 9):
  35.                 delay(100000);
  36.             if (j == 0 || j == 1 || j == 2 || j == 6 || j == 7 || j == 8 || j == 16)
  37.                 led3();
  38.             else if (j == 11 || j == 12 || j == 13 || j == 14 || j == 15)
  39.                 led4());
  40.             else
  41.                 led34();
  42.         }    
  43.     }
  44. }
  45.  
  46. void delay(int B) /*Определение функции delay()*/
  47. {
  48.     int i;
  49.     for (i=0;i<=B;i++)
  50.     ;
  51. }
  52.  
  53. void led3(void) /*Определение функции led3()*/
  54. {
  55.     GPIO_SetBits(GPIOB, GPIO_Pin_7);
  56.     delay(100000);
  57.     delay(100000);
  58.     delay(100000);
  59.     GPIO_ResetBits(GPIOB, GPIO_Pin_7);
  60.     delay(100000);
  61.     delay(100000);
  62.     delay(100000);
  63. }
  64.  
  65. void led4(void) /*Определение функции led4()*/
  66. {
  67.     GPIO_SetBits(GPIOB, GPIO_Pin_6);
  68.     delay(100000);
  69.     delay(100000);
  70.     delay(100000);
  71.     GPIO_ResetBits(GPIOB, GPIO_Pin_6);
  72.     delay(100000);
  73.     delay(100000);
  74.     delay(100000);
  75. }
  76.  
  77. void led34(void) /*Определение функции led4()*/
  78. {
  79.     GPIO_SetBits(GPIOB, GPIO_Pin_6);
  80.     GPIO_SetBits(GPIOB, GPIO_Pin_7);
  81.     delay(100000);
  82.     delay(100000);
  83.     delay(100000);
  84.     GPIO_ResetBits(GPIOB, GPIO_Pin_6);
  85.     GPIO_ResetBits(GPIOB, GPIO_Pin_7);
  86.     delay(100000);
  87.     delay(100000);
  88.     delay(100000);
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement