U8 serial_byte = 0; //we'll save our result here.
while ( serial_input == high ); // wait until the start bit
wait( 1.5_bit_periods ); // wait until we're in the middle of the first bit.
if ( serial_input == high )
//if the first (in our case least signifincat) bit is high,
//we'll need to set the most significant bit.
//we'll be rotating this to the right, so this bit will
//eventually be in the least significant position
for ( i = 0; i < 7; i++ )
serial_byte >>= 1; // shift your result byte to the left by one.
// We'll do this a total of 7 times.
if ( serial_input == high )
//we could also check the stop bits, to see if there is a framing error.