打印

2812 定时器程序

[复制链接]
662|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
qwe890asd|  楼主 | 2017-10-13 10:50 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
2812 定时器程序


#include "DSP28_Device.h"unsigned int Send_Flag;
unsigned int i;

void DelayNmSec(int N)
{
unsigned int j;
while(N--)
for(j=0;j<65535;j++);
}

interrupt void T1PINT_ISR(void)
{
strg[0]=105;
length=5;
length--;
Tx=(unsigned char*)strg;
if(length>0) SciaRegs.SCITXBUF=*Tx++;
else
{
length=0;
}
EvaRegs.EVAIMRA.bit.T1PINT=1;//中断允许
EvaRegs.EVAIFRA.bit.T1PINT=1;//清除中断标志
PieCtrl.PIEACK.bit.ACK2=1;//向cpu申请中断
}

interrupt void T2PINT_ISR(void)
{

strg[0]=104;
length=5;
length--;
Tx=(unsigned char*)strg;
if(length>0) SciaRegs.SCITXBUF=*Tx++;
else
{
length=0;
}
EvaRegs.EVAIMRB.bit.T2PINT=1;//中断允许
EvaRegs.EVAIFRB.bit.T2PINT=1;//清除中断标志
PieCtrl.PIEACK.bit.ACK3=1;//向cpu申请中断
}
void main(void)
{

/*初始化系统*/
InitSysCtrl();

/*关中断*/
DINT;
IER = 0x0000;
IFR = 0x0000;

/*初始化PIE中断*/
InitPieCtrl();

/*初始化PIE中断矢量表*/
InitPieVectTable();

/*初始化SCIA寄存器*/
InitSci();
for(i = 0; i < 8; i++)
{
Sci_VarRx = 0;
Sci_VarTx = 0;
}
i=0;
Rx=Sci_VarRx;
Tx=Sci_VarTx;
Send_Flag = 0;
rx_length=0;
add=0;
length=9;

EvaRegs.GPTCONA.all=0;
EvaRegs.T1PR = 65535; //
EvaRegs.EVAIMRA.bit.T1PINT=1;//中断允许
EvaRegs.EVAIFRA.bit.T1PINT=1;//清除中断标志
EvaRegs.T1CNT = 0x0000; // 定时器1计数器
EvaRegs.T1CON.all = 0x1440;//1 分频,使能定时器操作,连续增模式
// 初始化定时器2
EvaRegs.T2PR =65535; // 定时器2的周期为20k
EvaRegs.T2CNT =0x0000; // Timer2 counter
EvaRegs.T2CON.all =0x1440;//16分频,使能定时器操作,连续增模式
EvaRegs.EVAIMRB.bit.T2PINT = 1;//定时器2周期中断允许
EvaRegs.EVAIFRB.bit.T2PINT = 1;//清除标志
/*设置中断服务程序入口地址*/
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.TXAINT = &SCITXINTA_ISR;
PieVectTable.RXAINT = &SCIRXINTA_ISR;
PieVectTable.T1PINT = &T1PINT_ISR;
PieVectTable.T2PINT = &T2PINT_ISR;
EDIS; // This is needed to disable write to EALLOW protected registers

PieCtrl.PIEIER2.bit.INTx4=1;//T1pint中断
PieCtrl.PIEIER3.bit.INTx1=1;//T2pint中断
/*开中断*/
IER |= M_INT9;
IER |= M_INT2; // t1pint enable
IER |= M_INT3; // t2pint enable
EINT; // Enable lobal interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM

while(1)
{
/* DelayNmSec(10);
strg[1]='b';
strg[2]='c';
length=5;
length--;
Tx=(unsigned char*)strg;
if(length>0) SciaRegs.SCITXBUF=*Tx++;
else
{
length=0;
}
strg[1]='x';
strg[2]='y';*/
}
}


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









相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

455

主题

583

帖子

5

粉丝