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

RF Communication

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



Joined: 05 Apr 2013
Posts: 11

View user's profile Send private message

RF Communication
PostPosted: Fri Apr 05, 2013 8:15 pm     Reply with quote

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: 19513

View user's profile Send private message

PostPosted: Fri Apr 05, 2013 11:38 pm     Reply with quote

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: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Apr 06, 2013 5:20 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Apr 06, 2013 5:29 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Apr 06, 2013 8:50 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Apr 06, 2013 11:16 am     Reply with quote

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

View user's profile Send private message AIM Address

PostPosted: Sat Apr 06, 2013 3:29 pm     Reply with quote

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
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