乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      ADC1-DMA

       jianke 2010-01-29
       

      ADC1-DMA

      #include "stm32f10x_lib.h"

      /* Private typedef -----------------------------------------------------------*/
      /* Private define ------------------------------------------------------------*/
      #define ADC1_DR_Address    ((u32)0x4001244C)

      /* Private macro -------------------------------------------------------------*/
      /* Private variables ---------------------------------------------------------*/
      ADC_InitTypeDef ADC_InitStructure;
      DMA_InitTypeDef DMA_InitStructure;
      vu16 ADCConvertedValue;
      ErrorStatus HSEStartUpStatus;
         
      /* Private function prototypes -----------------------------------------------*/
      void RCC_Configuration(void);
      void GPIO_Configuration(void);
      void NVIC_Configuration(void);
       
      /* Private functions ---------------------------------------------------------*/

      /*******************************************************************************
      * Function Name  : main
      * Description    : Main program
      * Input          : None
      * Output         : None
      * Return         : None
      *******************************************************************************/
      int main(void)
      {
      #ifdef DEBUG
        debug();
      #endif

        /* System clocks configuration ---------------------------------------------*/
        RCC_Configuration();

        /* NVIC configuration ------------------------------------------------------*/
        NVIC_Configuration();

        /* GPIO configuration ------------------------------------------------------*/
        GPIO_Configuration();

        /* DMA1 channel1 configuration ----------------------------------------------*/
        DMA_DeInit(DMA1_Channel1);   //復(fù)位DMA1的通道1
        DMA_InitStructure.DMA_PeripheralBaseAddr = ADC1_DR_Address;//DMA對(duì)應(yīng)的外設(shè)基礎(chǔ)地址,這個(gè)地址可以在相應(yīng)的DATASHEET上查
        DMA_InitStructure.DMA_MemoryBaseAddr = (u32)&ADCConvertedValue;  //定義DMA通道存儲(chǔ)器地址
        DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;   //指定外設(shè)為源地址
        DMA_InitStructure.DMA_BufferSize = 1;    //定義DMA緩存大小為1
        DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;  //接收一次后,外設(shè)寄存器地址不變。
        DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable;    //設(shè)置DMA內(nèi)存模式為非遞增模式。ENABLE?
        DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;  //定義外設(shè)數(shù)據(jù)寬度為16位。
        DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;    //定義存儲(chǔ)器數(shù)據(jù)寬度為16位。
        DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;     //設(shè)置DMA為連續(xù)循環(huán)的傳輸模式。
        DMA_InitStructure.DMA_Priority = DMA_Priority_High;     //高優(yōu)先級(jí)
        DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;        //禁止DMA通道的M2M傳輸模式。
        DMA_Init(DMA1_Channel1, &DMA_InitStructure);         //初始化DMA通道1
                           
        /* Enable DMA1 channel1 */
        DMA_Cmd(DMA1_Channel1, ENABLE);           //使能DMA通道1
          
        /* ADC1 configuration ------------------------------------------------------*/
        ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;  //設(shè)置轉(zhuǎn)換模式為獨(dú)立轉(zhuǎn)換  。
        ADC_InitStructure.ADC_ScanConvMode = ENABLE;     //開啟掃描轉(zhuǎn)換模式。
        ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;  // 開啟連續(xù)轉(zhuǎn)換模式。
        ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_None;  //關(guān)閉ADC外部轉(zhuǎn)換觸發(fā)。
        ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;  //設(shè)置為右對(duì)齊方式。
        ADC_InitStructure.ADC_NbrOfChannel = 1;      //開啟通道數(shù)1個(gè)。
        ADC_Init(ADC1, &ADC_InitStructure);       //ADC初始化  。

        /* ADC1 regular channel14 configuration */
        ADC_RegularChannelConfig(ADC1, ADC_Channel_14, 1, ADC_SampleTime_55Cycles5);   //規(guī)則組通道設(shè)置

        /* Enable ADC1 DMA */
        ADC_DMACmd(ADC1, ENABLE);    //和DMA關(guān)聯(lián)
       
        /* Enable ADC1 */
        ADC_Cmd(ADC1, ENABLE);     //開戶ADC1

        /* Enable ADC1 reset calibaration register */  
        ADC_ResetCalibration(ADC1);      //重置校準(zhǔn)。
        /* Check the end of ADC1 reset calibration register */
        while(ADC_GetResetCalibrationStatus(ADC1));   //等待重置校準(zhǔn)完成。

        /* Start ADC1 calibaration */
        ADC_StartCalibration(ADC1);    //開始較準(zhǔn)。
        /* Check the end of ADC1 calibration */
        while(ADC_GetCalibrationStatus(ADC1));    //等待校準(zhǔn)完成。
          
        /* Start ADC1 Software Conversion */
        ADC_SoftwareStartConvCmd(ADC1, ENABLE);  //連續(xù)轉(zhuǎn)換開始。

        while (1)
        {
        }
      }

      /*******************************************************************************
      * Function Name  : RCC_Configuration
      * Description    : Configures the different system clocks.
      * Input          : None
      * Output         : None
      * Return         : None
      *******************************************************************************/
      void RCC_Configuration(void)    //配置系統(tǒng)時(shí)鐘
      {
        /* RCC system reset(for debug purpose) */
        RCC_DeInit();      //復(fù)位RCC

        /* Enable HSE */
        RCC_HSEConfig(RCC_HSE_ON);    //使能外部晶振

        /* Wait till HSE is ready */
        HSEStartUpStatus = RCC_WaitForHSEStartUp(); //等待外部晶振穩(wěn)定

        if(HSEStartUpStatus == SUCCESS)   //如果外部晶振啟動(dòng)成功則進(jìn)行下一步操作。
        {
          /* Enable Prefetch Buffer */
          FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); //選擇FLASH預(yù)取指緩存的模式

          /* Flash 2 wait state */
          FLASH_SetLatency(FLASH_Latency_2);   //設(shè)置FLASH存儲(chǔ)器延時(shí)時(shí)鐘周期數(shù)。
       
          /* HCLK = SYSCLK */
          RCC_HCLKConfig(RCC_SYSCLK_Div1);    //設(shè)置AHB時(shí)鐘=系統(tǒng)時(shí)鐘
       
          /* PCLK2 = HCLK */
          RCC_PCLK2Config(RCC_HCLK_Div1);   //設(shè)置APB2=HCLK時(shí)鐘

          /* PCLK1 = HCLK/2 */
          RCC_PCLK1Config(RCC_HCLK_Div2);     //設(shè)置APB1時(shí)鐘=HCLK時(shí)鐘/2。

          /* ADCCLK = PCLK2/4 */
          RCC_ADCCLKConfig(RCC_PCLK2_Div4);   // 設(shè)置ADC時(shí)鐘=APB2時(shí)鐘/4。
       
          /* PLLCLK = 8MHz * 7 = 56 MHz */
          RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_7);  //設(shè)置PLL時(shí)鐘源和PLL的輸入時(shí)鐘=7倍的HCLK

          /* Enable PLL */
          RCC_PLLCmd(ENABLE);     //使能PLL

          /* Wait till PLL is ready */
          while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) //等待PLL穩(wěn)定。
          {
          }

          /* Select PLL as system clock source */
          RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);    //系統(tǒng)時(shí)鐘來自PLL

          /* Wait till PLL is used as system clock source */
          while(RCC_GetSYSCLKSource() != 0x08)  //切換時(shí)鐘后等待系統(tǒng)穩(wěn)定。PLL返回用作系統(tǒng)時(shí)鐘的時(shí)鐘源。0x08:PLL作為系統(tǒng)時(shí)鐘
          {
          }
        }

      /* Enable peripheral clocks --------------------------------------------------*/
        /* Enable DMA1 clock */
        RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);  //啟動(dòng)DMA1的時(shí)鐘

        /* Enable ADC1 and GPIOC clock */
        RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_GPIOC, ENABLE);//啟動(dòng)ADC1和GPIOC的時(shí)鐘。
      }

      /*******************************************************************************
      * Function Name  : GPIO_Configuration
      * Description    : Configures the different GPIO ports.
      * Input          : None
      * Output         : None
      * Return         : None
      *******************************************************************************/
      void GPIO_Configuration(void)
      {
        GPIO_InitTypeDef GPIO_InitStructure;

        /* Configure PC.04 (ADC Channel14) as analog input -------------------------*/
        GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
        GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;
        GPIO_Init(GPIOC, &GPIO_InitStructure);
      }

      /*******************************************************************************
      * Function Name  : NVIC_Configuration
      * Description    : Configures Vector Table base location.
      * Input          : None
      * Output         : None
      * Return         : None
      *******************************************************************************/
      void NVIC_Configuration(void)
      {
      #ifdef  VECT_TAB_RAM 
        /* Set the Vector Table base location at 0x20000000 */
        NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
      #else  /* VECT_TAB_FLASH  */
        /* Set the Vector Table base location at 0x08000000 */
        NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);  
      #endif
      }

      #ifdef  DEBUG
      /*******************************************************************************
      * Function Name  : assert_failed
      * Description    : Reports the name of the source file and the source line number
      *                  where the assert_param error has occurred.
      * Input          : - file: pointer to the source file name
      *                  - line: assert_param error line source number
      * Output         : None
      * Return         : None
      *******************************************************************************/
      void assert_failed(u8* file, u32 line)
      {
        /* User can add his own implementation to report the file name and line number,
           ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

        /* Infinite loop */
        while (1)
        {
        }
      }
      #endif

        本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請(qǐng)注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評(píng)論

        發(fā)表

        請(qǐng)遵守用戶 評(píng)論公約

        類似文章 更多