im doing a project(a pacemaker) at school which is using a pic18f4520 and C18.
so we are supposed to use interrupts for sending and receiving data. We are sending packets of data each packet has 16 bytes in it. Now right now I am calling a function outside of the interrupt to store each byte (receiving) into a buffer.
This works, but i'm told the overhead to do this is huge and shouldnt be done at all.
My problem is we are supposed to modularize our code so i have a buffer module and my main module and i dont know how to use the interrupt without doing a function call. Some people are using defines. Any ideas?
I just want ideas and not anyone to do the actual code for me!
so we are supposed to use interrupts for sending and receiving data. We are sending packets of data each packet has 16 bytes in it. Now right now I am calling a function outside of the interrupt to store each byte (receiving) into a buffer.
This works, but i'm told the overhead to do this is huge and shouldnt be done at all.
My problem is we are supposed to modularize our code so i have a buffer module and my main module and i dont know how to use the interrupt without doing a function call. Some people are using defines. Any ideas?
I just want ideas and not anyone to do the actual code for me!
Rich (BB code):
#pragma interrupt intr_handler
void intr_handler(void) {
if (PIR1bits.RCIF == 1) {
RcBUF_ADD(RCREG); // Add the byte into receiving buffer
if ((opState==k_idle)&&(RcBUF_LENGTH() ==16))
opState = k_commState;
}
} /* If the microcontroller sent a byte */
if (PIR1bits.TXIF == 1) {
/* If there is nothing to send (the sending buffer is empty) */
if (TxBUF_EMPTY()) {
/* Turn off sending interrupt */
PIE1bits.TXIE = 0;
} else {
/* Send the first byte in the sending buffer */
TXREG = TxBUF_GET();
}
}
}
Rich (BB code):
void RcBUF_ADD(unsigned char byte) {
rcbuf.data[rcbuf.tail] = byte;
rcbuf.tail=((++rcbuf.tail) & e_Mask);
}