2 PIC, serial communication


Closed Thread
Results 1 to 7 of 7
  1. #1
    Join Date
    Sep 2009
    Posts
    2

    Default 2 PIC, serial communication

    hi,good day to everyone...
    I have a hard time throughout the process of learning serial communication, but gained nothing at last.
    I tried with 2 PIC where each of the PIC will control the LED that connected with it.
    There are 2 PIC in the drawing. Let the left PIC = A, right PIC = B.
    What i want to have is....A control the LED that connected with B, and B control the LED that connected with A.
    I started a bit of the coding but stuck somewhere in the middle. I don't know how to use HSERIN and HSEROUT even though I went through the manual.

    I know there should be 2 sets of similar coding which i can download it into PIC while doing the simulation in Proteus Isis. But at this moment, I can't even write my coding with HSERIN and HSEROUT.

    Attachment below shows the connection in Proteus. I only had problem with my coding.

    So any help.....I will be so grateful....Thanks in advance...

    Coding as below:

    Define osc 8
    define HSER_RCSTA 90H 'Enable serial port and continous receive
    DEFINE HSER_TXTSTA 24H 'Enable transmit
    DEFINE HSER_BAUD 9615
    DEFINE HSER_CLROERR 1 'Clear overflow automatically
    ADCON1 = 7


    TRISB.0 = 1 'switch
    TRISB.2 = 0 'LED
    TRISC.6 = 0 'set TX(portC.6) to out
    TRISC.7 = 1 'set RX(portC.7) to in

    led1 var portb.2

    Hserout [
    Attached Images Attached Images  

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default

    Welcome to the forum.

    I will suggest to get started use SERIN/SEROUT. These are bit banging routines that can be used on most any pin. When you ar comfortable with that look at SERIN2/SEROUT2, another bit of bit banging. Then try the hardware serial ports.

    So...
    Near the beginning of your code for both PICs add this line:
    Code:
    include "modedefs.bas"
    Then for the sending PIC do something like this:
    Code:
    SEROUT PORTC.4,T2400,[9,3]
    On the receiving PIC:
    Code:
    SERIN PORTC.4,T2400,[9],net
    
    IF net = 3 THEN LED_ON 'GOTOs label to turn a LED on
    The receiving PIC will wait for "9" and put the next character in the variable net.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Oct 2009
    Posts
    2

    Default

    I accept with linghtgreen about code:
    Coding as below:

    Define osc 8
    define HSER_RCSTA 90H 'Enable serial port and continous receive
    DEFINE HSER_TXTSTA 24H 'Enable transmit
    DEFINE HSER_BAUD 9615
    DEFINE HSER_CLROERR 1 'Clear overflow automatically
    ADCON1 = 7


    TRISB.0 = 1 'switch
    TRISB.2 = 0 'LED
    TRISC.6 = 0 'set TX(portC.6) to out
    TRISC.7 = 1 'set RX(portC.7) to in

    led1 var portb.2

  4. #4
    Join Date
    Sep 2009
    Posts
    2

    Default

    May I know what does T2400 represent?
    My guess is baud rate...If T2400 represent baud rate, then how about the baud rate that i defined on the top?

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default

    Quote Originally Posted by lightgreen View Post
    May I know what does T2400 represent?
    My guess is baud rate...If T2400 represent baud rate, then how about the baud rate that i defined on the top?
    Like I said, the example I gave is an alternative to using the hardware ports. Most start off using the alternative... less setup and things to understand at the beginning.

    The "T" makes the signal TRUE, the signal that is produced from the hardware ports is TRUE. When talking between to PICs the signal type does not matter as long as both PICs are using the same signal type. When connecting to a PC an INVERTED signal is needed, if using a bit banging routine it would be N2400 or whatever baud rate the PC is set for. When using the hardware ports an inverter chip such as a RS232 will be needed if you want to communicate with a PC.

    In response to your PM. When using SERIN/SEROUT you can use most any of the pins on a PIC. That is why I have PORTC.4 in my example to show that.
    Dave
    Always wear safety glasses while programming.

  6. #6

    Default do i need a resisitor

    Hi all

    To communicate between two pics do I need to add a resistor on the TX and RX lines??

    Kind regards

    Dennis

  7. #7
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924

    Default

    I do not from PIC to PIC.
    Dave
    Always wear safety glasses while programming.

Similar Threads

  1. serial to PIC
    By kindows in forum mel PIC BASIC Pro
    Replies: 22
    Last Post: - 14th July 2009, 13:58
  2. Automatic VB6 to pic serial connection
    By arniepj in forum Code Examples
    Replies: 13
    Last Post: - 10th January 2008, 07:57
  3. Serial Communication using 12F629
    By charudatt in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 14th March 2005, 04:24
  4. Serial Pic to Pic using HSER
    By Chadhammer in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th March 2005, 23:14
  5. How many serial ports can 1 PIC handle?
    By Tom Gonser in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd March 2005, 04:34

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts