📄 main.c
字号:
signal[AD_Index / 2].real = ADC0;
AD_Index ++;
}
//中断处理区
void Timer0_ISR (void) interrupt 1 //2.5ms
{
TH0 = (-SYSCLK/400) >> 8;
TL0 = -SYSCLK/400;
//---------------------------应用1------------------------------
if (Count25ms) Count25ms--; //延时加载
//---------------------------应用2------------------------------
For1S --; //一秒变换一次
if(For1S == 0)
{
For1S = 400;
SECEND ++; //控制时钟加一
if(SECEND >= 6)
SECEND = 0; //强制清零
}
}
void INT0_ISR(void) interrupt 0
{
EA =0;
Send7279Byte(0x15); //发读键盘指令
KeyValue = Receive7279Byte(); //获取键值
NOSELECT7279; //置CS高电平
if(KeyValue == 14) //软件复位
RSTSRC |= 10;
switch(KeyValue)
{
case 0: //功能切换
{
IsHold = ~IsHold;
break;
}
case 1: //向上翻页
{
if(DispalyIndex > 0)
DispalyIndex --;
break;
}
case 2: //功能切换 ANA - FDISO
{
IsDist = ~IsDist;
break;
}
case 3: //20HZ --- 100HZ切换
{
FREQSel = ~FREQSel;
break;
}
case 5: //上一次 现在的值 切换
{
ISLast = ~ISLast;
break;
}
case 9: //向下翻页
{
if(DispalyIndex < 1023)
DispalyIndex ++;
break;
}
}
//保存
EA = 1;
}
//FFT REGION
struct compx_S EE(struct compx_S b1,struct compx b2)
{
struct compx_S b3;
long int TMP1,TMP2;
TMP1 = b1.real * b2.real;
TMP2 = b1.imag * b2.imag;
b3.real = (TMP1 - TMP2) >> 10;
TMP1 = b1.real * b2.imag;
TMP2 = b1.imag * b2.real;
b3.imag = (TMP1 + TMP2) >> 10;
return(b3);
}
void FFT(struct compx_S *xin,int N)
{
int f,m,LH,nm,i,k,j,L,p;
int le,B,ip;
struct compx w; //旋转因子
struct compx_S t; //乘法得到的结果
struct compx CoL1; //使编译器按长整型计算
LH=N/2;
f=N;
for(m=1;(f=f/2)!=1;m++)
{
;
}
nm=N-2;
j=N/2;
/*变址运算*/
for(i=1;i<=nm;i++)
{
if(i<j)
{
t=xin[j];
xin[j]=xin[i];
xin[i]=t;
}
k=LH;
while(j>=k)
{
j=j-k;
k=k/2;
}
j=j+k;
}
for(L=1;L<=m;L++)
{
le=pow(2,L);
B=le/2;
for(j=0;j<=B-1;j++)
{
p = pow(2,m-L)*j;
w.real = COSMT[p];
if(p > 255)
{
p -= 256;
w.imag = - COSMT[p];
}
else
{
p += 256;
w.imag = COSMT[p];
}
for(i=j;i<=N-1;i=i+le)
{
ip = i+B;
t = EE( xin[ip] , w);
CoL1.real = xin[i].real;
CoL1.imag = xin[i].imag; //使编译器按长整型计算
xin[ip].real = ((CoL1.real - t.real) >> 1);
xin[ip].imag = ((CoL1.imag - t.imag) >> 1);
xin[i].real = ((CoL1.real + t.real) >> 1);
xin[i].imag = ((CoL1.imag + t.imag) >> 1); //共衰减 2^10 = 1024 倍
}
}
}
xin[1025].real = xin[0].real;
xin[1025].imag = xin[0].imag; //防止越界用
return;
}
void Change(struct compx_S *new,unsigned int T[])
{
unsigned int i;
struct compx CT1,CT2;
struct compx_S w , nnnnn , re;
struct compx ep,op;
float cc;
for(i=0;i < 1024;i++)
{
CT1.real = new[i].real;
CT1.imag = new[i].imag;
CT2.real = new[1024 - i].real;
CT2.imag = new[1024 - i].imag;
ep.real = (CT1.real + CT2.real) / 2;
ep.imag = (CT1.imag - CT2.imag) / 2;//共轭反对称
op.real = (CT1.real - CT2.real) / 2;
op.imag = (CT1.imag + CT2.imag) / 2;//共轭反对称
w.real = SINMT[i];
if(i > 511)
w.imag = - SINMT[i - 512];
else
w.imag = SINMT[i + 512];
nnnnn = EE(w,op);
re.real = ep.real - nnnnn.real;
re.imag = ep.imag - nnnnn.imag;
cc = sqrt(pow(re.real,2)+pow(re.imag,2));
T[i] = cc;
}
}
void sort_S(unsigned int A[],int n,unsigned int DEX[]) //选择排序
{
unsigned int tmp,i,j;
for(j=0;j<n-1;j++)
{
for(i=0;i<n-1-j;i++)
{
if(A[i+1]>A[i])
{
tmp=A[i+1];
A[i+1]=A[i];
A[i] = tmp;
tmp = DEX[i+1];
DEX[i+1] = DEX[i];
DEX[i] = tmp;
}
}
}
}
void ReapeatDis_F(void)
{
if(ISNSCR)
{
ISNSCR = 0;
clrscreen();
}
DisplayNum(1,2,FRANGE,5);
}
void ReapeatDis_A(void)
{
unsigned char i;
if(ISNSCR)
{
ISNSCR = 0;
clrscreen();
}
if(ISLast)
{
for(i =0; i < 3; i ++)
{
DisplayNum(1,i + 2,POW_Index_LAST[DispalyIndex + i],5);//频率
DisplayNum(4,i + 2,result_LAST[DispalyIndex + i],5);
}
}
else
{
for(i =0; i < 3; i ++)
{
DisplayNum(1,i + 2,POW_Index[DispalyIndex + i],5);//频率
DisplayNum(4,i + 2,result[DispalyIndex + i],5);
}
}
}
//---------------------------------
void PORT_Init ( void )
{
//配置交叉开关 并 使能
XBR0 = 0x16;
XBR1 = 0x1C;
XBR2 = 0x48;
//端口输入输出方式配置:默认为漏极开路数字输入输出方式 置1为推挽输出方式
P0MDOUT = 0xDD; //----------- ------------P0口固定配置无需更改
P2MDOUT |= 0x07;//P20 P21 P22 ----------- HD7279使用
P3MDOUT |= 0x01;//P30 -----------9833用 SPI
//P1MDOUT |= 0x08; // P1 的端口输入输出方式配置
//P1MDOUT |= 0x10; //P14推挽 不行
P74OUT = 0xFE; // ------------------------P5 P6 P7 地址和数据线全部推挽
P1MDIN = 0xFF; // P1为非模拟输出端口 无需更改
//当前端口配置情况:
// Port 0
// P0.0 = UART TX0 (推挽 输出)
// P0.1 = UART RX0 (漏极开路 输出/输入)(数字)
// P0.2 = SPI Bus SCK (推挽 输出)
// P0.3 = SPI Bus MISO (推挽 输出)
// P0.4 = SPI Bus MOSI (推挽 输出)
// P0.5 = SPI Bus NSS (漏极开路 输出/输入)(数字)
// P0.6 = PCA CEX0 (推挽 输出)
// P0.7 = PCA CEX1 (推挽 输出)
// Port 1
// P1.0 = /INT0 (漏极开路 输出/输入)(数字)
// P1.1 = T1 (漏极开路 输出/输入)(数字)
// P1.2 = /INT1 (漏极开路 输出/输入)(数字)
// P1.3 = T4 (漏极开路 输出/输入)(数字)
EMI0CF = 0x38; //外部存储器配置:地址线和数据线使用高端口P4-P7,数据和地址分离,带块选择分片(16位地址同时驱动)
EMI0TC = 0xff; //存储器时序控制:有地址建立时间、保持时间、读写脉冲宽度的配置
//INT0_Init
TCON |= 0x01; //配置为下降沿中断
IE |= 0x01; //允许中断0
}
void Delay25ms(tByte T)
{
Count25ms=T;
while (Count25ms);
}
void Delay1s(tByte T)
{
tByte i ;
for(i = 0; i < T; i ++)
{
Delay25ms(200);
Delay25ms(200);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -