首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

CPU的定时器0中断怎么进不去?

CPU的定时器0中断怎么进不去?

#include "2812.h"
cregister volatile WORD IER;
cregister volatile WORD IFR;
static WORD loopcount = 0;
void SetupInterrupts(void);
void Time0Init(DWORD Freq,DWORD Period)
{
DWORD temp;
temp = Freq*Period;
TIMER0TIM = 0;
TIMER0TPR = 0;
TIMER0PRD = temp-1;
TIMER0TCR = 0x4820;
}
void InitGpio(void)
{
EALLOW;
GPAMUX = 0x0000;
GPADIR = 0xffff;
GPAQUAL = 0x0000;
GPBMUX = 0x0000;     // GPIO:0-15;
GPBDIR = 0x07ff;     // Input:11-15; Output:0-10;
GPBQUAL = 0x00ff;     // Input Qual: HSPCLK/510;
GPDMUX = 0x0000;     // GPIO:0-15;
GPDDIR = 0xffff;     // Output:0-15;
GPDQUAL = 0x00;      // Input Qual: NULL;
GPEMUX = 0x0003;     // GPIO:8-15; 0:XINT1; 1:XINT2;
GPEDIR = 0x0000;     // Input:8-15;
GPEQUAL = 0x00ff;     // Input Qual: HSPCLK/510;
GPFMUX = 0x00f7;     // GPIO:8-15;
GPFDIR = 0xff08;     // Output:8-15;
GPGMUX = 0x00ff;     // GPIO:8-15;
GPGDIR = 0xff00;     // Output:8-15;
EDIS;
GPADAT = 0xffff;
GPBDAT = 0x0000;
GPDDAT = 0x0000;
GPEDAT = 0x0000;
GPFDAT = 0x0008;
GPGDAT = 0x0000;
}
void SystemInit(WORD Sysclk,WORD Oscclk)
{
WORD i,Freq,OSC;
Freq = Sysclk;
OSC = Oscclk;
EALLOW;
WDCR = 0x0068;   //Disable WatchDog;
PLLCR = Freq*2/OSC;  //SYSCLKOUT=CLKIN=150MHz,SYSCLKOUT=CLKIN=(OSCCLK*PLLCR/2);
for(i=0;i<1000;i++)  // Delay for PLL to stabilize;
{
  asm(" NOP");
}
PCLKCR = 0x0000;  //Enable of Peripheral Clock;
HISPCP = 0x0001;  
LOSPCP = 0x0002;  
IER = 0x0000;   
IFR = 0x0000;   
EDIS;
SetupInterrupts();
Time0Init(150,1000); //定时1ms
InitGpio();
}
interrupt void UnusedIsr(void)
{
return;
}
int main(void)
{
DINT;
SystemInit(150,30);
PIEIER1 = 0x0040;
PIECTRL |= 1;
IER |= 1;
EINT;
ERTM;
while(1);
}

/*CPU定时器,Time1、Time2、Time0*/
interrupt void CPU_Time0(void)
{
loopcount++;
if(loopcount>5000){loopcount = 0;GPADAT = 0x0000;}
TIMER0TCR |= 0x8000;
PIEACK |= 0x0001;
EINT;
}

typedef void (*VECTORS)();//函数指针
void SetupInterrupts(void)
{
VECTORS* pVectors = (VECTORS*)0x0d02;
asm(" EALLOW");
*pVectors++ = UnusedIsr;   // INT1   - Maskable int 1            ;
*pVectors++ = UnusedIsr;   // INT2   - Maskable int 2            ;
*pVectors++ = UnusedIsr;   // INT3   - Maskable int 3            ;
*pVectors++ = UnusedIsr;   // INT4   - Maskable int 4            ;
*pVectors++ = UnusedIsr;   // INT5   - Maskable int 5            ;
*pVectors++ = UnusedIsr;   // INT6   - Maskable int 6            ;
*pVectors++ = UnusedIsr;   // INT7   - Maskable int 7            ;
*pVectors++ = UnusedIsr;   // INT8   - Maskable int 8            ;
*pVectors++ = UnusedIsr;   // INT9   - Maskable int 9            ;
*pVectors++ = UnusedIsr;   // INT10  - Maskable int 10           ;
*pVectors++ = UnusedIsr;   // INT11  - Maskable int 11           ;
*pVectors++ = UnusedIsr;   // INT12  - Maskable int 12           ;
*pVectors++ = UnusedIsr;   // INT13  - Maskable int 13, timer 1  ;
*pVectors++ = UnusedIsr;   // INT14  - Maskable int 14, timer 2  ;
*pVectors++ = UnusedIsr;   // DLOGINT- Maskable data-logging int ;
*pVectors++ = UnusedIsr;   // RTOSINT- Maskable real-time OS int ;
*pVectors++ = UnusedIsr;   // Reserved                           ;
*pVectors++ = UnusedIsr;   // NMI    - Nonmaskable interrupt     ;
*pVectors++ = UnusedIsr;   // ILLEGAL- Illegal instruction trap  ;
*pVectors++ = UnusedIsr;   // USER1  - User-defined sw int/trap  ;
*pVectors++ = UnusedIsr;   // USER2  - User-defined sw int/trap  ;
*pVectors++ = UnusedIsr;   // USER3  - User-defined sw int/trap  ;
*pVectors++ = UnusedIsr;   // USER4  - User-defined sw int/trap  ;
*pVectors++ = UnusedIsr;   // USER5  - User-defined sw int/trap  ;
*pVectors++ = UnusedIsr;   // USER6  - User-defined sw int/trap  ;
*pVectors++ = UnusedIsr;   // USER7  - User-defined sw int/trap  ;
*pVectors++ = UnusedIsr;   // USER8  - User-defined sw int/trap  ;
*pVectors++ = UnusedIsr;   // USER9  - User-defined sw int/trap  ;
*pVectors++ = UnusedIsr;   // USER10 - User-defined sw int/trap  ;
*pVectors++ = UnusedIsr;   // USER11 - User-defined sw int/trap  ;
*pVectors++ = UnusedIsr;   // USER12 - User-defined sw int/trap  ;
*pVectors++ = UnusedIsr;            // PIE int 1.1 ;
*pVectors++ = UnusedIsr;            // PIE int 1.2 ;
*pVectors++ = UnusedIsr;            // PIE int 1.3 ;
*pVectors++ = UnusedIsr;          // PIE int 1.4 XINT1;
*pVectors++ = UnusedIsr;          // PIE int 1.5 XINT2;
*pVectors++ = UnusedIsr;            // PIE int 1.6 ;
*pVectors++ = CPU_Time0;            // PIE int 1.7 ;
*pVectors++ = UnusedIsr;            // PIE int 1.8 ;
asm(" EDIS");
}

新手谢谢指导!
返回列表