为什么PIC的两个中断响应就不能正常工作了
我用的是PIC16F877A开发板,我的程序当只含有串口接收中断处理函数时没有问题,当只含有定时中断时也没有问题,
可是当我把这两个中断响应函数放在一个程序里时,串口过一会就停在那里了不动了,但是定时器Timer0定时的led还在闪,不知道是怎么回事?
请指点一下吧,谢谢!
// based on PIC16F877A
#include<pic.h>
#define uchar unsigned char
#define uint unsigned int
//__CONFIG(0x3B31);
#define RESTART_TIMING 0x01
unsigned int couter = 0;
int i= 5400;
void init_UART()
{
TRISC = 0xC0; //config Rc6, RC7 as input pin
//PORTC = 0xff;
TXSTA = 0x24; //Transmit status register
//BRGH =1 : High baud rate bit selected
//SYNC =0 : Asynchronous mode
RCSTA=0x90; //SPEN = 1 : serial port is enable
//CREN = 1 : continuous receive is enable
SPBRG = 25; //ste up baud rate to 9600 bps
RCIE=1; //enable Receive SCI interrupt
}
/////////////////////////////////////////////////////////////////
void Config_Timer0()
{
//configure Timer 0
//when crystal is 4M
OPTION = OPTION & 0xDF; //internal instruction cycle clock select
OPTION = OPTION & 0xF7; //prescaler is assigned to Timer 0 module
//OPTION = OPTION | 0x07; //1:125 proscaler
//OPTION = OPTION | 0x04; //1:32 prescaler
PS2 = 0; //1:2
PS1 = 0;
PS0 = 0;
TMR0 = 0xc3; //定时器初值
INTCON = INTCON | 0x20; //TMR0IE: Enable TMR0 overflow intererupt
}
////////////////////////////////////////////
void interrupt com()
{
unsigned char uchTemp;
//if( RCIE && RCIF )
if ( RCIF )
{
TXREG = RCREG;
while( !TRMT );
//nGlobalTimeFlag = RESTART_TIMING;
//nTimeCount = 100;
}
if ( T0IF) //how many us is interval time 512us = 0.512ms
{
couter++;
if( couter >= 1953 )
{
couter = 0;
PORTC = PORTC | 0x01;
while ( i> 0 )
{
NOP();
i--;
}
PORTC = PORTC & 0xFE;
}
TMR0 = 0x00;
T0IF = 0;
}
}
/////////////////////////////////////////////////////
void main()
{
int nTimeCount = 0;
GIE = 0; //Disable all unmask interrupt
PEIE = 0;
Config_Timer0();
init_UART();
PEIE=1;
GIE=1; //enable all unmask interrupt
while(1)
{
}
} |