Hi everyone! I'm developing a project with pics and now i'm testing serial communication through rs232, using a pic, a max232 converter and my laptop.
The problem is simple to explain, but i don't know how to get over it and what i'm doing wrong..
When i establish a communication without using interrupts (Interrupt Service Routine), the communication works just fine. The problem is that i need to use the ISR on the main project. To test the communication with ISR, i created this simple program, but it doesn't work.
Can someone see any programming error or have any suggestion to help me solve this situation?
I'm using MPLAB IDE to develope code, using the compiler HI-Tech ANSI C Compiler..
Thanks in advance!
Here goes the code:
#include <htc.h>
#if defined(_16F877)
__CONFIG(UNPROTECT & XT & DEBUGDIS & LVPDIS & WDTDIS & PWRTDIS & LVPDIS & BORDIS);
#endif
void RS232Conf(void);
void DataArrival(unsigned char Data);
void interrupt rsi(void);
void RS232Tx(unsigned char Tx);
void main(void)
{
unsigned char Rx;
SYNC=0;
TX9=0;
CREN=1;
TXEN=1;
SPEN=1;
BRGH=1;
SPBRG=25;
TRISB=0;
RCIF=0;
TXIF=0;
RCIE=1;
TXIE=0;
PEIE=1;
GIE=1;
RS232Tx('h');
RS232Tx('i');
RS232Tx('!');
while(1)
{
RB3=1;
if(RCIF==1)
{
Rx=RCREG;
DataArrival(Rx);
}
}
}
void DataArrival(unsigned char Data)
{
TXREG=Data;
}
void RS232Tx(unsigned char Tx)
{
while(TRMT==0);
TXREG=Tx;
TXIF=0;
}
void interrupt rsi(void)
{
unsigned char Rx;
if(RCIF==1)
{
Rx=RCREG;
DataArrival(Rx);
}
}
The problem is simple to explain, but i don't know how to get over it and what i'm doing wrong..
When i establish a communication without using interrupts (Interrupt Service Routine), the communication works just fine. The problem is that i need to use the ISR on the main project. To test the communication with ISR, i created this simple program, but it doesn't work.
Can someone see any programming error or have any suggestion to help me solve this situation?
I'm using MPLAB IDE to develope code, using the compiler HI-Tech ANSI C Compiler..
Thanks in advance!
Here goes the code:
#include <htc.h>
#if defined(_16F877)
__CONFIG(UNPROTECT & XT & DEBUGDIS & LVPDIS & WDTDIS & PWRTDIS & LVPDIS & BORDIS);
#endif
void RS232Conf(void);
void DataArrival(unsigned char Data);
void interrupt rsi(void);
void RS232Tx(unsigned char Tx);
void main(void)
{
unsigned char Rx;
SYNC=0;
TX9=0;
CREN=1;
TXEN=1;
SPEN=1;
BRGH=1;
SPBRG=25;
TRISB=0;
RCIF=0;
TXIF=0;
RCIE=1;
TXIE=0;
PEIE=1;
GIE=1;
RS232Tx('h');
RS232Tx('i');
RS232Tx('!');
while(1)
{
RB3=1;
if(RCIF==1)
{
Rx=RCREG;
DataArrival(Rx);
}
}
}
void DataArrival(unsigned char Data)
{
TXREG=Data;
}
void RS232Tx(unsigned char Tx)
{
while(TRMT==0);
TXREG=Tx;
TXIF=0;
}
void interrupt rsi(void)
{
unsigned char Rx;
if(RCIF==1)
{
Rx=RCREG;
DataArrival(Rx);
}
}