📄 main_nonbios.c
字号:
#include "DSP281x_Device.h" // Peripheral address definitions
#ifdef EXAMPLE_BIOS
#include "example_BIOS.h"
#endif
#ifdef EXAMPLE_NONBIOS
#include "example_nonBIOS.h"
#endif
#include "f2812a.h"
#include "ctr.h"
#include "demo.h"
#include "math.h"
// for LCD control
#define LCDDELAY 1
#define LCDCMDTURNON 0x3f
#define LCDCMDTURNOFF 0x3e
#define LCDCMDSTARTLINE 0xc0
#define LCDCMDPAGE 0xb8
#define LCDCMDVERADDRESS 0x40
#define LCDLEFTPAGE 0
#define LCDRIGHTPAGE 1
#define LCDDATABYTE 1
#define LCDDATAWORD 2
#define STRINGREVERSE 1
#define STRINGNOREVERSE 0
#define T46uS 0x0d40
#define SCANCODE_0 0x70
#define SCANCODE_1 0x69
#define SCANCODE_2 0x72
#define SCANCODE_3 0x7A
#define SCANCODE_4 0x6B
#define SCANCODE_5 0x73
#define SCANCODE_6 0x74
#define SCANCODE_7 0x6C
#define SCANCODE_8 0x75
#define SCANCODE_9 0x7D
#define SCANCODE_Del 0x49
#define SCANCODE_Enter 0x5A
#define SCANCODE_Plus 0x79
#define SCANCODE_Minus 0x7B
#define SCANCODE_Mult 0x7C
#define SCANCODE_Divid 0x4A
#define SCANCODE_Num 0x77
#define led *(int *)0xc0000
#define SOUNDBUFFERLENGTH 128
void FFT(float dataR[128],float dataI[128]);
#define pi 3.1415926
#define X0_b 16
#define Y0_b 32
#define X0_t 16
#define Y0_t 16
#define led *(int *)0xc0000
void Delay(unsigned int nTime); // 延时子程序
void TurnOnLCD(); // 打开显示
void LCDCLS(); // 清除屏幕显示内容
void Gpio_select(void);
void error(int);
void program_stop();
char ConvertScanToChar(unsigned char cScanCode);
void RefreshLEDArray(); // 刷新显示
void SetLEDArray(int nNumber); // 修改显示内容
unsigned int uWork,bLCD,nScanCode,nMode,bShowAD;
int nModeAD;
unsigned int w[128];
float sin_tab[128],cos_tab[128];
float fDataR[128],fDataR1[128],fDataI[128];
interrupt void adc_isr(void);
Uint16 var1 = 0;
Uint16 var2 = 0;
Uint16 var3 = 0;
Uint16 test_count = 0;
Uint16 Test_flag = 0;
Uint16 Test_var = 0;
Uint16 Test_status[32];
struct CPUTIMER_VARS CpuTimer0;
int jishu=0;
int jishu1=0;
unsigned int uPort8000;
Uint16 LoopCount;
Uint16 ConversionCount;
int Position;
int nBW=0;//常写0,写1是反写液晶屏。
unsigned char cKey,cOldKey;
Uint16 Voltage1[256];
Uint16 Voltage2[256];
Uint16 ad1,ad2;
Uint16 jia[256];
unsigned int bBreak;
/*fir参数*/
#define PI 3.1415926
#define FIRNUMBER 25
#define SIGNAL1F 1000
#define SIGNAL2F 4500
/*低通滤波器系数可滤掉1k以上的波形,保留1k一下的波形*/
float fHn[FIRNUMBER]={
0.126,0.085,0.000,-0.103,-0.189,-0.216,-0.155,
-0.000,0.233,0.504,0.756,0.935,1.000,0.935,0.756,
0.504,0.233,-0.000,-0.155,-0.216,-0.189,-0.103,
0.000, 0.085, 0.126
};
/*高通滤波器系数可滤掉1k以下的波形,保留1k以上的波形*/
float fLn[FIRNUMBER]={
-0.031,-0.021,-0.000,0.025, 0.047, 0.054,
0.038, 0.000,-0.058,-0.126,-0.189,-0.233,
1.000,-0.233,-0.189,-0.126,-0.058, 0.000,
0.038, 0.054, 0.047, 0.025,-0.000,
-0.021,-0.031
};
float fXn[FIRNUMBER]={ 0.0 };
float fInput,fOutput;
float fSignal1,fSignal2;
float fStepSignal1,fStepSignal2;
float f2PI;
float fIn[256],fOut[256];
int nIn,nOut;
float FIR();
float FIR1();
float InputWave();
int j,a=0;
//int i;
/**********************************************************************
* Function: main()
*
* Description: Main function for F281x example.
**********************************************************************/
void main(void)
{int i,nCount1=0;
/*** CPU Initialization ***/
InitSysCtrl(); // Initialize the CPU (FILE: SysCtrl.c)
// Section secureRamFuncs contains user defined code that runs from CSM secured RAM
memcpy( &secureRamFuncs_runstart,
&secureRamFuncs_loadstart,
&secureRamFuncs_loadend - &secureRamFuncs_loadstart);
/*** Main Loop ***/
bLCD=nMode=0;
for ( i=0;i<8;i++ ) ledx[i]=(i<<4)|8; // 生成显示列控制字
for ( i=0;i<SOUNDBUFFERLENGTH;i++ )
{
sin_tab[i]=sin(pi*2*i/SOUNDBUFFERLENGTH);
cos_tab[i]=cos(pi*2*i/SOUNDBUFFERLENGTH);
}
LCDSetDelay(1);
LCDSetScreenBuffer(nScreenBuffer);
*(int *)0x108000=0x80; // 初始化ICETEK-CTR
Delay(LCDDELAY);
*(int *)0x108000=0x0;
Delay(LCDDELAY);
*(int *)0x108000=0x80;
Delay(LCDDELAY);
*(int *)0x108007=0; // 关闭东西方向的交通灯
Delay(LCDDELAY);
*(int *)0x108007=0x40; // 关闭南北方向的交通灯
Delay(LCDDELAY);
*(int *)0x108007=0x0c1;
//*(int *)0x108000=0x81;
// 打开显示
LCDTurnOn();
LCDPutCString(str8,CCXAD,CCYAD,6,1);
i=*(int *)0x108002;
k0=k1=0; cKey=cOldKey=0;
for ( i=0;i<1024;i++ ) nScreenBuffer[i]=0;
struGraph.pData=nGraphBuf2+20;
struGraph.uDataMode=DATAINTMODE;
struGraph.uDataLength=128;
struGraph.uMaxValue=2704;
struGraph.uWindowX0=0;
struGraph.uWindowY0=0;
struGraph.uWindowX1=128;
struGraph.uWindowY1=32;
struGraph.nOriginX=0;
struGraph.nOriginY=0;
struGraph.uLineMode=LINEMODE;
struGraph.bShowXCcoordinate=0;
struGraph.bShowYCcoordinate=0;
struGraph1.pData=nGraphBuf1+20;
struGraph1.uDataMode=DATAINTMODE;
struGraph1.uDataLength=128;
struGraph1.uMaxValue=2704;
struGraph1.uWindowX0=0;
struGraph1.uWindowY0=32;
struGraph1.uWindowX1=128;
struGraph1.uWindowY1=64;
struGraph1.nOriginX=0;
struGraph1.nOriginY=32;
struGraph1.uLineMode=LINEMODE;
struGraph1.bShowXCcoordinate=0;
struGraph1.bShowYCcoordinate=0;
nMode=MODEADC;
LCDCLS();
EALLOW;
SysCtrlRegs.HISPCP.all = 0x3; // HSPCLK = SYSCLKOUT/6
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
EALLOW; // This is needed to write to EALLOW protected register
PieVectTable.ADCINT = &adc_isr;
EDIS; // This is needed to disable write to EALLOW protected registers
AdcRegs.ADCTRL1.bit.RESET = 1; // Reset the ADC module
asm(" RPT #10 || NOP"); // Must wait 12-cycles (worst-case) for ADC reset to take effect
AdcRegs.ADCTRL3.all = 0x00C8; // first power-up ref and bandgap circuits
AdcRegs.ADCTRL3.bit.ADCBGRFDN = 0x3; // Power up bandgap/reference circuitry
Delay(200); // Delay before powering up rest of ADC
AdcRegs.ADCTRL3.bit.ADCPWDN = 1; // Power up rest of ADC
Delay(200); // Delay after powering up ADC
// Enable ADCINT in PIE
PieCtrlRegs.PIEIER1.bit.INTx6 = 1;
IER |= M_INT1; // Enable CPU Interrupt 1
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
LoopCount = 0;
ConversionCount = 0;
// Configure ADC
AdcRegs.ADCMAXCONV.all = 0x0001; // Setup 2 conv's on SEQ1
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0; // Setup ADCINA3 as 1st SEQ1 conv.
AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x1; // Setup ADCINA2 as 2nd SEQ1 conv.
AdcRegs.ADCTRL2.bit.EVA_SOC_SEQ1 = 1; // Enable EVASOC to start SEQ1
AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 1; // Enable SEQ1 interrupt (every EOS)
// Configure EVA
//Assumes EVA Clock is already enabled in InitSysCtrl();
EvaRegs.T1CMPR = 0x0080; // Setup T1 compare value
EvaRegs.T1PR = 0x500; // Setup period register
EvaRegs.GPTCONA.bit.T1TOADC = 1; // Enable EVASOC in EVA
EvaRegs.T1CON.all = 0x1042; // Enable timer 1 compare (upcount mode)
bBreak=nModeAD=0;
cKey=cOldKey=0;nCount1==0;
nIn=0; nOut=0;
f2PI=2*PI;
fSignal1=0.0;
fSignal2=PI*0.1;
fStepSignal1=2*PI/30;
fStepSignal2=2*PI*1.4;
while ( 1 )
{ Delay(100);
nScanCode=*(int *)0x108001;
nScanCode&=0x0ff;
uWork=*(int *)0x108002;
if ( nScanCode!=0 && nScanCode!=0x0ff )
{
if ( nScanCode==SCANCODE_Enter ) {AdcRegs.ADCTRL2.bit.INT_ENA_SEQ1 = 0; break;}
else
{
cKey=ConvertScanToChar(nScanCode);
}
switch ( cKey )
{
case '0':/*两路ad显示*/
nModeAD=0;
struGraph.pData=nGraphBuf2+20;
struGraph.uDataMode=DATAINTMODE;
struGraph.uDataLength=128;
struGraph.uMaxValue=2704;
struGraph.uWindowX0=0;
struGraph.uWindowY0=0;
struGraph.uWindowX1=128;
struGraph.uWindowY1=32;
struGraph.nOriginX=0;
struGraph.nOriginY=0;
struGraph.uLineMode=LINEMODE;
struGraph.bShowXCcoordinate=0;
struGraph.bShowYCcoordinate=0;
struGraph1.pData=nGraphBuf1+20;
struGraph1.uDataMode=DATAINTMODE;
struGraph1.uDataLength=128;
struGraph1.uMaxValue=2704;
struGraph1.uWindowX0=0;
struGraph1.uWindowY0=32;
struGraph1.uWindowX1=128;
struGraph1.uWindowY1=64;
struGraph1.nOriginX=0;
struGraph1.nOriginY=32;
struGraph1.uLineMode=LINEMODE;
struGraph1.bShowXCcoordinate=0;
struGraph1.bShowYCcoordinate=0;
break;
case '1':/*混叠显示*/
nModeAD=1;
struGraph.pData=nGraphBuf1+20;
struGraph.uDataMode=DATAINTMODE;
struGraph.uDataLength=128;
struGraph.uMaxValue=2704;
struGraph.uWindowX0=0;
struGraph.uWindowY0=0;
struGraph.uWindowX1=128;
struGraph.uWindowY1=64;
struGraph.nOriginX=0;
struGraph.nOriginY=0;
struGraph.uLineMode=LINEMODE;
struGraph.bShowXCcoordinate=0;
struGraph.bShowYCcoordinate=0;
break;
case '2':/*低通滤波显示*/
nModeAD=2;
struGraph.pData=nGraphBuf3+30;
struGraph.uDataMode=DATAINTMODE;
struGraph.uDataLength=128;
struGraph.uMaxValue=2704;
struGraph.uWindowX0=0;
struGraph.uWindowY0=0;
struGraph.uWindowX1=128;
struGraph.uWindowY1=64;
struGraph.nOriginX=0;
struGraph.nOriginY=0;
struGraph.uLineMode=LINEMODE;
struGraph.bShowXCcoordinate=0;
struGraph.bShowYCcoordinate=0;
break;
case '3':/*高通滤波显示*/
nModeAD=3;
struGraph.pData=nGraphBuf3+30;
struGraph.uDataMode=DATAINTMODE;
struGraph.uDataLength=128;
struGraph.uMaxValue=2704;
struGraph.uWindowX0=0;
struGraph.uWindowY0=0;
struGraph.uWindowX1=128;
struGraph.uWindowY1=64;
struGraph.nOriginX=0;
struGraph.nOriginY=0;
struGraph.uLineMode=LINEMODE;
struGraph.bShowXCcoordinate=0;
struGraph.bShowYCcoordinate=0;
break;
// }
}
}
}
DINT;
nMode=0;
//LCDCLS();
} //end of main()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -