Considering interrupt latencies etc, the point of sampling goes on towards the end. By reducing some count for the timer which is approximately equals interrupt latency and code execution will give proper results.
Any how the function is completely polling for eight bits, interrupt may not be necessary. you can sample eight bits in a while loop for eight times. Again small adjustments in timer count by considering the execution delay will correct the sampling point.
Check the following sample code
Code:
void get_char(void)
{
unsigned char buffer_l = 0x00, mask_l = 0x01;
// Wait for Start bit
while(DATA_RX == 1)
{
}
//Delay (208uS)
hardware_delay_208us();
while(mask_l != 0)
{
hardware_delay_208us();
hardware_delay_208us();
if(DATA_RX == 1)
{
buffer_l |= mask_l;
}
mask_l = mask_l << 1;
}
hardware_delay_208us();
hardware_delay_208us();
if (DATA_RX != 1)
{
// Remove the content in buffer_G
buffer_G = 0x00;
}
else
{
buffer_G = buffer_l;
}
}