# 8051 seriel data transfer

1. ## 8051 seriel data transfer

Dear All,
I want to transfer decimal from 0 to 999 serielly by using 89s52 seriel port for my project.but how to transfer or how to write code for decimal numbers.please reply.
thanks,
Tepu

2. ## Re: 8051 seriel data transfer

What exactly do you mean “send decimal numbers”? You can send them as BCD. You can send ASCII. You cand send them as binary and convert them at the receiving end. You don’t really explain what’s going on here. Where are these decimal numbers coming from?

•

3. ## Re: 8051 seriel data transfer

Actually I want to transfer decimals as BCD from one 89s52 to another 89s52 by using seriel port.please give program hint or link.
Thanks,
Tepu

•

4. ## Re: 8051 seriel data transfer

Hi,

* common serial interfaces are: UART, SPI, I2C....
* all of them work byte-wise.
* none of these interfaces cares about how you code the bytes

BCD is just a coding scheme.
It is only 4 bits wide.
You are free to transfer one or two BCD nibbles in a byte. (as payload)

HEX is also a 4 bits wide coding scheme, thus it makes no difference whether you transfer a HEX nibbke or a BCD nibble.

As a simple solution to transfer the decimal value of 987:
* code them as three BCD nibbles: "9", "8", "7"
* add a "frame identifier" (not "0"..."9", let"s use HEX "F"
* then you have four HEX (4 bit) nibbles: "F", "9", "8", "7"
* pack them in two bytes: 0xF9, 0x87
* transmit the two bytes

Klaus

•

5. ## Re: 8051 seriel data transfer

Hi,
i wrote a simple program.which transmit character 'z'.but how to generate bytes ??

Code:
```#include

void main()
{
SCON=0x50;
TMOD=0x20;
TH1=-3;
TR1=1;
SBUF = 'z';

while(TI==0);
TI=0;

}```

6. ## Re: 8051 seriel data transfer

Hi,

Your question looks "general" on one side and "unelaborated" on the other side.

We still have to guess: Do you want to transmit via UART?

If so:
I just did an internet search for "8051 UART tutorial". --> About half a million hits! Even video tutorials including code and testing. --> I think there is no need for another one.

My recommendation:
* go through a couple of UART tutorials
* look for UART example code
* modify it for your needs
* if you encounter problems then you are welcome to ask a detailed question.. with detailed error description.

Klaus

1 members found this post helpful.

7. ## Re: 8051 seriel data transfer

It's C programming, you can use C compiler features. I'm using printf() with hex format in this situation.

8. ## Re: 8051 seriel data transfer

Originally Posted by tapu
Hi,
i wrote a simple program.which transmit character 'z'.but how to generate bytes ??

Code:
```#include

void main()
{
SCON=0x50;
TMOD=0x20;
TH1=-3;
TR1=1;
SBUF = 'z';

while(TI==0);
TI=0;

}```
'z' IS a byte. It's hex 7A; ASCII 'z'.

You can generate your bytes any way you want; WE can't tell you how to generate them. You are being REALLY unclear about what you are trying to do, or what your problem(s) are. In your above example you could just substitute a packed BCD value for your 'z'.

•

9. ## Re: 8051 seriel data transfer

Yep tapu, FVM bro is correct, try using C compiler features as its C programming. :)

--[[ ]]--