Displaying numbers on 16x2 LCD
Fri Feb 18 2011, 09:28 pm
Schematics a bit later. Working codes:
Tx:
Rx:
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, 08:28 pm ] Tags rf communication 8051wireless communication microcontrollermicrocontroller wireless data transferHM-R868 TM-R868
Fri Feb 18 2011, 09:49 pm
reduce the delay and tell about schematic and final code so it helps others
Sat Mar 26 2011, 04:06 pm
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.
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, 04:43 pm
@ kirangowle
encoders r not in proteus
he make it custom ic package not a library
it will not work in proteus
encoders r not in proteus
he make it custom ic package not a library
it will not work in proteus
Sat Apr 23 2011, 03:00 pm
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.
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, 03:01 pm ]
Powered by e107 Forum System