I'm using MikroC for PIC v7.2, to program a PIC18f67k40.
Within functii.h, I have the following variable declaration:
extern volatile unsigned char byte_count;
Within main.c, the following code:
#include <functii.h>
// ...
volatile unsigned char byte_count = 0;
// ...
void interrupt () {
if (RC1IF_bit) {
uart_rx = Uart1_read();
uart_string[byte_count] = uart_rx;
byte_count++;
}
// ...
}
Then, within command.c, I have the following code:
#include <functii.h>
void how_many_bytes () {
// ...
uart1_write(byte_count);
// ...
}
In main.c, I process data coming through the UART, using an interrupt. Once the end of transmission character is received, I call how_many_bytes(), which sends back the length of the message that was received (plus the data bytes themselves, the code for which I didn't include here, but those are all OK!!).
The problem is that on the uart1_write() call, byte_count is always 0, instead of having been incremented in the interrupt sequence.
byte_countback to zero? Are you sure that doesn't happen? Also, are you sure that theinterruptfunction is called? And thatRC1IF_bitis "true"? - Some programmer dudeuart1_write(byte_count);. - Andrei OnigaRC1IF_bit) and see what is going on. - Joseuart_string[]array gives the correct bytes values. And since the vector is populated by usingbyte_countas the index and it's being incremented at each step, then the interrupt must be running correctly. What seems to happen is thatbyte_countgets reset to 0 somehow, before it's sent back via the UART. - Andrei Oniga