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

📄 main.lst

📁 STM32利用正交编码器实现电机的控制
💻 LST
📖 第 1 页 / 共 2 页
字号:
    184                  | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11;
    185            GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    186            GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    187            GPIO_Init(GPIOC, &GPIO_InitStructure);
    188          
    189            /* Configure PD.03, PC.04, PC.11 -- PC.15 as input floating */
    190            GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_11 | GPIO_Pin_12 |
    191                GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
    192            GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    193            GPIO_Init(GPIOD, &GPIO_InitStructure);
    194          
    195            /* Configure PE.00 -- PE.15 as Output push-pull */
    196            GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
    197            GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    198            GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    199            GPIO_Init(GPIOE, &GPIO_InitStructure);
    200          }
    201          
    202          /*******************************************************************************
    203          * Function Name  : NVIC_Configuration
    204          * Description    : Configures the NVIC and Vector Table base address.
    205          * Input          : None
    206          * Output         : None
    207          * Return         : None
    208          *******************************************************************************/
    209          void NVIC_Configuration(void)
    210          {
    211            NVIC_InitTypeDef NVIC_InitStructure;
    212          
    213          #ifdef  VECT_TAB_RAM
    214            /* Set the Vector Table base location at 0x20000000 */
    215            NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
    216          #else  /* VECT_TAB_FLASH  */
    217            /* Set the Vector Table base location at 0x08000000 */
    218            NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
    219          #endif
    220          
    221            /* Configure the Priority Group to 2 bits */
    222            NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
    223          
    224            /* enabling interrupt */
    225            NVIC_InitStructure.NVIC_IRQChannel=TIM2_IRQChannel;
    226            NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
    227            NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
    228            NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    229            NVIC_Init(&NVIC_InitStructure);  
    230          }
    231          
    232          /*******************************************************************************
    233          * Function Name  : LcdShow_Init
    234          * Description    : Configure the lcd dispaly: TIM2 initialize in Output Compare
    235          *                  Timing Mode
    236          * Input          : None
    237          * Return         : None
    238          * Comment        : TIM2 Configuration: Output Compare Timing Mode:
    239                             TIM2CLK = 36 *2 =72MHz, Prescaler = 17, TIM2 counter clock = 4 MHz
    240                             TIM2 update Period = ARR / TIM2 counter Period = 2 ms
    241                             CC1 OC period = 1ms
    242          *******************************************************************************/
    243          void LcdShow_Init(void)
    244          {
    245            TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
    246            TIM_OCInitTypeDef  TIM_OCInitStructure;
    247          
    248            /* Time base configuration */
    249            TIM_TimeBaseStructure.TIM_Period = 8000;
    250            TIM_TimeBaseStructure.TIM_Prescaler = 17;
    251            TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
    252            TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
    253            TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
    254          
    255            TIM_ARRPreloadConfig(TIM2,DISABLE);
    256            /* only counter overflow/underflow generate U interrupt */
    257            TIM_UpdateRequestConfig(TIM2,TIM_UpdateSource_Regular);
    258          
    259            /* Output Compare Timing Mode configuration: Channel1 */
    260            TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing;
    261            TIM_OCInitStructure.TIM_Channel = TIM_Channel_1;
    262            TIM_OCInitStructure.TIM_Pulse = 4000;
    263            TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
    264            TIM_OCInit(TIM2, &TIM_OCInitStructure);
    265          
    266            TIM_OC1PreloadConfig(TIM2, TIM_OCPreload_Disable);
    267          
    268            /* TIM IT enable */
    269            TIM_ITConfig(TIM2, TIM_IT_CC1 | TIM_IT_Update, ENABLE);
    270          
    271            /* TIM2 enable counter */
    272            TIM_Cmd(TIM2, ENABLE);
    273          }
    274          
    275          /*******************************************************************************
    276          * Function Name  : KEYS_Init
    277          * Description    : Init GPIOs for button management
    278          * Input          : None
    279          * Output         : None
    280          * Return         : None
    281          *******************************************************************************/
    282          void KEYS_Init(void)
    283          {
    284            GPIO_InitTypeDef GPIO_InitStructure;
    285              
    286            /* Enable GPIOD clock */
    287            RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
    288           
    289            GPIO_StructInit(&GPIO_InitStructure);
    290            
    291            /* Joystick GPIOs configuration*/
    292            
    293            GPIO_InitStructure.GPIO_Pin = KEY_2_BIT;
    294            GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    295            GPIO_Init(KEY_2_PORT, &GPIO_InitStructure);
    296            
    297            GPIO_InitStructure.GPIO_Pin = KEY_3_BIT;
    298            GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
    299            GPIO_Init(KEY_3_PORT, &GPIO_InitStructure);    
    300          }
    301          
    302          /*******************************************************************************
    303          * Function Name  : KEYS_Read
    304          * Description    : Reads key from demoboard.
    305          * Input          : None
    306          * Output         : None
    307          * Return         : Return KEY2,KEY3, KEY_HOLD or NOKEY
    308          *******************************************************************************/
    309          u8 KEYS_Read( void )
    310          {
    311            /* "KEY2" key is pressed */
    312            if(!GPIO_ReadInputDataBit(KEY_2_PORT, KEY_2_BIT))
    313            {
    314              if (bPrevious_key == KEY2) 
    315              {
    316                return KEY_HOLD;
    317              }
    318              else
    319              {
    320                bPrevious_key = KEY2;
    321                return KEY2;
    322              }
    323            }
    324            /* "KEY3" key is pressed */
    325            else if(!GPIO_ReadInputDataBit(KEY_3_PORT, KEY_3_BIT))
    326            {
    327              if (bPrevious_key == KEY3) 
    328              {
    329                return KEY_HOLD;
    330              }
    331              else
    332              {
    333                bPrevious_key = KEY3;
    334                return KEY3;
    335              }
    336            }    
    337            /* No key is pressed */
    338            else
    339            {
    340              bPrevious_key = NOKEY;
    341              return NOKEY;
    342            }
    343          }
    344          
    345          #ifdef  DEBUG
    346          /*******************************************************************************
    347          * Function Name  : assert_failed
    348          * Description    : Reports the name of the source file and the source line number
    349          *                  where the assert error has occurred.
    350          * Input          : - file: pointer to the source file name
    351          *                  - line: assert error line source number
    352          * Output         : None
    353          * Return         : None
    354          *******************************************************************************/
    355          void assert_failed(u8* file, u32 line)
    356          {
    357            /* User can add his own implementation to report the file name and line number,
    358               ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
    359          
    360            /* Infinite loop */
    361            while (1)
    362            {
    363          
    364            }
    365          }
    366          #endif
    367          /******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/

   Maximum stack usage in bytes:

     Function           CSTACK
     --------           ------
     GPIO_Configuration     8
     KEYS_Init              8
     KEYS_Read              4
     LcdShow_Init          20
     NVIC_Configuration     8
     RCC_Configuration      4
     assert_failed          0
     main                   4


   Segment part sizes:

     Function/Label     Bytes
     --------------     -----
     DisplayStatus         1
     bKey                  1
     bPrevious_key         1
     main                108
     RCC_Configuration   128
     GPIO_Configuration  104
     NVIC_Configuration   56
     LcdShow_Init        136
     KEYS_Init            66
     KEYS_Read            88
     ??assert_failed_0     2
     ??DataTable4          4
      Others             284

 
 964 bytes in segment CODE
   3 bytes in segment DATA_Z
  12 bytes in segment INITTAB
 
 692 bytes of CODE memory (+ 284 bytes shared)
   3 bytes of DATA memory

Errors: none
Warnings: none

⌨️ 快捷键说明

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