View previous topic :: View next topic |
Author |
Message |
fazreen
Joined: 18 Oct 2012 Posts: 10
|
Communicate PIC to PIC |
Posted: Thu Oct 18, 2012 8:24 am |
|
|
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
|
|
Posted: Thu Oct 18, 2012 11:15 am |
|
|
Can you get either of your boards to communicate with a PC?
Mike |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9226 Location: Greensville,Ontario
|
|
Posted: Thu Oct 18, 2012 12:41 pm |
|
|
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
|
|
Posted: Thu Oct 18, 2012 2:55 pm |
|
|
Another thought:-
Is this an ISIS simulation or real hardware?
Mike |
|
|
fazreen
Joined: 18 Oct 2012 Posts: 10
|
;0 |
Posted: Thu Oct 18, 2012 9:56 pm |
|
|
its working thank you |
|
|
tzehow_90
Joined: 28 May 2011 Posts: 3
|
atten to fazreen... |
Posted: Tue Mar 05, 2013 1:28 pm |
|
|
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
|
|
Posted: Tue Mar 05, 2013 2:54 pm |
|
|
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
|
thx |
Posted: Thu Mar 07, 2013 7:53 am |
|
|
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 |
|
|
|