|
发表于 2015-1-19 16:03:04
|
显示全部楼层
void SendByte(uint8_t data) {
uint8_t i;
for(i = 0; i < 8; i++) {
SCK(0);
DELAY_CLK(1);
SID(data & 0x80); //移出的位给SID
DELAY_CLK(1);
SCK(1);
DELAY_CLK(1);
SCK(0);
DELAY_CLK(1);
data = data << 1; //左移一位
}
}
uint8_t ReceiveByte(void) {
uint8_t i,temp1,temp2;
temp1 = 0;
temp2 = 0;
configSidPin(GPIO_Mode_IN_FLOATING);
DELAY_CLK(1);
for(i = 0; i < 8; i++) {
temp1 = temp1 << 1;
SCK(0);
DELAY_CLK(1);
SCK(1);
DELAY_CLK(1);
SCK(0);
DELAY_CLK(1);
if(GetSID())
temp1 |= 0x01;
}
for(i = 0 ;i < 8; i++) {
temp2 = temp2 <<1;
SCK(0);
DELAY_CLK(1);
SCK(1);
DELAY_CLK(1);
SCK(0);
DELAY_CLK(1);
if(GetSID())
temp2 |= 0x01;
}
configSidPin(GPIO_Mode_Out_PP);
return ((0xf0 & temp1) + (0x0f & temp2));
}
void CheckBusy( void ) {
do{
SendByte(0xfc); //11111,RW(1),RS(0),0
}while(0x80 & ReceiveByte()); //BF(.7)=1 Busy
} |
|