?? exp-dct-ad.c
字號:
/***************************************************
The programme of the DCT.
Using INT2 to get the input signal.
Array x is the input signal from A/D, the length is 128, 32-bit floating point.
Array y is the compress data, the length is 128, 32-bit floating point.
Array z is the reconstruction signal, the length is 128, 32-bit floating point.
****************************************************/
#pragma CODE_SECTION(vect,"vect")
#include <stdio.h>
#include "math.h"
#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 pi 3.1415927
#define Len 128
double x[Len],y[Len],z[Len];
void dct1c2 (double x[Len], double y[Len]);
void idct1c2 (double y[Len], double z[Len]);
unsigned int *pmem=0;
ioport unsigned char port8002;
int in_x[Len];
int m = 0;
int intnum = 0;
double xmean=0;
int i=0;
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 == Len)
{
intnum = 0;
xmean = 0.0;
for (i=0; i<Len; i++)
{
xmean = in_x[i] + xmean;
}
xmean = 1.0*xmean/Len;
for (i=0; i<Len; i++)
{
x[i] = (double)(in_x[i] - xmean);
}
dct1c2 (x,y);
idct1c2 (y,z);
m=0;
flag = 1;
}
}
void dct1c2 (double x[Len], double y[Len])
{
double s,t;
int i,j;
s=0.0;
for (i=0; i<Len; i++)
{
s=s+x[i];
}
for (i=1; i<Len; i++)
{
t=0.0;
for (j=0; j<Len; j++)
{
t=t+x[j]*cos((2.0*j+1)*i*pi/(2.0*Len));
}
y[i]=sqrt(2.0/Len)*t;
}
y[0]=s/(sqrt(Len/1.0));
}
void idct1c2(double y[Len], double z[Len])
{
double t;
int i,j;
for (i=0; i<Len; i++)
{
t=0.0;
for (j=0; j<Len; j++)
{
t=t+y[j]*cos((2.0*i+1)*j*pi/(2.0*Len));
}
z[i]=y[0]/(sqrt(Len/1.0))+sqrt(2.0/Len)*t;
}
}
void set_int()
{
asm(" ssbx intm");
IMR=IMR|0x0004;
asm(" rsbx intm");
}
void main(void)
{
cpu_init();
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 + -