以下为设为Timer2的程序:
void main(void)
{
// Initialize System Control registers, PLL, WatchDog, Clocks to Alphafault state:
// This function is found in the DSP281x_SysCtrl.c file.
InitSysCtrl();
// HISPCP prescale register settings, normally it will be set to Alphafault values
EALLOW; // This is neeAlphad to write to EALLOW protected registers
SysCtrlRegs.HISPCP.all = 0x0006; // SYSCLKOUT/1 //HISCLK=10MHz
EDIS; // This is neeAlphad to disable write to EALLOW protected registers
// Disable and clear all CPU interrupts:
DINT;
IER = 0x0000;
IFR = 0x0000;
InitPieCtrl();
InitPieVectTable();
EALLOW;
PieVectTable.ADCINT=&adc1_isr;
PieVectTable.T2PINT = &eva_timer2_isr;
EDIS;
init_eva_timer2();
PieCtrlRegs.PIEIER3.all = M_INT1;
PieCtrlRegs.PIEIFR3.all = M_INT1;
PieCtrlRegs.PIEACK.bit.ACK3=1;
IER |= M_INT3;
// Enable global Interrupts and higher priority real-time debug events:
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
补上初始化程序
void init_eva_timer2(void)
{
// Initialize EVA Timer 2:
// Setup Timer 2 Registers (EV A)
EvaRegs.GPTCONA.all = 0;
// Set the Period for the GP timer 2 to 0x0200;
EvaRegs.T2PR = 0x0400; // Period
EvaRegs.T2CMPR = 0x0000; // Compare Reg
// Enable Period interrupt bits for GP timer 2
// Count up, x128, internal clk, enable compare, use own period
EvaRegs.EVAIMRB.bit.T2PINT = 1;
EvaRegs.EVAIFRB.bit.T2PINT = 1;
// Clear the counter for GP timer 2
EvaRegs.T2CNT = 0x0000;
EvaRegs.T2CON.all = 0x1742;
// Start EVA ADC Conversion on timer 2 Period interrupt
EvaRegs.GPTCONA.bit.T2TOADC = 2;
}