本帖最后由 wuyuanxian 于 2014-7-11 14:25 编辑
小弟第一次用SH79F1621,用定时器2定时一直进不去中断,求大神们看看。在线等。谢谢!代码如下:
#include "intrins.h"
#include "absacc.h"
#include "SH79F1621.h" //单片机特殊寄存器文件
bit f_025ms = 0;
void InitSystem(void)
{
CLKCON = 0x60; //使用外部振荡,系统时钟12分频
TL2 = (65536-250)&0xff; //定时0.25ms
TH2 = ((65536-250)>>8)&0xff;
RCAP2L = (65536-250)&0xff;
RCAP2H = ((65536-250)>>8)&0xff;
TCON = 0x00;
T2CON = 0x00; //时钟源设为系统时钟,定时器方式
T2MOD &= 0xfc; //
TF2 = 0;
TR2 = 1;
/*-----------------------------------------------------
Interrupt
-----------------------------------------------------*/
IEN0 = 0x20;
IEN1 = 0x00; //
}
/**/
//函数:主函数
//入口:
//出口:
/**/
void main(void)
{
EA = 0;
CLKCON = 0x60;
InitSystem();
ET2 = 1;
EA = 1; // 开总中断
while(1)
{
if(f_025ms == 1)
{
f_025ms = 0;
}
}
}
/**/
//函数:定时器T2中断 定时0.25ms
//入口:
//出口:
/**/
void IntTimer2(void) interrupt 5
{
_push_(FLASHCON);
TR2 = 0;
TF2 = 0;
// TL2 = (65536-250)&0xff;
// TH2 = ((65536-250)>>8)&0xff;
// RCAP2L = (65536-250)&0xff;
// RCAP2H = ((65536-250)>>8)&0xff;
f_025ms = 1;
TR2 = 1;
_pop_(FLASHCON);
}
|