keil5-3: 基于STM32F302RBT6的AD采样实验——DMA方式

一 程序目的:

1 利用ADC1+ADC2+DMA1+DMA2进行ADC转换并传送结果到MCU;

2 0x01 0x01 对应指令:上电

  0x01 0x00  对应指令:掉电

  0x03           对应指令:AD测试

二 程序:

1 包括:


2 main.c

#include "rs485.h"
#include "delay.h"
#include "ad.h"
#include "dma.h"
#include "stm32f30x_dma.h"
#include "power_on.h"
#include "power_down.h"




#define SEND_BUF_SIZE 8200
float adcx;
u8 len,key;
float AD_W15V,AD_24V,AD_12V,AD_VGC,AD_U15V,AD_V15V,AD_5V,AD_15VF,AD_15V ;  
u16  ADC1_ConvertedValue[5];       
u16  ADC2_ConvertedValue[20];
int main(void)

GPIO_InitTypeDef GPIO_InitStructure1;
RCC_ClocksTypeDef ClockInfo; 
  float value_buf[14];
  RCC_GetClocksFreq(&ClockInfo);               // ²âÁ¿ÏµÍ³ËùÓÐʱÖÓ   

NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);// ÉèÖÃϵͳÖжÏÓÅÏȼ¶·Ö×é2
RS485_Init(9600);                           // ³õʼ»¯485ͨѶ²¨ÌØÂÊ9600
mydma();                                       // DMAÅäÖÃ
  adc_Init();                                    // ADCÅäÖÃ
  MCU_RX_EN;                                     // DEÇå0£¬485´¦ÓÚ½ÓÊÕ״̬
while(1)
{
if(cnt == 2)
{
MCU_TX_EN;
printf("Éϵç\r\n");
MCU_RX_EN;
power_on();   //Éϵç
 cnt=0;        //½ÓÊÕµ½µÄÊý¾Ý¸öÊýÇå0
}
else if (cnt == 4)   //RS485_RX_STAΪ1£¬±íʾ½ÓÊÕµ½¶ÏµçÖ¸Áî
{
MCU_TX_EN;
printf("¶Ïµç\r\n");
MCU_RX_EN;
power_down();         //¶Ïµç
 cnt=0;                //½ÓÊÕµ½µÄÊý¾Ý¸öÊýÇåÁã

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB,ENABLE);// ¿ªGPIOBʱÖÓ
     GPIO_InitStructure1.GPIO_Mode  = GPIO_Mode_OUT;
        GPIO_InitStructure1.GPIO_OType = GPIO_OType_PP;
     GPIO_InitStructure1.GPIO_Pin   = GPIO_Pin_0;
     GPIO_InitStructure1.GPIO_PuPd  = GPIO_PuPd_NOPULL;
     GPIO_InitStructure1.GPIO_Speed = GPIO_Speed_2MHz;
     GPIO_Init(GPIOB,&GPIO_InitStructure1);             // ÅäÖÃPB0  
        GPIO_SetBits(GPIOB,GPIO_Pin_0);                   // PB0 ÖÃ1
     delay(5);   //ÑÓʱ5ms
     GPIO_ResetBits(GPIOB,GPIO_Pin_0);                   // PB0 ÇåÁã
}
else if(cnt == 3)                      //RS485_RX_STAΪ0£¬±íʾ½ÓÊÕµ½AD²ÉÑùÖ¸Áî
{

ADC_StartConversion(ADC1);
ADC_StartConversion(ADC2);
delay(1);

value_buf[0]=(float)(u16)ADC1_ConvertedValue[0];//AD_W15V 
        value_buf[1]=(float)(u16)ADC2_ConvertedValue[0];//AD_24V  
        value_buf[2]=(float)(u16)ADC2_ConvertedValue[1];//AD_12V 
        value_buf[3]=(float)(u16)ADC2_ConvertedValue[2];//AD_VGC  
        value_buf[4]=(float)(u16)ADC2_ConvertedValue[3];//AD_U15V  
        value_buf[5]=(float)(u16)ADC2_ConvertedValue[4];//AD_V15V  
        value_buf[6]=(float)(u16)ADC2_ConvertedValue[5];//AD_15VF
        value_buf[7]=(float)(u16)ADC2_ConvertedValue[6];//AD_15V    
        value_buf[8]=(float)(u16)ADC2_ConvertedValue[7];//AD_5V

AD_W15V = getresult(value_buf[0]);   //PA0
AD_24V  = getresult(value_buf[1]);   //PA4
AD_12V  = getresult(value_buf[2]);   //PA5 
AD_VGC  = getresult(value_buf[3]);   //PA6
AD_U15V = getresult(value_buf[4]);   //PA7
AD_V15V = getresult(value_buf[5]);   //PC4
AD_15VF = getresult(value_buf[6]);   //PC0
AD_15V  = getresult(value_buf[7]);   //PC1
AD_5V   = getresult(value_buf[8]);   //PC2

MCU_TX_EN;
printf("The ADC Value:\r\n");
printf("AD_W15V =%4.3f\r\n",AD_W15V);
printf("AD_24V  =%4.3f\r\n",AD_24V);
printf("AD_12V  =%4.3f\r\n",AD_12V);
printf("AD_VGC  =%4.3f\r\n",AD_VGC);
printf("AD_U15V =%4.3f\r\n",AD_U15V);
printf("AD_V15V =%4.3f\r\n",AD_V15V);
printf("AD_15VF =%4.3f\r\n",AD_15VF);
printf("AD_15V  =%4.3f\r\n",AD_15V);
        printf("AD_5V   =%4.3f\r\n",AD_5V);
printf("\r\n");
MCU_RX_EN;
     
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB,ENABLE); // ¿ªGPIOBʱÖÓ
     GPIO_InitStructure1.GPIO_Mode  = GPIO_Mode_OUT;
        GPIO_InitStructure1.GPIO_OType = GPIO_OType_PP;
     GPIO_InitStructure1.GPIO_Pin   = GPIO_Pin_0;
     GPIO_InitStructure1.GPIO_PuPd  = GPIO_PuPd_NOPULL;
     GPIO_InitStructure1.GPIO_Speed = GPIO_Speed_2MHz;
     GPIO_Init(GPIOB,&GPIO_InitStructure1);             // ÅäÖÃPB0  
        GPIO_SetBits(GPIOB,GPIO_Pin_0);                    // PB0 ÖÃ1
     delay(5);                                          // ÑÓʱ5ms
     GPIO_ResetBits(GPIOB,GPIO_Pin_0);                  // PB0 ÇåÁã
cnt = 0;
}
}
}

3 system_stm32f30x.c

/**
  ******************************************************************************
  * @file    system_stm32f30x.c
  * @author  MCD Application Team
  * @version V1.2.3
  * @date    10-July-2015
  * @brief   CMSIS Cortex-M4 Device Peripheral Access Layer System Source File.
  *          This file contains the system clock configuration for STM32F30x devices,
  *          and is generated by the clock configuration tool
  *          stm32f30x_Clock_Configuration_V1.0.0.xls
  *             
  * 1.  This file provides two functions and one global variable to be called from 
  *     user application:
  *      - SystemInit(): Setups the system clock (System clock source, PLL Multiplier
  *                      and Divider factors, AHB/APBx prescalers and Flash settings),
  *                      depending on the configuration made in the clock xls tool. 
  *                      This function is called at startup just after reset and 
  *                      before branch to main program. This call is made inside
  *                      the "startup_stm32f30x.s" file.
  *
  *      - SystemCoreClock variable: Contains the core clock (HCLK), it can be used
  *                                  by the user application to setup the SysTick 
  *                                  timer or configure other parameters.
  *                                     
  *      - SystemCoreClockUpdate(): Updates the variable SystemCoreClock and must
  *                                 be called whenever the core clock is changed
  *                                 during program execution.
  *
  * 2. After each device reset the HSI (8 MHz) is used as system clock source.
  *    Then SystemInit() function is called, in "startup_stm32f30x.s" file, to
  *    configure the system clock before to branch to main program.
  *
  * 3. If the system clock source selected by user fails to startup, the SystemInit()
  *    function will do nothing and HSI still used as system clock source. User can 
  *    add some code to deal with this issue inside the SetSysClock() function.
  *
  * 4. The default value of HSE crystal is set to 8MHz, refer to "HSE_VALUE" define
  *    in "stm32f30x.h" file. When HSE is used as system clock source, directly or
  *    through PLL, and you are using different crystal you have to adapt the HSE
  *    value to your own configuration.
  *
  * 5. This file configures the system clock as follows:
  *=============================================================================
  *                         Supported STM32F30x device                          
  *-----------------------------------------------------------------------------
  *        System Clock source                    | PLL (HSE)
  *-----------------------------------------------------------------------------
  *        SYSCLK(Hz)                             | 72000000
  *-----------------------------------------------------------------------------
  *        HCLK(Hz)                               | 72000000
  *-----------------------------------------------------------------------------
  *        AHB Prescaler                          | 1
  *-----------------------------------------------------------------------------
  *        APB2 Prescaler                         | 1
  *-----------------------------------------------------------------------------
  *        APB1 Prescaler                         | 2
  *-----------------------------------------------------------------------------
  *        HSE Frequency(Hz)                      | 10000000
  *----------------------------------------------------------------------------
  *        PLLMUL                                 | 7
  *-----------------------------------------------------------------------------
  *        PREDIV                                 | 1
  *-----------------------------------------------------------------------------
  *        USB Clock                              | DISABLE
  *-----------------------------------------------------------------------------
  *        Flash Latency(WS)                      | 2
  *-----------------------------------------------------------------------------
  *        Prefetch Buffer                        | ON
  *-----------------------------------------------------------------------------
  *=============================================================================
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; COPYRIGHT 2015 STMicroelectronics</center></h2>
  *
  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  * You may not use this file except in compliance with the License.
  * You may obtain a copy of the License at:
  *
  *        http://www.st.com/software_license_agreement_liberty_v2
  *
  * Unless required by applicable law or agreed to in writing, software 
  * distributed under the License is distributed on an "AS IS" BASIS, 
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  *
  ******************************************************************************
  */
/** @addtogroup CMSIS
  * @{
  */


/** @addtogroup stm32f30x_system
  * @{
  */  
  
/** @addtogroup STM32F30x_System_Private_Includes
  * @{
  */


#include "stm32f30x.h"


/**
  * @}
  */


/* Private typedef -----------------------------------------------------------*/


/** @addtogroup STM32F30x_System_Private_Defines
  * @{
  */
/*!< Uncomment the following line if you need to relocate your vector Table in
     Internal SRAM. */ 
/* #define VECT_TAB_SRAM */
#define VECT_TAB_OFFSET  0x0 /*!< Vector Table base offset field. 
                                  This value must be a multiple of 0x200. */  
/**
  * @}
  */ 


/* Private macro -------------------------------------------------------------*/


/** @addtogroup STM32F30x_System_Private_Variables
  * @{
  */


  uint32_t SystemCoreClock = 72000000;


  __I uint8_t AHBPrescTable[16] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9};


/**
  * @}
  */


/** @addtogroup STM32F30x_System_Private_FunctionPrototypes
  * @{
  */


static void SetSysClock(void);


/**
  * @}
  */


/** @addtogroup STM32F30x_System_Private_Functions
  * @{
  */


/**
  * @brief  Setup the microcontroller system
  *         Initialize the Embedded Flash Interface, the PLL and update the 
  *         SystemFrequency variable.
  * @param  None
  * @retval None
  */
void SystemInit(void)
{
  /* FPU settings ------------------------------------------------------------*/
  #if (__FPU_PRESENT == 1) && (__FPU_USED == 1)
    SCB->CPACR |= ((3UL << 10*2)|(3UL << 11*2));  /* set CP10 and CP11 Full Access */
  #endif


  /* Reset the RCC clock configuration to the default reset state ------------*/
  /* Set HSION bit */
  RCC->CR |= (uint32_t)0x00000001;  //¿ªÆôÄÚ²¿¸ßËÙ8MµÄRCÕðµ´Æ÷


  /* Reset CFGR register */
  RCC->CFGR &= 0xF87FC00C;  //PLLMUL[3:0]=1111 ¼´PLL input clock*16; 
                            //PLLXTPRE=1£¬¼´HSE/2 selected as PLL input clock;ÉèÖÃÁËÕâ1λ£¬Í¬Ê±Ò²ÉèÖÃÁËRCC_CFGR2µÄ¶ÔӦλ
                            //PLLSRC=1£¬¼´HSE/PREDIV (PREDIV=2) selected as PLL input clock;
                            //SWS[1:0]=11
                            //SW[1:0]=00,HSI selected as system clock


  /* Reset HSEON, CSSON and PLLON bits */
  RCC->CR &= (uint32_t)0xFEF6FFFF;  //PLL¹Ø±Õ£»Ê±ÖÓ¼à²âÆ÷¹Ø±Õ£»HSEÕñµ´Æ÷¹Ø±Õ;




  /* Reset HSEBYP bit */
  RCC->CR &= (uint32_t)0xFFFBFFFF; //¾ÍÊÇʹHSEBYP=0£»Íⲿ4-25MHzÕñµ´Æ÷ûÓÐÅÔ·£»


  /* Reset PLLSRC, PLLXTPRE, PLLMUL and USBPRE bits */
  RCC->CFGR &= (uint32_t)0xFF80FFFF;   // PLLMUL=0011,PLL input clock x 5;
                                       //PLLXTPRE=0£¬HSE input to PLL not divided;ÉèÖÃÁËÕâ1λ£¬Í¬Ê±Ò²ÉèÖÃÁËRCC_CFGR2µÄ¶ÔӦλ
                                       //PLLSRC=0£¬: HSI/2 selected as PLL input clock
  /* Reset PREDIV1[3:0] bits */
  RCC->CFGR2 &= (uint32_t)0xFFFFFFF0;  //PREDIV[3:0]=0000: HSE input to PLL not divided


  /* Reset USARTSW[1:0], I2CSW and TIMs bits */
  RCC->CFGR3 &= (uint32_t)0xFF00FCCC;
  
  /* Disable all interrupts */
  RCC->CIR = 0x00000000;


  /* Configure the System clock source, PLL Multiplier and Divider factors, 
     AHB/APBx prescalers and Flash settings ----------------------------------*/
  SetSysClock();
  
#ifdef VECT_TAB_SRAM
  SCB->VTOR = SRAM_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal SRAM. */
#else
  SCB->VTOR = FLASH_BASE | VECT_TAB_OFFSET; /* Vector Table Relocation in Internal FLASH. */
#endif  
}


/**
   * @brief  Update SystemCoreClock variable according to Clock Register Values.
  *         The SystemCoreClock variable contains the core clock (HCLK), it can
  *         be used by the user application to setup the SysTick timer or configure
  *         other parameters.
  *           
  * @note   Each time the core clock (HCLK) changes, this function must be called
  *         to update SystemCoreClock variable value. Otherwise, any configuration
  *         based on this variable will be incorrect.         
  *     
  * @note   - The system frequency computed by this function is not the real 
  *           frequency in the chip. It is calculated based on the predefined 
  *           constant and the selected clock source:
  *             
  *           - If SYSCLK source is HSI, SystemCoreClock will contain the HSI_VALUE(*)
  *                                              
  *           - If SYSCLK source is HSE, SystemCoreClock will contain the HSE_VALUE(**)
  *                          
  *           - If SYSCLK source is PLL, SystemCoreClock will contain the HSE_VALUE(**) 
  *             or HSI_VALUE(*) multiplied/divided by the PLL factors.
  *         
  *         (*) HSI_VALUE is a constant defined in stm32f30x.h file (default value
  *             8 MHz) but the real value may vary depending on the variations
  *             in voltage and temperature.   
  *    
  *         (**) HSE_VALUE is a constant defined in stm32f30x.h file (default value
  *              8 MHz), user has to ensure that HSE_VALUE is same as the real
  *              frequency of the crystal used. Otherwise, this function may
  *              have wrong result.
  *                
  *         - The result of this function could be not correct when using fractional
  *           value for HSE crystal.
  *     
  * @param  None
  * @retval None
  */
void SystemCoreClockUpdate (void)
{
  uint32_t tmp = 0, pllmull = 0, pllsource = 0, prediv1factor = 0;


  /* Get SYSCLK source -------------------------------------------------------*/
  tmp = RCC->CFGR & RCC_CFGR_SWS;
  
  switch (tmp)
  {
    case 0x00:  /* HSI used as system clock */
      SystemCoreClock = HSI_VALUE;
      break;
    case 0x04:  /* HSE used as system clock */
      SystemCoreClock = HSE_VALUE;
      break;
    case 0x08:  /* PLL used as system clock */
      /* Get PLL clock source and multiplication factor ----------------------*/
      pllmull = RCC->CFGR & RCC_CFGR_PLLMULL;
      pllsource = RCC->CFGR & RCC_CFGR_PLLSRC;
      pllmull = ( pllmull >> 18) + 2;
      
      if (pllsource == 0x00)
      {
        /* HSI oscillator clock divided by 2 selected as PLL clock entry */
        SystemCoreClock = (HSI_VALUE >> 1) * pllmull;
      }
      else
      {
        prediv1factor = (RCC->CFGR2 & RCC_CFGR2_PREDIV1) + 1;
        /* HSE oscillator clock selected as PREDIV1 clock entry */
        SystemCoreClock = (HSE_VALUE / prediv1factor) * pllmull; 
      }      
      break;
    default: /* HSI used as system clock */
      SystemCoreClock = HSI_VALUE;
      break;
  }
  /* Compute HCLK clock frequency ----------------*/
  /* Get HCLK prescaler */
  tmp = AHBPrescTable[((RCC->CFGR & RCC_CFGR_HPRE) >> 4)];
  /* HCLK clock frequency */
  SystemCoreClock >>= tmp;  
}


/**
  * @brief  Configures the System clock source, PLL Multiplier and Divider factors,
  *               AHB/APBx prescalers and Flash settings
  * @note   This function should be called only once the RCC clock configuration  
  *         is reset to the default reset state (done in SystemInit() function).             
  * @param  None
  * @retval None
  */
static void SetSysClock(void)
{
  __IO uint32_t StartUpCounter = 0, HSEStatus = 0;


/******************************************************************************/
/*            PLL (clocked by HSE) used as System clock source                */
/******************************************************************************/


  /* SYSCLK, HCLK, PCLK2 and PCLK1 configuration -----------*/
  /* Enable HSE */
  RCC->CR |= ((uint32_t)RCC_CR_HSEON);
 
  /* Wait till HSE is ready and if Time out is reached exit */
  do
  {
    HSEStatus = RCC->CR & RCC_CR_HSERDY;
    StartUpCounter++;
  } while((HSEStatus == 0) && (StartUpCounter != HSE_STARTUP_TIMEOUT));


  if ((RCC->CR & RCC_CR_HSERDY) != RESET) //Èç¹ûHSERDY=1
  {
    HSEStatus = (uint32_t)0x01;
  }
  else
  {
    HSEStatus = (uint32_t)0x00;
  }


  if (HSEStatus == (uint32_t)0x01)
  {
    /* Enable Prefetch Buffer and set Flash Latency */
    FLASH->ACR = FLASH_ACR_PRFTBE | (uint32_t)FLASH_ACR_LATENCY_1;
 
     /* HCLK = SYSCLK / 1 */
     RCC->CFGR |= (uint32_t)RCC_CFGR_HPRE_DIV1;
       
     /* PCLK2 = HCLK / 1 */
     RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE2_DIV1;
     
     /* PCLK1 = HCLK / 2 */
     RCC->CFGR |= (uint32_t)RCC_CFGR_PPRE1_DIV2;


    /* PLL configuration */
    RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_PLLSRC | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLMULL));
    RCC->CFGR |= (uint32_t)(RCC_CFGR_PLLSRC_PREDIV1 | RCC_CFGR_PLLXTPRE_PREDIV1 | RCC_CFGR_PLLMULL7);
    // SHE²»·ÖƵ×÷ΪPLLµÄÊäÈ룬PLLµÄÊäÈëÔÙ³ËÒÔ7£¬¼´ÏµÍ³Ê±ÖÓλHSE*9=10*7=70MHZ


    /* Enable PLL */
    RCC->CR |= RCC_CR_PLLON;


    /* Wait till PLL is ready */
    while((RCC->CR & RCC_CR_PLLRDY) == 0)
    {
    }
    
    /* Select PLL as system clock source */
    RCC->CFGR &= (uint32_t)((uint32_t)~(RCC_CFGR_SW));
    RCC->CFGR |= (uint32_t)RCC_CFGR_SW_PLL;


    /* Wait till PLL is used as system clock source */
    while ((RCC->CFGR & (uint32_t)RCC_CFGR_SWS) != (uint32_t)RCC_CFGR_SWS_PLL)
    {
    }
  }
  else
  { /* If HSE fails to start-up, the application will have wrong clock
         configuration. User can add here some code to deal with this error */
  }
}


/**
  * @}
  */


/**
  * @}
  */


/**
  * @}
  */


/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

4 rs485.c

#include "rs485.h"
#include "delay.h"






#pragma import(__use_no_semihosting)             
//±ê×¼¿âÐèÒªµÄÖ§³Öº¯Êý                 
struct __FILE 

int handle; 
}; 


FILE __stdout;       
//¶¨Òå_sys_exit()ÒÔ±ÜÃâʹÓðëÖ÷»úģʽ    
int _sys_exit(int x) 

x = x; 





                                 


//ÖØ¶¨Òåfputcº¯Êý £¬ÕâÑù¶¨ÒåÖ®ºóUSART1±ã¿ÉÒÔÖ±½Óµ÷ÓÃprintfº¯Êý·¢ËÍÊý¾Ý
int fputc(int ch, FILE *f)
{
USART_SendData(USART1,ch);
  while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET);      
return ch;
// while((USART1->ISR&0X40)==0);//Ñ­»··¢ËÍ,Ö±µ½·¢ËÍÍê±Ï   
// USART1->TDR = (u8) ch;      
// return ch;
}


 
u8 RS485_RX_BUF[64];   //½ÓÊÕ»º³å,×î´ó64¸ö×Ö½Ú.
u8 RS485_RX_CNT = 0;   //½ÓÊÕµ½µÄÊý¾Ý³¤¶È
u16 RS485_RX_STA = 0;  //½ÓÊÕ״̬±êÖ¾£¬bit15±íʾ½ÓÊÕÍê³É£¬bit14±íʾ½ÓÊÕµ½0x0D±êÖ¾£¬bit13~0±íʾ½ÓÊÕµ½µÄÓÐЧÊý¾Ý¸öÊý
u8 RS485_REC_LEN=200;
u16 USART_RX_BUF[200];
u8 rs485buf[5];
u8 t,cnt=0;
void delay(u32 n);




void RS485_Init(u32 bound)
{    
  GPIO_InitTypeDef  GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
  NVIC_InitTypeDef  NVIC_InitStructure;

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE);     //ʹÄÜGPIOAʱÖÓ
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);  //ʹÄÜUART1ʱÖÓ



GPIO_PinAFConfig(GPIOA,GPIO_PinSource9,GPIO_AF_7);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource10,GPIO_AF_7);

//USART1   
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; //USART1 TX
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//¸´Óù¦ÄÜ
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //ËÙ¶È100MHz
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //ÍÆÍ츴ÓÃÊä³ö
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //ÉÏÀ­
GPIO_Init(GPIOA,&GPIO_InitStructure); 

//USART1   
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10; //USART1 RX
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;//¸´Óù¦ÄÜ
GPIO_Init(GPIOA,&GPIO_InitStructure); 

//PA12ÍÆÍìÊä³ö£¬485ģʽ¿ØÖÆ  
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; //GPIOA12
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;//Êä³ö
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; //ËÙ¶È100MHz
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //ÍÆÍìÊä³ö
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; 
GPIO_Init(GPIOA,&GPIO_InitStructure); //³õʼ»¯PA12



  //USART1 ³õʼ»¯ÉèÖÃ
USART_InitStructure.USART_BaudRate = bound;//²¨ÌØÂÊÉèÖÃ
USART_InitStructure.USART_WordLength = USART_WordLength_8b;//×Ö³¤Îª8λÊý¾Ý¸ñʽ
USART_InitStructure.USART_StopBits = USART_StopBits_1;//Ò»¸öֹͣλ
USART_InitStructure.USART_Parity = USART_Parity_No;//ÎÞÆæÅ¼Ð£Ñéλ
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;//ÎÞÓ²¼þÊý¾ÝÁ÷¿ØÖÆ
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; //ÊÕ·¢Ä£Ê½
  USART_Init(USART1, &USART_InitStructure); //³õʼ»¯´®¿Ú1




  USART_Cmd(USART1, ENABLE);  //ʹÄÜ´®¿Ú 1,Ö´ÐÐÍêÕâÒ»¾ä£¬ISR´ÓC0±äΪD0£¬¼´¼ì²âµ½¿ÕÏÐÖ¡
//  USART_ClearFlag(USART1,USART_FLAG_TC);
  USART_ITConfig(USART1,USART_IT_RXNE,ENABLE);
  NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;        //´®¿Ú1ÖжÏ
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =1; //ÉèÖÃÇÀÕ¼ÓÅÏȼ¶Îª1£»
NVIC_InitStructure.NVIC_IRQChannelSubPriority        =1; //ÉèÖÃÏìÓ¦ÓÅÏȼ¶Îª1£»
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;     //IRQͨµÀʹÄÜ
NVIC_Init(&NVIC_InitStructure);

}




void USART1_IRQHandler(void)
{
u8 test;
if(USART_GetITStatus(USART1,USART_IT_RXNE)!=RESET)  //½ÓÊÕÊý¾Ý¼Ä´æÆ÷·Ç¿Õ
{
test = USART_ReceiveData(USART1);   //¶ÁÈ¡RDRÖеÄÊý¾Ý£¬ÕâÒ»²Ù×÷»á½«RXNEλÇå0

if(cnt< 2)                            //½ÓÊÕδÍê³É
{
if(test!=0x01 && test!=0x00 && test!=0x03)

cnt=0;
MCU_TX_EN;
            printf("½ÓÊÕ´íÎó1\r\n");
MCU_RX_EN;
}

else if(test == 0x03)
{
rs485buf[cnt]=test; // ½«½ÓÊÕµ½µÄÊý¾Ý·ÅÈ뻺´æÇø
cnt = 3;
}

else if(test == 0x00)
{
if(cnt==1)          //µÚÒ»´Î½ÓÊÕµ½ÁË0x01
{
rs485buf[cnt]=test; // ½«½ÓÊÕµ½µÄÊý¾Ý·ÅÈ뻺´æÇø
                  cnt=4;
}
else if(cnt==0)
{
MCU_TX_EN;
printf("½ÓÊÕ´íÎó2\r\n");
 MCU_RX_EN;
}
}

else if(test == 0x01)
{
rs485buf[cnt]=test; // ½«½ÓÊÕµ½µÄÊý¾Ý·ÅÈ뻺´æÇø
cnt++;
       }

}
}
}

5 delay.c

#include "delay.h"
u32 m;


void delay(u32 n)  //ÑÓʱn ms
{
m = 70000*n;
 
while(m)
{
m--;
}

}

6 AD.c

#include "ad.h"
#include "delay.h"
#include "stm32f30x_adc.h"


int n;
float value_buf[20];
void adc_Init(void)

GPIO_InitTypeDef       GPIO_InitStructure,GPIO_InitStructure1;
ADC_CommonInitTypeDef  ADC_CommonInitStructure,ADC_CommonInitStructure1; 
ADC_InitTypeDef        ADC_InitStructure,ADC_InitStructure1;



RCC_ADCCLKConfig(RCC_ADC12PLLCLK_Div2);       //ADC12CLK = PLLCLK/2
  RCC_AHBPeriphClockCmd(RCC_AHBPeriph_ADC12|RCC_AHBPeriph_GPIOA|RCC_AHBPeriph_GPIOC,ENABLE); // 1 ¿ªÆôÏà¹ØÊ±ÖÓ



GPIO_InitStructure.GPIO_Pin  = GPIO_Pin_0|GPIO_Pin_4|GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7;   //ÅäÖÃPA0:AD_W15V(ADC1_IN1)
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;                                             //²¢ÅäÖÃPA4:AD_24V(ADC2_IN1)
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;                                        //²¢ÅäÖÃPA5:AD_12V(ADC2_IN2)
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;                                       //²¢ÅäÖÃPA6:AD_VGC(ADC2_IN3)
GPIO_Init(GPIOA,&GPIO_InitStructure);                                                    //²¢ÅäÖÃPA7:AD_U15V(ADC2_IN4)
                                                                                            
                                                                                        //²¢ÅäÖÃPC0:AD_W15V(ADC12_IN6)
GPIO_InitStructure1.GPIO_Pin  = GPIO_Pin_0|GPIO_Pin_1|GPIO_Pin_2|GPIO_Pin_4;             //²¢ÅäÖÃPC1:AD_+15V(ADC12_IN7)           
GPIO_InitStructure1.GPIO_Mode = GPIO_Mode_AN;                                            //²¢ÅäÖÃPC2:AD_5V(ADC12_IN8)
GPIO_InitStructure1.GPIO_Speed = GPIO_Speed_50MHz;                                       //²¢ÅäÖÃPC4:AD_V15V(ADC2_IN5)
GPIO_InitStructure1.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOC,&GPIO_InitStructure1);


ADC_CommonInitStructure.ADC_Mode             = ADC_Mode_Independent;                //¶àADC:³£¹æÍ¨µÀͬʱת»»Ä£Ê½
ADC_CommonInitStructure.ADC_DMAAccessMode    = ADC_DMAAccessMode_1;              // 12 λDMA
ADC_CommonInitStructure.ADC_TwoSamplingDelay = 5;                                //Á½¸ö²ÉÑù¼ä¸ô5¸öÖÜÆÚ
ADC_CommonInit(ADC1,&ADC_CommonInitStructure); //ÅäÖÃADCµÄͨÓÃÌØÐÔ


ADC_InitStructure.ADC_Resolution             = ADC_Resolution_12b;               //12λ
ADC_InitStructure.ADC_ContinuousConvMode     = ENABLE;                         //ʹÄÜÁ¬Ðø×ª»»   
ADC_InitStructure.ADC_ExternalTrigEventEdge  = ADC_ExternalTrigEventEdge_None;   //ÎÞÍⲿ´¥·¢Ê¼þ
  ADC_InitStructure.ADC_OverrunMode            = DISABLE;
  ADC_InitStructure.ADC_AutoInjMode            = DISABLE;
ADC_InitStructure.ADC_DataAlign              = ADC_DataAlign_Right;              //ÓÒ¶ÔÆë
ADC_InitStructure.ADC_NbrOfRegChannel        = 1;                                //ADC1ÐèҪת»»µÄͨµÀÊýΪ1                               
ADC_Init(ADC1,&ADC_InitStructure);             //ÅäÖþßÌåµÄADCÌØÐÔ


ADC_CommonInitStructure1.ADC_Mode             = ADC_Mode_Independent;               //¶àADC:³£¹æÍ¨µÀͬʱת»»Ä£Ê½
ADC_CommonInitStructure1.ADC_DMAAccessMode    = ADC_DMAAccessMode_1;             // 12 λDMA
ADC_CommonInitStructure1.ADC_TwoSamplingDelay = 5;                               //Á½¸ö²ÉÑù¼ä¸ô5¸öÖÜÆÚ
ADC_CommonInit(ADC2,&ADC_CommonInitStructure1); //ÅäÖÃADCµÄͨÓÃÌØÐÔ


ADC_InitStructure1.ADC_Resolution             = ADC_Resolution_12b;              //12λ
ADC_InitStructure1.ADC_ContinuousConvMode     = ENABLE;                         //ʹÄÜÁ¬Ðø×ª»»   
ADC_InitStructure1.ADC_ExternalTrigEventEdge  = ADC_ExternalTrigEventEdge_None;  //ÎÞÍⲿ´¥·¢Ê¼þ
  ADC_InitStructure1.ADC_OverrunMode            = DISABLE;
  ADC_InitStructure1.ADC_AutoInjMode            = DISABLE;
ADC_InitStructure1.ADC_DataAlign              = ADC_DataAlign_Right;             //ÓÒ¶ÔÆë
ADC_InitStructure1.ADC_NbrOfRegChannel        = 8;                               //ADC2ÐèҪת»»µÄͨµÀÊýΪ8                               
ADC_Init(ADC2,&ADC_InitStructure1);             //ÅäÖþßÌåµÄADCÌØÐÔ


A_D_C->CR &=0x0FFFFFFF; 
A_D_C->CR |=0x10000000;  //¿ªÆôADC voltage regulator
delay(1);                //ÑÓʱ£¬ÒÔʹregulator ÓÐ×ã¹»µÄʱ¼äÍê³ÉÆô¶¯


ADC_RegularChannelConfig(ADC1, ADC_Channel_1, 1, ADC_SampleTime_601Cycles5 ); //ADC1,ADCͨµÀ,480¸öÖÜÆÚ,Ìá¸ß²ÉÑùʱ¼ä¿ÉÒÔÌá¸ß¾«È·¶È
  ADC_DMACmd(ADC1,ENABLE);
  ADC_Cmd(ADC1,ENABLE);
  ADC_RegularChannelConfig(ADC2, ADC_Channel_1,1, ADC_SampleTime_601Cycles5 );
ADC_RegularChannelConfig(ADC2, ADC_Channel_2,2, ADC_SampleTime_601Cycles5 );
ADC_RegularChannelConfig(ADC2, ADC_Channel_3,3, ADC_SampleTime_601Cycles5 );
ADC_RegularChannelConfig(ADC2, ADC_Channel_4,4, ADC_SampleTime_601Cycles5 );
ADC_RegularChannelConfig(ADC2, ADC_Channel_5,5, ADC_SampleTime_601Cycles5 );
ADC_RegularChannelConfig(ADC2, ADC_Channel_6,6, ADC_SampleTime_601Cycles5 );
ADC_RegularChannelConfig(ADC2, ADC_Channel_7,7, ADC_SampleTime_601Cycles5 );
ADC_RegularChannelConfig(ADC2, ADC_Channel_8,8, ADC_SampleTime_601Cycles5 );
ADC_DMACmd(ADC2,ENABLE);
ADC_Cmd(ADC2,ENABLE);
// ADCµÄÒ»´Îת»»Ê±¼äTconv=1/35M *(1.5+12)=0.386us
}









float getresult(float y)
{


float result,Vref=3.3;
  result = Vref *(y/4096);
return result;
}

7 dma.c

#include "dma.h"
#include "stm32f30x_rcc.h"






#define ADC1_DR_Address    ((u32)0x50000000+0x40)  
#define ADC2_DR_Address    ((u32)0x50000100+0x40)




void mydma(void)
{
DMA_InitTypeDef DMA_InitStructure,DMA_InitStructure1;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1|RCC_AHBPeriph_DMA2,ENABLE);    //¿ªDMA12ʱÖÓ

DMA_DeInit(DMA1_Channel1);      //¸´Î»DMA1
DMA_InitStructure.DMA_BufferSize = 100;   //ÓÃÒÔ¶¨ÒåÖ¸¶¨DMAͨµÀµÄDMA»º´æµÄ´óС£¬µ¥Î»ÎªÊý¾Ýµ¥Î»£¬ÉèÖÃÒ»´Î´«ÊäÊý¾ÝÁ¿µÄ´óС
DMA_InitStructure.DMA_DIR        = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_M2M        = DMA_M2M_Disable;
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&ADC1_ConvertedValue;
  DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.DMA_MemoryInc      = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_Mode           = DMA_Mode_Circular;  //ÉèÖÃΪһ´ÎÁ¬Ðø²É¼¯Íê³ÉÖ®ºó²»ÔÙÑ­»·
DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure.DMA_PeripheralInc  = DMA_PeripheralInc_Disable;   //ÍâÉèµØÖ·ÊÇ·ñ×Ô¼Ó:ÓÉÓÚÒ»Ö±´ÓADCµÄÊý¾Ý¼Ä´æÆ÷·¢ËÍ£¬ËùÒÔÉèÖÃΪDisable
DMA_InitStructure.DMA_Priority       = DMA_Priority_High;
  DMA_Init(DMA1_Channel1,&DMA_InitStructure);          //³õʼ»¯DMA1µÄͨµÀ 
DMA_Cmd(DMA1_Channel1,ENABLE);

  
DMA_DeInit(DMA2_Channel1);      //¸´Î»DMA2
DMA_InitStructure1.DMA_BufferSize = 100;   //ÓÃÒÔ¶¨ÒåÖ¸¶¨DMAͨµÀµÄDMA»º´æµÄ´óС£¬µ¥Î»ÎªÊý¾Ýµ¥Î»£¬ÉèÖÃÒ»´Î´«ÊäÊý¾ÝÁ¿µÄ´óС
DMA_InitStructure1.DMA_DIR        = DMA_DIR_PeripheralSRC;
DMA_InitStructure1.DMA_M2M        = DMA_M2M_Disable;
DMA_InitStructure1.DMA_MemoryBaseAddr = (u32)&ADC2_ConvertedValue;
  DMA_InitStructure1.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure1.DMA_MemoryInc      = DMA_MemoryInc_Enable;
DMA_InitStructure1.DMA_Mode           = DMA_Mode_Circular;  //ÉèÖÃΪһ´ÎÁ¬Ðø²É¼¯Íê³ÉÖ®ºó²»ÔÙÑ­»·
DMA_InitStructure1.DMA_PeripheralBaseAddr = ADC2_DR_Address;
DMA_InitStructure1.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure1.DMA_PeripheralInc  = DMA_PeripheralInc_Disable;   //ÍâÉèµØÖ·ÊÇ·ñ×Ô¼Ó:ÓÉÓÚÒ»Ö±´ÓADCµÄÊý¾Ý¼Ä´æÆ÷·¢ËÍ£¬ËùÒÔÉèÖÃΪDisable
DMA_InitStructure1.DMA_Priority       = DMA_Priority_Medium;
  DMA_Init(DMA2_Channel1,&DMA_InitStructure1);          //³õʼ»¯DMA1µÄͨµÀ 
DMA_Cmd(DMA2_Channel1,ENABLE);
}

8 startup_stm32f30x.c

;******************** (C) COPYRIGHT 2016 STMicroelectronics ********************
;* File Name          : startup_stm32f302xc.s
;* Author             : MCD Application Team
;* Description        : STM32F302xB/xC devices vector table for MDK-ARM toolchain.
;*                      This module performs:
;*                      - Set the initial SP
;*                      - Set the initial PC == Reset_Handler
;*                      - Set the vector table entries with the exceptions ISR address
;*                      - Branches to __main in the C library (which eventually
;*                        calls main()).
;*                      After Reset the CortexM4 processor is in Thread mode,
;*                      priority is Privileged, and the Stack is set to Main.
;*
;*******************************************************************************
;
;* Redistribution and use in source and binary forms, with or without modification,
;* are permitted provided that the following conditions are met:
;*   1. Redistributions of source code must retain the above copyright notice,
;*      this list of conditions and the following disclaimer.
;*   2. Redistributions in binary form must reproduce the above copyright notice,
;*      this list of conditions and the following disclaimer in the documentation
;*      and/or other materials provided with the distribution.
;*   3. Neither the name of STMicroelectronics nor the names of its contributors
;*      may be used to endorse or promote products derived from this software
;*      without specific prior written permission.
;*
;* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
;* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
;* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
;* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
;* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
;* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
;* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
;* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
;* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
;* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
;
;*******************************************************************************


; Amount of memory (in bytes) allocated for Stack
; Tailor this value to your application needs
; <h> Stack Configuration
;   <o> Stack Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>


Stack_Size      EQU     0x00000400                          ;¶¨ÒåÕ»´óСΪ1024B£»


                AREA    STACK, NOINIT, READWRITE, ALIGN=3   ;
Stack_Mem       SPACE   Stack_Size                          ;·ÖÅäÁ¬ÐøStack_Size×ֽڵĴ洢µ¥Ôª²¢³õʼ»¯Îª0£»
__initial_sp                                                ;³õʼ»¯¶ÑÕ»£¬±êºÅ_initial_sp±íʾָÏò¶ÑÕ»Õ»¶¥£»




; <h> Heap Configuration
;   <o>  Heap Size (in Bytes) <0x0-0xFFFFFFFF:8>
; </h>


Heap_Size       EQU     0x00000200                           ;¶¨Òå¶Ñ´óСΪ512B£»


                AREA    HEAP, NOINIT, READWRITE, ALIGN=3     ;¶Ñ¶Î£¬mallocÓõĵط½£¬²»Ò»¶¨Á¬Ðø¿Õ¼ä£¬Î´³õʼ»¯£¬ÔÊÐí¶Áд£¬¶ÑÊý¾Ý¶Î8×ֽڱ߽ç¶ÔÆë
__heap_base                                                  ;±íʾ¶Ñ¿Õ¼äÆðʼµØÖ·
Heap_Mem        SPACE   Heap_Size                            ;·ÖÅä¶Ñ¿Õ¼ä
__heap_limit                                                 ;±íʾ¶Ñ¿Õ¼ä½áÊøµØÖ·Óë_heap_baseÅäºÏÏÞÖÆ¶ÑµÄ´óС


                PRESERVE8                                    ;Ö¸¶¨µ±Ç°Îļþ±£³ÖÕ»µÄ8×Ö½Ú¶ÔÆë
                THUMB                                        ;Ö¸Á£¬THUMB±ØÐëλÓÚʹÓÃÐÂÓï·¨µÄÈκÎThumb´úÂë֮ǰ
                                                             ;EXPORT ÃüÁîÉùÃ÷Ò»¸ö·ûºÅ£¬¿ÉÓÉÁ´½ÓÆ÷ÓÃÓÚ½âÊ͸÷¸öÄ¿±êºÍ¿âÎļþÖеķûºÅÒýÓã¬
;Ï൱ÓÚÉùÃ÷ÁËÒ»¸öÈ«¾Ö±äÁ¿£¬GLOBAL ÓëEXPORTÏàͬ


; Vector Table Mapped to Address 0 at Reset                  ;ÒÔÏÂΪÏòÁ¿±í£¬ÔÚ¸´Î»Ê±±»Ó³Éäµ½FlashµÄ0µØÖ·
                AREA    RESET, DATA, READONLY                ;¶¨ÒåÒ»¸öÊý¾Ý¶Î£¬¶ÎÃû×ÖÊÇRESET,Ö»°üº¬Êý¾Ý£¬Ö»¶Á
                EXPORT  __Vectors                            ;ÉùÃ÷Ò»¸öÈ«¾Ö±êºÅ_Vectors,ÖжÏÏòÁ¿±í¿ªÊ¼
                EXPORT  __Vectors_End                        ;
                EXPORT  __Vectors_Size                       ;
                                                             ;·ÖÅäÒ»¸ö»ò¶à¸ö×ֵĴ洢Æ÷£¬ÔÚËĸö×ֽڵı߽çÉÏ¶ÔÆë£¬²¢¶¨Òå´æ´¢Æ÷µÄÔËÐÐʱ³õÖµ
__Vectors       DCD     __initial_sp               ; Top of Stack
                DCD     Reset_Handler              ; Reset Handler
                DCD     NMI_Handler                ; NMI Handler
                DCD     HardFault_Handler          ; Hard Fault Handler
                DCD     MemManage_Handler          ; MPU Fault Handler
                DCD     BusFault_Handler           ; Bus Fault Handler
                DCD     UsageFault_Handler         ; Usage Fault Handler
                DCD     0                          ; Reserved
                DCD     0                          ; Reserved
                DCD     0                          ; Reserved
                DCD     0                          ; Reserved
                DCD     SVC_Handler                ; SVCall Handler
                DCD     DebugMon_Handler           ; Debug Monitor Handler
                DCD     0                          ; Reserved
                DCD     PendSV_Handler             ; PendSV Handler
                DCD     SysTick_Handler            ; SysTick Handler


                ; External Interrupts              ;ÒÔÉÏΪCoretex M4ÄÚºË×Ô´øµÄ£¬ÒÔÏÂΪÍⲿÖжÏÏòÁ¿±í
                DCD     WWDG_IRQHandler                   ; Window WatchDog
                DCD     PVD_IRQHandler                    ; PVD through EXTI Line detection
                DCD     TAMP_STAMP_IRQHandler             ; Tamper and TimeStamps through the EXTI line
                DCD     RTC_WKUP_IRQHandler               ; RTC Wakeup through the EXTI line
                DCD     FLASH_IRQHandler                  ; FLASH
                DCD     RCC_IRQHandler                    ; RCC
                DCD     EXTI0_IRQHandler                  ; EXTI Line0
                DCD     EXTI1_IRQHandler                  ; EXTI Line1
                DCD     EXTI2_TSC_IRQHandler              ; EXTI Line2 and Touch Sense controller
                DCD     EXTI3_IRQHandler                  ; EXTI Line3
                DCD     EXTI4_IRQHandler                  ; EXTI Line4
                DCD     DMA1_Channel1_IRQHandler          ; DMA1 Channel 1
                DCD     DMA1_Channel2_IRQHandler          ; DMA1 Channel 2
                DCD     DMA1_Channel3_IRQHandler          ; DMA1 Channel 3
                DCD     DMA1_Channel4_IRQHandler          ; DMA1 Channel 4
                DCD     DMA1_Channel5_IRQHandler          ; DMA1 Channel 5
                DCD     DMA1_Channel6_IRQHandler          ; DMA1 Channel 6
                DCD     DMA1_Channel7_IRQHandler          ; DMA1 Channel 7
                DCD     ADC1_2_IRQHandler                 ; ADC1 and ADC2
                DCD     USB_HP_CAN_TX_IRQHandler          ; USB Device High Priority or CAN TX
                DCD     USB_LP_CAN_RX0_IRQHandler         ; USB Device Low Priority or CAN RX0
                DCD     CAN_RX1_IRQHandler                ; CAN RX1
                DCD     CAN_SCE_IRQHandler                ; CAN SCE
                DCD     EXTI9_5_IRQHandler                ; External Line[9:5]s
                DCD     TIM1_BRK_TIM15_IRQHandler         ; TIM1 Break and TIM15
                DCD     TIM1_UP_TIM16_IRQHandler          ; TIM1 Update and TIM16
                DCD     TIM1_TRG_COM_TIM17_IRQHandler     ; TIM1 Trigger and Commutation and TIM17
                DCD     TIM1_CC_IRQHandler                ; TIM1 Capture Compare
                DCD     TIM2_IRQHandler                   ; TIM2
                DCD     TIM3_IRQHandler                   ; TIM3
                DCD     TIM4_IRQHandler                   ; TIM4
                DCD     I2C1_EV_IRQHandler                ; I2C1 Event
                DCD     I2C1_ER_IRQHandler                ; I2C1 Error
                DCD     I2C2_EV_IRQHandler                ; I2C2 Event
                DCD     I2C2_ER_IRQHandler                ; I2C2 Error
                DCD     SPI1_IRQHandler                   ; SPI1
                DCD     SPI2_IRQHandler                   ; SPI2
                DCD     USART1_IRQHandler                 ; USART1
                DCD     USART2_IRQHandler                 ; USART2
                DCD     USART3_IRQHandler                 ; USART3
                DCD     EXTI15_10_IRQHandler              ; External Line[15:10]s
                DCD     RTC_Alarm_IRQHandler              ; RTC Alarm (A and B) through EXTI Line
                DCD     USBWakeUp_IRQHandler              ; USB Wakeup through EXTI line
                DCD     0                                 ; Reserved
                DCD     0                                 ; Reserved
                DCD     0                                 ; Reserved
                DCD     0                                 ; Reserved
                DCD     0                                 ; Reserved
                DCD     0                                 ; Reserved
                DCD     0                                 ; Reserved
                DCD     0                                 ; Reserved
                DCD     SPI3_IRQHandler                   ; SPI3
                DCD     UART4_IRQHandler                  ; UART4
                DCD     UART5_IRQHandler                  ; UART5
                DCD     TIM6_DAC_IRQHandler               ; TIM6 and DAC1&2 underrun errors
                DCD     0                                 ; Reserved
                DCD     DMA2_Channel1_IRQHandler          ; DMA2 Channel 1
                DCD     DMA2_Channel2_IRQHandler          ; DMA2 Channel 2
                DCD     DMA2_Channel3_IRQHandler          ; DMA2 Channel 3
                DCD     DMA2_Channel4_IRQHandler          ; DMA2 Channel 4
                DCD     DMA2_Channel5_IRQHandler          ; DMA2 Channel 5
                DCD     0                                 ; Reserved
                DCD     0                                 ; Reserved
                DCD     0                                 ; Reserved
                DCD     COMP1_2_IRQHandler                ; COMP1 and COMP2
                DCD     COMP4_6_IRQHandler                ; COMP4 and COMP6
                DCD     0                                 ; Reserved
                DCD     0                                 ; Reserved
                DCD     0                                 ; Reserved
                DCD     0                                 ; Reserved
                DCD     0                                 ; Reserved
                DCD     0                                 ; Reserved
                DCD     0                                 ; Reserved
                DCD     0                                 ; Reserved
                DCD     USB_HP_IRQHandler                 ; USB High Priority remap
                DCD     USB_LP_IRQHandler                 ; USB Low Priority remap
                DCD     USBWakeUp_RMP_IRQHandler          ; USB Wakeup remap through EXTI
                DCD     0                                 ; Reserved
                DCD     0                                 ; Reserved
                DCD     0                                 ; Reserved
                DCD     0                                 ; Reserved
                DCD     FPU_IRQHandler                    ; FPU


__Vectors_End                                             ; ÏòÁ¿±í½áÊø±êÖ¾


__Vectors_Size  EQU  __Vectors_End - __Vectors            ; ¼ÆËãÏòÁ¿±íµØÖ·¿Õ¼ä´óС


                AREA    |.text|, CODE, READONLY           ; |.text| ±íʾÓÉC±àÒë³ÌÐò²úÉúµÄ´úÂë¶Î£¬»òÒÔijÖÖ·½Ê½ÓëC¿â¹ØÁªµÄ´úÂë¶Î
                                                          ; ¶¨ÒåC±àÒëÆ÷Ô´´úÂëµÄ´úÂë¶Î£¬Ö»¶Á
; Reset handler                                           
Reset_Handler    PROC                                     ; ÀûÓÃPROC ENDPÕâÒ»¶ÔαָÁî°Ñ³ÌÐò¶Î·ÖΪÈô¸É¸ö¹ý³Ì£¬Ê¹³ÌÐòµÄ½á¹¹¸ü¼ÓÇåÎú
                 EXPORT  Reset_Handler             [WEAK] ; ´Ë´¦±íʾÈõ¶¨Ò壬ÔÚÍⲿûÓж¨Òå¸Ã·ûºÅʱµ¼³ö¸Ã·ûºÅReset_Handler¡£Èõ¶¨Ò壺ÈôÍâÃæÉùÃ÷Á˵ϰ£¬»áÓÅÏȵ÷ÓÃÍâÃæµÄ
        IMPORT  SystemInit                                ; IMPROT αָÁÓÃÓÚ֪ͨ±àÒëÆ÷ҪʹÓõıêºÅÔÚÆäËûÔ´ÎļþÖж¨Ò壬µ«ÒªÔÚµ±Ç°Ô´ÎļþÖÐÒýÓÃ
        IMPORT  __main                                    ; ¶øÇÒÎÞÂÛµ±Ç°Ô´ÎļþÊÇ·ñÒýÓøñêºÅ£¬¸Ã±êºÅ¾ù»á±»¼ÓÈëµ½µ±Ç°Ô´ÎļþµÄ·ûºÅ±íÖÐ


                 LDR     R0, =SystemInit                  ; ×°ÔØ¼Ä´æÆ÷Ö¸Áî
                 BLX     R0                               ; ´øÁ´½ÓµÄÌø×ª£¬Çл»Ö¸Á
                 LDR     R0, =__main                      ; 
                 BX      R0                               ; Çл»Ö¸Á£¬mainº¯Êý²»·µ»Ø£¬Ìøµ½_main,½øÈëCµÄÊÀ½ç
                 ENDP


; Dummy Exception Handlers (infinite loops which can be modified)


NMI_Handler     PROC                                      ; Êä³öÒì³£ÏòÁ¿±í±êºÅ£¬·½±ãÍⲿʵÏÖÒì³£µÄ¾ßÌ幦ÄÜ
                EXPORT  NMI_Handler                [WEAK]
                B       .
                ENDP
HardFault_Handler\
                PROC
                EXPORT  HardFault_Handler          [WEAK]
                B       .
                ENDP
MemManage_Handler\
                PROC
                EXPORT  MemManage_Handler          [WEAK]
                B       .
                ENDP
BusFault_Handler\
                PROC
                EXPORT  BusFault_Handler           [WEAK]
                B       .
                ENDP
UsageFault_Handler\
                PROC
                EXPORT  UsageFault_Handler         [WEAK]
                B       .
                ENDP
SVC_Handler     PROC
                EXPORT  SVC_Handler                [WEAK]
                B       .
                ENDP
DebugMon_Handler\
                PROC
                EXPORT  DebugMon_Handler           [WEAK]
                B       .
                ENDP
PendSV_Handler  PROC
                EXPORT  PendSV_Handler             [WEAK]
                B       .
                ENDP
SysTick_Handler PROC
                EXPORT  SysTick_Handler            [WEAK]
                B       .
                ENDP


Default_Handler PROC


                EXPORT  WWDG_IRQHandler                   [WEAK]
                EXPORT  PVD_IRQHandler                    [WEAK]
                EXPORT  TAMP_STAMP_IRQHandler             [WEAK]
                EXPORT  RTC_WKUP_IRQHandler               [WEAK]
                EXPORT  FLASH_IRQHandler                  [WEAK]
                EXPORT  RCC_IRQHandler                    [WEAK]
                EXPORT  EXTI0_IRQHandler                  [WEAK]
                EXPORT  EXTI1_IRQHandler                  [WEAK]
                EXPORT  EXTI2_TSC_IRQHandler              [WEAK]
                EXPORT  EXTI3_IRQHandler                  [WEAK]
                EXPORT  EXTI4_IRQHandler                  [WEAK]
                EXPORT  DMA1_Channel1_IRQHandler          [WEAK]
                EXPORT  DMA1_Channel2_IRQHandler          [WEAK]
                EXPORT  DMA1_Channel3_IRQHandler          [WEAK]
                EXPORT  DMA1_Channel4_IRQHandler          [WEAK]
                EXPORT  DMA1_Channel5_IRQHandler          [WEAK]
                EXPORT  DMA1_Channel6_IRQHandler          [WEAK]
                EXPORT  DMA1_Channel7_IRQHandler          [WEAK]
                EXPORT  ADC1_2_IRQHandler                 [WEAK]
                EXPORT  USB_HP_CAN_TX_IRQHandler          [WEAK]
                EXPORT  USB_LP_CAN_RX0_IRQHandler         [WEAK]
                EXPORT  CAN_RX1_IRQHandler                [WEAK]
                EXPORT  CAN_SCE_IRQHandler                [WEAK]
                EXPORT  EXTI9_5_IRQHandler                [WEAK]
                EXPORT  TIM1_BRK_TIM15_IRQHandler         [WEAK]
                EXPORT  TIM1_UP_TIM16_IRQHandler          [WEAK]
                EXPORT  TIM1_TRG_COM_TIM17_IRQHandler     [WEAK]
                EXPORT  TIM1_CC_IRQHandler                [WEAK]
                EXPORT  TIM2_IRQHandler                   [WEAK]
                EXPORT  TIM3_IRQHandler                   [WEAK]
                EXPORT  TIM4_IRQHandler                   [WEAK]
                EXPORT  I2C1_EV_IRQHandler                [WEAK]
                EXPORT  I2C1_ER_IRQHandler                [WEAK]
                EXPORT  I2C2_EV_IRQHandler                [WEAK]
                EXPORT  I2C2_ER_IRQHandler                [WEAK]
                EXPORT  SPI1_IRQHandler                   [WEAK]
                EXPORT  SPI2_IRQHandler                   [WEAK]
                EXPORT  USART1_IRQHandler                 [WEAK]
                EXPORT  USART2_IRQHandler                 [WEAK]
                EXPORT  USART3_IRQHandler                 [WEAK]
                EXPORT  EXTI15_10_IRQHandler              [WEAK]
                EXPORT  RTC_Alarm_IRQHandler              [WEAK]
                EXPORT  USBWakeUp_IRQHandler               [WEAK]
                EXPORT  SPI3_IRQHandler                   [WEAK]
                EXPORT  UART4_IRQHandler                  [WEAK]
                EXPORT  UART5_IRQHandler                  [WEAK]
                EXPORT  TIM6_DAC_IRQHandler               [WEAK]
                EXPORT  DMA2_Channel1_IRQHandler          [WEAK]
                EXPORT  DMA2_Channel2_IRQHandler          [WEAK]
                EXPORT  DMA2_Channel3_IRQHandler          [WEAK]
                EXPORT  DMA2_Channel4_IRQHandler          [WEAK]
                EXPORT  DMA2_Channel5_IRQHandler          [WEAK]
                EXPORT  COMP1_2_IRQHandler                [WEAK]
                EXPORT  COMP4_6_IRQHandler                [WEAK]
                EXPORT  USB_HP_IRQHandler                 [WEAK]
                EXPORT  USB_LP_IRQHandler                 [WEAK]
                EXPORT  USBWakeUp_RMP_IRQHandler              [WEAK]
                EXPORT  FPU_IRQHandler                    [WEAK]
;ÈçÏÂÖ»ÊǶ¨ÒåÒ»¸ö¿Õº¯Êý
WWDG_IRQHandler
PVD_IRQHandler
TAMP_STAMP_IRQHandler
RTC_WKUP_IRQHandler
FLASH_IRQHandler
RCC_IRQHandler
EXTI0_IRQHandler
EXTI1_IRQHandler
EXTI2_TSC_IRQHandler
EXTI3_IRQHandler
EXTI4_IRQHandler
DMA1_Channel1_IRQHandler
DMA1_Channel2_IRQHandler
DMA1_Channel3_IRQHandler
DMA1_Channel4_IRQHandler
DMA1_Channel5_IRQHandler
DMA1_Channel6_IRQHandler
DMA1_Channel7_IRQHandler
ADC1_2_IRQHandler
USB_HP_CAN_TX_IRQHandler
USB_LP_CAN_RX0_IRQHandler
CAN_RX1_IRQHandler
CAN_SCE_IRQHandler
EXTI9_5_IRQHandler
TIM1_BRK_TIM15_IRQHandler
TIM1_UP_TIM16_IRQHandler
TIM1_TRG_COM_TIM17_IRQHandler
TIM1_CC_IRQHandler
TIM2_IRQHandler
TIM3_IRQHandler
TIM4_IRQHandler
I2C1_EV_IRQHandler
I2C1_ER_IRQHandler
I2C2_EV_IRQHandler
I2C2_ER_IRQHandler
SPI1_IRQHandler
SPI2_IRQHandler
USART1_IRQHandler
USART2_IRQHandler
USART3_IRQHandler
EXTI15_10_IRQHandler
RTC_Alarm_IRQHandler
USBWakeUp_IRQHandler
SPI3_IRQHandler
UART4_IRQHandler
UART5_IRQHandler
TIM6_DAC_IRQHandler
DMA2_Channel1_IRQHandler
DMA2_Channel2_IRQHandler
DMA2_Channel3_IRQHandler
DMA2_Channel4_IRQHandler
DMA2_Channel5_IRQHandler
COMP1_2_IRQHandler
COMP4_6_IRQHandler
USB_HP_IRQHandler
USB_LP_IRQHandler
USBWakeUp_RMP_IRQHandler
FPU_IRQHandler


                B       .    


                ENDP


                ALIGN       ; ĬÈÏÊÇ×Ö¶ÔÆë·½Ê½£¬Ò²ËµÃ÷ÁË´úÂëÊÇ4×Ö½Ú¶ÔÆëµÄ


;*******************************************************************************
; User Stack and Heap initialization
;*******************************************************************************
                 IF      :DEF:__MICROLIB               ;ÅжÏÊÇ·ñʹÓÃDEF:__MICROLIB 


                 EXPORT  __initial_sp                  ;ʹÓõϰ£¬½«Õ»¶¥µØÖ·£¬¶ÑʼĩµØÖ·¸³ÓèÈ«¾ÖÌØÐÔ£¬Ê¹Íⲿ³ÌÐò¿ÉÒÔʹÓÃ
                 EXPORT  __heap_base
                 EXPORT  __heap_limit


                 ELSE                                   ;Èç¹ûʹÓÃĬÈÏC¿âÔËÐÐʱ


                 IMPORT  __use_two_region_memory        ;¶¨ÒåÈ«¾Ö±êºÅ_use_two_region_memory 
                 EXPORT  __user_initial_stackheap       ;ÉùÃ÷È«¾Ö±êºÅ__user_initial_stackheap£¬ÕâÑùÍⲿ³ÌÐòÒ²¿ÉÒÔµ÷Óô˱êºÅ
                                                        ;½øÐжÑÕ»ºÍ¶ÑµÄ¸³Öµ£¬ÔÚ_mainº¯ÊýÖ´Ðйý³ÌÖе÷ÓÃ
__user_initial_stackheap                                ;±êºÅ__user_initial_stackheap £¬±íʾÓû§¶ÑÕ»³õʼ»¯
;´Ë´¦Êdzõʼ»¯Á½ÇøµÄ¶ÑÕ»¿Õ¼ä£¬¶ÑÊÇÓɵ͵½¸ßµÄÔö³¤£¬Õ»ÊÇÓɸßÏòµÍÉú³¤£¬Á½¸öÊÇÏ໥¶ÀÁ¢µÄÊý¾Ý¶Î£¬²¢²»Äܽ»²æÊ¹ÓÃ
                 LDR     R0, =  Heap_Mem                ;±£´æ¶ÑʼµØÖ·
                 LDR     R1, =(Stack_Mem + Stack_Size)  ;±£´æÕ»µÄ´óС
                 LDR     R2, = (Heap_Mem +  Heap_Size)  ;±£´æ¶ÑµÄ´óС
                 LDR     R3, = Stack_Mem                ;±£´æÕ»¶¥Ö¸Õë
                 BX      LR


                 ALIGN


                 ENDIF


                 END                                    ;END ָʾ»ã±àÆ÷£¬Òѵ½´ïÒ»¸öÔ´ÎļþµÄĩβ


;************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE*****

 

9  power_down.c

#include "power_down.h"
#include "stm32f30x_gpio.h"
#include "delay.h"


void power_down(void)
{
GPIO_InitTypeDef GPIO_InitStructure;



// RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE);  // ¿ªGPIOAʱÖÓ
GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_1;
GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);               // ÅäÖÃPA1
GPIO_ResetBits(GPIOA,GPIO_Pin_1);                     // PA1 ÖÃ1

}


10 power_on.c

#include "power_on.h"
#include "stm32f30x_gpio.h"


void power_on()
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA,ENABLE);  // ¿ªGPIOAʱÖÓ

GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_1;
GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStructure);               // ÅäÖÃPA1

GPIO_SetBits(GPIOA,GPIO_Pin_1);                     // PA1 ÖÃ1

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB,ENABLE);// ¿ªGPIOBʱÖÓ
GPIO_InitStructure.GPIO_Mode  = GPIO_Mode_OUT;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_0;
GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB,&GPIO_InitStructure);             // ÅäÖÃPB0  
  GPIO_SetBits(GPIOB,GPIO_Pin_0);                   // PB0 ÖÃ1

}

11 rs485.h

#ifndef __RS485_H
#define __RS485_H  
#include "stm32f30x.h" 
#include <stdio.h>




typedef struct __FILE FILE;
extern u8 RS485_REC_LEN ;
extern u8 rs485buf[5]; //½ÓÊÕ»º³å,×î´ó64¸ö×Ö½Ú
extern u8 RS485_RX_CNT;   //½ÓÊÕµ½µÄÊý¾Ý³¤¶È
extern u16 USART_RX_BUF[200];
extern u16 RS485_RX_STA;
extern u8 cnt;


void RS485_Init(u32 bound);
void RS485_Send_Data(u8 *buf,u8 len);
void RS485_Receive_Data(u8 *buf,u8 *len);


#define MCU_RX_EN GPIO_ResetBits(GPIOA,GPIO_Pin_12)
#define MCU_TX_EN GPIO_SetBits(GPIOA,GPIO_Pin_12)




#endif

12 delay.h

#ifndef __DELAY_H
#define __DELAY_H   
#include "stm32f30x.h"   
 


void delay(u32 n);


#endif

13 AD.h

#ifndef __AD_H


#include "stm32f30x_gpio.h"
#include "stm32f30x_rcc.h"
#include "stm32f30x_adc.h"
#include "stm32f30x.h"


void adc_Init(void);
float getresult(float y);
u16 Get_Adc(ADC_TypeDef *ADCx,u8 ch);
u16 Get_Adc_Average(u8 ch,u8 times);
extern float value_buf[20];
#define A_D_C ADC2


#endif

14 dma.h

#ifndef __DMA_H
#include "stm32f30x.h"
void mydma(void);
extern u16  ADC1_ConvertedValue[5];       
extern u16  ADC2_ConvertedValue[20];

#endif

15 power_down.h

#ifndef __power_down_H
void power_down(void);


#endif

16 power_on.h

#ifndef __POWER_ON_H
void power_on(void);


#endif

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值