# PIC to PIC 433 MHz RF Communication Fails [SOLVED]

I've got two PIC16F628A. one for transmitter and one for receiver... (433 MHz) I set B pins as input in order to use transmitter and receiver...

The codes are written in mikroC.

Here is the code for the transmitter:

void main() {

trisb = 1;
portb = 0;
cmcon = 7;

UART1_Init(9600);
delay_ms(1000);

while(1){
UART1_Write_Text('a');
delay_ms(1000);
UART1_Write_Text('b');
delay_ms(1000);
}

}


Here is the code for the receiver:

void main() {

trisb = 1;
trisa = 0;
portb = 0;
porta = 0;
cmcon = 7;

UART1_Init(9600);
delay_ms(100);
while(1){

if(UART1_Read() == 'a') porta.b1 = 1;
if(UART1_Read() == 'b') porta.b1 = 0;
}

}

}


I want to light the led on when I get message 'a' from transmitter and light led off when message 'b' is received. The led is connected to 18.pin (porta.b1).

EDIT

I have no proteus. That's why I drew the diagram of the circuits on a paper.

EDIT 2 I succeeded to light on the led but at this time It doesn't light on according to my desire.

The problem I told is about the low power of battery, I think.

Now, I work with other batteries in order to get enough power...

char x;
void main() {

trisb = 0xFF;
trisa = 0;
trisa.b5 = 1; //MCLR pini için
cmcon = 7;
porta = 0;
porta.b5 = 1;

UART1_Init(9600);
delay_ms(100);

while(1){

if (x == 'a') porta.b1 = 1;
if (x == 'b') porta.b1 = 0;

}

}

}


New transmitter code:

void main() {

trisb = 0xFF;
trisa = 0;
trisa.b5 = 1; //MCLR
porta = 0;
porta.b5 = 1; //MCLR

cmcon = 7;

UART1_Init(9600);
delay_ms(100);

while(1){
UART1_Write_Text("a");
delay_ms(1000);
UART1_Write_Text("b");
delay_ms(1000);

}

}


According to these codes, the led should light on for 1 second and off for 1 second...

But It wasn't so. When I touch the cables which are connected to receiver, the led lit on or off.

Sometimes it does it without touching...

Even if transmitter circuit is disabled, the led in receiver circuit lights on or off itself...

It doesn't have a specific lighting on type. It does it according to its decision.

• Definitely not enough information here to help. The PIC16F628A isn't an RF MCU, is it? How does writing to the UART send an RF transmission? – DigitalNinja Aug 31 '16 at 23:30
• Please explain how you have connected your microcontrollers and TX/RX units. A schematic, and optionally an image, of the setup would help greatly. – user2943160 Aug 31 '16 at 23:47
• I added the picture of the diagram... – PIC16F84A Sep 1 '16 at 2:17
• This is far from being an answerable question. What research have you done to conclude that you can use the modules this way to move a serial stream with reasonable chance of success? What have you done to test the MCU configuration and firmware without the radios? What have you done to test and evaluate the performance of the radios independently of the MCUs? – Chris Stratton Sep 1 '16 at 4:02
• I think you mean connect RX to TX of both of pics, ha ? I will try. – PIC16F84A Sep 2 '16 at 8:41

The problem is solved; thanks... Apparently, it is a obligation to connect an antenna to transmitter. There is a hole at transmitter's right-top side. I connected a jumper cable there and It worked. When I touch the hole with my finger, the same happens. But for long distances, transmitter needs an antenna. But when the transmitter is near the receiver; finger, copper wire is enough.

Those codes work well: (It is quote from https://mikrodunya.wordpress.com/2011/11/08/udea-nin-rf-veri-iletimi-alanindaki-kucuk-devleri-atx-34-nrx-34)

char az,i=0, msg[6];
void main()
{
UART1_Init(2400);
trisb.f0=0;
portb.f0=1;
delay_ms(100);

while(1)
{
{
if(msg[0]=='y' || msg[0] == 's')//Eğer msg[0] 'y' veya 's' ise i değişkeninin 1 arttır.
{
i++;
}
}
if(i==3)
{
if(msg[0]=='y' && msg[1]=='a' && msg[2]=='n' )portb.f0=1;  //Senkron için gönderilen sıfır veya 255 aranmaz....
if(msg[0]=='s' && msg[1]=='o' && msg[2]=='n' )portb.f0=0;
i=0;
msg[0]=0;

}
}
}


Transmitter:

char pre[15]={'U','U','U','U','U',255,255,255,255,255,0,0,0,0,0};
char yak[3]={'y','a','n'};  //Senkron için en az bir byte sıfır gönder kesinlikle.....
char son[3]={'s','o','n'};
char i=0,j=0;

void kurulum()
{
UART1_Init(2400);
trisb.f0=1;
Delay_100ms();

}

void main()
{
kurulum();
while(1)
{
if(portb.f0)
{
for(i=0;i<15;i++)
{
UART1_Write(pre[i]);
}
for(j=0;j<10;j++)                   //garanti olması açısından 10 kez gönderiliyor veriler...
{
for(i=0;i<3;i++)
{
while(!UART1_Tx_Idle());
UART1_Write(yak[i]);
}
}
}

//*************************************************************
if(!portb.f0)
{
for(i=0;i<15;i++)
{
UART1_Write(pre[i]);
}
for(j=0;j<10;j++)
{
for(i=0;i<3;i++)
{
while(!UART1_Tx_Idle());
UART1_Write(son[i]);
}
}
}
}
}


The website above is written in Turkish language. You can translate it using google translate...