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

📄 main.lst

📁 STM32利用正交编码器实现电机的控制
💻 LST
📖 第 1 页 / 共 2 页
字号:
##############################################################################
#                                                                            #
# IAR ARM ANSI C/C++ Compiler V4.42A/W32               15/May/2008  12:06:29 #
# Copyright 1999-2005 IAR Systems. All rights reserved.                      #
#                                                                            #
#    Cpu mode        =  thumb                                                #
#    Endian          =  little                                               #
#    Stack alignment =  4                                                    #
#    Source file     =  C:\David JIANG\ST MCU\Docs\STM32\AN_JIANG\TIM        #
#                       Encoder\example\project\source\main.c                #
#    Command line    =  "C:\David JIANG\ST MCU\Docs\STM32\AN_JIANG\TIM       #
#                       Encoder\example\project\source\main.c" -D            #
#                       VECT_TAB_FLASH -lcN "C:\David JIANG\ST               #
#                       MCU\Docs\STM32\AN_JIANG\TIM                          #
#                       Encoder\example\project\EWARM\BOOT_FLASH\List\" -lb  #
#                       "C:\David JIANG\ST MCU\Docs\STM32\AN_JIANG\TIM       #
#                       Encoder\example\project\EWARM\BOOT_FLASH\List\" -o   #
#                       "C:\David JIANG\ST MCU\Docs\STM32\AN_JIANG\TIM       #
#                       Encoder\example\project\EWARM\BOOT_FLASH\Obj\" -z3   #
#                       --no_cse --no_unroll --no_inline --no_code_motion    #
#                       --no_tbaa --no_clustering --no_scheduling --debug    #
#                       --cpu_mode thumb --endian little --cpu cortex-M3     #
#                       --stack_align 4 --require_prototypes --fpu None      #
#                       --dlib_config "C:\Program Files\IAR                  #
#                       Systems\Embedded Workbench                           #
#                       4.0\arm\LIB\dl7mptnnl8f.h" -I "C:\David JIANG\ST     #
#                       MCU\Docs\STM32\AN_JIANG\TIM                          #
#                       Encoder\example\project\EWARM\" -I "C:\David         #
#                       JIANG\ST MCU\Docs\STM32\AN_JIANG\TIM                 #
#                       Encoder\example\project\EWARM\..\include\" -I        #
#                       "C:\David JIANG\ST MCU\Docs\STM32\AN_JIANG\TIM       #
#                       Encoder\example\project\EWARM\..\..\FWLib\inc\" -I   #
#                       "C:\Program Files\IAR Systems\Embedded Workbench     #
#                       4.0\arm\INC\"                                        #
#    List file       =  C:\David JIANG\ST MCU\Docs\STM32\AN_JIANG\TIM        #
#                       Encoder\example\project\EWARM\BOOT_FLASH\List\main.l #
#                       st                                                   #
#    Object file     =  C:\David JIANG\ST MCU\Docs\STM32\AN_JIANG\TIM        #
#                       Encoder\example\project\EWARM\BOOT_FLASH\Obj\main.r7 #
#                       9                                                    #
#                                                                            #
#                                                                            #
##############################################################################

C:\David JIANG\ST MCU\Docs\STM32\AN_JIANG\TIM Encoder\example\project\source\main.c
      1          /******************** (C) COPYRIGHT 2008 STMicroelectronics ********************
      2          * File Name          : main.c
      3          * Author             : Jian-guo JIANG
      4          * Date First Issued  : 2008.5.14
      5          * Description        : Main program body
      6          ********************************************************************************
      7          * History:
      8          * 2008.5.14: V1.0
      9          ********************************************************************************
     10          * THE PRESENT SOFTWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
     11          * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
     12          * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
     13          * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
     14          * CONTENT OF SUCH SOFTWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
     15          * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
     16          *******************************************************************************/
     17          
     18          /* Includes ------------------------------------------------------------------*/
     19          #include "stm32f10x_lib.h"
     20          #include "lcd.h"
     21          #include "stm32f10x_encoder.h"
     22          #include "stm32f10x_Timebase.h"
     23          
     24          /* Local includes ------------------------------------------------------------*/
     25          /* Private typedef -----------------------------------------------------------*/
     26          /* Private define ------------------------------------------------------------*/
     27          #define KEY_2_PORT GPIOD
     28          #define KEY_2_BIT  GPIO_Pin_3
     29          
     30          #define KEY_3_PORT GPIOD
     31          #define KEY_3_BIT  GPIO_Pin_4
     32          
     33          // These are defines for reading the buttonS
     34          #define  NOKEY      (u8)0
     35          #define  KEY2       (u8)1
     36          #define  KEY3       (u8)2
     37          #define  KEY_HOLD   (u8)3
     38          
     39          /* Private macro -------------------------------------------------------------*/
     40          /* Private variables ---------------------------------------------------------*/
     41          static DisplayType DisplayStatus = DISPLAY_TIMCNT;
     42          static u8 bKey = NOKEY;
     43          static u8 bPrevious_key = NOKEY;
     44          
     45          /* Private functions ---------------------------------------------------------*/
     46          void RCC_Configuration(void);
     47          void GPIO_Configuration(void);
     48          void NVIC_Configuration(void);
     49          void LcdShow_Init(void);
     50          void KEYS_Init(void);
     51          u8 KEYS_Read( void );
     52          
     53          /*******************************************************************************
     54          * Function Name  : main
     55          * Description    : Main program
     56          * Input          : None
     57          * Output         : None
     58          * Return         : None
     59          *******************************************************************************/
     60          int main(void)
     61          {
     62          
     63          #ifdef DEBUG
     64            debug();
     65          #endif
     66          
     67            /* System Clocks Configuration */
     68            RCC_Configuration();
     69          
     70            /* GPIO ports pins Configuration */
     71            GPIO_Configuration();
     72          
     73            /* NVIC Configuration */
     74            NVIC_Configuration();
     75          
     76            /* Configure the systick */
     77            TB_Init();
     78            ENC_Init();
     79            
     80            LcdShow_Init();
     81            KEYS_Init();
     82          
     83            while(1)
     84            {    
     85              bKey = KEYS_Read();    // read key pushed (if any...)
     86              if (bKey == KEY2)
     87              {
     88                if (DisplayStatus == DISPLAY_W) DisplayStatus = DISPLAY_TIMCNT;
     89                else DisplayStatus++;
     90              }
     91              
     92              if (TB_DisplayDelay_IsElapsed() == TRUE)
     93              {
     94                TB_Set_DisplayDelay_500us(100);  // 50ms    
     95                LCD_Display(DisplayStatus);            
     96              }    
     97            }
     98          }
     99          
    100          /*******************************************************************************
    101          * Function Name  : RCC_Configuration
    102          * Description    : Configures the different system clocks.
    103          * Input          : None
    104          * Output         : None
    105          * Return         : None
    106          *******************************************************************************/
    107          void RCC_Configuration(void)
    108          {
    109            ErrorStatus HSEStartUpStatus;
    110          
    111            /* RCC system reset(for debug purpose) */
    112          //  RCC_DeInit();
    113          
    114            /* Enable HSE */
    115            RCC_HSEConfig(RCC_HSE_ON);
    116          
    117            /* Wait till HSE is ready */
    118            HSEStartUpStatus = RCC_WaitForHSEStartUp();
    119          
    120            if(HSEStartUpStatus == SUCCESS)
    121            {
    122              /* HCLK = SYSCLK */
    123              RCC_HCLKConfig(RCC_SYSCLK_Div1);
    124          
    125              /* PCLK2 = HCLK */
    126              RCC_PCLK2Config(RCC_HCLK_Div1);
    127          
    128              /* PCLK1 = HCLK/2 */
    129              RCC_PCLK1Config(RCC_HCLK_Div2);
    130          
    131              /* ADCCLK = PCLK2/6 */
    132              RCC_ADCCLKConfig(RCC_PCLK2_Div6);
    133          
    134              /* Flash 2 wait state */
    135              FLASH_SetLatency(FLASH_Latency_2);
    136          
    137              /* Enable Prefetch Buffer */
    138              FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
    139          
    140              /* PLLCLK = 8MHz * 9 = 72 MHz */
    141              RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
    142          
    143              /* Enable PLL */
    144              RCC_PLLCmd(ENABLE);
    145          
    146              /* Wait till PLL is ready */
    147              while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
    148              {
    149              }
    150          
    151              /* Select PLL as system clock source */
    152              RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
    153          
    154              /* Wait till PLL is used as system clock source */
    155              while(RCC_GetSYSCLKSource() != 0x08)
    156              {
    157              }
    158            }
    159          
    160            /* Enable GPIOA, GPIOB, GPIOC, GPIOD, GPIOE and AFIO clocks */
    161            RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |RCC_APB2Periph_GPIOC
    162                   | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO, ENABLE);
    163          
    164            /* TIM2 clocks enable */
    165            RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
    166          
    167            /* CAN Periph clock enable */
    168            RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN, ENABLE);
    169          }
    170          
    171          /*******************************************************************************
    172          * Function Name  : GPIO_Configuration
    173          * Description    : Configures the different GPIO ports.
    174          * Input          : None
    175          * Output         : None
    176          * Return         : None
    177          *******************************************************************************/
    178          void GPIO_Configuration(void)
    179          {
    180            GPIO_InitTypeDef GPIO_InitStructure;
    181          
    182            /* Configure PC.04 -- PC.11 as Output push-pull */
    183            GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 |GPIO_Pin_6 | GPIO_Pin_7

⌨️ 快捷键说明

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