justin_sane
New Member
Can this by done any faster:
I handed coded into assembly as:
I can't think of any ways to get the assembly version any faster, or a better way of clocking eight bits in for that matter.
Code:
/* receive a clocked byte from the host */
inline char getbyte(void)
{
char count, recdata = 0;
// load 8 clocked bits
for (count = 0; count < 8; count++)
{
// shift data right
recdata >>= 1; // (rotate right)
// wait for high clock
while (!clock);
if (data)
recdata |= 0x80; //set the MSB
// wait for low clock
while (clock);
}
return(recdata);
}
/* end of get byte */
I handed coded into assembly as:
Code:
movlw 0x08 // count = 8
movwf count
BCF 0x03,Carry // reset carry
// we only need to reset the carry once per call
countlp
RRF recdata,1 // recdata >>= 1; shift data right
waitckh btfss clock // wait for high clock
goto waitckh // while (!clock);
btfsc data // if (data) set the MSB
BSF recdata,7 // recdata |= 0x80;
waitckl btfsc clock // wait for low clock
goto waitckl // while (clock);
decfsz count
goto countlp
I can't think of any ways to get the assembly version any faster, or a better way of clocking eight bits in for that matter.