volatile unsigned char rs232_rx_register;
unsigned char* receivedString; //allocate this somewhere to some length...
unsigned char receivedLength; //something to make this go a bit faster. set to 0 before interrupts are enabled
unsigned char newString; //read this in your main function. it is a flag. set to 0 before interrupts are enabled
/**
* The RS-232 interrupt
*/
void interrupt()
{
///....code determining that this is indeed the rs232 interrupt....
receivedString[receivedLength] = rs232_rx_register;
if (receivedString[receivedLength] == 0x00) { newString = 1; }
receievedLength++;
///....other interrupt code or something....
}
/**
* Your main program
*/
void main()
{
///...startup code...
while(1) //your main loop
{
///...other code...
//disable interrupts to reduce the chance of reading while writing (it sucks when that happens)
if (newString==1)
{
//do something with this new string that we just got
receivedLength = 0; //reset everything for the next string
newString = 0;
}
//re-enable interrupts so you can get more strings
///...other code...
}
}