I am now doing a project in which I using Timer 0 Interrupt and UART transmission at the same time.
At first, it works perfectly before I add in UART transmission configuration. Once I add in UART transmission configuration, the program will never run the Interrupt function. Do any one can tell me what is the problem?
//Configuration
//==================================================================
__CONFIG ( 0x3E31 );
#define BAUD 9600
#define _XTAL_FREQ 4000000
//#define DELAY 28
#define ALLOW_RECIEVE RA5
//#define TRAN_SONIC RB2
#define LED1 RB5
#define SONIC_IN RC2
#define RX_PIN RC7
#define TX_PIN RC6
void pic_init(void);
int counter;
static void interrupt isr(void)
{
if(TMR0IE && TMR0IF)
{
//TMR0 Overflow ISR
//Clear Flag
TMR0IF=0;
if (counter > 500)
{
LED1 = 1;
}
else
LED1 = 0;
counter++;
if (counter > 1000)
{
counter = 0;
}
}
}
void main()
{
pic_init(); //initialize PIC
TMR0IE = 1;
while(1);
}
void pic_init(void)
{
ADCON0=0b00000001; //Turn on A/D module
ADCON1=0b10000000; //Right Justify
TRISA=0b00001111;
TRISB=0b01001111;
TRISC=0b00000000;
TRISD=0b00000000;
TRISE=0b00000000;
PORTA=0b00000000;
PORTB=0b00000000;
PORTC=0b00000000;
PORTD=0b00000000;
PORTE=0b00000000;
OPTION_REG=0b00000000;
INTCON=0b11010000;
PIE1=0b00100000; //Enable RX interrupt
TMR0 = 0b11110000;
//initialize UART
SPBRG=(int)(_XTAL_FREQ/(64.0*BAUD)-1);
BRGH = 1; //baud rate high speed option
TXEN = 1; //enable transmission
TX9 = 0;
CREN = 1; //enable reception
SPEN = 1; //enable serial port
RX9 = 0;
TX_PIN = 1;
RCIE = 0;
GIE = 0;
PEIE = 0;
TMR0IE = 0;
}
At first, it works perfectly before I add in UART transmission configuration. Once I add in UART transmission configuration, the program will never run the Interrupt function. Do any one can tell me what is the problem?
//Configuration
//==================================================================
__CONFIG ( 0x3E31 );
#define BAUD 9600
#define _XTAL_FREQ 4000000
//#define DELAY 28
#define ALLOW_RECIEVE RA5
//#define TRAN_SONIC RB2
#define LED1 RB5
#define SONIC_IN RC2
#define RX_PIN RC7
#define TX_PIN RC6
void pic_init(void);
int counter;
static void interrupt isr(void)
{
if(TMR0IE && TMR0IF)
{
//TMR0 Overflow ISR
//Clear Flag
TMR0IF=0;
if (counter > 500)
{
LED1 = 1;
}
else
LED1 = 0;
counter++;
if (counter > 1000)
{
counter = 0;
}
}
}
void main()
{
pic_init(); //initialize PIC
TMR0IE = 1;
while(1);
}
void pic_init(void)
{
ADCON0=0b00000001; //Turn on A/D module
ADCON1=0b10000000; //Right Justify
TRISA=0b00001111;
TRISB=0b01001111;
TRISC=0b00000000;
TRISD=0b00000000;
TRISE=0b00000000;
PORTA=0b00000000;
PORTB=0b00000000;
PORTC=0b00000000;
PORTD=0b00000000;
PORTE=0b00000000;
OPTION_REG=0b00000000;
INTCON=0b11010000;
PIE1=0b00100000; //Enable RX interrupt
TMR0 = 0b11110000;
//initialize UART
SPBRG=(int)(_XTAL_FREQ/(64.0*BAUD)-1);
BRGH = 1; //baud rate high speed option
TXEN = 1; //enable transmission
TX9 = 0;
CREN = 1; //enable reception
SPEN = 1; //enable serial port
RX9 = 0;
TX_PIN = 1;
RCIE = 0;
GIE = 0;
PEIE = 0;
TMR0IE = 0;
}