通用定时器1初始化程序(启动ADC)
// $ Date: 4/11/2009 整理: eyes417 $
//###########################################################################
//
// FILE : Example_281xEvTimerPeriod.c
//
// TITLE: 事件管理器GP定时器--周期中断启动ADC转换
//
// ASSUMPTIONS:
//
// As supplied, this project is configured for "boot to H0" operation.
// Other then boot mode pin configuration, no other hardware configuration is required.
//
//###########################################################################
#i nclude "DSP281x_Device.h"
#i nclude "DSP281x_Examples.h"
interrupt void eva_timer1_isr(void);
void init_eva_timer1(void);
void main(void)
{
InitSysCtrl();
InitGpio(); //IO口初始化
DINT; //关CPU总中断
InitPieCtrl(); //初始化PIE控制寄存器
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable(); //初始化PIE中断向量表
EALLOW;
//将相应的向量指向中断服务程序,中断发生时,自动跳转
PieVectTable.T1PINT = &eva_timer1_isr;
EDIS;
init_eva_timer1(); //初始化EV-A定时器1
//使能PIE中断INT2.4(T1PINT中断)
PieCtrlRegs.PIEIER2.all = M_INT4;
IER |= M_INT2 ;
EINT; // 使能INTM(全局中断)
ERTM; // Enable Global realtime interrupt DBGM
for(;;);
}
//EV-A定时器1初始化
void init_eva_timer1(void)
{
EvaRegs.GPTCONA.all = 0;
EvaRegs.T1PR = 0x1200; // Period---周期值
EvaRegs.T1CMPR = 0x0000; // Compare Reg--比较值
//清除周期EV-A定时器1中断位
EvaRegs.EVAIMRA.bit.T1PINT = 1;
EvaRegs.EVAIFRA.bit.T1PINT = 1;
EvaRegs.T1CNT = 0x0000; //计数器初值
//递增模式,x/1分频,内部时钟,使能比较,使用自己的周期,立即启动定时器计数
EvaRegs.T1CON.all = 0x1042;
//启动由EVA定时器1周期中断产生的ADC转换
EvaRegs.GPTCONA.bit.T1TOADC = 2;
}
//EV-A定时器1中断服务函数
interrupt void eva_timer1_isr(void)
{
...... //中断服务内容程序
//清除定时器中断位
EvaRegs.EVAIMRA.bit.T1PINT = 1;
EvaRegs.EVAIFRA.all = BIT7; //BIT7---0x0080
//响应中断,从而使INT2中断组继续接收中断
PieCtrlRegs.PIEACK.all = PIEACK_GROUP2;
}