Discussion in "8051 Discussion Forum" started by    Gastonio    Sep 9, 2010.
Fri Feb 18 2011, 10:58 AM
#91
Schematics a bit later. Working codes:

Tx:
#include<intrins.h>

#include<reg52.h>

#include<math.h>

#include<stdio.h>

void DelayMs(unsigned int count);
sbit DQ=P2^7;
sbit TE=P3^7;	

void delay(int useconds)
{
int s;
for (s=0; s<useconds;s++);
}

unsigned char ow_reset(void)
{
unsigned char presence;
DQ = 0; //pull DQ line low
delay(29); // leave it low for 480us
DQ = 1; // allow line to return high
delay(3); // wait for presence
presence = DQ; // get presence signal
delay(25); // wait for end of timeslot
return(presence); // presence signal returned
} // 0=presence, 1 = no part   

unsigned char read_bit(void) 
{
unsigned char i;
DQ = 0; // pull DQ low to start timeslot
DQ = 1; // then return high
for (i=0; i<3; i++); // delay 15us from start of timeslot
return(DQ); // return value of DQ line
}

void write_bit(char bitval)
{
DQ = 0; // pull DQ low to start timeslot
if(bitval==1) DQ =1; // return DQ high if write 1
delay(5); // hold value for remainder of timeslot
DQ = 1;
}

unsigned char read_byte(void)
{
unsigned char i;
unsigned char value = 0;
for (i=0;i<8;i++)
{
if(read_bit()) 
value|=0x01<<i; // reads byte in, one byte at a time and then shifts it left. If DQ=0, skip, if DQ=1 execute shifting of "1" then OR.
delay(6); // wait for rest of timeslot
}
return(value);
}// Delay provides 16us per loop, plus 24us. Therefore delay(5) = 104us

void write_byte(char val)
{
unsigned char i;
unsigned char temp2;
for (i=0; i<8; i++) // writes byte, one bit at a time
{
temp2 = val>
>
i; // shifts val right 'i' spaces
temp2 &= 0x01; // copy that bit to temp
write_bit(temp2); // write bit in temp into
}
delay(5); 
}

unsigned char tmp1, tmp2;

void get_temp(void)
{	
	ow_reset();
	write_byte(0xCC);
	write_byte(0x44);
	ow_reset();
	write_byte(0xCC);
    write_byte(0xBE);
	tmp1=read_byte();
	tmp2=read_byte();
}

void main()
{		
	while(1)
	{
	get_temp();
 P1=tmp1; // LSB 4 bit of temp1  
 TE=0; // enable transmission   	  
 DelayMs(300); // can be tune better keep 500 or more
 TE=1;
 DelayMs(200);
 
 P1=tmp1>
>
4; // MSB 4 bit of temp1
 TE=0; // enable transmission
 DelayMs(300); // can be tune better keep 500 or more
 TE=1;
 DelayMs(200);

 P1=tmp2; // LSB 4 bit of temp1
 TE=0; // enable transmission
 DelayMs(300); // can be tune better keep 500 or more 
 TE=1;
 DelayMs(200);
 
 P1=tmp2>
>
4; // MSB 4 bit of temp1
 TE=0; // enable transmission
 DelayMs(300); // can be tune better keep 500 or more
 TE=1;
 DelayMs(200);
	}
}

void DelayMs(unsigned int count)
 { 
 unsigned int i; 
 while(count) {
 i = 115;
 while(i>
0) i--;
 count--;
 }}

Rx:
#include<reg51.h>

#include<1602.h>

#include<intrins.h>

#include<stdio.h>

unsigned char buffer[16];
unsigned char cdis1[16] = {"  TEMPERATURE:  "};
unsigned char cdis2[16] = {"           C    "}; 
sbit VT =P3^7; // VT is connected to p3.7
 
 float Receiver ()
 { 
 float temp1;
 bit flag;
 unsigned int temp;
 unsigned char byte1,byte2,res1,res2;

 while(VT==0); //waiting to incoming data
 byte1=(P1 & 0x0f);
 while(VT==1);
 while(VT==0); // for next 4 bits
 byte2=(P1 & 0x0f);
 res1=(byte2<<4) | (byte1); // now res1 has value of temp1 that was in tx side
 while (VT==1);
 
 while(VT==0); //waiting to incoming data
 byte1=(P1 & 0x0f);
 while(VT==1);
 while(VT==0); // for next 4 bits
 byte2=(P1 & 0x0f);
 res2=(byte2<<4) | (byte1);
 while(VT==1); // for next 4 bits
  
 temp=res2<<8;
 temp=temp+res1; 
 flag=temp&&0xf800;

 	if(flag==0)
	{
		temp1=(~temp+1)*0.0625;
		temp1=temp1*-1;	
	}
	else
	temp1=temp*0.0625;
	return temp1;	
    }

void main()
 {
 float temp1;
 unsigned int temp2;
 init();
 writeCmd(0x80);
 sendstring(cdis1);
 writeCmd(0xC0);
 sendstring(cdis2);
 writeCmd(0xCA);	
 writedat(0xDF);
 
 while(1)
 {
  temp1 = Receiver(); 
  temp2 = temp1 * 100;
  sprintf(buffer, "%d.%02d", temp2/100, temp2%100);
  writeCmd(0xC4);
  sendstring(buffer);
  temp2=0x00;
}}


[ Edited Mon Feb 21 2011, 09:58 AM ]
Tags rf communication 8051wireless communication microcontrollermicrocontroller wireless data transferHM-R868 TM-R868
Fri Feb 18 2011, 11:19 AM
#92
reduce the delay and tell about schematic and final code so it helps others
Mon Feb 21 2011, 12:51 PM
#93
Schematics:



[ Edited Mon Feb 21 2011, 12:54 PM ]
Mon Feb 21 2011, 09:55 PM
#94
good work and share
Sat Mar 26 2011, 06:36 AM
#95
Hi Gastonio,

I m doing almost same kind of project.
I saw your schematic. How did you got HT12E chips in proteus.
Did you created a library.
Sat Mar 26 2011, 07:13 AM
#96
@ kirangowle
encoders r not in proteus
he make it custom ic package not a library
it will not work in proteus
Sat Mar 26 2011, 07:29 AM
#97
good work Gastonio.really good for beginner like me.
Sat Apr 23 2011, 05:30 AM
#98
Yes, Majoka is right, I did a custom IC package in Proteus. And there is one mistake. Resistor from decoder should be placed to encoder IC and vice versa.
I've already made PCB's for both transmitter and receiver.
There is also mistake in showing negative temperature which I solved too:
flag=temp&0xF800;

if(flag == 0)
{
temp1=temp*0.0625;
}
if (flag == 0xF800)
{
temp1=(~temp+1)*0.0625;
temp1=temp1*-1;
}
return temp1;

And one more thing that should be noted is that when transimtter and receiver are in seperate boards and are powered by seperate power sources it is esential to add some kind of synchro character. For example, send number 0x09 first and at the receiver side check if this number is received. And if it is received, then start receiving temperature bits.
I am thinking of making more sophisticated synchro thing, because it is not working as good as I would want. But it's not bad either. It is working well, when you turn off the receiver and turn it on again. You will see the reight temp value again. Without syncro character, you will lose synchronzation in case if receiver is turned off.


[ Edited Sat Apr 23 2011, 05:31 AM ]
Mon Apr 25 2011, 01:16 PM
#99
is it RF nice.. i should tag this post.
Mon Apr 25 2011, 01:56 PM
yes ajay its RF

Get Social

Information

Powered by e107 Forum System

Conversation

scena
Tue May 19 2020, 06:29 PM
Does anyone have microcontroller programming software for STC15F104W (core 8051, 4 k, 128 byte, 6 I/O pin, UART ... DIL8), that works?
Sat May 02 2020, 03:38 PM
Tamu Gurung
Hi I am looking for a assembly language program for a digital decimal counter. Time counts max limit of 2 mins starting from 2.00 mins and ending at 0.00. time is to be displayed on 4 7-segment LED displays. Edsim51 simulator to be used. Thanks
Wed Mar 25 2020, 09:39 AM
Tajammul
Sir kindly send the code file i2c for 8051
ExperimenterUK
Fri Mar 13 2020, 06:36 PM
@ Rohitnani,ABEBE..which project ?
Fri Mar 13 2020, 08:55 AM
ABEBE
how can get hadwere of this project
Rohitnani
Sat Mar 07 2020, 12:11 PM
Sir, Could you please send me the zip file input password....
Wed Feb 26 2020, 11:58 AM
Peter Parker
Is it possible to send multiple messages using only 1 GSM module?
Sat Feb 01 2020, 05:12 AM
Pearl Olin
Hello,
Wed Jan 22 2020, 01:16 PM
MINU CHAUDHARY
I m getting errors while simulation process during interfacing socket output and lcd... Can i get the report of ur project which is same as us.
Tue Jan 14 2020, 02:08 AM
shubham kharade
when i am trying to simulate the program in Proteus 8 professional, I am getting some errors as cannot find module file dhtxx.md can u help me

Downloads

Comments

Davidthils
Thu May 21 2020, 08:44 AM
Jakeror
Wed May 20 2020, 09:28 PM
motorCar
Wed May 20 2020, 03:05 PM
Vordrync
Wed May 20 2020, 07:52 AM
JadenjiT
Wed May 20 2020, 03:15 AM
scena
Tue May 19 2020, 06:08 PM
CodySiz
Tue May 19 2020, 02:22 PM
ClaireSat
Mon May 18 2020, 09:50 PM

Online

Guests: 34, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 01:37 AM

Members: 38211
Newest member: Davidthils
Forum Activity
xrxx Avatar
Posted By xrxx
Thu Apr 30 2020, 06:59 AM
BCD MULTIPLICATIONAssume that you have to 2 BCD nu...
liqian Avatar
Posted By liqian
Tue Apr 28 2020, 05:26 AM
I happened to see your post and I got many useful ...
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Apr 28 2020, 04:21 AM
The code is hard to read.Please zip it and attach ...
rogermado Avatar
Posted By rogermado
Sun Apr 26 2020, 01:53 AM
@ExperimenterUK, thanks for your reply. You'll fin...
ExperimenterUK Avatar
Posted By ExperimenterUK
Sat Apr 25 2020, 05:42 PM
Some simulators handle displays better than others...
rogermado Avatar
Posted By rogermado
Sat Apr 25 2020, 03:59 PM
Hello everyone, sorry in advance if i'm not in the...
PHANTOM28 Avatar
Posted By PHANTOM28
Fri Feb 28 2020, 10:25 AM
Hi.I hope you all can help me. I am relatively ne...
ExperimenterUK Avatar
Posted By ExperimenterUK
Fri Feb 21 2020, 05:05 PM
ajay_bhargav Avatar
Posted By ajay_bhargav
Fri Feb 21 2020, 04:45 AM
Yes you can do that.1. Create a channel @Thingspea...
ananyagupta Avatar
Posted By ananyagupta
Thu Feb 20 2020, 03:58 AM
With regards to the particular characters sent to ...