They say that exercise clears the mind. Well, after struggling for hours on how to send a serial data stream that can both carry the required port pin settings AND a series of commands to a remote PIC chip, I went on my lunch break to practice my Heian Nidan Kata.
During this practice, three things occured to me -
1. By using the 16F887 with its 35 I/O lines, I can assign each of the needed 4- or 5-bit BCD outputs to its own port,
2. The 5 I/O ports of the '887 then leave me with Port E, which is only 4-bits (and one of them is read only) which I can use for the Local/Remote control line,
3. And the epiphany - by using RS232 protocol with a 9-bit data word, I can assign 5 bits of that word as the BCD code group, and the remaining 4 bits as a set of commands,
so, for example, the dataword for 'Set Port E bit 0 high (set system to Remote) would be 000000100, whereas the instruction to 'Set Port A outputs with 5-bit BCD code 11011 would be 110111000
The result is I have a potential 15 command codes available (I need around 11), plus one of the ports need only carry a 4-bit BCD code, so its 5-bit counterpart could be used for another purpose.
So this has simplified what I need to do regarding serial comms to the device - just use the libraries to code the serial comms, move the dataword into a variable in the chip, then depending what its first 4 bits are, carry out the required action. And by making it RS232, I can test it from a PC terminal program!
I know all this probably means nothing to anyone reading this, but all will become clear when I receive the 16F887's!
When I later read the instructions for using the MikroBasic software UART library, I found that it can only handle single byte (8- bit) words.
But it then came to my attention that my protocol using 9 bits was very inefficient, and that by changing the position in the word of the command code from the least significant bit to the highest end, essentially just reversing the binary stream, I could fit the whole 55/60 varients of BCD code and commands into an 8- bit word with plenty of spare combinations!
And a sudden realisation on the way home resolved a possible data contention issue!