⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 exp-conv-ad-main.c

📁 卷积算法实验 实验设备:计算机
💻 C
字号:
/********************************************************************************
The programme of the Convolution Algorithm.
Using INT2 to get the input signal.
Array Input, in first step, is the input signal produced programme,
in next step, is the input signal get from A/D,
the length is 128, 32-bit floating point.
Array Impulse, in first step, is the input signal produced programme,
in next step, is the input signal get from A/D,
the length is 128, 32-bit floating point.
Array Output is the Convolution result, the length is 256, 32-bit floating point. 
*********************************************************************************/
#pragma CODE_SECTION(vect,"vect")
extern void InitC5402(void);

#include "stdlib.h"
#include "stdio.h"
#include "typedef.h"
#include "Convolve.h"
#include "math.h"
#define pi 3.1415927
#define IMR   *(pmem+0x0000)  
#define IFR   *(pmem+0x0001)  
#define PMST  *(pmem+0x001D)  
#define SWCR  *(pmem+0x002B)  
#define SWWSR *(pmem+0x0028) 
#define AL    *(pmem+0x0008) 
#define CLKMD  0x0058 /* clock mode reg*/

#define Length  128
#define Length3  2*Length

int s,t=0;
double Input[Length] ;
double Impulse[Length] ;
double Output[Length3] ;
int xm;

unsigned int  *pmem=0;
ioport	unsigned char	port8002;
int in_x[Length];
int m = 0;
int intnum = 0;
double xavg;
int flag = 0;

void cpu_init()
{
   *(unsigned int*)CLKMD=0x0;         //switch to DIV mode clkout= 1/2 clkin
     while(((*(unsigned int*)CLKMD)&01)!=0);
   *(unsigned int*)CLKMD=0x77ff;      //switch to PLL 
	
	PMST=0x3FA0;
	SWWSR=0x7fff;
	SWCR=0x0000;
	IMR=0;
	IFR=IFR;
} 

interrupt void int2()   
{
	in_x[m] = port8002;
	in_x[m] &= 0x00FF;
	m++;
	intnum = m;
	
	if (intnum == Length)
	{
		intnum = 0;
		
		xavg = 0.0;
		
		for (s=0; s<Length; s++)
		{
			xavg = in_x[s] + xavg;
		}		
		
		xavg = xavg/Length;
		
		for (s=0; s<Length; s++)
		{
			Input[s] = 1.0*(in_x[s] - xavg);
			Impulse[s] = Input[s];
		}
		
		Convolveok( Input, Impulse, Output, Length);
		
		m=0;
		flag = 1;
	}
}
 
void set_int()    
{
	asm(" ssbx intm");
	IMR=IMR|0x0004;  
	asm(" rsbx intm");  
}

void main(void)
{
    Input[0] = 200;
    Impulse[0] = 100 ;

	cpu_init();

	for( s = 1 ; s < Length ; s ++ )
	{

		if(s < Length/2)
		{
    		  Input[s] = 200;
		}  
		else
		  {
    		  Input[s]=0;
		  }
	}

	for( s = 1 ; s < Length ; s ++ )
	{

		if(s<Length/2)
		{
	    	  Impulse[s] = 100;		
		}  
		else
		  {
    		  Impulse[s]=0;  
		  }
	}

	Convolveok( Input, Impulse, Output, Length);

	t++;	

	set_int();

	for(;;)
	{
		if (flag == 1)
		{
		   flag = 0;    /* set breakpoint here */

		}
	}
}

void vect()
{
   asm(" .ref _c_int00");/*pseudoinstruction*/
   asm(" .ref _int2");

   asm(" b _c_int00");/* reset */  
   asm(" nop");
   asm(" nop");
   asm(" rete");        
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");     /* int0 */
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");     /* int1 */
   asm(" nop");			    
   asm(" nop");
   asm(" nop");
   asm(" b _int2");  /* int2 */
   asm(" nop");
   asm(" nop");
   asm(" rete");     /* tint0 */
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");     /* brint0 */
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");     /* bxint0 */
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");     /* dmac0 */
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");     /* tint1 */
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");     /* int3 */
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");     /* hpint */
   asm(" nop");
   asm(" nop");
   asm(" rete");     /* brint1 */
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");     /* bxint1 */
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");     /* dmac4 */
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" rete");     /* dmac5 */
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" nop");
   asm(" nop");
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -