Hello John,
The usual way of handling the incoming serial data is to shift each bit value into a multiple byte array - in this case the array could be of byte type, with one nybble of each byte occupied, to represent the final form of the data. Thus, the array size would be 13 bytes.
With assembly code, the shifting through multiple bytes is simple because of direct access to the carry flag. With C code, the process is somewhat more complex. With the following untested code snippet, I have assumed that MSB of the data is sent first, so that there is a left shift of each data bit into the last nybble of the array. However, before this can be done, the rest of the array needs to be rotated left to make room for the new bit value.
byte array[13]; // Global array for 13 data nybbles (52 bits)byte bitcount = 52; // Value is decremented as each bit is received// Local variable:byte i;for (i = 0; i < 13; i++) { // Commence with first nybble array[i] <<= 1; // Left shift nybble array[i] &= 0x0F; // Mask nybble value if (i < 12) { // Not last nybble if (array[i+1] & 0x08) array[i] |= 0x01; // Carry bit from next nybble } else { // Last nybble of array if (PTAD_PTAD0) // Serial input data at PTA0 is assumed array[12] |= 0x01; }}bitcount--; // Decrement countif (bitcount == 0) // Test for end of data sequence...
Each element of the array should ultimately contain a value within the limits 0-15 decimal.
Regards,
Mac