View previous topic :: View next topic |
Author |
Message |
midoroi
Joined: 05 Apr 2013 Posts: 11
|
RF Communication |
Posted: Fri Apr 05, 2013 8:15 pm |
|
|
hello
I will make rf communication using tx433 and rx433 with 16f876.
2 led in receceiver and 2 button in transmitter.
Transmitter program:
Code: |
#include <16F876.h>
#fuses XT,NOWDT,PROTECT,NOBROWNOUT,PUT
#use delay(clock=4M)
#use rs232(baud=2400, xmit=PIN_C6, rcv=PIN_C7)
void main()
{
char var;
int i;
set_tris_b(0xff);
while(true)
{
if (input(pin_b0))
{
putc('a');}
while (input (pin_b0)) ;
if (input(pin_b1))
{
putc('b');
}
while (input (pin_b1)) ;
}
}
|
Receiver:
Code: |
#include <16F876.h>
#fuses XT,NOWDT,PROTECT,NOBROWNOUT,PUT
#use delay(clock=4M)
#use rs232(baud=2400, xmit=PIN_C6, rcv=PIN_C7)
#include <stdlib.h>
void main()
{
char c;
set_tris_b(0x00);
output_b (0);
port_b_pullups (TRUE);
while(true)
{
c=getc();
delay_ms(20);
if (c=='a')
{
output_high(pin_b1);
output_low(pin_b0);
}
else if (c=='b')
{
output_low(pin_b1);
output_high(pin_b0);
}
}
}
|
This work perfectly in isis proteus (if i change to 10 mhz clock and baud 9600)
This will work ???? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19545
|
|
Posted: Fri Apr 05, 2013 11:38 pm |
|
|
Simple answer.
No.
Search the forum.
These units require level synchronisation, before they will send data reliably.
This is a typical example of why Proteus is not the real world....
Best Wishes |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9244 Location: Greensville,Ontario
|
|
Posted: Sat Apr 06, 2013 5:20 am |
|
|
and...
your schematic does not include the ' tx433 and rx433 ' modules !
So even the 'simulation' is NOT working correctly.
As well there are at least 10 fatal errors in your schematic,once again proving _why_ you cannot put any faith in Proteus.
please read PIC101, search this forum , or google your devices for more info.
hth
jay |
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Sat Apr 06, 2013 5:29 am |
|
|
The transmit code looks OK if the receiver was perfect. It would be better if the transmitted messages were longer redundant sequences, like "aaaaaa". It would also be better if the difference between the two messages was more than 2 bits.
The receiver will probably be getting a constant stream of garbage bytes. You need to read a byte and see if it is valid before waiting of 20ms. Also if the receiver is halfway through a garbage byte when a valid byte comes through the first half of the valid byte will be lost and the last half will be out of sync. By sending a long redundant sequence the receiver has a better chance of syncing to a valid byte before the sequence is over.
Lots of people have dealt with these problems before. Search the forum. _________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
midoroi
Joined: 05 Apr 2013 Posts: 11
|
|
Posted: Sat Apr 06, 2013 8:50 am |
|
|
SherpaDoug wrote: | The transmit code looks OK if the receiver was perfect. It would be better if the transmitted messages were longer redundant sequences, like "aaaaaa". It would also be better if the difference between the two messages was more than 2 bits.
The receiver will probably be getting a constant stream of garbage bytes. You need to read a byte and see if it is valid before waiting of 20ms. Also if the receiver is halfway through a garbage byte when a valid byte comes through the first half of the valid byte will be lost and the last half will be out of sync. By sending a long redundant sequence the receiver has a better chance of syncing to a valid byte before the sequence is over.
Lots of people have dealt with these problems before. Search the forum. |
you means that when i want to send 'a' i should do like this for example
Code: | for (i = 0; i <8; i + +)
{putc (1);} |
or you means i have to change the code to send for example like this
Code: |
gets(string);
//test here if the first byte is valid. example (if string[1]=='a')
puts(string);
|
|
|
|
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
|
|
Posted: Sat Apr 06, 2013 11:16 am |
|
|
With CCS if you pass putc() a string the compiler will pass the string one byte at a time to putc() till it is done. That is a CCS specific extension to standard C. If you need your code to be transportable to other compilers you can use a loop.
For the receiver you need something like: Code: |
while(1)
x = getc();
switch(x){
case a: do 'a' stuff
delay_ms(20):
break;
case b: do 'b' stuff
delay_ms(20):
break;
other cases as required
default: bogus byte - do nothing to get back to getc() quickly
} |
_________________ The search for better is endless. Instead simply find very good and get the job done. |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Sat Apr 06, 2013 3:29 pm |
|
|
repeating myself, once again.
You are trying to use a very primitive transceiver system
( proteus problems side )
There is no DC restoration in the receiver.
To try to get around this in crude fashion, makers of these toys have you send 0xAA to establish a DC reference point in the receiver.
And then to send only a byte at a time - with checksum.
Even if you attempt a long sync word of 0xAA repeated,
to better stabilize the receiver output,
following on by sending a data string of @ symbols will
quickly deteriorate into garbage as received.
In summary these devices employ a horrible "protocol" that is :
1- inefficient
and
2- error prone
The units you want to use are meant ( at best) for a constant NRZ type code, and are very poor with TTL RS-232 signals coming from a PIC.
It will take a lot of code and overhead to "paper over" this glaring problem. RS232 is an RTZ signal type and is ill suited for this kind of transceiver.
explanatory waveforms and more info here:
http://www.picosecond.com/objects/AN-12.pdf |
|
|
|