搜档网
当前位置:搜档网 › DSP28335 看门狗中断程序如何变为看门狗重启程序

DSP28335 看门狗中断程序如何变为看门狗重启程序

/*
DSP28335 看门狗中断程序如何变为看门狗重启程序

编28335C程序时没有现成的看门狗重启程序, 但有许多看门狗中断程序, 中断程序运行正常, 取消主循环程序的喂狗 ServiceDog(), 可进入中断. 想改为看门狗重启程序 , 按IT 28335的说明修改, 将中断设置语句SysCtrlRegs.SCSR = BIT1;改为重启设置语句SysCtrlRegs.SCSR =0; 取消喂狗, 程序并不能重启, 将SysCtrlRegs.SCSR =0放到:

"
PieCtrlRegs.PIECTRL.bit.ENPIE = 1; //su3 Enable the PIE block
PieCtrlRegs.PIEIER1.bit.INTx8 = 1; //su4 Enable PIE Gropu 1 INT8
IER |= M_INT1; //su5 Enable CPU int1
EINT;
ServiceDog(); //su7
"
的后面, 取消主循环程序的ServiceDog(); 程序重启, 这是花了几天时间的调试结果

*/

///201506串口//


#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File

#define POST_SHIFT 0 // Shift results after the entire sample table is full
#define INLINE_SHIFT 1 // Shift results as the data is taken from the results regsiter
#define NO_SHIFT 0 // Do not shift the results//

// ADC start parameters
#if (CPU_FRQ_150MHZ) // Default - 150 MHz SYSCLKOUT
#define ADC_MODCLK 0x3 // HSPCLK = SYSCLKOUT/2*ADC_MODCLK2 = 150/(2*3) = 25.0 MHz
#endif
#if (CPU_FRQ_100MHZ)
#define ADC_MODCLK 0x2 // HSPCLK = SYSCLKOUT/2*ADC_MODCLK2 = 100/(2*2) = 25.0 MHz
#endif
#define ADC_CKPS 0x0 // ADC module clock = HSPCLK/1 = 25.5MHz/(1) = 25.0 MHz
#define ADC_SHCLK 0x1 // S/H width in ADC module periods = 2 ADC cycle
#define AVG 1000 // Average sample limit
#define ZOFFSET 0x00 // Average Zero offset
#define BUF_SIZE 1024 // Sample buffer size//

//////int3
//#define LED1 GpioDataRegs.GPBDAT.bit.GPIO60
//#define LED2 GpioDataRegs.GPBDAT.bit.GPIO61

///I2C
Uint16 geti2cdata[1];
Uint16 getdata=0;
Uint16 clei=0;
//Uint16 timerinterrupti=0;
//unsigned long timerinterrupti=0;
unsigned long counti=0;
//unsigned long LASTcounti=0;
unsigned char nocount=0;
//unsigned long WakeCount;
Uint16 ad1data[1025];
Uint16 jj;
//Uint16 ii;
//Uint16 kk;```````````````````````````````
Uint16 ad2data[1025];
Uint16 addata;
Uint16 temp[1];
Uint16 bigcount=0;
Uint16 i2cwreturn;
Uint16 i2crreturn;

Uint16 admax=0;
Uint16 testend=0;
Uint16 saveadmax=0;
/// Uint16 opencount=0;
Uint16 hadd32c=0;
Uint16 ladd32c=0;
Uint16 nowADR24C32=0;
Uint16 ADR24C32=0;
//2015i2c


Uint16 addr=0;

//i2c
void InitI2C(void);



Uint16 I2C_xrdy();
Uint16 I2C_rrdy();

Uint16 Readbyte(Uint16 *RamAddr, Uint16 RomAddress);
Uint16 Writebyte(Uint16 Ramdata, Uint16 RomAddress);
interrupt void wakeint_isr(void);


//i2c




//void InsertionSort(Uint16 input[] ,int len) ;
interrupt void xint4_isr(void)

;
interrupt void xint3_isr(void);
//interrupt void ISRTimer0(void);

void scic_echoback_init(void);
void scic_fifo_init(void);
void scic_xmit(int a);
void scic_msg(char *msg);
void InitI2CGpio(void);
void InitI2C(void);
///i2c
/******************************IO口初始化****************************/
void InitI2C(void)
{
// Initialize I2C-A:
// Initialize I2C
I2caRegs.I2CMDR.bit.IRS =0;
I2caRegs.I2CSAR = 0x0050; // Slave address - EEPROM control code
I2caRegs.I2CPSC.all = 9; // Prescaler - need 7-12 Mhz on module clk
I2caRegs.I2CCLKL = 15; // NOTE: must be non zero
I2caRegs.I2CCLKH = 15; // NOTE: must be non zero
I2caRegs.I2CIER.all = 0x00; // Enable SCD & ARDY interrupts

I2caRegs.I2CMDR.bit.IRS = 1; // Take I2C out of reset

//tbd...
}

void InitI2CGpio( void )
{

EALLOW;
/* Enable internal pull-up for the selected pins */
// Pull-ups can be enabled or disabled disabled by the user.
// This will enable the pullups for the specified pins.
// Comment out other unwanted lines.

GpioCtrlRegs.GPBPUD.bit.GPIO32 = 0; // Enable pull-up for GPIO32 (SDAA)
GpioCtrlRegs.GPBPUD.bit.GPIO33 = 0; // Enable pull-up for GPIO33 (SCLA)

/* Set qualification for selected pins to asynch only */
// This will select asynch (no qualification) for the selected pins.
// Comment out other unwanted lines.

GpioCtrlRegs.GPBQSEL1.bit.GPIO32 = 3; // Asynch input GPIO32 (SDAA)
GpioCtrlRegs.GPBQSEL1.bit.GPIO33 = 3; // Asynch input GPIO33 (SCLA)

/* Configure SCI pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be I2C functional pins.
// Comment out other unwanted lines.

GpioCtrlRegs.GPBMUX1.bit.GPIO32 = 1; // Configure GPIO32 for SDAA operation
GpioCtrlRegs.GPBMUX1.bit.GPIO33 = 1; // Configure GPIO33 for SCLA operation

EDIS;
}

/////////////////i2c


void sci_init(void)
{
EALLOW;
ScicRegs.SCICCR.all =0x0007;
ScicRegs.SCICTL1.all =0x0003;
// ScicRegs.SCICTL2.all =0x0003;
ScicRegs.SCICTL2.bit.TXINTENA=1;
ScicRegs.SCICTL2.bit.RXBKINTENA=1;
//ScicRegs.SCIHBAUD =0x0001;
/// ScicRegs.SCILBAUD =0x0086;
ScicRegs.SCICTL1.bit.SWRESET=1;
EDIS;
}

///

//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
main()
{
Uint16 i;



//AD步骤1.初始化系统控制:PLL、看门狗、使能外设时钟
InitSysCtrl();///timer0 xintstep1
// InitGpio(); //// xintstep1
//x_Sci.c file. com


InitScicGpio();//IN THIS PRO FOU
InitXintf16Gpio();//20241123


InitI2CGpio();///i21c

InitI2C();//i2c




///有这才有串口输出
scic_fifo_init(); // Initialize the SCI FIFO//初始化SCI FIFO
scic_echoback_init(); // Initalize SCI for

PieCtrlRegs.PIEIER8.bit.INTx5=1; // PIE Group 9, int1 20141123
PieCtrlRegs.PIEIER8.bit.INTx6=1; // PIE Group 9, INT2 2014

1123



// IER = 0x100; // Enable CPU INT EINT;
IER = 0x80; // 20141120Enable CPU INT EINT; //20141123
EALLOW;
// Y 记入C接收中断向量表
//PieVectTable.SCITXINTC = &uart_send; // 记入C中断向量表
EDIS;
//

EINT;
ERTM;


///rrr2015

for (i=0; i<5;i++)
{
scic_xmit (107);

scic_xmit (105);

scic_xmit (104);

}

///i2c2803

Readbyte(geti2cdata, 31007) ;

admax=geti2cdata[0];
DELAY_US(100);

Readbyte(geti2cdata, 31005) ; //低位
DELAY_US(100);

ladd32c= geti2cdata[0]& 0x00ff;

//ladd32c= nowADR24C32&0x00ff ;
Readbyte(geti2cdata, 31004) ; // 高位
DELAY_US(100);

hadd32c=geti2cdata[0];///
// ladd32c= nowADR24C32&0x00ff ;

DELAY_US(100);
ADR24C32=hadd32c<<8 ; //左移
nowADR24C32=ADR24C32+ ladd32c;
//// nowADR24C32= ADR24C32 ;


//Readbyte(geti2cdata, 31009) ; // open count
// DELAY_US(100);
//opencount=geti2cdata[0];
// DELAY_US(100);
//opencount=opencount+1;

// Writebyte( opencount,31009 ) ;
//Writebyte( opencount<<8,31008 ) ;


/// i2cstop= I2C_24c32_read_byte(0 , 30000) ;////// stop





scic_xmit (hadd32c);
scic_xmit (ladd32c);


scic_xmit (admax);



scic_xmit (55);




///// i2c2803
///ADXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
//本例的时钟配置
EALLOW;//EALLOW允许DSP指令对关键寄存器进行操作,宏定义EALLOW,设置状态寄存器1的C6位设置与复
SysCtrlRegs.HISPCP.all = ADC_MODCLK; // HSPCLK = SYSCLKOUT/ADC_MODCLK
EDIS;///清除状态寄存器1的C6位 //与EALLOW对应使用


//步骤2.初始化GPIO
///inigipo3();
//initgpio1();// xintstep2


EALLOW;
GpioCtrlRegs.GPBMUX2.bit.GPIO61 = 0; // GPIO61 = GPIO61
GpioCtrlRegs.GPBDIR.bit.GPIO61 = 1;
EDIS;

// EALLOW;
// This is needed to write to EALLOW protected registers
// PieVectTable.SCITXINTA = &ISRTxUart;

//EDIS;







//禁止CPU中断
DINT;//关全局中断timero xintstep3

InitPieCtrl();//初始化Pie控制寄存器xintstep3 ///所有PIE中断的默认状态为禁止,并且标志位被清除???timero
// MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart);
// InitFlash();//201505copy


// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts

//初始化Pie控制寄存器,timero



///AD
// Disable CPU interrupts and clear all CPU interrupt flags:
//禁止CPU中断,清除所有CPU中断标志
IER = 0x0000;//关所有CPU级中断xintstep3
IFR = 0x0000;////清除CPU所有中断标志xintstep3

InitPieVectTable();//BOTH//初始

化中断向量表xintstep3

/////////int3

EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.WAKEINT = &wakeint_isr; ////su1
EDIS; // This is needed to disable write to EALLOW protected registers

EALLOW;
// SysCtrlRegs.SCSR = BIT1; //su2 //DOG中断可放在这有效
//SysCtrlRegs.SCSR =0; //su2 放在这REST无效
// SysCtrlRegs.SCSR =0; //su2 rest eng

EDIS;



PieCtrlRegs.PIECTRL.bit.ENPIE = 1; //su3 Enable the PIE block
PieCtrlRegs.PIEIER1.bit.INTx8 = 1; //su4 Enable PIE Gropu 1 INT8
IER |= M_INT1; //su5 Enable CPU int1
EINT;



//su6 Enable Global Interrupts
ServiceDog(); //su7

EALLOW;
// s.SCSR = BIT1; //su2
SysCtrlRegs.SCSR =0; //su2 DOG REST 放在这才有效
// SysCtrlRegs.SCSR =0; //su2 rest eng

EDIS;




EALLOW;
// DisableDog();

SysCtrlRegs.WDCR = 0x002f; //su8
EDIS;






EALLOW; // This is needed to write to EALLOW protected registers

////timero
// EALLOW; // This is needed to write to EALLOW protected registers
// Interrupts that are used in this example are re-mapped to
// ISR functions found within this file.


//imc没有这一句INT不中断
///PieVectTable.TINT0 = &ISRTimer0; //2015RRRRxxxxx填入定时器中断地趣到向量表 T001


//PieVectTable.XINT13 = &cpu_timer1_isr;
//PieVectTable.TINT2 = &cpu_timer2_isr;
/// EDIS; /////nnnnnnnnnnnnnnnnnn2015



////////timero

// timero//

//// InitCpuTimers(); //T002 20141109RRRRR For this example, only initialize the Cpu Timers


/// ConfigCpuTimer(&CpuTimer0, 150, 100000); //0.1S中断定时器

//没有这一句timero不中断
//ConfigCpuTimer(&CpuTimer0, 150, 1000);//T003RRRR2015 F=100K,10US
//ConfigCpuTimer(&CpuTimer0, 150, 100);// F=100K,10US
//(定时器名,工作频率150, 周期US, ) 9

//ConfigCpuTimer(&CpuTimer1, 150, 1000000);
//ConfigCpuTimer(&CpuTimer2, 150, 1000000);



// Enable CPU int1 which is connected to CPU-Timer 0, CPU int13
// which is connected to CPU-Timer 1, and CPU int 14, which is connected
// to CPU-Timer 2:




////// CpuTimer0Regs.TCR.all = 0x4001; //T004 141130 Use write-only instruction to set TSS bit = 0
//CpuTimer1Regs.TCR.all = 0x4001; // 141130Use write-only instruction to set TSS bit = 0
// CpuTimer2Regs.TCR.all = 0x4001; // 141130Use write-only instruction to set TSS bit = 0

IER |= M_INT1; ///T006

//IER |= M_INT13;
//IER |= M_INT14;

// EINT; //141130 Enable Global interrupt INTM


/// ERTM; // 141130Enable Global realtime interrupt DBGM



// Enable TINT0 in the PIE: Group 1 interrupt 7
////// PieCtrlRegs.PIEIER1.bit.INTx7 = 1; //这句放在这会停机



PieVectTable.XINT3 = &xint3_isr; //填中断向量地址
PieVectTable.XINT4 = &xint4_isr;//setp3





EDIS; // This is needed to disable write to EALLOW protected registers


PieCtrlRegs.PIECTRL.bit.ENPIE = 1; // xintStep 5Enable the PIE block
PieCtrlRegs.PIEIER12.bit.INTx1 = 1; //xintStep 5int3 // Enable PIE Gropu

//2 INT1
PieCtrlRegs.PIEIER12.bit.INTx2 = 1; //xint Step 5int4 // Enable PIE Gropu 12 INT2
// IER |= M_INT12; //使能 CPU 中断 // Enable CPU int12

// IER |= M_INT1;使能 CPU 中断 IER = 0x100;
//IER |= M_INT13;
//IER |= M_INT14;
//ERTM; // Enable Global realtime interrupt DBGM
// Enable TINT0 in the PIE: Group 1 interrupt 7
// 、 EINT; // Enable Global interrupt INTM

//timer0

// Enable TINT0 in the PIE: Group 1 interrupt 7

///// PieCtrlRegs.PIEIER1.bit.INTx7 = 1;/////T07

//timero

IER |= M_INT12; //xintStep 5使能 CPU 中断


EINT; // xintStep 5使能全局中断 // Enable Global Interrupts
// timer0

ERTM; // xxxxxEnable Global realtime interrupt DBGM



///// StartCpuTimer0(); //// 2015rrrrT08

//timero
//// configtestled();

// GPIO58 and GPIO59 are inputs
EALLOW;
GpioCtrlRegs.GPBMUX2.bit.GPIO58 = 0; // GPIOXintStep 5
GpioCtrlRegs.GPBDIR.bit.GPIO58 = 0; // input
GpioCtrlRegs.GPBQSEL2.bit.GPIO58 = 0; // Xint3 Synch to SYSCLKOUT only

GpioCtrlRegs.GPBMUX2.bit.GPIO59 = 0; // GPIO
GpioCtrlRegs.GPBDIR.bit.GPIO59 = 0

; // input
GpioCtrlRegs.GPBQSEL2.bit.GPIO59 = 2; // XINT4 Qual using 6 samples
GpioCtrlRegs.GPBCTRL.bit.QUALPRD0 = 0xFF; // XintStep 5Each sampling window is 510*SYSCLKOUT
EDIS;

// GPIO58 is XINT3, GPIO59 is XINT4
// GPIO58 is XINT3, GPIO59 is XINT4
EALLOW;
GpioIntRegs.GPIOXINT3SEL.bit.GPIOSEL = 58; // Xint3 XintStep 5is GPIO58
GpioIntRegs.GPIOXINT4SEL.bit.GPIOSEL = 59; // XINT4 XintStep 5is GPIO59
EDIS;

EALLOW;
// Configure XINT3 and XINT4
XIntruptRegs.XINT3CR.bit.POLARITY = 0; // Falling edge interrupt
XIntruptRegs.XINT4CR.bit.POLARITY = 1; // Rising edge interrupt

// Enable XINT3 and XINT4
XIntruptRegs.XINT3CR.bit.ENABLE = 1; // Enable Xint3
XIntruptRegs.XINT4CR.bit.ENABLE = 1; // Enable XINT4
EDIS;

// LED1 = 1;
// LED2 = 1;

/// GpioDataRegs.GPBDAT.bit.GPIO60;
///GpioDataRegs.GPBDAT.bit.GPIO61;




//////////int3
//AD
///XXXX
//在使用的中断被重新影射到文件中的ISR函数
// EALLOW; //在写EALLOW保护寄存器,该语句是必须的
//pievecttable.ADCINT = &adc_isr;
/// EDIS; //当禁止写EALLOW保护寄存器




///XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

//////////////////////////
///ADXXXXXXX
InitAdc(); // For this example, init the ADC本程序是要初始化ADC

// Specific ADC setup for this example:
///AdcRegs.ADCTRL1.bit.ACQ_PS =ADC_SHCLK; //rrrrrrr20131024 Sequential mode: Sample rate

AdcRegs.ADCTRL1.bit.ACQ_PS =1;//ADC_SHCLK; //0;/// Sequential mode: Sample rate = 1/[(2+ACQ_PS)*ADC clock in ns]
// ADC_SHCLK;=1 = 1/(3*40ns) =8.3MHz (for 150 MHz SYSCLKOUT)
// = 1/(3*80ns) =4.17MHz (for 100 MHz SYSCLKOUT)
//ACQ_PS=bit11-8 ACQ_PS3-ACQ_PS0
//采集窗口大小。此位字段控制SOC 脉宽,后者确定采样开关关闭的时间段。SOC 脉宽为ADCTRL1[11:8] + 1 乘以ADCLK 周期。
// If Simultaneous mode enabled: Sample rate = 1/[(3+ACQ_PS)*ADC clock in ns]




AdcRegs.ADCTRL3.bit.ADCCLKPS =1;// ADC_CKPS;//0x0 // ADC module clock = HSPCLK/1 = 25.5MHz/(1)
//内核时钟预分频器。预分频器用于对器件外设时钟HSPCLK 进行分频。
// 0 ADCCLK = Fclk/1
//1 ADCCLK = Fclk/2
////注: CLK = 被预分频的HSPCLK (ADCCLKPS[3:0])

//
AdcRegs.ADCTRL1.bit.SEQ_CASC = 1; // 1 Cascaded mode级联模式
//AdcRegs.ADCTRL1.bit.SEQ_CASC=0;//rrrrrrrrrrrrrrr20141024
/*设置顺序采样模式*/
AdcRegs.ADCTRL3.bit.SMODE_SEL=0;/// 选择顺序采样模式。rrrrrrrrrrrrrrr20141024



//AdcRegs.A

DCCHSELSEQ1.bit.CONV00 = 0x1; //rr设置ADCINA0作为第一次SEQ1转换
// AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0; //设置ADCINA0作为第一次SEQ1转换
////
/*采样 ADCINA0*/
AdcRegs.ADCCHSELSEQ1.bit.CONV00=0x0;// 第一个转换
/*采样 ADCINA1*/
AdcRegs.ADCCHSELSEQ1.bit.CONV01=0x1;// 第二个转换
/*采样 ADCINA2*/
// AdcRegs.ADCCHSELSEQ1.bit.CONV02=0x2;
/*采样 ADCINA3*/
// AdcRegs.ADCCHSELSEQ1.bit.CONV03=0x3;
/*采样 ADCINA4*/
//AdcRegs.ADCCHSELSEQ2.bit.CONV04=0x4;
/*采样 ADCINA5*/
//AdcRegs.ADCCHSELSEQ2.bit.CONV05=0x5;
/*采样 ADCINA6*/
// AdcRegs.ADCCHSELSEQ2.bit.CONV06=0x6;
/*采样 ADCINA7*/
// AdcRegs.ADCCHSELSEQ2.bit.CONV07=0x7;
//从下面开始每四位的最高位决定了是用的B采样保持器

/*采样 ADCINB0*/

// AdcRegs.ADCCHSELSEQ3.bit.CONV08=0x8;///9 ???xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx


//Adcregs.ADCCHSELSEQ1.bit.CONV00 = 0x3; // 设置ADCINA3作为第一次SEQ1转换
//Adcregs.ADCCHSELSEQ1.bit.CONV01 = 0x2; // 设置ADCINA2作为第二次SEQ1转换
AdcRegs.ADCTRL1.bit.CONT_RUN = 1; // Setup continuous run

/*
连续运行。此位决定序列发生器工作是处于连续转换模式还是启动/停止模式。可在当前转换序列有效

时写入此位。此位在当前转换序列结束时生效;即,为了采取有效的操作,在发生EOS 之前,可用软件设

置/清除此位。在连续转换模式下,不必复位序列发生器;但是,在启动/停止模式下必须复位序列发生器

,以使转换器进入状态CONV00。
0 启动/停止模式。到达EOS 后序列发生器停止。除非执行了序列发生器复位,否
则序列发生器在遇到下一个SOC 时将从结束时的状态启动。
1 连续转换模式。到达EOS 后,序列发生器的行为取决于SEQ_OVRD 位的状态。
如果清除此位,则序列发生器将再次从其复位状态启动(对SEQ1 和级联模式为
CONV00,对SEQ2 为CONV08)。

*/
AdcRegs.ADCTRL1.bit.SEQ_OVRD = 1; // Enable Sequencer override feature



///最大转换通道寄存器(ADCMAXCONV)(地址偏移02H)
AdcRegs.ADCMAXCONV.bit.MAX_CONV1 = 0x01; //0x08 convert and store in 8 results registers

AdcRegs.ADCTRL2.all = 0x2000;//启动序列器1
//Adcregs.ADCTRL2.bit.INT_ENA_SEQ1=1;///???

ServiceDog(); //su7


for(;;)//死循环
{

do{
counti= counti+1;

while (AdcRegs.ADCST.bit.INT_SEQ1== 0){} //等待转换结束中断,中断为1

ad1data[i]=AdcRegs.ADCRESULT0>>8;
ad2data[i]=AdcRegs.ADCRESULT1>>8;

/// AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;//中断标志变0

if (ad2data[i]> ad1data[i] )
{


ad1data[i]=ad2data[i];///2015rrrrr

}
///ad1

data[i]=143;
if (ad1data[i]>3 )//////datafaif (ad1data[i]>8 )2015RR
{
bigcount=bigcount+1;//

}
else
{

bigcount=0;///
}


i=i+1;

if (i>5 )
{
i=0;

}


if (counti>2000000)///2015RRRRR
{
counti=0;

scic_xmit (ad1data[2]);

}






ServiceDog(); //su7

AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;//中断标志变0

}while(bigcount<2) ; //数据检验员测循环

// testend =3;


// do///rrr201505
// {

// scic_xmit (65);
// DELAY_US(10000);

// ServiceDog(); //su7

/// } while(testend >1);





for (i=4 ;i<1024 ;i++ )
{
while (AdcRegs.ADCST.bit.INT_SEQ1== 0){} //等待转换结束中断,中断为1

ad1data[i]=AdcRegs.ADCRESULT1>>8;
ad2data[i]=AdcRegs.ADCRESULT2>>8;
if (ad2data[i]>ad1data[i])
{
ad1data[i]=ad2data[i];
}


AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;//中断标志变0


} //数据取样循环


///////AXTEST

ServiceDog();


for (i=0 ;i<1024 ;i++ )//
{

if (ad1data[i]> admax )

{

admax= ad1data[i] ;



saveadmax=1;


}


}// i = 0; i <最大值检测



// scic_xmit (250);
// DELAY_US(10000);
// scic_xmit (250);
// DELAY_US(10000);
// scic_xmit (250);
// DELAY_US(10000);
// scic_xmit (250);
// DELAY_US(10000);
// scic_xmit (250);
// ServiceDog();

//f// {

// scic_xmit (ad1data[i-1]);
DELAY_US(1000);
ServiceDog(); //su7

/// }

/////admax=219;



//////////////////MAXTEST
//sae 28008
// nowADR24C32=10;
// saveadmax=1;
if (nowADR24C32>27000 )
{


if (saveadmax==1)
{

saveadmax=0;

Writebyte(admax,31007);//=存最大值

DELAY_US(1000);
ServiceDog(); //su7
nowADR24C32=28020; //只能存2800,2900

for (i = 1; i <1024; i++)

{
Writebyte( ad1data[i],nowADR24C32 ) ; ///存到29000 28000

// WDT_CONTR =0x43;

// delay(2);

DELAY_US(1000);
ServiceDog(); //su7
nowADR24C32= nowADR24C32+1;


// ladd32c=nowADR24C32;
// hadd32c=nowADR24C32>>8;


} ///i=1024////d存I2C


}// if (saveadmax==1)

scic_xmit (admax);


scic_xmit (admax);


ServiceDog();


scic_xmit (180);


scic_xmit (180);
ServiceDog();



} // (ADR24C32>2800 )


///nowADR24C32=2048;
////save00000--28000
if ( nowADR24C32<26999)
{

for (i = 0; i <1024; i++) ////存数据存到L内存 ,

{
Writebyte( ad1data[i],nowADR24C32 ) ; // 存到l内存
DELAY_US(1000);
ServiceDog();
// WDT_CONTR =63;
nowADR24C32= nowADR24C32+1;

//ladd32c=nowADR24C32;

//



} ///i=1024d存I2C

ladd32c= nowADR24C32&0x00ff ;
hadd32c=nowADR24C32>>8;

Writebyte( hadd32c,31004 ) ; // ADDR高位位 存开始


scic_xmit (hadd32c);

DELAY_US(1000);
ServiceDog();


Writebyte( ladd32c,31005 ) ; //ADDR低位 存开始
DELAY_US(1000);

scic_xmit ( ladd32c);


scic_xmit (233);
ServiceDog();


scic_xmit (233);


scic_xmit (233);
ServiceDog();


}//ADR24C32<27999

///senddata to com



///////// sernddata to com

///save0-2800



// testend=9; ///

}// for(;;)



}//main()




//===========================================================================
// No more.
//===========================================================================

void scic_xmit(int a)
{
while (ScicRegs.SCIFFTX.bit.TXFFST != 0) {}
ScicRegs.SCITXBUF=a;

DELAY_US(5000);
}

//////111
void InitScicGpio()
{
EALLOW;

/* Enable internal pull-up for the selected pins */
// Pull-ups can be enabled or disabled disabled by the user.
// This will enable the pullups for the specified pins.

GpioCtrlRegs.GPBPUD.bit.GPIO62 = 0; // Enable pull-up for GPIO62 (SCIRXDC)
GpioCtrlRegs.GPBPUD.bit.GPIO63 = 0; // Enable pull-up for GPIO63 (SCITXDC)

/* Set qualification for selected pins to asynch only */
// Inputs are

synchronized to SYSCLKOUT by default.
// This will select asynch (no qualification) for the selected pins.

GpioCtrlRegs.GPBQSEL2.bit.GPIO62 = 3; // Asynch input GPIO62 (SCIRXDC)

/* Configure SCI-C pins using GPIO regs*/
// This specifies which of the possible GPIO pins will be SCI functional pins.

GpioCtrlRegs.GPBMUX2.bit.GPIO62 = 1; // Configure GPIO62 for SCIRXDC operation
GpioCtrlRegs.GPBMUX2.bit.GPIO63 = 1; // Configure GPIO63 for SCITXDC operation

EDIS;
}


//com
void scic_fifo_init()
{
ScicRegs.SCIFFTX.all=0xE040;
ScicRegs.SCIFFRX.all=0x204f;
ScicRegs.SCIFFCT.all=0x0;

}
//com

void scic_echoback_init()
{
// Note: Clocks were turned on to the SCIA peripheral
// in the InitSysCtrl() function

ScicRegs.SCICCR.all =0x0007; // 1 stop bit, No loopback
// No parity,8 char bits,
// async mode, idle-line protocol
ScicRegs.SCICTL1.all =0x0003; // enable TX, RX, internal SCICLK,
// Disable RX ERR, SLEEP, TXWAKE
ScicRegs.SCICTL2.all =0x0003;
ScicRegs.SCICTL2.bit.TXINTENA = 1;
ScicRegs.SCICTL2.bit.RXBKINTENA =1;
#if (CPU_FRQ_150MHZ)
ScicRegs.SCIHBAUD =0x0001; // 9600 baud @LSPCLK = 37.5MHz.
ScicRegs.SCILBAUD =0x00E7;
#endif
#if (CPU_FRQ_100MHZ)
ScicRegs.SCIHBAUD =0x0001; // 9600 baud @LSPCLK = 20MHz.
ScicRegs.SCILBAUD =0x0044;
#endif
ScicRegs.SCICTL1.all =0x0023; // Relinquish SCI from Reset
}

/////timero





/*
interrupt void ISRTimer0(void) //数据处理中断 100 uS 中断
{






PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; //中断应答, 以便下一次中断,无这只中断一次


CpuTimer0Regs.TCR.bit.TIF=1; ///没有这一句一样中断
CpuTimer0Regs.TCR.bit.TRB=1; ///没有这一句就只是见中断


}///interrupt

*/

////////////i2c


///////////////onebyte
Uint16 Writebyte(Uint16 bytedata, Uint16 RomAddress)
{
Uint16 HAddress;
if (I2caRegs.I2CSTR.bit.BB == 1)
{
return I2C_BUS_BUSY_ERROR;
}
while(!I2C_xrdy());
I2caRegs.I2CSAR = 0x50;
I2caRegs.I2CCNT =3;//number + 2;
HAddress = RomAddress>>8;
I2caRegs.I2CDXR = HAddress&0xFF; //Send high byte of RomAddress
I2caRegs.I2CMDR.all = 0x6E20;
while(!I2C_xrdy());
I2caRegs.I2CDXR = RomAddress&0xFF; //Send low byte of RomAddress


while(!I2C_xrdy());
I2caRegs.I2CDXR = bytedata;

if (I2caRegs.I2CSTR.bit.NACK == 1)
return I2C_BUS_BUSY_ERROR;

return I2C_SUCCESS;
}

Uint16 Readbyte(Uint16 *RamAddr, Uint16 RomAddress)
{
Uint16 Temp,HAddress;

if (I2caRegs.I2CSTR.bit.BB == 1)
{
return I2C_BUS_BUSY_ERROR;
}
while(!I2C_xrdy());
I2caRegs.I2CSAR = 0x50;
I2caRegs.I2CCNT = 2;
HAddress = RomAddress>>8;
I2caRegs.I2CDXR = HAddress&0x

FF; //Send high byte of RomAddress
I2caRegs.I2CMDR.all = 0x6620;
while(!I2C_xrdy());
I2caRegs.I2CDXR = RomAddress&0xFF; //Send low byte of RomAddress
if (I2caRegs.I2CSTR.bit.NACK == 1)
return I2C_BUS_BUSY_ERROR;
DELAY_US(50);
while(!I2C_xrdy());
I2caRegs.I2CSAR = 0x50;
I2caRegs.I2CCNT =1; ///// number
I2caRegs.I2CMDR.all = 0x6C20;
if (I2caRegs.I2CSTR.bit.NACK == 1)
return I2C_BUS_BUSY_ERROR;

{
while(!I2C_rrdy());
Temp = I2caRegs.I2CDRR;
if (I2caRegs.I2CSTR.bit.NACK == 1)
return I2C_BUS_BUSY_ERROR;
*RamAddr = Temp;

}
return I2C_SUCCESS;
}



///////////////obnebyte
Uint16 I2C_xrdy()
{
Uint16 t;
t = I2caRegs.I2CSTR.bit.XRDY;
return t;
}

Uint16 I2C_rrdy()
{
Uint16 t;
t = I2caRegs.I2CSTR.bit.RRDY;
return t;
}





///i2c
interrupt void xint4_isr(void)//读出全部字节
{
DisableDog();
/*
for(ii=0;ii<3;ii++)

{
//
jj=jj+1;
ad1data[jj]=jj;
if( jj>256)
{
jj=0;
}

//mydata[jj]=jj;

i2cwreturn=Writebyte(ad1data[jj],ii);

DELAY_US(10000);
//////////////////

while (ScicRegs.SCIFFTX.bit.TXFFST != 0) {}
ScicRegs.SCITXBUF=ad1data[jj];



while (ScicRegs.SCIFFTX.bit.TXFFST != 0) {}
ScicRegs.SCITXBUF=i2cwreturn;




while (ScicRegs.SCIFFTX.bit.TXFFST != 0) {}
ScicRegs.SCITXBUF=155;




}//ii
*/


for(jj=0;jj<31180;jj++)//读出全部字节
{
//ad1data[jj]=jj;
//mydata[jj]=jj;

i2crreturn=Readbyte(temp,jj);


while (ScicRegs.SCIFFTX.bit.TXFFST != 0) {}
ScicRegs.SCITXBUF=temp[0];
DELAY_US(1000);






}
SysCtrlRegs.WDCR = 0x002f; //su8
/// nocount=1;

//LED2 = ~LED2;
// Acknowledge this interrupt to get more from group 12
PieCtrlRegs.PIEACK.all = PIEACK_GROUP12;////没有这一句只中断一次
}

////////INT3
interrupt void xint3_isr(void)// 写1
{

clei=clei+1;




while (ScicRegs.SCIFFTX.bit.TXFFST != 0) {}
ScicRegs.SCITXBUF=22;
DELAY_US(1000);


if (clei>3)//删除开写1
{
DisableDog();
//

for(jj=0;jj<31180;jj++)
{

//nowADR24C32=jj;
Writebyte( 1,jj ) ; ///存到29000 28000
DELAY_US(1000);

while (ScicRegs.SCIFFTX.bit.TXFFST != 0) {}
ScicRegs.SCITXBUF=251;



}







///
Writebyte( 1,31007 ) ; //MAX
DELAY_US(1000);


scic_xmit (107);

Writebyte( 1,31005 ) ; ///LADR
DELAY_US(1000);


scic_xmit (105);

Writebyte( 1,31004 ) ; ///HADR
DELAY_US(1000);

scic_xmit (104);//结束标志

scic_xmit (155);//结束标志





SysCtrlRegs.WDCR = 0x002f; //su8 dog eng






} ///if clei>3

PieCtrlRegs.PIEACK.all = PIEACK_GROUP12;//没有这一句只中断一次

}

///////////// WakeCount

interrupt void wakeint_isr(void)
{
// WakeCount= WakeCount+1;
EALLOW;


//SysCtrlRegs.SCSR =0; //su2 rest eng

EDIS;
// SysCtrlRegs.SCSR =0; //su2 rest eng


scic_xmit (119);




// Acknowledge this interrupt to get more from group 1
PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;
}


相关主题