Rev 410 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download
void send(byte command)
{
int n;
int parity=0;
//Request-to-send
input(DATA);
output_low(CLK);
delay_us(100);
// start bit
output_low(DATA);
delay_us(20);
while(!input(CLK));
// 8 bitu
for(n=0; n<8; n++)
{
while(input(CLK));
output_bit(DATA, command & 1);
parity += command & 1;
command>>=1;
while(!input(CLK));
};
// parita
while(input(CLK));
output_bit(DATA, ~parity & 1);
while(!input(CLK));
// stop bit
while(input(CLK));
output_bit(DATA, 1);
while(!input(CLK));
output_float(DATA);
}
int8 read_byte(int8 const poradi)
{
int8 bajt;
int8 i;
// cekani na komunikacni klid
for (i=0; i<poradi; i++)
{
if (!input(CLK) || !input(DATA)) i=0;
};
// cekani na startbit
while(input(CLK) || input(DATA));
while(!input(CLK));
bajt = 0;
for(i=0; i<8; i++)
{
while(input(CLK)); // ceka na nulu hodin
bajt >>= 1;
bajt |= input(DATA) << 7;
while(!input(CLK)); // ceka na jednicku hodin
};
return (bajt);
}
/*void read_all_byte(int8*st,*nd,*rd) // precte 3 bajty
{
int8 i;
// *st=read_byte(1st);
// cekani na startbit
while(input(CLK) || input(DATA));
while(!input(CLK));
*nd = 0;
for(i=0; i<8; i++)
{
while(input(CLK)); // ceka na nulu hodin
*nd |= input(DATA) << 7;
*nd >>= 1;
while(!input(CLK)); // ceka na jednicku hodin
};
// cekani na startbit
while(input(CLK) || input(DATA));
while(!input(CLK));
*rd = 0;
for(i=0; i<8; i++)
{
while(input(CLK)); // ceka na nulu hodin
*rd |= input(DATA) << 7;
*rd >>= 1;
while(!input(CLK)); // ceka na jednicku hodin
};
}*/