久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 4174|回復: 1
打印 上一主題 下一主題
收起左側

STM32采集AD后FFT源程序

[復制鏈接]
跳轉到指定樓層
樓主
ID:456205 發表于 2018-12-27 10:40 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
STM32采集AD后FFT

單片機源程序如下:
  1.                                    /* Includes ------------------------------------------------------------------*/
  2. #include "stm32f10x.h"                                           //調用的庫文件
  3. #include "stm32f10x_conf.h"
  4. #include "stm32f10x_adc.h"
  5. #include "stm32f10x_rcc.h"
  6. #include "stm32f10x_gpio.h"
  7. #include "stm32f10x_flash.h"
  8. #include "misc.h"
  9. #include"stdio.h"
  10. #define NPT 256   
  11. #include <math.h>
  12. #include "stm32_dsp.h"
  13. #include "sys.h"
  14. #include "delay.h"
  15. #include "tftlcd.h"                    
  16. #include "touch.h"   
  17. #include "platform_config.h"        
  18. #include "stm32f10x_exti.h"        
  19. #include "fsmc_sram.h"
  20. #include "stm32f10x_dac.h"
  21. /*定義變量*/
  22. int adc_count1=0;
  23. int adc_count2=0;
  24. int AD_value0[NPT]={0};
  25. int AD_value1[NPT]={0};
  26. long lBUFOUT1[NPT]={0};        /* Complex output vector */
  27. long lBUFMAG1[NPT]={0};       /* Magnitude vector */
  28. long lBUFMAG0[NPT]={0};
  29. long lBUFMAG2[NPT]={0};
  30. unsigned int fy_cc2=7031;
  31. int source_x[240]={0};                //液晶畫點移位地址數組
  32. u8 j=0,mul=1,func=0,i=0,mul_old=1;
  33. float lX,lY,Mag;
  34. ADC_InitTypeDef ADC_InitStructure;
  35. vu16 ADC_ConvertedValue;
  36. ErrorStatus HSEStartUpStatus;
  37. TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
  38. TIM_OCInitTypeDef  TIM_OCInitStructure;   
  39. GPIO_InitTypeDef GPIO_InitStructure;  
  40.    DAC_InitTypeDef DAC_InitStructure;
  41. ErrorStatus HSEStartUpStatus;
  42. /* Private function prototypes -----------------------------------------------*/
  43. void RCC_Configuration(void);                                   //申明時鐘初始化函數
  44. void GPIO_Configuration(void);                                   //申明IO初始化函數
  45. void adc_Configuration(void);
  46. void TIM_Configuration(void);
  47. void RCC_Configuration(void);
  48. void GPIO_Configuration(void);
  49. void Delay(__IO uint32_t nCount);
  50. void NVIC_Configuration(void);
  51. void lcd_rst(void);
  52. void powerMag(long *input,int nfill,long *output);
  53. void delay_us(u32 Nus);
  54. void delay_init(u8 SYSCLK);
  55. void tft_configuration(void);
  56. void funcselect(void);
  57. void mulselect(void);
  58. void scan_minus(void);
  59. void scan_add(void);
  60. void DAC_Configuration(void);
  61. /* Private functions ---------------------------------------------------------*/

  62. /*******************************************************************************
  63. * Function Name  : main
  64. * Description    : Main program
  65. * Input          : None
  66. * Output         : None
  67. * Return         : None
  68. *******************************************************************************/

  69. int main(void)
  70. {
  71. #ifdef DEBUG
  72.   debug();
  73. #endif
  74.   DAC_Configuration();
  75.   RCC_Configuration();
  76.   delay_init(72);
  77.   GPIO_Configuration();
  78.   RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);  
  79.   GPIO_Configuration();
  80.   GPIO_SetBits(GPIOC, GPIO_Pin_7 );
  81.   /* Configure FSMC Bank1 NOR/PSRAM */
  82.   FSMC_LCD_Init();
  83.   LCD_Init();
  84.   LCD_test(0xffff);
  85.   delay_us(0xffff);
  86.   LCD_test(0xffff);
  87.   delay_us(0xffff);
  88.   NVIC_Configuration();
  89.   tft_configuration();
  90.         for(i=1;i<240;i++)
  91. {
  92.         source_x[i]=i*2;                        
  93. }
  94.   adc_Configuration();         
  95.   TIM_Configuration();
  96. while(1)
  97. {  
  98.    if(adc_count1>=255&&func==0)//采樣點數到了255
  99.      {
  100.         if(j==0)
  101.                 {
  102.                         cr4_fft_256_stm32(lBUFOUT1, AD_value1, NPT);          //FFT計算
  103.                         powerMag(lBUFOUT1,110,lBUFMAG0);
  104.                         
  105.                         POINT_COLOR=0xffff;                //以下是屏幕畫點
  106.                    for(i=0;i<109;i++)
  107.                    {
  108.                         TFT_Drawl(source_x[i]+20,300-lBUFMAG2[i],300-lBUFMAG1[i]);
  109.                    }
  110.                    POINT_COLOR=BRED;
  111.                    for(i=0;i<109;i++)
  112.                    {               
  113.                         TFT_Drawl(source_x[i]+20,300,300-lBUFMAG1[i]);               
  114.                    }
  115.                    j++;
  116.                 }
  117.            else
  118.                 {  
  119.                    cr4_fft_256_stm32(lBUFOUT1, AD_value0, NPT);          //FFT計算
  120.                    for(i=0;i<109;i++)  lBUFMAG2[i]=lBUFMAG1[i];//保存初始結果
  121.                    powerMag(lBUFOUT1,110,lBUFMAG1);          //功率計算  
  122.                         for(i=0;i<109;i++)
  123.                           {               
  124.                                 lBUFMAG1[i]=(lBUFMAG1[i]+lBUFMAG0[i])*mul;
  125.                                 if(lBUFMAG1[i]>280) lBUFMAG1[i]=280;
  126.                                         else  lBUFMAG1[i]=lBUFMAG1[i];         
  127.                           }
  128.                  j--;
  129.                 }         
  130.         }
  131. /************************************************/         
  132.    if(adc_count1>=255&&func==1)//采樣點數到了255
  133.    {
  134.            if(j==0)
  135.         {
  136.            cr4_fft_256_stm32(lBUFOUT1, AD_value1, NPT);          //FFT計算
  137.            powerMag(lBUFOUT1,110,lBUFMAG0);
  138.                
  139.                 POINT_COLOR=0xffff;
  140.            for(i=0;i<109;i++)
  141.            {
  142.                 TFT_Drawl(source_x[i]+20,300-lBUFMAG2[i],300-lBUFMAG1[i]);
  143.            }
  144.            POINT_COLOR=BRED;
  145.            for(i=0;i<109;i++)
  146.            {               
  147.                 TFT_Drawl(source_x[i]+20,300,300-lBUFMAG1[i]);
  148.                 lBUFMAG2[i]=lBUFMAG1[i];        //        lBUFMAG2頻率值,lBUFMAG1電壓值
  149.            }
  150.            
  151.            j++;
  152.                 TIM_CtrlPWMOutputs(TIM1, DISABLE);  
  153.         }
  154.    else
  155.     {  
  156.            cr4_fft_256_stm32(lBUFOUT1, AD_value0, NPT);          //FFT計算
  157.            for(i=0;i<109;i++)  lBUFMAG2[i]=lBUFMAG1[i];
  158.            powerMag(lBUFOUT1,110,lBUFMAG1);            
  159.                 for(i=0;i<109;i++)
  160.                   {               
  161.                 lBUFMAG1[i]=(lBUFMAG1[i]+lBUFMAG0[i])*mul;
  162.                 if(lBUFMAG1[i]>280) lBUFMAG1[i]=280;         
  163.                   }
  164.                  j--;
  165.         }  
  166.    }

  167. funcselect();
  168. mulselect();
  169. scan_minus();
  170. scan_add();
  171. }
  172. }
  173. void DAC_Configuration(void)
  174. {
  175.   DAC_InitStructure.DAC_Trigger = DAC_Trigger_Software;                                                   //DAC觸發方式為軟件控制
  176.   DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None;                           //不從DAC端口產生波形
  177.   DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_LFSRUnmask_Bits8_0; //8位DA波形生成模式
  178.   DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable;                                   //使能DAC輸出緩沖器
  179.   DAC_Init(DAC_Channel_1, &DAC_InitStructure);                                                                   //用上面參數初始化DAC通道1

  180.   DAC_Cmd(DAC_Channel_1, ENABLE);                                                                //使能DAC通道1
  181.   DAC_SetChannel1Data(DAC_Align_12b_L, 0x0fff);                                //設置DAC通道1為12位且數據左對齊模式
  182.   DAC_SoftwareTriggerCmd(DAC_Channel_1, ENABLE);                            //使能DAC通道1的軟件觸發方式,轉換一次
  183. }

  184. //           powerMag(lBUFOUT1,110,lBUFMAG1);
  185. void powerMag(long *input,int nfill,long *output)
  186. {
  187.    for (i=0; i < nfill; i++)
  188.    {      
  189.     lX = (float) ((input[i]<<16)>>16); /* 取高16位sine_cosine --> cos */
  190.     lY = (float) (input[i] >> 16);  /*取低16位 sine_cosine --> sin */
  191.     Mag = sqrt(lX*lX+ lY*lY)*0.122;                 // 先平方和,再開方
  192.     output[i] = (u32)(Mag);   
  193.    }  
  194. }

  195. void scan_minus(void)
  196. {
  197. if(!GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_4))        
  198.    {
  199.            delay_us(100000);
  200.            if(!GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_4))
  201.            {
  202.            if(i>0)
  203.                 {
  204.                 i--;
  205.                 POINT_COLOR=WHITE;
  206.                 TFT_Drawl(source_x[i+1]+20,19,299-lBUFMAG2[i+1]);
  207.             POINT_COLOR=BLACK;
  208.              TFT_Drawl(source_x[i]+20,19,299-lBUFMAG2[i]);        
  209.             TFT_ShowString(184,19,"F :    Hz");
  210.                 TFT_ShowString(184,31,"AM:    mV");               
  211.                 TFT_ShowNum(202,31,(u32)(((3.2)*lBUFMAG1[i])/mul_old));
  212.                 TFT_ShowNum(202,19,(u32)(i*40));
  213.                 }
  214.                 else
  215.                 {
  216.                 i=109;
  217.             POINT_COLOR=BLACK;
  218.              TFT_Drawl(source_x[i]+20,19,299-lBUFMAG2[i]);        
  219.             TFT_ShowString(184,19,"F :    Hz");
  220.                 TFT_ShowString(184,31,"AM:    mV");               
  221.                 TFT_ShowNum(202,31,(u32)(((3.2)*lBUFMAG1[i])/mul_old));
  222.                 TFT_ShowNum(202,19,(u32)(i*40));
  223.                 }
  224.            }
  225.    }
  226. }
  227. void scan_add(void)
  228. {
  229. if((!GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_5))&&func==1)        
  230.   {
  231.     delay_us(100000);
  232.         if(!GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_5))
  233.          {               
  234.          
  235.                 if(i<109)
  236.                 {
  237.                 i++;
  238.                 POINT_COLOR=WHITE;
  239.                 TFT_Drawl(source_x[i-1]+20,19,299-lBUFMAG2[i-1]);
  240.             POINT_COLOR=BLACK;
  241.              TFT_Drawl(source_x[i]+20,19,299-lBUFMAG2[i]);        
  242.             TFT_ShowString(184,19,"F :    Hz");
  243.                 TFT_ShowString(184,31,"AM:    mV");               
  244.                 TFT_ShowNum(202,31,(u32)(((3.2)*lBUFMAG1[i])/mul_old));
  245.                 TFT_ShowNum(202,19,(u32)(i*40));            
  246.                 }
  247.                 else
  248.                 {
  249.                 i=0;
  250.             POINT_COLOR=WHITE;
  251.                 TFT_Drawl(source_x[109]+20,19,299-lBUFMAG2[109]);
  252.                 POINT_COLOR=BLACK;
  253.              TFT_Drawl(source_x[i]+20,19,299-lBUFMAG2[i]);        
  254.             TFT_ShowString(184,19,"F :    Hz");
  255.                 TFT_ShowString(184,31,"AM:    mV");               
  256.                 TFT_ShowNum(202,31,(u32)(((3.2)*lBUFMAG1[i])/mul_old));
  257.                 TFT_ShowNum(202,19,(u32)(i*40));
  258.                 }
  259.          }
  260.   }
  261. }
  262. void mulselect(void)
  263. {
  264.    if(!GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0))
  265.      {

  266.          delay_us(100000);
  267.          if(!GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0))
  268.            {
  269.            if(mul<=1) mul=2;
  270.            else if(mul<8) mul=mul*2;
  271.            else mul=1;
  272.            tft_configuration();
  273.            if(func==1)
  274.            {
  275.                   POINT_COLOR=WHITE;
  276.                 for(i=0;i<109;i++)
  277.                 {
  278.                         TFT_Drawl(source_x[i]+20,20,300-lBUFMAG2[i]);        
  279.                 }
  280.                   POINT_COLOR=BRED;
  281.         for(i=0;i<109;i++)
  282.          {        
  283.                          lBUFMAG2[i]=(lBUFMAG1[i]*mul)/((float)mul_old);
  284.                          if(lBUFMAG2[i]>280) lBUFMAG2[i]=280;
  285.                         TFT_Drawl(source_x[i]+20,300,300-lBUFMAG2[i]);                                       
  286.          }
  287.                  i=0;
  288.              POINT_COLOR=BLACK;
  289.              TFT_Drawl(source_x[i]+20,19,299-lBUFMAG2[i]);        
  290.             TFT_ShowString(184,19,"F :    Hz");
  291.                 TFT_ShowString(184,31,"AM:    mV");               
  292.                 TFT_ShowNum(202,31,(u32)(((3.2)*lBUFMAG1[i])/mul_old));
  293.                 TFT_ShowNum(202,19,(u32)(i*40));
  294.                 }
  295.                 else if(func==0)
  296.                 {
  297.                         mul_old=mul;
  298.                 }
  299.            }
  300.          }   
  301. }
  302. void funcselect(void)
  303. {
  304.       if(!GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_13))        
  305.    {
  306.            delay_us(100000);
  307.            if(!GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_13))
  308.            {
  309.                 if(func==0)
  310.                 {
  311.                 func++;
  312.                 i=0;
  313.                 tft_configuration();
  314.             POINT_COLOR=BLACK;
  315.              TFT_Drawl(source_x[i]+20,19,299-lBUFMAG2[i]);        
  316.             TFT_ShowString(184,19,"F :    Hz");
  317.                 TFT_ShowString(184,31,"AM:    mV");               
  318.                 TFT_ShowNum(202,31,(u32)(((3.2)*lBUFMAG1[i])/mul_old));
  319.                 TFT_ShowNum(202,19,(u32)(i*40));
  320.                 }
  321.                 else
  322.                 {
  323.                 func--;
  324.                 tft_configuration();
  325.                 TIM_CtrlPWMOutputs(TIM1, ENABLE);
  326.                 }
  327.            }
  328. //                   for(i=0;i<240;i++)
  329. //      {
  330. //            source_x[i]=i*(2-func);                        
  331. //       }
  332.    }
  333. }
  334. /*******************************************************************************
  335. * Function Name  : RCC_Configuration
  336. * Description    : Configures the different system clocks.
  337. * Input          : None
  338. * Output         : None
  339. * Return         : None
  340. *******************************************************************************/
  341. void RCC_Configuration(void)
  342. {
  343.   /* RCC system reset(for debug purpose) */
  344.   RCC_DeInit();                                                                                //時鐘控制寄存器全部恢復默認值
  345.   RCC_HSEConfig(RCC_HSE_ON);                                                //外部高速時鐘源開啟(8M晶振)
  346.   HSEStartUpStatus = RCC_WaitForHSEStartUp();                //等待外部時鐘就緒

  347.   if(HSEStartUpStatus == SUCCESS)                                        //如果時鐘啟動成功
  348.   {
  349.     RCC_HCLKConfig(RCC_SYSCLK_Div1);                                //定義AHB設備時鐘為系統時鐘1分頻
  350.     RCC_PCLK2Config(RCC_HCLK_Div1);                                        //定義AHB2設備時鐘為HCLK時鐘1分頻
  351.     RCC_PCLK1Config(RCC_HCLK_Div2);                                        //定義AHB1設備時鐘為HCLK時鐘2分頻
  352.     FLASH_SetLatency(FLASH_Latency_2);                                //設定內部FLASH的的延時周期為2周期
  353.     FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);         //使能FLASH預存取緩沖區
  354.     RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);         //配置PLL時鐘為外部高速時鐘的9倍頻,8MHz * 9 = 72 MHz
  355.     RCC_PLLCmd(ENABLE);                                                                                 //使能PLL時鐘
  356.     while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)                 //等待PLL時鐘設置完成準備就緒
  357.     {
  358.     }
  359.     RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);                                 //使用PLL時鐘作為系統時鐘源
  360.     while(RCC_GetSYSCLKSource() != 0x08)                                         //返回系統所用時鐘源確認為外部高速晶振,8M晶振。
  361.     {
  362.     }
  363.   }
  364.   /* Enable ADC1 and GPIOC clock */
  365.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_GPIOC, ENABLE);          //使能由APB2時鐘控制的外設中的ADC1和PC端口
  366.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
  367.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);

  368.   /* Enable USART1 and GPIOA clock */
  369.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);          //使能由APB2時鐘控制的外設中的USART1和PA端口
  370.   RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
  371. }

  372. /*******************************************************************************
  373. * Function Name  : GPIO_Configuration
  374. * Description    : Configures the different GPIO ports.
  375. * Input          : None
  376. * Output         : None
  377. * Return         : None
  378. *******************************************************************************/
  379. void GPIO_Configuration(void)
  380. {
  381.   GPIO_InitTypeDef GPIO_InitStructure;

  382.   /*配置PC0 (ADC Channel10) 為模擬輸入 -------------------------*/
  383.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;                  //IO端口的第0位
  384.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;          //端口模式為模擬輸入方式
  385.   GPIO_Init(GPIOC, &GPIO_InitStructure);                  //用以上幾個參數初始化PC口

  386.   RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC |
  387.                          RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE , ENABLE);         
  388.                               //LED1
  389.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  390.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  391.                                        

  392.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 |GPIO_Pin_6|GPIO_Pin_3;                 //LED2, LED3
  393.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  394.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  395.   GPIO_Init(GPIOD, &GPIO_InitStructure);

  396.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;               
  397.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;                                   //LCD-RST
  398.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  399.   GPIO_Init(GPIOE, &GPIO_InitStructure);

  400.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;               
  401.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;                                   //LCD-RST
  402.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  403.   GPIO_Init(GPIOC, &GPIO_InitStructure);        
  404.   
  405.   


  406.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5 |
  407.                                 GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_14 |
  408.                                 GPIO_Pin_15;
  409.   GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  410.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  411.   GPIO_Init(GPIOD, &GPIO_InitStructure);

  412.   /* Set PE.07(D4), PE.08(D5), PE.09(D6), PE.10(D7), PE.11(D8), PE.12(D9), PE.13(D10),
  413.      PE.14(D11), PE.15(D12) as alternate function push pull */
  414.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 |
  415.                                 GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 |
  416.                                 GPIO_Pin_15;
  417.   GPIO_Init(GPIOE, &GPIO_InitStructure);
  418.   /* NE1 configuration */
  419.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
  420.   GPIO_Init(GPIOD, &GPIO_InitStructure);  
  421.   /* RS */
  422.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 ;
  423.   GPIO_Init(GPIOD, &GPIO_InitStructure);

  424.    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_13;               
  425.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;                                            //端口模式為上拉輸入方式
  426.   GPIO_Init(GPIOC, &GPIO_InitStructure);  
  427.   GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;               
  428.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
  429.   GPIO_Init(GPIOA, &GPIO_InitStructure);

  430.   GPIO_SetBits(GPIOD, GPIO_Pin_7);                        //CS=1
  431.   GPIO_SetBits(GPIOD, GPIO_Pin_14| GPIO_Pin_15 |GPIO_Pin_0 | GPIO_Pin_1);           
  432.   GPIO_SetBits(GPIOE, GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10);   
  433.   GPIO_ResetBits(GPIOE, GPIO_Pin_1);                //RESET=0
  434.   GPIO_SetBits(GPIOD, GPIO_Pin_4);                    //RD=1
  435.   GPIO_SetBits(GPIOD, GPIO_Pin_5);                        //WR=1
  436.   GPIO_SetBits(GPIOD, GPIO_Pin_13);        
  437.   

  438.    GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_4;                                //IO端口的第4位
  439.   GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN;                                //端口模式為模擬輸入方式
  440.   GPIO_Init(GPIOA, &GPIO_InitStructure);                                        //用以上幾個參數初始化PA口

  441. }



  442. void adc_Configuration(void)
  443. {

  444. /* ADC1 模數器轉換配置 ------------------------------------------------------*/
  445.   ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;         //ADC1和ADC2工作的獨立模式
  446.   ADC_InitStructure.ADC_ScanConvMode = DISABLE;                         //ADC設置為多通道掃描模式
  447.   ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;         //設置為連續轉換模式
  448.   ADC_InitStructure.ADC_ExternalTrigConv =ADC_ExternalTrigConv_T1_CC1;           //由軟件控制開始轉換(還有觸方式等)
  449.   ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;           //AD輸出數值為右端對齊方式
  450.   ADC_InitStructure.ADC_NbrOfChannel = 1;                                           //指定要進行AD轉換的信道1
  451.   ADC_Init(ADC1, &ADC_InitStructure);                                                   //用上面的參數初始化ADC1

  452.   //將ADC1信道1的轉換通道10(PC0)的采樣時間設置為55.5個周期
  453.   ADC_RegularChannelConfig(ADC1, ADC_Channel_11, 1, ADC_SampleTime_7Cycles5);
  454.   ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE);
  455.   ADC_Cmd(ADC1, ENABLE);                                 //使能ADC1
  456.   ADC_ResetCalibration(ADC1);                                                         //重置ADC1校準寄存器
  457.   while(ADC_GetResetCalibrationStatus(ADC1));                         //得到重置校準寄存器狀態
  458.   ADC_StartCalibration(ADC1);                                                         //開始校準ADC1
  459.   while(ADC_GetCalibrationStatus(ADC1));                                 //得到校準寄存器狀態
  460.   ADC_ExternalTrigConvCmd(ADC1, ENABLE);
  461. }


  462. void TIM_Configuration(void)
  463. {
  464.   /* Time base configuration ,F=32M/fy_cc2=10.24K */
  465.   TIM_TimeBaseStructure.TIM_Period =fy_cc2;         
  466.   TIM_TimeBaseStructure.TIM_Prescaler = 0x0;                  
  467.   TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;   
  468.   TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;  
  469.   TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);

  470.   TIM_OCInitStructure.TIM_OCMode =TIM_OCMode_PWM1;
  471.   TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;               
  472.   TIM_OCInitStructure.TIM_Pulse =fy_cc2/2;
  473.   TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;         
  474.   TIM_OC1Init(TIM1, &TIM_OCInitStructure);
  475.   /* TIM1 counter enable */
  476.   TIM_Cmd(TIM1, ENABLE);
  477.   /* TIM1 main Output Enable */
  478.   TIM_CtrlPWMOutputs(TIM1, ENABLE);  
  479. }

  480. void NVIC_Configuration(void)
  481. {
  482.   NVIC_InitTypeDef NVIC_InitStructure;
  483. #ifdef  VECT_TAB_RAM
  484.   /* Set the Vector Table base location at 0x20000000 */
  485.   NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);
  486. #else  /* VECT_TAB_FLASH  */
  487.   /* Set the Vector Table base location at 0x08000000 */
  488.   NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
  489. #endif
  490.   /* Configure one bit for preemption priority */
  491. //  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);  
  492.   NVIC_InitStructure.NVIC_IRQChannel = ADC1_2_IRQn  ;
  493.   NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
  494.   NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
  495.   NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  496.   NVIC_Init(&NVIC_InitStructure);
  497.   
  498. }

  499. void Delay(__IO uint32_t nCount)
  500. {
  501.   for(; nCount != 0; nCount--);
  502. }
  503. void delay_init(u8 SYSCLK)
  504. {
  505.         SysTick->CTRL&=0xfffffffb;//選擇內部時鐘 HCLK/8
  506.         fac_us=SYSCLK/8;                    
  507.         fac_ms=(u16)fac_us*1000;
  508. }
  509. void delay_us(u32 Nus)
  510. {               
  511.         u32 temp;                     
  512.         SysTick->LOAD=Nus*fac_us; //時間加載                           
  513.         SysTick->VAL=0x00;        //清空計數器
  514.         SysTick->CTRL=0x01 ;      //開始倒數         
  515.         do
  516.         {
  517.                 temp=SysTick->CTRL;
  518.         }
  519.         while(temp&0x01&&!(temp&(1<<16)));//等待時間到達   
  520.         SysTick->CTRL=0x00;       //關閉計數器
  521.         SysTick->VAL =0X00;       //清空計數器            
  522. }
  523. void tft_configuration(void)
  524. {
  525.   LCD_test(0xffff);
  526.   POINT_COLOR=RED;
  527.   TFT_ShowChar(232,304,'k');
  528.   TFT_ShowChar( 20,304,'0');
  529.   TFT_ShowChar( 70,304,'1');  
  530.   TFT_ShowChar(120,304,'2');
  531.   TFT_ShowChar(170,304,'3');
  532. //  TFT_ShowChar(220,304,'4');
  533.   TFT_ShowChar(3,300,'U');
  534.   TFT_ShowChar(13,304,'F');
  535.   TFT_ShowString(0,289,"  0");
  536.   TFT_ShowString(6,25 ,"mV");
  537.   TFT_ShowString(220,304,"kHz");
  538.         TFT_ShowString(0,227,"   ");
  539.         TFT_ShowString(0,164,"   ");
  540.         TFT_ShowString(0,101,"   ");
  541.         TFT_ShowString(0, 39,"   ");
  542.   TFT_ShowNum(0,227,(int)(200/mul));
  543.   TFT_ShowNum(0,164,(int)(400/mul));
  544.   TFT_ShowNum(0,101,(int)(600/mul));
  545.   TFT_ShowNum(0,39 ,(int)(800/mul));
  546.   POINT_COLOR=BLACK;
  547.   TFT_DrawLine(11,304,5,314);
  548.   TFT_DrawLine( 20,300, 20,305);
  549.   TFT_DrawLine( 70,300, 70,305);
  550.   TFT_DrawLine(120,300,120,305);
  551.   TFT_DrawLine(170,300,170,305);
  552.   TFT_DrawLine(220,300,220,305);
  553.   TFT_DrawLine(16 ,300, 20,300);
  554.   TFT_DrawLine(16 ,238, 20,238);
  555.   TFT_DrawLine(16 ,175, 20,175);
  556.   TFT_DrawLine(16 ,112, 20,112);  
  557.   TFT_DrawLine(16 , 50, 20, 50);
  558.   TFT_ShowString(90,3,"Audio Analyzer");
  559. }
  560.          
  561. /*******************************************************************************
  562. * Function Name  : fputc
  563. * Description    : Retargets the C library printf function to the USART or ITM Viewer.
  564. * Input          : None
  565. * Output         : None
  566. * Return         : None
  567. *******************************************************************************/

  568. #ifdef  DEBUG
  569. /*******************************************************************************
  570. * Function Name  : assert_failed
  571. * Description    : Reports the name of the source file and the source line number
  572. *                  where the assert error has occurred.
  573. * Input          : - file: pointer to the source file name
  574. *                  - line: assert error line source number
  575. * Output         : None
  576. * Return         : None
  577. *******************************************************************************/
  578. void assert_failed(u8* file, u32 line)
  579. {
  580.   /* User can add his own implementation to report the file name and line number,
  581.      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  582.   /* Infinite loop */
  583.   while (1)
  584.   {
  585.   }
  586. }
  587. #endif
  588. /******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/
  589. // ++++++++++++++++TFT 復位操作
  590. void lcd_rst(void)
  591. {
  592.         GPIO_ResetBits(GPIOE, GPIO_Pin_1);
  593.     Delay(0xFFFf);                                          
  594.     GPIO_SetBits(GPIOE, GPIO_Pin_1 );                          
  595.         Delay(0xFFFf);        
  596. }
復制代碼

所有資料51hei提供下載:
ADC11.7z (348.34 KB, 下載次數: 98)


評分

參與人數 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏3 分享淘帖 頂 踩
回復

使用道具 舉報

沙發
ID:498455 發表于 2019-3-26 09:26 | 只看該作者
能下載嗎?不知道能不能用
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 色综合久久88色综合天天 | 国产日韩精品视频 | 亚洲精品乱码久久久久久蜜桃91 | a国产视频| 久久网站免费视频 | 欧美一区免费 | 日日夜夜天天 | 天天干狠狠 | 欧美午夜精品久久久久久浪潮 | 午夜精品久久久久久久久久久久久 | 亚洲精品99 | 91麻豆久久久 | 国产精品高潮呻吟久久av野狼 | 精品久久久久久久久久久下田 | 欧美日韩在线一区二区 | 国产精品一区二区三区四区 | 久久久女女女女999久久 | 成人精品鲁一区一区二区 | 99re视频| 偷拍自拍在线观看 | 国产一区二区三区在线看 | 国产精品一区在线 | 三级免费av| 欧美videosex性极品hd | 免费在线观看一区二区三区 | 在线观看国产wwwa级羞羞视频 | 日韩欧美中文 | 色婷婷精品国产一区二区三区 | 久久久高清| 日本国产一区二区 | 视频一二三区 | 国产精品美女久久久av超清 | 免费黄色a视频 | 欧美日韩中文字幕 | 日韩视频在线观看 | 国产精品视频播放 | 羞羞视频在线观看网站 | 亚洲日本乱码在线观看 | 成人在线视频免费看 | 日韩精品无码一区二区三区 | 国产人成精品一区二区三 |