|
|
View previous topic :: View next topic |
Author |
Message |
cura
Joined: 27 May 2006 Posts: 2
|
Connecting two PIC16F84A using RS-232 |
Posted: Sat May 27, 2006 5:58 am |
|
|
Is it possible to connecto two 16f84a using the rs-232 protocol? I'm trying to do it but what I get is that there is no transmission/reception.
I want to use a single wire (in one pic as rx channel, in the other as tx channel).
Is there any place where I can find an example of this two PIC connection?
THANK YOU! |
|
|
Humberto
Joined: 08 Sep 2003 Posts: 1215 Location: Buenos Aires, La Reina del Plata
|
|
Posted: Sat May 27, 2006 7:25 am |
|
|
You can do it connecting Tx pin of one PIC to the Rx pin of the other PIC directly.
Quote: |
Is there any place where I can find an example of this two PIC connection?
|
...........?
Humberto |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Sat May 27, 2006 8:25 am |
|
|
Ever think that maybe your code might be the problem? Post what you have and make sure that you use the "Code" button. |
|
|
cura
Joined: 27 May 2006 Posts: 2
|
|
Posted: Sat May 27, 2006 9:31 am |
|
|
This is the code, it is just a remote control for 10 channels. What I want that the Rx PIC copies exactly the channel configuration in the Tx PIC.
For the Rx PIC
Code: |
#case
#include <16F84A.H>
#include <defs_f84.h> // registers and bits
#include <STDLIB.H>
#fuses xt,nowdt,put,noprotect
#define RS232_XMIT PIN_A1 //Pin de transmision
#define RS232_RCV PIN_A1 // Pin de recepcion (sera el mismo que transmision)
#use delay(clock=4000000) // 4 MHz OSC
#use rs232(baud=1200,xmit=NULL, rcv=RS232_RCV)
int canales[2];
void main(void) {
trisa1=1; //Receiving Pin
trisb0=0;
trisb1=0;
trisb2=0;
trisb3=0;
trisb4=0;
trisb5=0;
trisb6=0;
trisb7=0;
trisa2=0;
trisa3=0;
trisa0=0;
//Setting Channels
output_low(PIN_B7);
output_low(PIN_B6);
output_low(PIN_B5);
output_low(PIN_B4);
output_low(PIN_B3);
output_low(PIN_B2);
output_low(PIN_B1);
output_low(PIN_B0);
output_low(PIN_A3);
output_low(PIN_A2);
while(1){
canales[0]=getchar();
canales[1]=getchar();
if(bit_test(canales[0], 0)){
output_high(PIN_B7);
}
else output_low(PIN_B7);
if(bit_test(canales[0], 1)){
output_high(PIN_B6);
}
else output_low(PIN_B6);
if(bit_test(canales[0], 2)){
output_high(PIN_B5);
}
else output_low(PIN_B5);
if(bit_test(canales[0], 3)){
output_high(PIN_B4);
}
else output_low(PIN_B4);
if(bit_test(canales[0], 4)){
output_high(PIN_B3);
}
else output_low(PIN_B3);
if(bit_test(canales[0], 5)){
output_high(PIN_B2);
}
else output_low(PIN_B2);
if(bit_test(canales[0], 6)){
output_high(PIN_B1);
}
else output_low(PIN_B1);
if(bit_test(canales[0], 7)){
output_high(PIN_B0);
}
else output_low(PIN_B0);
if(bit_test(canales[1], 0)){
output_high(PIN_A3);
}
else output_low(PIN_A3);
if(bit_test(canales[1], 1)){
output_high(PIN_A2);
}
else output_low(PIN_A2);
delay_ms(15);
}
} // end of main
|
For the TX PIC:
Code: |
#case
#include <16F84A.H>
#include <defs_f84.h> // registers and bits
#include <STDLIB.H>
#fuses xt,nowdt,put,noprotect
#define RS232_XMIT PIN_A1 //Transmitter pin
#define RS232_RCV PIN_A0
#use delay(clock=4000000) // 4 MHz OSC
#use rs232(baud=1200, xmit=RS232_XMIT, rcv=NULL)
int canales0;
int canales1;
void read_ch(void){
if (input(PIN_A2)){
bit_set(canales1,1);
}
if (input(PIN_A3)){
bit_set(canales1,0);
}
if (input(PIN_B0)){
bit_set(canales0,7);
}
if (input(PIN_B1)){
bit_set(canales0,6);
}
if (input(PIN_B2)){
bit_set(canales0,5);
}
if (input(PIN_B3)){
bit_set(canales0,4);
}
if (input(PIN_B4)){
bit_set(canales0,3);
}
if (input(PIN_B5)){
bit_set(canales0,2);
}
if (input(PIN_B6)){
bit_set(canales0,1);
}
if (input(PIN_B7)){
bit_set(canales0,0);
}
}
void send_data(void) {
putchar(canales0);
delay_ms(50);
putchar(canales1);
}
void main(void) {
trisa1=0; //tx pin
trisb0=1; // channels
trisb1=1;
trisb2=1;
trisb3=1;
trisb4=1;
trisb5=1;
trisb6=1;
trisb7=1;
trisa1=1;
trisa2=1;
trisa3=1;
while(1){
read_ch();
send_data();
delay_ms(100);
}
} // end of main
|
The data will only travel from Tx to Rx, this means that no feedback from the receptor is needed in the transmitter for the application in order to work.
THANKS!!! |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1933 Location: Norman, OK
|
|
|
|
|
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
|