Search This Blog

Tuesday, January 3, 2012

The data serialization using 8051 C.

There are 2 ways to transfer a byte serially.
1)      Using serial port.
2)      To transfer data 1 bit at a time and control the sequence of data and spaces in between them.

The data serialization is very easy in C. seriously.
#include<reg51.h>
/*
 * send some data through port
 * say P2.1
 * lsb should go first
 *
 */
sbit p21 = P2^1;
sbit lsbA = ACC^0;

void main()
{
                unsigned char sendMePleasebyte = 0x55h;
                unsigned char i;
                ACC = sendMePleasebyte;
                for(i = 0;i<8;i++)
                {
                                p21 = lsbA;
                                ACC = ACC<<1;
                }//end of for loop
}// end of main

#include<reg51.h>
/*
 * recieve some data through port
 * say P2.1
 * lsb should come first
 *
 */
sbit p21 = P2^1;
sbit lsbA = ACC^7;
void main()
{
                unsigned char i;
                ACC = sendMePleasebyte;
                for(i = 0;i<8;i++)
                {
                                lsbA = p21;
                                ACC = ACC>>1;
                }//end of for loop
}// end of main

No comments:

Post a Comment