View previous topic :: View next topic |
Author |
Message |
freedom
Joined: 10 Jul 2011 Posts: 54
|
input output communication between two pic |
Posted: Sun Nov 09, 2014 2:18 am |
|
|
Hello everyone
I want to use two pics in my project. Suppose pic16f84a and pic16f877a.
This two pics are connected via RS232 ,RS485 or SPI or I2C, UART or whatever you suggest.
I want, if I activate one input of pic16f84 then execute one output of pic16f877a. Similarly , if I activate one input of pic16f877a then execute one output of pic16f84. This is because I need more input outpu pin in my project
and communicate one another.
Would anyone like to give me some guideline and example?
which communication method is better for this ?
if I want to use more than two pics then which protocol is better? |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19382
|
|
Posted: Sun Nov 09, 2014 2:28 am |
|
|
1) Get rid of the F84a.....
Very old PIC, can be replaced more cheaply by chips with more speed (and internal clocks), and does not have any of the peripherals to make the communications easy. I would not use this chip in any design being done today.
2) You need to learn about hardware. The communication method that is best, will depends on the nature of the electrical environment between the chips, how close they are, and the data rate you need. No 'generic' solution.
3) Solution also depends on what else the chips are doing. If (for instance) the UART is already in use on the 877a, this rules this peripheral out for the communications, etc. etc.. |
|
![](templates/subSilver/images/spacer.gif) |
freedom
Joined: 10 Jul 2011 Posts: 54
|
|
Posted: Sun Nov 09, 2014 3:02 am |
|
|
Thanks to reply.
This two pic are in same board. suppose 2 inch away.
16f84 is not main issue.
If I want to do it in Two 16f877a or two pic16f72 then what? |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19382
|
|
Posted: Sun Nov 09, 2014 3:22 am |
|
|
You are missing the point.
_You_ need to do some thinking.
For instance, 'step back', and work out how many inputs you need, and how many outputs.
Then if (for instance) the inputs would all fit on the 877a, with a few pins spare, put these on here.
Your extra chip then becomes 'output only'. Potentially much easier.
You might also be able to just use something like the MCP23016. For just three pins on your PIC (I2C), gives you 16 more programmable I/O pins.
There is no generic solution, the solution depends on _your_ design totally, and no-one else can solve problems without doing the job for you. It also varies according to the latencies you can accept on the pins, etc..
This is not an 'electronics design' forum (go and ask on one if you really can't think of a solution), this is a forum to _help_ with CCS code. |
|
![](templates/subSilver/images/spacer.gif) |
freedom
Joined: 10 Jul 2011 Posts: 54
|
|
Posted: Sun Nov 09, 2014 4:36 am |
|
|
Thanks a lot Ttelmah.
I've success fully finished some project with pic16f877a.
But i never communicate between two pic.
I search in this forum on this issue but can't find any example on my need.
I just want to learn on this issue.
I never expect that someone write down my code or build my project |
|
![](templates/subSilver/images/spacer.gif) |
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Sun Nov 09, 2014 6:30 am |
|
|
I would look at SPI. Whenever an input changes that chip asserts itself as bus master and after a short delay clocks the bus exchanging buffers with the other chip. Then the bus is free and you wait for the next input change. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9177 Location: Greensville,Ontario
|
|
Posted: Sun Nov 09, 2014 7:58 am |
|
|
CCS does supply an example of single wire communications between PICs i the FAQ section of their manual. I've used a variation of it for 2 decades...
They also have an 'examples' folder which has a bunch of 'serial communications' code....
hth
Jay |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19382
|
|
Posted: Sun Nov 09, 2014 3:33 pm |
|
|
Also there are examples of an I2C slave, and an I2C master, while every serial example, that talks to a PC, can equally well be used with a PIC at the other end.
There are innumerable example, but as I've already said you _need_, to work out what you actually want to do.
SPI, and I2C, and the single wire examples, are all 'master slave' communications. One device 'controls' the other.
This can still be 'two way', but the master device initiates each communication.
SPI has the advantage of really high speed.
I2C allows a lot of devices and longer wires, but is massively slower.
Both really _need_ the hardware for the slave device.
The only easy two way form, is async serial TTL (not RS232, just the logic signals out of the chips).
The point is that the protocol used over the interface, will depend on _your_ needs, nothing else.
For a 'receive only' device controlling four wires, I've used a PIC12F675, with software UART, and it's internal clock, and simply putc the bit pattern I want from the 'master' unit.
However for what you were originally describing of giving extra I/O lines, then as already said, just use one of the programmable I/O controller chips. Microchip does several with different numbers of pins and different capabilities. |
|
![](templates/subSilver/images/spacer.gif) |
freedom
Joined: 10 Jul 2011 Posts: 54
|
|
Posted: Tue Nov 11, 2014 7:26 am |
|
|
Thanks to all
Finally I decide to use MCP23016 or similar.
I want to use MCP23016 as 8 bit input and 8 bit output. How can I do this?
In my previous 16f877a project I use this code to on a LED
Code: |
if (input (pin_C1)==0 )
output_high(Pin_D2);
|
if I want to output any output pin of MCP23016 depending on input of 16f877a then what? please give me code example.
similarly , if I want to output any output pin of pic depending on any input pin of MCP23016 then what? please give me code example.
what will be the I2C parameter?
Note that in my previous project I used 24c08 eprom and for this I define SDA and SCL pin from microcontroller. Can I use this two pin for MCP23016 ? |
|
![](templates/subSilver/images/spacer.gif) |
dyeatman
Joined: 06 Sep 2003 Posts: 1924 Location: Norman, OK
|
|
Posted: Tue Nov 11, 2014 7:48 am |
|
|
Before you start asking for code how about trying to find it yourself with a search first? _________________ Google and Forum Search are some of your best tools!!!! |
|
![](templates/subSilver/images/spacer.gif) |
freedom
Joined: 10 Jul 2011 Posts: 54
|
|
Posted: Tue Nov 11, 2014 8:02 am |
|
|
Quote: | Before you start asking for code how about trying to find it yourself with a search first? |
I just ask code example.
I search in this forum but i can't get the right thing |
|
![](templates/subSilver/images/spacer.gif) |
alan
Joined: 12 Nov 2012 Posts: 357 Location: South Africa
|
|
Posted: Tue Nov 11, 2014 9:33 am |
|
|
In the Code Library is a driver for the MCP23016 by PICoholic.
A search on this forum did bring that up. |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9177 Location: Greensville,Ontario
|
|
Posted: Tue Nov 11, 2014 9:33 am |
|
|
FIRST place to look for a 'code example' is in the code library...
http://www.ccsinfo.com/forum/viewtopic.php?t=21797
Usually programmers who get 'drivers' or 'test code' will post their working examples there.
hth
jay |
|
![](templates/subSilver/images/spacer.gif) |
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Wed Nov 12, 2014 7:44 am |
|
|
if you are fixated on working with a 40 pin Pic - there is one other method of
input expansion you might consider. if you want up to 16 I/O pins plus
a F A S T !!! Interrupt on change service- consider the 82C55A .
it will require a byte wide port of the pic ( D?) plus a few other pins on port B
BUT you will get no faster peripheral expansion than with this part.
I've used this chip in a mission critical , multiple Interrupt on change program,
using port B for sensing /control and port D for parallel I/O of a 40 pin pic. super low latency possible... |
|
![](templates/subSilver/images/spacer.gif) |
|