Home > other >  24 our fleet to read and write subroutines and explanation, the best sentence by sentence, thank you
24 our fleet to read and write subroutines and explanation, the best sentence by sentence, thank you

Time:12-03

/* send Data subroutine, the Data for the request to send Data */
Void the Send (uchar Data)
{
Uchar BitCounter=8;
Uchar temp.
Do
{
Temp=Data;//will sent data staging temp
Scl=0;
The Nop ();
If ((temp& 0 x80)==0 x80)//to read data & amp; 0 x80
Sda=1;
The else
Sda=0;
Scl=1;
Temp=Data<1;//data left
Data=https://bbs.csdn.net/topics/temp;//Data after the shift to the left to assignment Data
BitCounter -;//the variable to 0, the data transfer is completed
}
While (BitCounter);//determine whether delivered complete
Scl=0;
}

/* read a byte of data, and returns the byte value */
Uchar Read (void)
{
Uchar temp=0;
Uchar temp1=0;
Uchar BitCounter=8;
Sda=1;
Do
{
Scl=0;
The Nop ();
Scl=1;
The Nop ();
If (Sda)//whether the data bits are 1
Temp=temp | 0 x01;//for the lowest temp for 1, | 0 x01, lowest is to 1)
If the else//0
Temp=temp& 0 xfe;//temp lowest is 0 (& amp; 0 xfe (11111110) the lowest is 0)
If (BitCounter - 1)//BitCounter whether is true after minus 1
{
Temp1=temp<1;//temp left
Temp=temp1;
}
BitCounter -;//BitCounter down to zero, the data is received through
}
While (BitCounter);//determine whether receive complete
Return (temp);
}
  • Related