Discussion in "8051 Discussion Forum" started by    Gastonio    Sep 9, 2010.
Wed Oct 13 2010, 02:53 pm
#31
No no, the program is ok, don't worry about it. I think there is problem with my code, not the program.
Wed Oct 13 2010, 04:55 pm
#32
Yeah, the problem was really in JNZ part. In my code A is never 0. I wrote CJNE A, #"S", LOOP1 and the string appeared, just it is essential to write string with "S" being the last letter.
Wed Oct 13 2010, 10:42 pm
#33
yes some software has setting
that what character u want to send at the end of string normally use null so i made the asm code to consider that ur also sending a null at the end of string
now s can be inside the string so ur code consider it as the end of string
let say
this is a sentence
"I AM SORRY" now when S come controller things it is the last character but in fact it is not the last so normally null is used in the end of string as a indication for ending
hop so u got it
Thu Oct 14 2010, 05:50 pm
#34
Well, I just wrote #' ' and hit space after the string so it's ok now.
Thu Oct 14 2010, 08:08 pm
#35
hi Gastonio
yes it should be ok now
Mon Jan 17 2011, 07:19 pm
#36
Hi to you all! Thanks, Majoka, for the help, however it would be more helpful if I posted problem here.
I am making wirless temperature transmitting device with 2x8051 and Hope HM-T and HM-R 868MHz FSK RF modules.
I did wired conncetion and it works just fine. The problem is with wireless conncetion, there is a lot of garbage on LCD and no temperature values. I read a lot of topics about RF modules and 8051, however there was no detailed info how to interface encoders and decoders to 8051.
What is more, I am thinking of making a Mancherster coding subprogram without using encoders and decoders. The problem is that I don't know what info I should code and how to modify my code below. Temp is float so I am not sure, how coding must be done. Ant I am using printf() function.

Transmitter:

#define uchar unsigned char
#define uint unsigned int
#include<intrins.h>
#include<reg52.h>
#include<math.h>
#include<stdio.h>

sbit DQ=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;
}// Delay provides 16us per loop, plus 24us. Therefore delay(5) = 104us

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);
}

float get_temp()
{
uchar tmp1,tmp2;
float temp;
uint tmp;
bit flag;
ow_reset();
write_byte(0xCC);
write_byte(0x44);
ow_reset();
write_byte(0xCC);
write_byte(0xBE);
tmp1=read_byte();
tmp2=read_byte();
tmp=tmp2*256;
tmp=tmp+tmp1;
flag=tmp&&0xf800;
if(flag==0)
{
temp=(~tmp+1)*0.0625;
temp=temp*-1;
}
else
temp=tmp*0.0625;
return temp;
}

void sercon(void)
{
SCON = 0x50;
TMOD |= 0x20;
TH1 = 0xE6;
TR1 = 1;
TI = 1;
}

void main()
{
float temp;
uint cnt = 0;

sercon();

while(1)
{
temp = get_temp();

printf("%.2f\r\n",temp);
cnt = 10000;
for(;cnt > 0;cnt--)
{};
}
}

Receiver:

#include<intrins.h>
#include<reg51.h>
#include<math.h>
#include<stdio.h>
#include<1602.h>

unsigned char a[8];
unsigned char buffer[8];

void sercon(void)
{
SCON = 0x50;
TMOD |= 0x20;
TH1 = 0xE6;
TR1 = 1;
TI = 1; /*clear the buffer */

}

void main()
{
sercon();
init();


while(1)
{
writeCmd(0x80);
gets (a, sizeof(a)-1);
sprintf(buffer,"%s",a);
sendstring(buffer);
}}

Manchester coding subprogram example:

encoding:

void SendData(BYTE txbyte)
{
int i,j,b,me;
b = txbyte;
for (i=0; i<2; i++) {
me = 0; // manchester encoded txbyte
for (j=0 ; j<4; j++) {
me >>=2;
if (bit_test(b,0) )
me |= 0b01000000; // 1->0
else
me |= 0b10000000; // 0->1
b >>=1;
}
putc(me);
}
}

decoding:

BYTE DecodeData(BYTE encoded)
{
BYTE i,dec,enc,pattern;
enc = encoded;
if (enc == 0xf0) // start/end condition encountered
return 0xf0;
dec = 0;
for (i=0; i<4; i++) {
dec >>=1;
pattern = enc & 0b11;
if (pattern == 0b01) // 1
bit_set(dec,3);
else if (pattern == 0b10)
bit_clear(dec,3); // 0
else
return 0xff; // illegal code
enc >>=2;
}
return dec;
}


[ Edited Mon Jan 17 2011, 10:36 pm ]
Mon Jan 17 2011, 10:59 pm
#37
did you try the simple way by sending some preamble bytes before sending data?

i mean encapsulating data packet between headers. send 'U' 5-10 bytes before sending data, that will clear your channel then you can send a start of byte and then your data. try it if that solves your problem of transmission.

Now regarding float. remember float can also be treated as 4 byte array here is a small example.

unsigned char *Float; //Float is a byte pointer to use float as array of 4 bytes
float f; //f is the actual float variable
Float = (unsigned char*)&f; //now we store address of 'f' in byte pointer
//now Float can be used as a four byte array

//reverse is also simple and similar way
unsigned char Float[4]; //You will receive 4 bytes and store in this array, bytes are stored in same order the way they were received
float *f; //now f is a float pointer

f = (float *)Float; //store address of array in float pointer

//now we can access float value as *f
//e.g.

*f = *f * 100;



NOTE: Do not keep wireless modules too close, that generates lot of noise.
Mon Jan 17 2011, 11:48 pm
#38
No, I didn't try to do so. You mean write a code just to send single characters and test wirless connection? I see that there is a lot of noise... Even when I remove transmitter module, the reciever keeps receiving garbage as I am able to see that on the LCD. And my modules are very close to each other maybe 10cm, so I guess I'll try to conncet them to longer wires and place them a bit further from each other.
Tue Jan 18 2011, 01:48 am
#39
Take a look at this thread.
http://www.8051projects.net/forum-t43496-0.html#post_43517
Wed Jan 19 2011, 12:38 am
#40
hi Gastonio
use encoder and decoder
first try to send a simple character and receive that if u receive it mean it is ok
if not then use encoder and decoder ic's
as many make this with encoder and decoder and they say's that after that they gets better results

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Michailqfh
Fri Mar 29 2024, 01:53 am
Bobbyerilar
Thu Mar 28 2024, 08:08 am
pb58
Thu Mar 28 2024, 05:54 am
Clarazkafup
Thu Mar 28 2024, 02:24 am
Walterkic
Thu Mar 28 2024, 01:19 am
Davidusawn
Wed Mar 27 2024, 08:30 pm
Richardsop
Tue Mar 26 2024, 10:33 pm
Stevencog
Tue Mar 26 2024, 04:26 pm