STM32采集AD后FFT
單片機源程序如下:
- /* Includes ------------------------------------------------------------------*/
- #include "stm32f10x.h" //調用的庫文件
- #include "stm32f10x_conf.h"
- #include "stm32f10x_adc.h"
- #include "stm32f10x_rcc.h"
- #include "stm32f10x_gpio.h"
- #include "stm32f10x_flash.h"
- #include "misc.h"
- #include"stdio.h"
- #define NPT 256
- #include <math.h>
- #include "stm32_dsp.h"
- #include "sys.h"
- #include "delay.h"
- #include "tftlcd.h"
- #include "touch.h"
- #include "platform_config.h"
- #include "stm32f10x_exti.h"
- #include "fsmc_sram.h"
- #include "stm32f10x_dac.h"
- /*定義變量*/
- int adc_count1=0;
- int adc_count2=0;
- int AD_value0[NPT]={0};
- int AD_value1[NPT]={0};
- long lBUFOUT1[NPT]={0}; /* Complex output vector */
- long lBUFMAG1[NPT]={0}; /* Magnitude vector */
- long lBUFMAG0[NPT]={0};
- long lBUFMAG2[NPT]={0};
- unsigned int fy_cc2=7031;
- int source_x[240]={0}; //液晶畫點移位地址數組
- u8 j=0,mul=1,func=0,i=0,mul_old=1;
- float lX,lY,Mag;
- ADC_InitTypeDef ADC_InitStructure;
- vu16 ADC_ConvertedValue;
- ErrorStatus HSEStartUpStatus;
- TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
- TIM_OCInitTypeDef TIM_OCInitStructure;
- GPIO_InitTypeDef GPIO_InitStructure;
- DAC_InitTypeDef DAC_InitStructure;
- ErrorStatus HSEStartUpStatus;
- /* Private function prototypes -----------------------------------------------*/
- void RCC_Configuration(void); //申明時鐘初始化函數
- void GPIO_Configuration(void); //申明IO初始化函數
- void adc_Configuration(void);
- void TIM_Configuration(void);
- void RCC_Configuration(void);
- void GPIO_Configuration(void);
- void Delay(__IO uint32_t nCount);
- void NVIC_Configuration(void);
- void lcd_rst(void);
- void powerMag(long *input,int nfill,long *output);
- void delay_us(u32 Nus);
- void delay_init(u8 SYSCLK);
- void tft_configuration(void);
- void funcselect(void);
- void mulselect(void);
- void scan_minus(void);
- void scan_add(void);
- void DAC_Configuration(void);
- /* Private functions ---------------------------------------------------------*/
- /*******************************************************************************
- * Function Name : main
- * Description : Main program
- * Input : None
- * Output : None
- * Return : None
- *******************************************************************************/
- int main(void)
- {
- #ifdef DEBUG
- debug();
- #endif
- DAC_Configuration();
- RCC_Configuration();
- delay_init(72);
- GPIO_Configuration();
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_FSMC, ENABLE);
- GPIO_Configuration();
- GPIO_SetBits(GPIOC, GPIO_Pin_7 );
- /* Configure FSMC Bank1 NOR/PSRAM */
- FSMC_LCD_Init();
- LCD_Init();
- LCD_test(0xffff);
- delay_us(0xffff);
- LCD_test(0xffff);
- delay_us(0xffff);
- NVIC_Configuration();
- tft_configuration();
- for(i=1;i<240;i++)
- {
- source_x[i]=i*2;
- }
- adc_Configuration();
- TIM_Configuration();
- while(1)
- {
- if(adc_count1>=255&&func==0)//采樣點數到了255
- {
- if(j==0)
- {
- cr4_fft_256_stm32(lBUFOUT1, AD_value1, NPT); //FFT計算
- powerMag(lBUFOUT1,110,lBUFMAG0);
-
- POINT_COLOR=0xffff; //以下是屏幕畫點
- for(i=0;i<109;i++)
- {
- TFT_Drawl(source_x[i]+20,300-lBUFMAG2[i],300-lBUFMAG1[i]);
- }
- POINT_COLOR=BRED;
- for(i=0;i<109;i++)
- {
- TFT_Drawl(source_x[i]+20,300,300-lBUFMAG1[i]);
- }
- j++;
- }
- else
- {
- cr4_fft_256_stm32(lBUFOUT1, AD_value0, NPT); //FFT計算
- for(i=0;i<109;i++) lBUFMAG2[i]=lBUFMAG1[i];//保存初始結果
- powerMag(lBUFOUT1,110,lBUFMAG1); //功率計算
- for(i=0;i<109;i++)
- {
- lBUFMAG1[i]=(lBUFMAG1[i]+lBUFMAG0[i])*mul;
- if(lBUFMAG1[i]>280) lBUFMAG1[i]=280;
- else lBUFMAG1[i]=lBUFMAG1[i];
- }
- j--;
- }
- }
- /************************************************/
- if(adc_count1>=255&&func==1)//采樣點數到了255
- {
- if(j==0)
- {
- cr4_fft_256_stm32(lBUFOUT1, AD_value1, NPT); //FFT計算
- powerMag(lBUFOUT1,110,lBUFMAG0);
-
- POINT_COLOR=0xffff;
- for(i=0;i<109;i++)
- {
- TFT_Drawl(source_x[i]+20,300-lBUFMAG2[i],300-lBUFMAG1[i]);
- }
- POINT_COLOR=BRED;
- for(i=0;i<109;i++)
- {
- TFT_Drawl(source_x[i]+20,300,300-lBUFMAG1[i]);
- lBUFMAG2[i]=lBUFMAG1[i]; // lBUFMAG2頻率值,lBUFMAG1電壓值
- }
-
- j++;
- TIM_CtrlPWMOutputs(TIM1, DISABLE);
- }
- else
- {
- cr4_fft_256_stm32(lBUFOUT1, AD_value0, NPT); //FFT計算
- for(i=0;i<109;i++) lBUFMAG2[i]=lBUFMAG1[i];
- powerMag(lBUFOUT1,110,lBUFMAG1);
- for(i=0;i<109;i++)
- {
- lBUFMAG1[i]=(lBUFMAG1[i]+lBUFMAG0[i])*mul;
- if(lBUFMAG1[i]>280) lBUFMAG1[i]=280;
- }
- j--;
- }
- }
- funcselect();
- mulselect();
- scan_minus();
- scan_add();
- }
- }
- void DAC_Configuration(void)
- {
- DAC_InitStructure.DAC_Trigger = DAC_Trigger_Software; //DAC觸發方式為軟件控制
- DAC_InitStructure.DAC_WaveGeneration = DAC_WaveGeneration_None; //不從DAC端口產生波形
- DAC_InitStructure.DAC_LFSRUnmask_TriangleAmplitude = DAC_LFSRUnmask_Bits8_0; //8位DA波形生成模式
- DAC_InitStructure.DAC_OutputBuffer = DAC_OutputBuffer_Enable; //使能DAC輸出緩沖器
- DAC_Init(DAC_Channel_1, &DAC_InitStructure); //用上面參數初始化DAC通道1
-
- DAC_Cmd(DAC_Channel_1, ENABLE); //使能DAC通道1
- DAC_SetChannel1Data(DAC_Align_12b_L, 0x0fff); //設置DAC通道1為12位且數據左對齊模式
- DAC_SoftwareTriggerCmd(DAC_Channel_1, ENABLE); //使能DAC通道1的軟件觸發方式,轉換一次
- }
- // powerMag(lBUFOUT1,110,lBUFMAG1);
- void powerMag(long *input,int nfill,long *output)
- {
- for (i=0; i < nfill; i++)
- {
- lX = (float) ((input[i]<<16)>>16); /* 取高16位sine_cosine --> cos */
- lY = (float) (input[i] >> 16); /*取低16位 sine_cosine --> sin */
- Mag = sqrt(lX*lX+ lY*lY)*0.122; // 先平方和,再開方
- output[i] = (u32)(Mag);
- }
- }
- void scan_minus(void)
- {
- if(!GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_4))
- {
- delay_us(100000);
- if(!GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_4))
- {
- if(i>0)
- {
- i--;
- POINT_COLOR=WHITE;
- TFT_Drawl(source_x[i+1]+20,19,299-lBUFMAG2[i+1]);
- POINT_COLOR=BLACK;
- TFT_Drawl(source_x[i]+20,19,299-lBUFMAG2[i]);
- TFT_ShowString(184,19,"F : Hz");
- TFT_ShowString(184,31,"AM: mV");
- TFT_ShowNum(202,31,(u32)(((3.2)*lBUFMAG1[i])/mul_old));
- TFT_ShowNum(202,19,(u32)(i*40));
- }
- else
- {
- i=109;
- POINT_COLOR=BLACK;
- TFT_Drawl(source_x[i]+20,19,299-lBUFMAG2[i]);
- TFT_ShowString(184,19,"F : Hz");
- TFT_ShowString(184,31,"AM: mV");
- TFT_ShowNum(202,31,(u32)(((3.2)*lBUFMAG1[i])/mul_old));
- TFT_ShowNum(202,19,(u32)(i*40));
- }
- }
- }
- }
- void scan_add(void)
- {
- if((!GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_5))&&func==1)
- {
- delay_us(100000);
- if(!GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_5))
- {
-
- if(i<109)
- {
- i++;
- POINT_COLOR=WHITE;
- TFT_Drawl(source_x[i-1]+20,19,299-lBUFMAG2[i-1]);
- POINT_COLOR=BLACK;
- TFT_Drawl(source_x[i]+20,19,299-lBUFMAG2[i]);
- TFT_ShowString(184,19,"F : Hz");
- TFT_ShowString(184,31,"AM: mV");
- TFT_ShowNum(202,31,(u32)(((3.2)*lBUFMAG1[i])/mul_old));
- TFT_ShowNum(202,19,(u32)(i*40));
- }
- else
- {
- i=0;
- POINT_COLOR=WHITE;
- TFT_Drawl(source_x[109]+20,19,299-lBUFMAG2[109]);
- POINT_COLOR=BLACK;
- TFT_Drawl(source_x[i]+20,19,299-lBUFMAG2[i]);
- TFT_ShowString(184,19,"F : Hz");
- TFT_ShowString(184,31,"AM: mV");
- TFT_ShowNum(202,31,(u32)(((3.2)*lBUFMAG1[i])/mul_old));
- TFT_ShowNum(202,19,(u32)(i*40));
- }
- }
- }
- }
- void mulselect(void)
- {
- if(!GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0))
- {
- delay_us(100000);
- if(!GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_0))
- {
- if(mul<=1) mul=2;
- else if(mul<8) mul=mul*2;
- else mul=1;
- tft_configuration();
- if(func==1)
- {
- POINT_COLOR=WHITE;
- for(i=0;i<109;i++)
- {
- TFT_Drawl(source_x[i]+20,20,300-lBUFMAG2[i]);
- }
- POINT_COLOR=BRED;
- for(i=0;i<109;i++)
- {
- lBUFMAG2[i]=(lBUFMAG1[i]*mul)/((float)mul_old);
- if(lBUFMAG2[i]>280) lBUFMAG2[i]=280;
- TFT_Drawl(source_x[i]+20,300,300-lBUFMAG2[i]);
- }
- i=0;
- POINT_COLOR=BLACK;
- TFT_Drawl(source_x[i]+20,19,299-lBUFMAG2[i]);
- TFT_ShowString(184,19,"F : Hz");
- TFT_ShowString(184,31,"AM: mV");
- TFT_ShowNum(202,31,(u32)(((3.2)*lBUFMAG1[i])/mul_old));
- TFT_ShowNum(202,19,(u32)(i*40));
- }
- else if(func==0)
- {
- mul_old=mul;
- }
- }
- }
- }
- void funcselect(void)
- {
- if(!GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_13))
- {
- delay_us(100000);
- if(!GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_13))
- {
- if(func==0)
- {
- func++;
- i=0;
- tft_configuration();
- POINT_COLOR=BLACK;
- TFT_Drawl(source_x[i]+20,19,299-lBUFMAG2[i]);
- TFT_ShowString(184,19,"F : Hz");
- TFT_ShowString(184,31,"AM: mV");
- TFT_ShowNum(202,31,(u32)(((3.2)*lBUFMAG1[i])/mul_old));
- TFT_ShowNum(202,19,(u32)(i*40));
- }
- else
- {
- func--;
- tft_configuration();
- TIM_CtrlPWMOutputs(TIM1, ENABLE);
- }
- }
- // for(i=0;i<240;i++)
- // {
- // source_x[i]=i*(2-func);
- // }
- }
- }
- /*******************************************************************************
- * Function Name : RCC_Configuration
- * Description : Configures the different system clocks.
- * Input : None
- * Output : None
- * Return : None
- *******************************************************************************/
- void RCC_Configuration(void)
- {
- /* RCC system reset(for debug purpose) */
- RCC_DeInit(); //時鐘控制寄存器全部恢復默認值
- RCC_HSEConfig(RCC_HSE_ON); //外部高速時鐘源開啟(8M晶振)
- HSEStartUpStatus = RCC_WaitForHSEStartUp(); //等待外部時鐘就緒
- if(HSEStartUpStatus == SUCCESS) //如果時鐘啟動成功
- {
- RCC_HCLKConfig(RCC_SYSCLK_Div1); //定義AHB設備時鐘為系統時鐘1分頻
- RCC_PCLK2Config(RCC_HCLK_Div1); //定義AHB2設備時鐘為HCLK時鐘1分頻
- RCC_PCLK1Config(RCC_HCLK_Div2); //定義AHB1設備時鐘為HCLK時鐘2分頻
- FLASH_SetLatency(FLASH_Latency_2); //設定內部FLASH的的延時周期為2周期
- FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); //使能FLASH預存取緩沖區
- RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9); //配置PLL時鐘為外部高速時鐘的9倍頻,8MHz * 9 = 72 MHz
- RCC_PLLCmd(ENABLE); //使能PLL時鐘
- while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET) //等待PLL時鐘設置完成準備就緒
- {
- }
- RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); //使用PLL時鐘作為系統時鐘源
- while(RCC_GetSYSCLKSource() != 0x08) //返回系統所用時鐘源確認為外部高速晶振,8M晶振。
- {
- }
- }
- /* Enable ADC1 and GPIOC clock */
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_GPIOC, ENABLE); //使能由APB2時鐘控制的外設中的ADC1和PC端口
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
- /* Enable USART1 and GPIOA clock */
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //使能由APB2時鐘控制的外設中的USART1和PA端口
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
- }
- /*******************************************************************************
- * Function Name : GPIO_Configuration
- * Description : Configures the different GPIO ports.
- * Input : None
- * Output : None
- * Return : None
- *******************************************************************************/
- void GPIO_Configuration(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- /*配置PC0 (ADC Channel10) 為模擬輸入 -------------------------*/
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; //IO端口的第0位
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; //端口模式為模擬輸入方式
- GPIO_Init(GPIOC, &GPIO_InitStructure); //用以上幾個參數初始化PC口
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC |
- RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE , ENABLE);
- //LED1
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
-
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 |GPIO_Pin_6|GPIO_Pin_3; //LED2, LED3
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOD, &GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //LCD-RST
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOE, &GPIO_InitStructure);
-
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //LCD-RST
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOC, &GPIO_InitStructure);
-
-
-
-
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_4 | GPIO_Pin_5 |
- GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_14 |
- GPIO_Pin_15;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_Init(GPIOD, &GPIO_InitStructure);
- /* Set PE.07(D4), PE.08(D5), PE.09(D6), PE.10(D7), PE.11(D8), PE.12(D9), PE.13(D10),
- PE.14(D11), PE.15(D12) as alternate function push pull */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 |
- GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 |
- GPIO_Pin_15;
- GPIO_Init(GPIOE, &GPIO_InitStructure);
- /* NE1 configuration */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
- GPIO_Init(GPIOD, &GPIO_InitStructure);
- /* RS */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11 ;
- GPIO_Init(GPIOD, &GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_13;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //端口模式為上拉輸入方式
- GPIO_Init(GPIOC, &GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- GPIO_SetBits(GPIOD, GPIO_Pin_7); //CS=1
- GPIO_SetBits(GPIOD, GPIO_Pin_14| GPIO_Pin_15 |GPIO_Pin_0 | GPIO_Pin_1);
- GPIO_SetBits(GPIOE, GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10);
- GPIO_ResetBits(GPIOE, GPIO_Pin_1); //RESET=0
- GPIO_SetBits(GPIOD, GPIO_Pin_4); //RD=1
- GPIO_SetBits(GPIOD, GPIO_Pin_5); //WR=1
- GPIO_SetBits(GPIOD, GPIO_Pin_13);
-
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; //IO端口的第4位
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AIN; //端口模式為模擬輸入方式
- GPIO_Init(GPIOA, &GPIO_InitStructure); //用以上幾個參數初始化PA口
- }
- void adc_Configuration(void)
- {
- /* ADC1 模數器轉換配置 ------------------------------------------------------*/
- ADC_InitStructure.ADC_Mode = ADC_Mode_Independent; //ADC1和ADC2工作的獨立模式
- ADC_InitStructure.ADC_ScanConvMode = DISABLE; //ADC設置為多通道掃描模式
- ADC_InitStructure.ADC_ContinuousConvMode = DISABLE; //設置為連續轉換模式
- ADC_InitStructure.ADC_ExternalTrigConv =ADC_ExternalTrigConv_T1_CC1; //由軟件控制開始轉換(還有觸方式等)
- ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; //AD輸出數值為右端對齊方式
- ADC_InitStructure.ADC_NbrOfChannel = 1; //指定要進行AD轉換的信道1
- ADC_Init(ADC1, &ADC_InitStructure); //用上面的參數初始化ADC1
- //將ADC1信道1的轉換通道10(PC0)的采樣時間設置為55.5個周期
- ADC_RegularChannelConfig(ADC1, ADC_Channel_11, 1, ADC_SampleTime_7Cycles5);
- ADC_ITConfig(ADC1, ADC_IT_EOC, ENABLE);
- ADC_Cmd(ADC1, ENABLE); //使能ADC1
- ADC_ResetCalibration(ADC1); //重置ADC1校準寄存器
- while(ADC_GetResetCalibrationStatus(ADC1)); //得到重置校準寄存器狀態
- ADC_StartCalibration(ADC1); //開始校準ADC1
- while(ADC_GetCalibrationStatus(ADC1)); //得到校準寄存器狀態
- ADC_ExternalTrigConvCmd(ADC1, ENABLE);
- }
- void TIM_Configuration(void)
- {
- /* Time base configuration ,F=32M/fy_cc2=10.24K */
- TIM_TimeBaseStructure.TIM_Period =fy_cc2;
- TIM_TimeBaseStructure.TIM_Prescaler = 0x0;
- TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
- TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
- TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
- TIM_OCInitStructure.TIM_OCMode =TIM_OCMode_PWM1;
- TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
- TIM_OCInitStructure.TIM_Pulse =fy_cc2/2;
- TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
- TIM_OC1Init(TIM1, &TIM_OCInitStructure);
- /* TIM1 counter enable */
- TIM_Cmd(TIM1, ENABLE);
- /* TIM1 main Output Enable */
- TIM_CtrlPWMOutputs(TIM1, ENABLE);
- }
- void NVIC_Configuration(void)
- {
- NVIC_InitTypeDef NVIC_InitStructure;
- #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
- /* Configure one bit for preemption priority */
- // NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
- NVIC_InitStructure.NVIC_IRQChannel = ADC1_2_IRQn ;
- NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init(&NVIC_InitStructure);
-
- }
- void Delay(__IO uint32_t nCount)
- {
- for(; nCount != 0; nCount--);
- }
- void delay_init(u8 SYSCLK)
- {
- SysTick->CTRL&=0xfffffffb;//選擇內部時鐘 HCLK/8
- fac_us=SYSCLK/8;
- fac_ms=(u16)fac_us*1000;
- }
- void delay_us(u32 Nus)
- {
- u32 temp;
- SysTick->LOAD=Nus*fac_us; //時間加載
- SysTick->VAL=0x00; //清空計數器
- SysTick->CTRL=0x01 ; //開始倒數
- do
- {
- temp=SysTick->CTRL;
- }
- while(temp&0x01&&!(temp&(1<<16)));//等待時間到達
- SysTick->CTRL=0x00; //關閉計數器
- SysTick->VAL =0X00; //清空計數器
- }
- void tft_configuration(void)
- {
- LCD_test(0xffff);
- POINT_COLOR=RED;
- TFT_ShowChar(232,304,'k');
- TFT_ShowChar( 20,304,'0');
- TFT_ShowChar( 70,304,'1');
- TFT_ShowChar(120,304,'2');
- TFT_ShowChar(170,304,'3');
- // TFT_ShowChar(220,304,'4');
- TFT_ShowChar(3,300,'U');
- TFT_ShowChar(13,304,'F');
- TFT_ShowString(0,289," 0");
- TFT_ShowString(6,25 ,"mV");
- TFT_ShowString(220,304,"kHz");
- TFT_ShowString(0,227," ");
- TFT_ShowString(0,164," ");
- TFT_ShowString(0,101," ");
- TFT_ShowString(0, 39," ");
- TFT_ShowNum(0,227,(int)(200/mul));
- TFT_ShowNum(0,164,(int)(400/mul));
- TFT_ShowNum(0,101,(int)(600/mul));
- TFT_ShowNum(0,39 ,(int)(800/mul));
- POINT_COLOR=BLACK;
- TFT_DrawLine(11,304,5,314);
- TFT_DrawLine( 20,300, 20,305);
- TFT_DrawLine( 70,300, 70,305);
- TFT_DrawLine(120,300,120,305);
- TFT_DrawLine(170,300,170,305);
- TFT_DrawLine(220,300,220,305);
- TFT_DrawLine(16 ,300, 20,300);
- TFT_DrawLine(16 ,238, 20,238);
- TFT_DrawLine(16 ,175, 20,175);
- TFT_DrawLine(16 ,112, 20,112);
- TFT_DrawLine(16 , 50, 20, 50);
- TFT_ShowString(90,3,"Audio Analyzer");
- }
-
- /*******************************************************************************
- * Function Name : fputc
- * Description : Retargets the C library printf function to the USART or ITM Viewer.
- * Input : None
- * Output : None
- * Return : None
- *******************************************************************************/
- #ifdef DEBUG
- /*******************************************************************************
- * Function Name : assert_failed
- * Description : Reports the name of the source file and the source line number
- * where the assert error has occurred.
- * Input : - file: pointer to the source file name
- * - line: assert 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
- /******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/
- // ++++++++++++++++TFT 復位操作
- void lcd_rst(void)
- {
- GPIO_ResetBits(GPIOE, GPIO_Pin_1);
- Delay(0xFFFf);
- GPIO_SetBits(GPIOE, GPIO_Pin_1 );
- Delay(0xFFFf);
- }
復制代碼
所有資料51hei提供下載:
ADC11.7z
(348.34 KB, 下載次數: 98)
2018-12-28 01:58 上傳
點擊文件名下載附件
FFT 下載積分: 黑幣 -5
|