zulkifliaziz
Junior Member level 1
Hi all,
I'm having a problem to understand how to convert 10 bit data to become 8 bit.
First of all, what i want to implement is to use an ADC from analog data (0-5V).
So, from my understanding,
10 bit data = 1024 (max)
in this case, if 5V=1024 and if 2.5V=512
But, to communicate with rs232, we have to use 8 bit = 1 byte each data being sent plus start bit and stop bit.
From the code above, do u see any wrong doing. pls help. What i want to know is that, why the number for this chattared keeps alway changing itself.
I'm having a problem to understand how to convert 10 bit data to become 8 bit.
First of all, what i want to implement is to use an ADC from analog data (0-5V).
So, from my understanding,
10 bit data = 1024 (max)
in this case, if 5V=1024 and if 2.5V=512
But, to communicate with rs232, we have to use 8 bit = 1 byte each data being sent plus start bit and stop bit.
Code:
char temp_res;
char temp_text[7];
void main()
{
Uart1_Init(9600);
ADCON1 = 0x80;
TRISA = 0xFF;
TRISB = 0;
PORTB = 0B00000000;
for(;;)
{
temp_res = ADC_Read(1);
if(temp_res>125)
{
ByteToStr(temp_res,temp_text);
PORTB=0B00000001;
Delay_ms(100);
PORTB=0B00000000;
Delay_ms(100);
Uart1_Write(temp_text);
Delay_ms(100);
}
}
}
From the code above, do u see any wrong doing. pls help. What i want to know is that, why the number for this chattared keeps alway changing itself.