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 support@ccsinfo.com

transmitter-receiver communication based on radio frequency

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



Joined: 11 Jun 2007
Posts: 25

View user's profile Send private message MSN Messenger

transmitter-receiver communication based on radio frequency
PostPosted: Wed Oct 07, 2009 7:24 am     Reply with quote

I want to realize a rf transmission between tx and rx: in the tx circuit there's a temperature sensor, in the rx this measure should be displayed on a LDC 2x16...

I think to use a 5 byte protocol: the first byte to identify the beginning (00000001), 2nd and 3rd to save temperature measure, and 4th and 5th to an incognit function "x" (for example to connect something from an other analog input)...

Someone could help me to write C++ code??

There's a beta version code:
Code:

int16 value,value_x;
int vett[40];

while(1)
{
   set_adc_channel(0);
   value=read_adc();
   delay_us(20);
   for(i=0;i<15;i++)
   {
      if(value%2==0)
         {
            vett[23-i]=0;
            
         }      
         else
         {
            vett[23-i]=1;
            
         }
      
      value=value/2;
   
      
   
   }
   set_adc_channel(1);
   value_x=read_adc();
   delay_us(20);
   for(i=0;i<15;i++)
   {
      if(value_x%2==0)
         {
            vett[39-i]=0;
            
         }      
         else
         {
            vett[39-i]=1;
            
         }
      
      value_x=value_x/2;
   
      
   
   }
}
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Wed Oct 07, 2009 10:06 am     Reply with quote

Forum Rule

6. Stay on topic

This forum's sole purpose is to help people with programming Microchip's in CCS PIC C. Also, generally any discussion about Microchip's, firmware designing and electronic components in embedded systems is considered on topic.


C++ is out of scope for this forum unless you are somehow using that C++ code specifically for a microchip based controller. (and I would imagine that's a stretch)
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
giustraman



Joined: 11 Jun 2007
Posts: 25

View user's profile Send private message MSN Messenger

PostPosted: Thu Oct 08, 2009 12:50 am     Reply with quote

I rewrote all the code in C using CCS, someone can help me now?
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Thu Oct 08, 2009 2:34 am     Reply with quote

In my opinion, it's a long-winded and rather ineffective method to generate a bitstream from numbers. It should work as such, but you don't show, how you want to sendout the bitstream, which involves also timed sequences. Receiving is the more challenging job.

Depending on your transmitter/receiver chips, transmission of unmodified raw binary data can be possible or not. Some will require manchester coding.
giustraman



Joined: 11 Jun 2007
Posts: 25

View user's profile Send private message MSN Messenger

PostPosted: Thu Oct 08, 2009 6:24 am     Reply with quote

I'm using a protocol of 6 bytes so divided: 1st and 2nd to identify the beginning of transmission, 3rd and 4th to temperature measure, 5th and 6th to an other analog input.
This is the last version code:

Code:
//dichiarazione variabili e inizializzazione

int16 temp, value_x;
int1 vett[48];
int count;

for(int i=0;i<48;i++)
   vett[i]=0;

for(int i=0;i<16;i++)
{
   if((i+1)%2==1)
      vett[i]=1;
   else
      vett[i]=0;
}



while(1)
{
   
//temperatura

   set_adc_channel(0);
   delay_us(10);
   temp = read_adc();
   
   temp=temp*10;

   for(int i=0;i<15;i++)
   {
      if(temp%2==0)
         {
            vett[31-i]=0;
            
         }      
         else
         {
            vett[31-i]=1;
            
         }
      
      temp=temp/2;
   
   }

   
//ulteriore ingresso analogico


   set_adc_channel(1);
   delay_us(10);
   value_x = read_adc();
   
   value_x=value_x*10;

   for(int i=0;i<16;i++)
   {
      if(value_x%2==0)
         {
            vett[47-i]=0;
            
         }      
         else
         {
            vett[47-i]=1;
            
         }
      
      value_x=value_x/2;
   }
   

//controllo parità

   for(int i=0;i<48;i++)
      if(vett[i]==1)
         count++;


   for(i=0;i<48;i++)
   {
      if(count%2==1)
         vett[16]=1;
   }

   

   for(int i=0;i<48;i++)
   {
      if(vett[i]==1)
      {
         output_high(PIN_A2);
         delay_us(666);
         output_low(PIN_A2);
         delay_us(333);   
      }
      else
      {
         output_high(PIN_A2);
         delay_us(333);
         output_low(PIN_A2);
         delay_us(666);   
      }
   }   
      

}


In the aim of reducing power consumption, I'm tring to sleeping device (pic 12f675). Someone can help me to sleeping/unsleeping it after rf transmission???
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