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

send temperature with rf

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



Joined: 17 Oct 2010
Posts: 3

View user's profile Send private message Send e-mail MSN Messenger

send temperature with rf
PostPosted: Thu Oct 28, 2010 9:43 am     Reply with quote

Hi everyone,
I work in a project witch I take the temperature from a sensor (ds18b20) this sensor connected with a pic(18f4423) and I send it to lcd.
Now I want to send through rf to another pic (18f4423)and agαιn to print the temperature to lcd, my rf modules is er400trs!

transmitter
Code:

#include <18f4423.h>
#device *=16
// internal osilator used

#fuses HS, NOWDT, NOPROTECT, PUT
#use delay(clock=2000000)
#define WireTX PIN_C6
#use rs232(baud=9600, xmit=WireTX, BITS=9, ERRORS, STREAM=Wireless)

#include "wire1.c"
#include "flex_lcd2.c"

int8 tH,tL,Conf;

float ds1820_read()
{
int8 busy=0, temp1, temp2;
signed int16 temp3;
float result;

onewire_reset();
onewire_write(0xCC);
onewire_write(0x44);
delay_ms(200);
while (busy == 0)
  busy = onewire_read();

onewire_reset();
onewire_write(0xCC);
onewire_write(0xBE);
temp1 = onewire_read();
temp2 = onewire_read();
tH=onewire_read();
tL=onewire_read();
Conf=onewire_read();
temp3 = make16(temp2, temp1);

result = (float) temp3 / 16.0;   // 0.1 deg C resolution
delay_ms(200);
return(result);
}
void main()
{
float temperature;
signed int16 temp;
int8 b[2];
int n;


setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);

//for  10 bit resolution mod
onewire_write(0xCC);
onewire_write(0x4E);

onewire_write(125);
  onewire_write(-55);
   onewire_write(127);

onewire_reset();
   onewire_write(0xCC);
    onewire_write(0x48);
    delay_ms(15);

lcd_init();
lcd_putc("\f");

while (1)
{
  temperature = ds1820_read();
  temp = onewire_read();
  b[0]=make8(temp,1);
  b[1]=make8(temp,0);
  for (n=0; n<2; n++)
  {
   fputc(b[n],wireless);
  }
  lcd_gotoxy(1,1);
  printf(lcd_putc,"TEMP: %3.1f ", temperature);
  lcd_putc(223);
  lcd_putc("C    ");

  lcd_gotoxy(1,2);
  if(temperature >= 29.0)
   printf(lcd_putc,"Hot!    ");
  else if( temperature >= 20 && temperature < 29.0)
   printf(lcd_putc,"Comfort!");
  else
   printf(lcd_putc,"Cold!   ");
 }

}



receiver
Code:

#include <18f4423.h>
#device *=16
// internal osilator used

#fuses HS, NOWDT, NOPROTECT, PUT
#use delay(clock=20000000)
#define WireRX PIN_C7
#use rs232(baud=9600, rcv=WireRX, ERRORS, BITS=9, STREAM=Wireless)

#include "flex_lcd2.c"



void main()
{
float temperature;
long temp;
int8 b[2];
int n;

setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DISABLED,0,1);

lcd_init();
lcd_putc("\f");

while (1)
{
   for (n=0; n<2; n++)
  {
   b[n]=fgetc(wireless);
  }
  temp=make16 (b[0],b[1]);
  temperature = (float) temp / 16.0;   // 0.5 deg C resolution

  lcd_gotoxy(1,1);
  printf(lcd_putc,"TEMP: %3.1f ", temperature);
  lcd_putc(223);
  lcd_putc("C    ");

  lcd_gotoxy(1,2);
  if(temperature >= 29.0)
   printf(lcd_putc,"Hot!    ");
  else if( temperature >= 20 && temperature < 29.0)
   printf(lcd_putc,"Comfort!");
  else
   printf(lcd_putc,"Cold!   ");
 }

}


This code work in first pic(18f4423), I take the temperature in lcd but I can't make the rf connection.
Any ideas someone?
newguy



Joined: 24 Jun 2004
Posts: 1911

View user's profile Send private message

PostPosted: Thu Oct 28, 2010 9:46 am     Reply with quote

Have a look at this post in the code library: http://www.ccsinfo.com/forum/viewtopic.php?t=23953&highlight=wireless
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Oct 28, 2010 2:27 pm     Reply with quote

Quote:
transmitter

#include <18f4423.h>
#device *=16

// internal osilator used

#fuses HS, NOWDT, NOPROTECT, PUT
#use delay(clock=2000000)
#define WireTX PIN_C6
#use rs232(baud=9600, xmit=WireTX, BITS=9, ERRORS, STREAM=Wireless)

1. #device *=16 is not necessary for 18F. The compiler always uses
16-bit pointers with 18F PICs. Delete that line.

2. Your comment says internal oscillator used, but your fuse is HS, which
is used for external crystal. The comment is incorrect. Delete it.

3. Your #use delay() is set for 2 MHz. Almost certainly, it should be set
for 20 MHz. Edit that line to correct it.

4. Why are using specifying 9 bits for the UART ?
aldoudou



Joined: 17 Oct 2010
Posts: 3

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Thu Oct 28, 2010 3:34 pm     Reply with quote

Yes now I have see my fault to crystal, thank you for your suggestion. The crystal which I use is 20 Mhz I forgot a '0'
The BITS=9 I have see some examples with rs 232 because of that I have write this like that:
http://ccsinfo.com/forum/viewtopic.php?t=27889&highlight=inte

My temperature is 2 bytes

Code:

temp = onewire_read();
  b[0]=make8(temp,1);
  b[1]=make8(temp,0);
  for (n=0; n<2; n++)
  {
   fputc(b[n],wireless);
  }


this code line to transmitter is right?
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Fri Oct 29, 2010 1:00 am     Reply with quote

aldoudou wrote:
The BITS=9 I have see some examples with rs 232 because of that I have write this like that:
http://ccsinfo.com/forum/viewtopic.php?t=27889&highlight=inte
Only 1 out of 10000 projects has a good reason to use 9 bits. Most other examples, like the one you refer to, are made by programmers who don't know what they are doing and think 'more is better'.
1 byte == 1 character == 8 bits
Only when you want to add things like error detection bits (parity for example) it makes sense to add a 9th bit but in all other cases you are making things more complex to yourself. So change to 8 bits.

Code:
  temperature = ds1820_read();
  temp = onewire_read();
  b[0]=make8(temp,1);
  b[1]=make8(temp,0);
  for (n=0; n<2; n++)
  {
   fputc(b[n],wireless);
  }
This code is for reading and transmitting the temperature. But you are using two different functions for reading the temperature. You say the temperature is shown good in the first program, this is using the ds1820_read() function. You should test the second function on the display too. It is very well possible the onewire_read() function is not working correct.
aldoudou



Joined: 17 Oct 2010
Posts: 3

View user's profile Send private message Send e-mail MSN Messenger

PostPosted: Sat Oct 30, 2010 6:48 am     Reply with quote

IF I make this is better?
Code:

temperature = ds1820_read();
  temp = (int)temperature;
  b[0]=make8(temp,1);
  b[1]=make8(temp,0);
  for (n=0; n<2; n++)
  {
   fputc(b[n],wireless);
  }

Or is better to change the temperature to characters?
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