[SOLVED] 8051 hex value sending to a single port

Status
Not open for further replies.

thannara123

Advanced Member level 5
Joined
Jan 7, 2010
Messages
1,580
Helped
122
Reputation
244
Reaction score
114
Trophy points
1,353
Location
India
Activity points
10,387
Hi how can i send a hex data to a single port as serially
for example
i need to send the following data to
P0_1 = oxff;
how can i do this simply
please help me
 

Re: 8051 hex value sending to a single pot

Hello thannara? Serial means? just like shift register or SPI or UART or I2C?
 

Re: 8051 hex value sending to a single pot

i want to give the data to a serial shift register
 

Re: 8051 hex value sending to a single pot

Sending 0xff serially means to set the port to constantly "1".

If 0xff is just an example for an arbitrary value, you should use a shift instruction in your favourite programming language and run it in a loop eight times, sending the carry bit to the port (or the lowest/highest bit before the shift, whatever you prefer). To make the data stream readable to anyone, you would want to apply a specific time delay for each bit (asynchronous serial transmission) or send a clock along with the data (synchronous serial transmission).
 

but sir tats just example if 0x10; how can i ?
please see the following example.


array[] = {0x23,0x10,0xff,0x34,0x00,0x12};

for(i=0;i<5; i++)
{
P1_0 = array;
}
 

Please take a look at the above C code:

Code:
void SendSerial (unsigned char data)
{
  unsigned char bMask;
    
  for (bMask = 0x80; bMask; bMask >>= 1)
  {
    if (data & bMask)
    {
      pin = 1;
    }
    else
    {
      pin = 0;
    }

    //You could add a delay here if you wish
  }
}

If you need the byte to be sent with the reverse order, just implement the loop from 1 to 0x80 and rotating left.

Hope that helped.
 
thanx aleex pleas explain using comment
what is the "data"

or
how can i interface 8051 with 74Hc595

in c programm
 
Last edited:

thannara123 said:
pleas explain using comment what is the "data"

Variable "data" is the hex value that is going to be serially shifted. So using your own example:

Code:
array[] = {0x23,0x10,0xff,0x34,0x00,0x12};

for(i = 0; i < 5; i++)
{
  SendSerial(array[i]);
}

Inside SendSerial() function replace variable "pin" with P1_0, and you have your example working.


About 74HC595:
https://www.edaboard.com/threads/213613/
 
Last edited:
Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…