各位好!我用PIC16F73单片机编一个定时器程序,但无法进入中断程序,如果把中断程序放到主函数中能正常运行。程序如下:
#include "init.h"
#define set_bit(a,b) a|=1<<b
#define clr_bit(a,b) a&=~(1<<b)
uchar timecnt;
//看门狗初始化
void watchdoginit(void)
{
OPTION = 0x0F; //B口上拉,内部RC时钟,预分频给WDT,WDT分频为1:128
}
//定时器1初始化,10ms定时
void timer1init(void)
{
TMR1H = 0XFB;
TMR1L = 0X1E;
TMR1IF = 0;
PEIE = 1;
TMR1IE = 1;
T1CON = 0X31;
}
//端口初始化
void portinit(void)
{
//clr_bit(OPTION,7); //端口B内部上拉使能
TRISA = 0xFF;
TRISB = 0x7F;
clr_bit(PORTB,7);
TRISC = 0x00;
PORTC = 0x10;
}
void init(void)
{
di();
portinit();
timer1init();
ei();
}
//中断服务程序
void interrupt ISR(void)
{
if(TMR1IF)
{
TMR1IF = 0;
TMR1H = 0XFB;
TMR1L = 0X1E;
timecnt++;
if(timecnt<30)
{
set_bit(PORTC,0);
}
else
{
clr_bit(PORTC,0);
}
if(timecnt>60)
timecnt = 0;
}
}
void main(void)
{
clr_bit(TRISC,0);
clr_bit(TRISC,1);
clr_bit(TRISC,3);
watchdoginit();
init();
while(1)
{
CLRWDT();
}
}
求高手求解! |