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 CCS Technical Support

Communicate PIC to PIC

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



Joined: 18 Oct 2012
Posts: 10

View user's profile Send private message

Communicate PIC to PIC
PostPosted: Thu Oct 18, 2012 8:24 am     Reply with quote

Why this tx and rx from PIC to PIC can't communicate ? Someone can help me...

This program for transmitter:
Code:

#include <18F4550.h> // PIC18F4550 HEADER FILE
#fuses XT, PUT, HS,NOWDT, NOLVP, NOBROWNOUT // EXTERNAL CLOCK, NO WATCH DOG TIMER, NO LOW VOLTAGE PROGRAMMING

//#include <utility.c>
#use delay (clock=20M)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) // 4 MHZ CRYSTAL

#define BUTTON1 PIN_B0 // PRESET BUTTON 1
#define BUTTON2 PIN_B1 // PRESET BUTTON 2

#define LED1 PIN_B6 // LED 1
#define LED2 PIN_B7 // LED 2
#define LED3 PIN_D0 // LED 3
#define LED4 PIN_D1 // LED 4

void main ()
{
set_tris_b(0x01); // SET ALL PORT 0-b3 AS INPUT b4-b7 OUTPUT
//set_tris_d(0x00);
set_tris_c(0x11); // SET ALL PORT d AS OUTPUT PORT(0b 0000 0000)

output_b(0x00);

while(true)
  {
   putc('a');
   delay_ms(10);
   //putc('b');
   //delay_ms(1000);
  }
}


AND this is for receiver:
Code:

#include <18F4620.h> // PIC18F4550 HEADER FILE
#fuses XT, PUT, HS, NOWDT, NOLVP, NOBROWNOUT // EXTERNAL CLOCK, NO WATCH DOG TIMER, NO LOW VOLTAGE PROGRAMMING

//#include <utility.c>
#use delay (clock=20M)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7) // 4 MHZ CRYSTAL

#define BUTTON1 PIN_B0 // PRESET BUTTON 1
#define BUTTON2 PIN_B1 // PRESET BUTTON 2

#define LED1 PIN_B6 // LED 1
#define LED2 PIN_B7 // LED 2
#define LED3 PIN_D0 // LED 3
#define LED4 PIN_D1 // LED 4

void main ()
{
set_tris_b(0x01); // SET ALL PORT 0-b3 AS INPUT b4-b7 OUTPUT
//set_tris_d(0x00);
set_tris_c(0x11); // SET ALL PORT d AS OUTPUT PORT(0b 0000 0000)

output_b(0x00);

while(true)
  {
   char data;

   while(true) // always repeat program
    {
     if (kbhit())

     data=getc();

     if (data='z') // when press button 1
       {
        output_high(LED2);
        output_low(LED1);
        //output_low(PIN_A3);
       }
     else
      {
       output_low(LED2);
       output_high(LED1);
       //ouptut_low(PIN_A3);
     }
  }
}

}
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Thu Oct 18, 2012 11:15 am     Reply with quote

Can you get either of your boards to communicate with a PC?

Mike
temtronic



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

View user's profile Send private message

PostPosted: Thu Oct 18, 2012 12:41 pm     Reply with quote

1) add 'errors' to the use rs232(.....) lines,needed to keep the UART from 'freezing'.

2) get rid of set_tris....() lines, let the compiler automatically handle this

3) have you proved the LEDs function correctly? maybe in backwards?

4)do you have max232 or equal chips in the UART xmt/rcv lines?

5)do you have a common ground between the PICs?

6)you xmt only 'a' or 'b' but only test for a 'z', so how do you know it's not working ?

hth
jay
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Thu Oct 18, 2012 2:55 pm     Reply with quote

Another thought:-

Is this an ISIS simulation or real hardware?

Mike
fazreen



Joined: 18 Oct 2012
Posts: 10

View user's profile Send private message

;0
PostPosted: Thu Oct 18, 2012 9:56 pm     Reply with quote

its working thank you
tzehow_90



Joined: 28 May 2011
Posts: 3

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

atten to fazreen...
PostPosted: Tue Mar 05, 2013 1:28 pm     Reply with quote

I am new in uart... can you post the full program that sucessful run?? and the connection??
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Tue Mar 05, 2013 2:54 pm     Reply with quote

I sincerely hope fazreen does not.

You will learn nothing if he does.

This is a help forum, not a do it for you one.

If you really want to become good with uarts I suggest:-

1) You start by using the CCS examples to communicate with a PC.
2) Progress from there.
3) If (when) you get stuck ask for specific help.
4) Read the forum guidelines.

Mike

PS My comments here also apply to your post on another thread.
Others and I have provided enough hints here to show you a way.
tzehow_90



Joined: 28 May 2011
Posts: 3

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

thx
PostPosted: Thu Mar 07, 2013 7:53 am     Reply with quote

Mike Walne wrote:
I sincerely hope fazreen does not.

You will learn nothing if he does.

This is a help forum, not a do it for you one.

If you really want to become good with uarts I suggest:-

1) You start by using the CCS examples to communicate with a PC.
2) Progress from there.
3) If (when) you get stuck ask for specific help.
4) Read the forum guidelines.

Mike

PS My comments here also apply to your post on another thread.
Others and I have provided enough hints here to show you a way.





thx
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