CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

input output communication between two pic

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
freedom



Joined: 10 Jul 2011
Posts: 54

View user's profile Send private message Send e-mail

input output communication between two pic
PostPosted: Sun Nov 09, 2014 2:18 am     Reply with quote

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?
Ttelmah



Joined: 11 Mar 2010
Posts: 19382

View user's profile Send private message

PostPosted: Sun Nov 09, 2014 2:28 am     Reply with quote

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..
freedom



Joined: 10 Jul 2011
Posts: 54

View user's profile Send private message Send e-mail

PostPosted: Sun Nov 09, 2014 3:02 am     Reply with quote

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?
Ttelmah



Joined: 11 Mar 2010
Posts: 19382

View user's profile Send private message

PostPosted: Sun Nov 09, 2014 3:22 am     Reply with quote

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.
freedom



Joined: 10 Jul 2011
Posts: 54

View user's profile Send private message Send e-mail

PostPosted: Sun Nov 09, 2014 4:36 am     Reply with quote

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
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Sun Nov 09, 2014 6:30 am     Reply with quote

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.
temtronic



Joined: 01 Jul 2010
Posts: 9177
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sun Nov 09, 2014 7:58 am     Reply with quote

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
Ttelmah



Joined: 11 Mar 2010
Posts: 19382

View user's profile Send private message

PostPosted: Sun Nov 09, 2014 3:33 pm     Reply with quote

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.
freedom



Joined: 10 Jul 2011
Posts: 54

View user's profile Send private message Send e-mail

PostPosted: Tue Nov 11, 2014 7:26 am     Reply with quote

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 ?
dyeatman



Joined: 06 Sep 2003
Posts: 1924
Location: Norman, OK

View user's profile Send private message

PostPosted: Tue Nov 11, 2014 7:48 am     Reply with quote

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!!!!
freedom



Joined: 10 Jul 2011
Posts: 54

View user's profile Send private message Send e-mail

PostPosted: Tue Nov 11, 2014 8:02 am     Reply with quote

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
alan



Joined: 12 Nov 2012
Posts: 357
Location: South Africa

View user's profile Send private message

PostPosted: Tue Nov 11, 2014 9:33 am     Reply with quote

In the Code Library is a driver for the MCP23016 by PICoholic.

A search on this forum did bring that up.
temtronic



Joined: 01 Jul 2010
Posts: 9177
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Nov 11, 2014 9:33 am     Reply with quote

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
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Wed Nov 12, 2014 7:44 am     Reply with quote

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...
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group