×
单片机 > 单片机程序设计 > 详情

PIC单片机FFT音乐频谱Proteus仿真程序

发布时间:2024-06-02 发布时间:
|

单片机源程序如下:

/********************************************************************************

;* File:FFT v1.0 *

;* Date:2015-10-22 *

;* Version:1.0 *

;* Author:Ben *

;* Wechat:feeling1791 *

;********************************************************************************/

/*

// Configuration Mask Definitions

#define CONFIG_ADDR 0x2007

// Oscillator

#define EXTCLK 0x3FFF // External RC Clockout

#define EXTIO 0x3FFE // External RC No Clock

#define INTCLK 0x3FFD // Internal RC Clockout

#define INTIO 0x3FFC // Internal RC No Clock

#define EC 0x3FFB // EC

#define HS 0x3FFA // HS

#define XT 0x3FF9 // XT

#define LP 0x3FF8 // LP

// Watchdog Timer

#define WDTEN 0x3FFF // On

#define WDTDIS 0x3FF7 // Disabled / SWDTEN control

// Power Up Timer

#define PWRTDIS 0x3FFF // Off

#define PWRTEN 0x3FEF // On

// Master Clear Enable

#define MCLREN 0x3FFF // MCLR function is enabled

#define MCLRDIS 0x3FDF // MCLR functions as IO

// Code Protect

#define UNPROTECT 0x3FFF // Code is not protected

#define CP 0x3FBF // Code is protected

// Data EE Read Protect

#define DUNPROTECT 0x3FFF // Do not read protect EEPROM data

#define CPD 0x3F7F // Read protect EEPROM data

// Brown Out Detect

#define BORDIS 0x3CFF // BOD and SBOREN disabled

#define SWBOREN 0x3DFF // SBOREN controls BOR function (Software control)

#define BORXSLP 0x3EFF // BOD enabled in run, disabled in sleep, SBOREN disabled

#define BOREN 0x3FFF // BOD Enabled, SBOREN Disabled

// Internal External Switch Over Mode

#define IESOEN 0x3FFF // Enabled

#define IESODIS 0x3BFF // Disabled

// Monitor Clock Fail-safe

#define FCMEN 0x3FFF // Enabled

#define FCMDIS 0x37FF // Disabled

// Low Voltage Programming

#define LVPDIS 0x2FFF // Disabled

#define LVPEN 0x3FFF // Enabled

// In-Circuit Debugger Mode

#define DEBUGEN 0x1FFF // Enable ICD2 debugging

#define DEBUGDIS 0x3FFF // Disable ICD2 debugging

#define CONFIG_ADDR2 0x2008

// Brown-out Reset Voltage

#define BORV21 0x3EFF // 2.1 Volts

#define BORV40 0x3FFF // 4.0 Volts

// Flash Memory Write Protection

#define WP0 0x3DFF // Protect 0h-0FFh

#define WP1 0x3BFF // Protect lower half of flash

#define WP2 0x39FF // Protect all of flash

*/

#include //pic16f887

__CONFIG(INTIO&WDTDIS&PWRTDIS&MCLREN&BOREN&LVPDIS&DUNPROTECT&DEBUGDIS&UNPROTECT&IESOEN&FCMEN);


#define LOG_NUMBER 5


unsigned char AD_count;

const unsigned char BRTable[32] = {0,16,8,24,4,20,12,28,2,18,10,26,6,22,14,30,

1,17,9,25,5,21,13,29,3,19,11,27,7,23,15,31};

const char SIN_TAB[32] =

{ 0 ,25 ,49 ,71 ,90 ,106 ,117 ,125 ,127 ,

125 ,117 ,106 ,90 ,71 ,49 ,25 ,0 ,

-25 ,-49 ,-71 ,-90 ,-106 ,-117 ,-125 ,-127 ,

-125 ,-117 ,-106 ,-90 ,-71 ,-49 ,-25 };

const char COS_TAB[32] =

{127 ,125 ,117 ,106 ,90 ,71 ,49 ,25 ,0 ,

-25 ,-49 ,-71 ,-90 ,-106 ,-117 ,-125 ,-127 ,

-125 ,-117 ,-106 ,-90 ,-71 ,-49 ,-25 ,0 ,

25 ,49 ,71 ,90 ,106 ,117 ,125 };


unsigned char disp_time;

unsigned char Led_scan_count;


bit AD_readed_flag = 0;

bit AD_getonce_flag = 0;


bank3 const unsigned char Disp_Number[8]={0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0xff};//0-7

bank3 const unsigned char Disp_peak[8]={0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80};//0-7

bank3 unsigned char led_num[16];


bank2 unsigned char MAIN_TAB[16];

bank1 unsigned char PEAK_TAB[16];

bank3 unsigned char Peak_speed[16];


bank1 int Fft_Real[32];

bank2 int Fft_Image[32];


unsigned int FFT_value;


/********************************************************************/

void delay_1ms(void)

{

unsigned int i;

for(i = 0;i < 65;i++);

}


void delay_ms(unsigned int n)

{

unsigned int i;

for(i = 0;i < n;i++)

{

delay_1ms();

}

}



/********************************************************************/

void disp(void) //2ms scan 16 segment

{

PORTD = 0xff;

PORTC = 0xff;


switch(Led_scan_count)

{

case 1:

PORTB = led_num[0] ;

RD0 = 0;

break;


case 2:

PORTB = led_num[1];

RD1 = 0;

break;


case 3:


PORTB = led_num[2] ;

RD2=0;

[1] [2] [3]
PIC单片机FFT音乐频谱Proteus仿真

『本文转载自网络,版权归原作者所有,如有侵权请联系删除』

热门文章 更多
基于单片机的医院护理呼叫对讲系统设计