View previous topic :: View next topic |
Author |
Message |
giustraman
Joined: 11 Jun 2007 Posts: 25
|
transmitter-receiver communication based on radio frequency |
Posted: Wed Oct 07, 2009 7:24 am |
|
|
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: 1615 Location: Central Illinois, USA
|
|
Posted: Wed Oct 07, 2009 10:06 am |
|
|
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
|
|
Posted: Thu Oct 08, 2009 12:50 am |
|
|
I rewrote all the code in C using CCS, someone can help me now? |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Thu Oct 08, 2009 2:34 am |
|
|
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
|
|
Posted: Thu Oct 08, 2009 6:24 am |
|
|
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??? |
|
|
|