|
stm32+3.2寸屏顯示音樂頻譜!
- #include "stm32f10x.h"
- #include "./lcd/bsp_ili9341_lcd.h"
- #include "./usart/bsp_usart.h"
- #include <stdio.h>
- #include "fft.h"
- #include "timer.h"
- #include "adc.h"
- #include "bsp_led.h"
- #include "bsp_SysTick.h"
- #include "set.h"
- #include "./key/bsp_key.h"
- u16 count;
- u32 voltage_val[256];
- extern float32_t InputData[512];//輸入復數數據
- extern float32_t OutputData[256];//輸出復數數據
- extern float32_t maxValue;//存儲變換后的最大值
- uint16_t point[128]={0};
- uint16_t lcd_w = 0;
- uint16_t color_mode = 0;
- extern u32 time_us;
- /**
- * @brief 主函數
- * @param 無
- * @retval 無
- */
- int main ( void )
- {
- int i = 0;
-
-
- lcd_w = 2;
-
- color_mode = 1;
-
- ILI9341_Init(); //LCD 初始化
- USART_Config();
- SysTick_Init();
- time_us = 0;
-
-
- ILI9341_GramScan ( 1 );
-
- LCD_SetFont(&Font8x16);
- LCD_SetColors(RED,BLACK);
- ILI9341_Clear(0,0,LCD_X_LENGTH,LCD_Y_LENGTH); /* 清屏,顯示全黑 */
-
-
-
- LED_GPIO_Config();
- Key_GPIO_Config();
- Adc_Init();
- TIM2_Int_Init(4,359);//200kHz計數頻率,40kHz中斷頻率(采樣頻率)
-
-
-
-
-
-
-
- while ( 1 )
- {
-
-
- if(count == 256)
- {
- TIM_ITConfig(TIM2,TIM_IT_Update,DISABLE );//關定時器中斷
-
- //LED2_TOGGLE;
- count = 0;
-
- if(KEY_ON == Key_Scan(KEY1_GPIO_PORT,KEY1_GPIO_PIN))
- {
- lcd_w++;
- lcd_w %= 5;
- lcd_w++;
- }
- if(KEY_ON == Key_Scan(KEY2_GPIO_PORT,KEY2_GPIO_PIN))
- {
- color_mode++;
- color_mode %= 3;
- }
-
- for(i=0;i<256;i++)//裝載256點復數數據
- {
-
- InputData[i*2]=(float)voltage_val[i];//實部
-
-
- InputData[i*2+1]=0.0;//虛部
- }
-
-
-
- if(DO_FFT())
- {
-
- for(i=0;i < 300/(lcd_w+1);i++)
- {
- uint32_t temp = (u32)OutputData[i+1]/30;
-
- if(temp >= point[i])
- {
- if(temp >= 239)
- {
- point[i] = 239;
- }
- else
- {
- point[i] = temp;
- }
- }
- else
- {
- if(point[i] >= lcd_w )
- {
- point[i]-=lcd_w;
- }
- else
- {
- point[i] = 0;
- }
- }
-
- set_color(temp);
- if(lcd_w != 1)
- {
- m_line(i,temp);
- }
- else
- {
- ILI9341_OpenWindow ( (lcd_w + 1)*i, 0, (lcd_w+1), LCD_Y_LENGTH );
- ILI9341_FillColor ( (lcd_w + 1) * LCD_Y_LENGTH, BLACK );
- }
- m_point(i,point[i]);
- }
- }
-
-
-
- SysTick_Delay_Ms(60);
-
-
-
- TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE );//開定時器中斷
- }
-
-
-
- }
-
-
- }
復制代碼
|
-
-
project.7z
2021-3-4 15:05 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
223.98 KB, 下載次數: 19, 下載積分: 黑幣 -5
|