I am looking at building a project that will basically allow me to read and
write to 128 output lines from a PC's serial port. I know I need a UART and
PIC, but I have no clue which ones. I have built a basic 16x8 memory
structure that controls the output lines with a basic addressing system.
(Each output controls a relay) I am fuzzy on the PC communications and any
help/advise would be greatly appreciated =)
If I understand you well, you need to switch 128 relays independedly. You
already have a 4 to16 lines address decoder of which each (decoded) address
line correspond to a 8 bits memory word (usually called a register.) So each
of the 16 address lines controls 8 relays.
Some simple calculation tells me that you have to get 12 bits of data out of
the computer, 4 address bits and 8 data bits. To achieve this, a micro with
a build in uart and 12 output pins (plus the pins used by the uart of
course) will do. But.... an asynchronous serial data link only transfers
groups of 8 bits (or less.) So your main task is to develop a protocol that
makes it possible to distinguish between adress and data bits or, in other
words, reliably transfers 12 bits of "data" using an eight bits channel.
One method may be to cut the 12 bits into three portions of four. Then you
first send an eight bit word containing the address in one nibble and the
number one in the second. Next you send four databits in one nibble and a
two in the second nibble. You will guess that you send the remaining four
databits with a three. The receiving micro checks the sequence of the parts
and re-establishes the original form so it can be used to switch the relays
addressed.
If something goes wrong the micro will have to send back an error message to
the PC. Otherwise your main controlling program is not aware of it and may
make wrong decisions.
A PIC16F870 will do all this for you, that's to say, when you programmed it
correctly first. But this is only an example. There are lots of other micros
that can do the same.
pieter