+ Post New Thread
Results 1 to 9 of 9
  1. #1
    Full Member level 4
    Points: 1,776, Level: 9

    Join Date
    Sep 2014
    Location
    india
    Posts
    218
    Helped
    1 / 1
    Points
    1,776
    Level
    9

    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. #2
    Advanced Member level 5
    Points: 23,285, Level: 37
    barry's Avatar
    Join Date
    Mar 2005
    Location
    California, USA
    Posts
    4,460
    Helped
    985 / 985
    Points
    23,285
    Level
    37

    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?



    •   AltAdvertisement

        
       

  3. #3
    Full Member level 4
    Points: 1,776, Level: 9

    Join Date
    Sep 2014
    Location
    india
    Posts
    218
    Helped
    1 / 1
    Points
    1,776
    Level
    9

    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. #4
    Super Moderator
    Points: 74,693, Level: 66
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    15,146
    Helped
    3448 / 3448
    Points
    74,693
    Level
    66

    Re: 8051 seriel data transfer

    Hi,

    Please understand:
    * 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
    Please don´t contact me via PM, because there is no time to respond to them. No friend requests. Thank you.



    •   AltAdvertisement

        
       

  5. #5
    Full Member level 4
    Points: 1,776, Level: 9

    Join Date
    Sep 2014
    Location
    india
    Posts
    218
    Helped
    1 / 1
    Points
    1,776
    Level
    9

    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. #6
    Super Moderator
    Points: 74,693, Level: 66
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    15,146
    Helped
    3448 / 3448
    Points
    74,693
    Level
    66

    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
    Please don´t contact me via PM, because there is no time to respond to them. No friend requests. Thank you.


    1 members found this post helpful.

  7. #7
    Super Moderator
    Points: 256,096, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    44,654
    Helped
    13586 / 13586
    Points
    256,096
    Level
    100

    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. #8
    Advanced Member level 5
    Points: 23,285, Level: 37
    barry's Avatar
    Join Date
    Mar 2005
    Location
    California, USA
    Posts
    4,460
    Helped
    985 / 985
    Points
    23,285
    Level
    37

    Re: 8051 seriel data transfer

    Quote Originally Posted by tapu View Post
    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'.



    •   AltAdvertisement

        
       

  9. #9
    Newbie level 1
    Points: 13, Level: 1

    Join Date
    Apr 2019
    Posts
    1
    Helped
    0 / 0
    Points
    13
    Level
    1

    Re: 8051 seriel data transfer

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



--[[ ]]--