?? example_28xgpio.c
字號:
#include "DSP28_Device.h"
#include "DSP28_Globalprototypes.h"
#define SCIA_INT 1
#define SetData GpioDataRegs.GPFDAT.bit.GPIOF12 = 1
#define ClrData GpioDataRegs.GPFDAT.bit.GPIOF12 = 0
#define SetClk GpioDataRegs.GPFDAT.bit.GPIOF8 = 1
#define ClrClk GpioDataRegs.GPFDAT.bit.GPIOF8 = 0
unsigned int *LedReg = (unsigned int *)0x27FF;
unsigned int *Led8Lock = (unsigned int *)0x2BFF;
const Uint16 LedCode[]={0x7F,0xBF,0xDF,0xEF,0xF7,0xFB,0xFD,0xFE,0xFF};
const Uint16 SpiCode[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x90,0x88,0x83,0xC6,0xA1,0x86,0x8E,0xFF};
Uint16 LedCount = 0;
Uint16 SpiCount = 0;
unsigned long Timer0Counter=0,Timer0Counter1=0;
//float a1[TotalChannelNumber][NOrder];
int16 *a1 = (int16 *)0x100000;
extern struct ADChannelStruct* ADChannel;
float adclo;
unsigned int ADIndex;
unsigned int CaculateSign,CaculateSign1;
int StoreSign=1,nCaculateMode=-2;
unsigned int Sci_VarRx[100];
unsigned int RXIndex=0;
unsigned int Send_Flag;
unsigned long CaculateTimeCounter=0,CaculateTimeCounter1=0;
// Prototype statements for functions found within this file.
interrupt void ad(void);
interrupt void ISRTimer0(void);
interrupt void ISRTimer2(void);
interrupt void RX_sci_A(void);
//interrupt void TX_sci_A(void);
void SendData(Uint16 data);
extern void CacluateValue(int AreaNo,int *CaculateMode);
void ad1(void);
void main(void)
{
unsigned int i,j;
/*初始化系統*/
InitSysCtrl();
/*關中斷*/
DINT;
IER = 0x0000;
IFR = 0x0000;
/*初始化PIE*/
InitPieCtrl();
/*初始化PIE中斷矢量表*/
InitPieVectTable();
/*初始化外設*/
InitPeripherals();
InitGpio();
InitSci();
for(i = 0; i < 100; i++)
{
Sci_VarRx[i] = 0;
}
i = 0;
j = 0;
Send_Flag = 0;
EALLOW;
PieVectTable.TINT0 = &ISRTimer0;
PieVectTable.TINT2 = &ISRTimer2;
PieVectTable.ADCINT=&ad;
#if SCIA_INT
// PieVectTable.TXAINT = &TX_sci_A;
PieVectTable.RXAINT = &RX_sci_A;
#endif
EDIS;
/*設置CPU*/
//ConfigCpuTimer(&CpuTimer0, 10, 5000000);//10MHz,500000 period=0.5s
ConfigCpuTimer(&CpuTimer0, 100, 10000); //0.0001s per interrupt, 10kHz
ConfigCpuTimer(&CpuTimer2, 100, 1000000);
InitAdc();
ADIndex=0;
CaculateSign=0;
CaculateSign1=0;
StartCpuTimer0();
StartCpuTimer2();
/*開中斷*/
IER |= M_INT1;
IER |= M_INT14;
IER |= M_INT9;
PieCtrl.PIEIER1.bit.INTx7=1;
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
*Led8Lock = 0X01;
*LedReg = 0xFF;
// while(AdcRegs.ADC_ST_FLAG.bit.SEQ1_BSY==0)
{
// AdcRegs.ADCTRL2.bit.SOC_SEQ1=1;
}
nCaculateMode=-2;
for(;;)
{
KickDog();
if((SciaTx_Ready() == 1) && (Send_Flag == 1))
{
SciaRegs.SCITXBUF = Sci_VarRx[i];
Send_Flag = 0;
i++;
if(i == j)
{
i = 0;
j = 0;
}
}
#if !SCIA_INT
if(SciaRx_Ready() == 1)
{
Sci_VarRx[j] = SciaRegs.SCIRXBUF.all;
Send_Flag = 1;
j++;
if(j == 100)
{
j = 0;
}
}
#endif
if(CaculateSign==1)
{
CaculateTimeCounter++;
CacluateValue(0,&nCaculateMode);
CaculateSign=0;
}
if(CaculateSign1==1)
{
CaculateTimeCounter++;
CacluateValue(1,&nCaculateMode);
CaculateSign1=0;
}
}
}
interrupt void ISRTimer0(void)
{
PieCtrl.PIEACK.bit.ACK7=1;
// ad1();
Timer0Counter++;
// while(AdcRegs.ADC_ST_FLAG.bit.SEQ1_BSY==0)
{
//Timer0Counter1++;
// AdcRegs.ADCTRL2.bit.SOC_SEQ1=1;
}
}
interrupt void ISRTimer2(void)
{
*LedReg = LedCode[LedCount];
LedCount++;
if (LedCount>8)
LedCount=0;
SendData(SpiCode[SpiCount]);
SpiCount++;
if (SpiCount>16)
SpiCount=0;
if(nCaculateMode==-2)nCaculateMode=-1; //Cacluate Mode=-1 to caculate channel offset
}
void Delay(Uint16 data)
{
Uint16 i;
for (i=0;i<data;i++) { ; }
}
void SendData(Uint16 data)
{
Uint16 i,Temp;
Temp = 0x80;
for (i=0;i<8;i++)
{
if ((data & Temp)==0) ClrData;
else SetData;
Temp >>= 1;
ClrClk;
Delay(10);
SetClk;
}
*Led8Lock = 0x00;
Delay(10);
*Led8Lock = 0x01;
SetData;
}
//===========================================================================
// No more.
//===========================================================================
interrupt void ad(void)
{
int i=0;
// IFR=0x0000;
// PieCtrl.PIEIFR1.all = 0;
// PieCtrl.PIEACK.all=0xffff;
PieCtrl.PIEACK.bit.ACK6=1;
/*
a1[0][ADIndex]=((float)AdcRegs.RESULT0)*3.0/65520.0+adclo;
a1[1][ADIndex]=((float)AdcRegs.RESULT1)*3.0/65520.0+adclo;
a1[2][ADIndex]=((float)AdcRegs.RESULT2)*3.0/65520.0+adclo;
a1[3][ADIndex]=((float)AdcRegs.RESULT3)*3.0/65520.0+adclo;
a1[4][ADIndex]=((float)AdcRegs.RESULT4)*3.0/65520.0+adclo;
a1[5][ADIndex]=((float)AdcRegs.RESULT5)*3.0/65520.0+adclo;
a1[6][ADIndex]=((float)AdcRegs.RESULT6)*3.0/65520.0+adclo;
a1[7][ADIndex]=((float)AdcRegs.RESULT7)*3.0/65520.0+adclo;
a1[8][ADIndex]=((float)AdcRegs.RESULT8)*3.0/65520.0+adclo;
a1[9][ADIndex]=((float)AdcRegs.RESULT9)*3.0/65520.0+adclo;
a1[10][ADIndex]=((float)AdcRegs.RESULT10)*3.0/65520.0+adclo;
a1[11][ADIndex]=((float)AdcRegs.RESULT11)*3.0/65520.0+adclo;
a1[12][ADIndex]=((float)AdcRegs.RESULT12)*3.0/65520.0+adclo;
a1[13][ADIndex]=((float)AdcRegs.RESULT13)*3.0/65520.0+adclo;
a1[14][ADIndex]=((float)AdcRegs.RESULT14)*3.0/65520.0+adclo;
a1[15][ADIndex]=((float)AdcRegs.RESULT15)*3.0/65520.0+adclo;
*/
if(ADIndex==0&&nCaculateMode!=-1)
{
if(CaculateSign==0)
{
a1=(int16 *)0x100000;
StoreSign=1;
}
else if(CaculateSign1==0)
{
a1=(int16 *)0x100c80;
StoreSign=2;
}
else
{
StoreSign=0;
}
}
if(StoreSign>0)
{
/*
*(a1+ADIndex)=AdcRegs.RESULT0;
ADIndex++;
*(a1+ADIndex)=AdcRegs.RESULT2;
ADIndex++;
*(a1+ADIndex)=AdcRegs.RESULT4;
ADIndex++;
*(a1+ADIndex)=AdcRegs.RESULT6;
ADIndex++;
*(a1+ADIndex)=AdcRegs.RESULT8;
ADIndex++;
*(a1+ADIndex)=AdcRegs.RESULT10;
ADIndex++;
*(a1+ADIndex)=AdcRegs.RESULT12;
ADIndex++;
*(a1+ADIndex)=AdcRegs.RESULT14;
ADIndex++;
*(a1+ADIndex)=AdcRegs.RESULT1;
ADIndex++;
*(a1+ADIndex)=AdcRegs.RESULT3;
ADIndex++;
*(a1+ADIndex)=AdcRegs.RESULT5;
ADIndex++;
*(a1+ADIndex)=AdcRegs.RESULT7;
ADIndex++;
*(a1+ADIndex)=AdcRegs.RESULT9;
ADIndex++;
*(a1+ADIndex)=AdcRegs.RESULT11;
ADIndex++;
*(a1+ADIndex)=AdcRegs.RESULT13;
ADIndex++;
*(a1+ADIndex)=AdcRegs.RESULT15;
ADIndex++;
*/
for(i=0;i<16;i++)
{
// *(a1+ADIndex+i) =*((Uint16 *)(0x007108+i));//-(Uint16)(*(float *)(0x102000+i*6+3));//ADCResult0
*(a1+ADIndex+i) =*((int16 *)(0x007108+i))-(int16)(*(float *)(0x102000+i*12+6));//ADCResult0
}
ADIndex+=16;
if(ADIndex>=3200)
{
if(StoreSign==1)CaculateSign=1;
if(StoreSign==2)CaculateSign1=1;
ADIndex=0;
//CaculateTimeCounter++;
}
}
CaculateTimeCounter1++;
AdcRegs.ADC_ST_FLAG.bit.INT_SEQ1_CLR=1;
// AdcRegs.ADCTRL2.bit.RST_SEQ1=1;
// AdcRegs.ADCTRL2.bit.SOC_SEQ1=1;
// EINT;
}
interrupt void RX_sci_A(void)
{
Sci_VarRx[RXIndex++] = SciaRegs.SCIRXBUF.all;
Send_Flag = 1;
if(RXIndex == 100)
{
RXIndex = 0;
}
}
void ad1(void)
{
if(CaculateSign==0)
{
*(a1+ADIndex)=(float)AdcRegs.RESULT0;
ADIndex++;
*(a1+ADIndex)=(float)AdcRegs.RESULT1;
ADIndex++;
*(a1+ADIndex)=(float)AdcRegs.RESULT2;
ADIndex++;
*(a1+ADIndex)=(float)AdcRegs.RESULT3;
ADIndex++;
*(a1+ADIndex)=(float)AdcRegs.RESULT4;
ADIndex++;
*(a1+ADIndex)=(float)AdcRegs.RESULT5;
ADIndex++;
*(a1+ADIndex)=(float)AdcRegs.RESULT6;
ADIndex++;
*(a1+ADIndex)=(float)AdcRegs.RESULT7;
ADIndex++;
*(a1+ADIndex)=(float)AdcRegs.RESULT8;
ADIndex++;
*(a1+ADIndex)=(float)AdcRegs.RESULT9;
ADIndex++;
*(a1+ADIndex)=(float)AdcRegs.RESULT10;
ADIndex++;
*(a1+ADIndex)=(float)AdcRegs.RESULT11;
ADIndex++;
*(a1+ADIndex)=(float)AdcRegs.RESULT12;
ADIndex++;
*(a1+ADIndex)=(float)AdcRegs.RESULT14;
ADIndex++;
*(a1+ADIndex)=(float)AdcRegs.RESULT15;
ADIndex++;
if(ADIndex>=3290)
{
CaculateSign=1;
ADIndex=0;
CaculateTimeCounter++;
}
AdcRegs.ADC_ST_FLAG.bit.INT_SEQ1_CLR=1;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -