Discussion in "8051 Discussion Forum" started by    Gastonio    Sep 9, 2010.
Fri Feb 18 2011, 03:58 PM
#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, 02:58 PM ]
Tags rf communication 8051wireless communication microcontrollermicrocontroller wireless data transferHM-R868 TM-R868
Fri Feb 18 2011, 04:19 PM
#92
reduce the delay and tell about schematic and final code so it helps others
Mon Feb 21 2011, 05:51 PM
#93
Schematics:



[ Edited Mon Feb 21 2011, 05:54 PM ]
Tue Feb 22 2011, 02:55 AM
#94
good work and share
Sat Mar 26 2011, 10: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, 11: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, 11:29 AM
#97
good work Gastonio.really good for beginner like me.
Sat Apr 23 2011, 09: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, 09:31 AM ]
Mon Apr 25 2011, 05:16 PM
#99
is it RF nice.. i should tag this post.
Mon Apr 25 2011, 05:56 PM
yes ajay its RF

Get Social

Information

Powered by e107 Forum System

Conversation

Thu Nov 21 2019, 12:30 PM
raj2555
how to interface 8051 microcontroller with NRF24L01+ module
ExperimenterUK
Sat Oct 12 2019, 10:23 PM
Log in.. then post your code in the 8051 forum
Sat Oct 12 2019, 10:18 AM
Bhadra Sajikumar
i am doing a countdown timer with 8051 for my project, unfortunately our professor had to take a leave of absence before he could teach us most of it.. can someone explain the .asm code of it for me?
Mon Sep 23 2019, 07:37 AM
Nathaniel
I am doing a project for my schools wireless security system with cameras,sensors and spot lights using 8051 micro controller, could you help me out with the design and its source code.
Wed Sep 18 2019, 08:48 PM
Caryn Kover
Thank you for your time,
ExperimenterUK
Mon Aug 05 2019, 07:09 PM
@Ismail ..post in forum, give details
Mon Aug 05 2019, 04:33 PM
Ismail balghmi
Hello. Please I won't download
ExperimenterUK
Wed Jul 24 2019, 12:47 AM
@BUSTER123 Please post in the forum
Tue Jul 23 2019, 06:13 PM
BUSTER123
hello! newbie here. i am kind of a guy who hates using ready - made existing libraries, so this helped a lot as i was trying to control and write to a character lcd display. however, i can't figure out how to set the cursor position. for example, i want to set it to the 5th column in the first row, so position 5. so according to the table, i am sending 10000101 on the 8 data lines of the lcd (register select pulled low). the cursor does not move there however. and i cant move the cursor left or right too. is it something wrong that i am doing? thank you.
ExperimenterUK
Thu Jul 11 2019, 07:55 PM
@ramos https://www.theengineeringprojects.com/2017/09/l298-motor-driver-library-proteus.html

Downloads

Comments

auwal
Tue Nov 19 2019, 03:13 PM
ANKITPATEL
Mon Nov 18 2019, 11:00 AM
Casmir
Wed Nov 13 2019, 06:25 AM
DeepakBGattani
Mon Nov 11 2019, 01:31 PM
Jeanbusatta
Sun Nov 10 2019, 04:42 AM
mdayaz
Sat Nov 09 2019, 03:41 PM
baoyen123
Fri Nov 08 2019, 10:06 AM
xiwang
Fri Nov 08 2019, 07:28 AM

Online

Guests: 41, Members: 0 ...

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

Members: 38105
Newest member: auwal
Forum Activity
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Nov 19 2019, 10:44 PM
The 8051 has too little memory to do anything us...
ilylily07 Avatar
Posted By ilylily07
Mon Nov 18 2019, 09:54 AM
0v7670 camera interfacing with stc 8051.using asse...
Jeanbusatta Avatar
Posted By Jeanbusatta
Sun Nov 10 2019, 04:43 AM
ty, really needed it
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue Oct 22 2019, 05:18 AM
wimac Avatar
Posted By wimac
Mon Oct 21 2019, 09:18 AM
I’ve been following this thread and looking at the...
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Sun Oct 20 2019, 03:09 PM
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Sun Oct 20 2019, 03:02 PM
sir, when i on display ,sometime 3rd display is no...
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Sun Oct 20 2019, 02:53 PM
sir, when i on display ,sometime 3rd display is no...
ExperimenterUK Avatar
Posted By ExperimenterUK
Sun Oct 20 2019, 12:21 AM
Your code seems okay on my simulationTry my code o...
s_dinesh40@yahoo.com Avatar
Posted By [email protected]
Sat Oct 19 2019, 07:13 PM
please find video attachment. 3rd & 4th displa...