#include<60s2.h>
#define uint unsigned int
#define uchar unsigned char
sbit r1=P2^6;
sbit r2=P2^7;
sbit g1=P2^4;
sbit g2=P2^5;
sbit jat=P1^7;
sbit clk=P1^6;
sbit oe=P1^5;
sbit la=P2^0;
sbit lb=P2^1;
sbit lc=P2^2;
sbit ld=P2^3;
code char SIN_TAB[128] = { 0, 6, 12, 18, 24, 30, 36, 42, 48, 54, 59, 65, 70, 75, 80, 85, 89, 94, 98, 102,
105, 108, 112, 114, 117, 119, 121, 123, 124, 125, 126, 126, 126, 126, 126, 125, 124, 123, 121, 119, 117, 114, 112,
108, 105, 102, 98, 94, 89, 85, 80, 75, 70, 65, 59, 54, 48, 42, 36, 30, 24, 18, 12, 6, 0, -6, -12, -18, -24, -30,
-36, -42, -48, -54, -59, -65, -70, -75, -80, -85, -89, -94, -98, -102, -105, -108, -112, -114, -117, -119, -121,
-123, -124, -125, -126, -126, -126, -126, -126, -125, -124, -123, -121, -119, -117, -114, -112, -108, -105, -102,
-98, -94, -89, -85, -80, -75, -70, -65, -59, -54, -48, -42, -36, -30, -24, -18, -12, -6 };
//放大128倍后的cos整数表(128)
code char COS_TAB[128] = { 127, 126, 126, 125, 124, 123, 121, 119, 117, 114, 112, 108, 105, 102, 98, 94,
89, 85, 80, 75, 70, 65, 59, 54, 48, 42, 36, 30, 24, 18, 12, 6, 0, -6, -12, -18, -24, -30, -36, -42, -48, -54, -59,
-65, -70, -75, -80, -85, -89, -94, -98, -102, -105, -108, -112, -114, -117, -119, -121, -123, -124, -125, -126, -
126, -126, -126, -126, -125, -124, -123, -121, -119, -117, -114, -112, -108, -105, -102, -98, -94, -89, -85, -80,
-75, -70, -65, -59, -54, -48, -42, -36, -30, -24, -18, -12, -6, 0, 6, 12, 18, 24, 30, 36, 42, 48, 54, 59, 65, 70,
75, 80, 85, 89, 94, 98, 102, 105, 108, 112, 114, 117, 119, 121, 123, 124, 125, 126, 126 };
//采样存储序列表
code char LIST_TAB[128] = { 0, 64, 32, 96, 16, 80, 48, 112,
8, 72, 40, 104, 24, 88, 56, 120,
4, 68, 36, 100, 20, 84, 52, 116,
12, 76, 44, 108, 28, 92, 60, 124,
2, 66, 34, 98, 18, 82, 50, 114,
10, 74, 42, 106, 26, 90, 58, 122,
6, 70, 38, 102, 22, 86, 54, 118,
14, 78, 46, 110, 30, 94, 62, 126,
1, 65, 33, 97, 17, 81, 49, 113,
9, 73, 41, 105, 25, 89, 57, 121,
5, 69, 37, 101, 21, 85, 53, 117,
13, 77, 45, 109, 29, 93, 61, 125,
3, 67, 35, 99, 19, 83, 51, 115,
11, 75, 43, 107, 27, 91, 59, 123,
7, 71, 39, 103, 23, 87, 55, 119,
15, 79, 47, 111, 31, 95, 63, 127
};
uchar COUNT=63,COUNT1=0,ADC_Count=0,LINE=15,G,T;
uchar i,j,k,b,p;
int Temp_Real,Temp_Imag,temp; // 中间临时变量
uint TEMP1;
int xdata Fft_Real[128];
int xdata Fft_Image[128]; // fft的虚部
uchar xdata LED_TAB2[64]; //记录 漂浮物 是否需要 停顿一下
uchar xdata LED_TAB[64]; //记录红色柱状
uchar xdata LED_TAB1[64]; //记录 漂浮点
void delay(uint x)
{
while(x--);
}
void FFT()
{ //uchar x;
for( i=1; i<=7; i++) // /* for(1) */
{
b=1;
b <<=(i-1); //碟式运算,用于计算 隔多少行计算 例如 第一极 1和2行计算,,第二级
for( j=0; j<=b-1; j++) // /* for (2) */
{
p=1;
p <<= (7-i);
p = p*j;
for( k=j; k<128; k=k+2*b) // /* for (3) 基二fft */
{
Temp_Real = Fft_Real[k]; Temp_Imag = Fft_Image[k]; temp = Fft_Real[k+b];
Fft_Real[k] = Fft_Real[k] + ((Fft_Real[k+b]*COS_TAB[p])>>7) + ((Fft_Image[k+b]*SIN_TAB[p])>>7);
Fft_Image[k] = Fft_Image[k] - ((Fft_Real[k+b]*SIN_TAB[p])>>7) + ((Fft_Image[k+b]*COS_TAB[p])>>7);
Fft_Real[k+b] = Temp_Real - ((Fft_Real[k+b]*COS_TAB[p])>>7) - ((Fft_Image[k+b]*SIN_TAB[p])>>7);
Fft_Image[k+b] = Temp_Imag + ((temp*SIN_TAB[p])>>7) - ((Fft_Image[k+b]*COS_TAB[p])>>7);
// 移位.防止溢出. 结果已经是本值的 1/64
Fft_Real[k] >>= 1;
Fft_Image[k] >>= 1;
Fft_Real[k+b] >>= 1;
Fft_Image[k+b] >>= 1;
}
}
}
Fft_Real[0]=Fft_Image[0]=0; //去掉直流分量
for(j=0;j<64;j++)
{
TEMP1=((((Fft_Real[j+1]* Fft_Real[j+1]))+((Fft_Image[j+1]*Fft_Image[j+1])))>>1);//求功率
if(TEMP1>1)TEMP1--;
else TEMP1=0;
if(TEMP1>31)TEMP1=31;
if(TEMP1>(LED_TAB[j]))LED_TAB[j]=TEMP1;
if(TEMP1>(LED_TAB1[j]))
{
LED_TAB1[j]=TEMP1;
LED_TAB2[j]=18; //提顿速度=12
}
}
}
uint AD_init()
{
delay(3);
while(!(ADC_CONTR&0x10)); //等待转换完成
ADC_CONTR&=0xe7; //关闭AD转换,ADC_FLAG位由软件清0
return(ADC_RES*4+ADC_RESL); //返回AD转换完成的10位数据(16进制)
}
void init()
{
AUXR=0xc0;
EADC=1;
TMOD=0x11;
TH0=0XF3;
TL0=0XF3;
TH1=0XBE;
TL1=0XFF;
EA=1;
ET0=1;
ET1=1;
TR0=0;
TR1=1;
P2M1=0x00;
P2M0=0xff;
P1M1=0x01;
P1M0=0xff;
oe=0;
}
void main()
{
init();
while(1)
{
ADC_Count=0;
TR0=1;
EADC=1;
while(ADC_Count>128);
for(i=0;i<128;i++)
{
Fft_Image=0;
}
FFT();
}
}
void ADC_Finish() interrupt 5
{
Fft_Real[LIST_TAB[ADC_Count]]=AD_init();
if(ADC_Count<=127)
ADC_Count++;
else {EADC=0;TR0=0;}
}
void kaiqiAD() interrupt 1
{
ADC_CONTR=0x88;
//开启AD转换1000 1000 即POWER SPEED1 SPEED0 ADC_FLAG ADC_START CHS2 CHS1 CHS0
}
void xianshi() interrupt 3
{
TH1=0XBE;
TL1=0XFF;
for (G=0;G<64;G++) //往点阵屏填充 一行的 数据
{
if(LED_TAB[G]<=LINE+16)r1=1;
else r1=0;
if(LED_TAB[G]<=LINE)r2=1;
else r2=0;
if(LED_TAB1[G]==LINE){g1=1;g2=0;}
else if(LED_TAB1[G]==(LINE+16)){g1=0;g2=1;}
else g2=g1=1;
clk=1;clk=0;
}
jat=1;jat=0;
P2=15-LINE;
if(LINE>0)LINE--;
else LINE=15;
if(LED_TAB[COUNT]>0)LED_TAB[COUNT]--; //柱状递减,
if(COUNT>0)COUNT--;
else COUNT=63;
if(LED_TAB[COUNT]>0)LED_TAB[COUNT]--;
if(COUNT>0)COUNT--;
else COUNT=63;
//漂浮物递减
if(LED_TAB2[COUNT1]==0) //判断是否需要停顿
{
if(LED_TAB1[COUNT1]>LED_TAB[COUNT1])LED_TAB1[COUNT1]--;//大于柱状则递减(保持漂浮物在柱状之上)
}
else LED_TAB2[COUNT1]--;
COUNT1++;
if(COUNT1>=64)COUNT1=0;
if(LED_TAB2[COUNT1]==0)
{
if(LED_TAB1[COUNT1]>LED_TAB[COUNT1])LED_TAB1[COUNT1]--;
}
else LED_TAB2[COUNT1]--;
COUNT1++;
if(COUNT1>=64)COUNT1=0;
}
程序如上,显示效果如图,还是会比较有节奏的跳动,但是显示是怎么回事?帮忙看看
|