Hi,

I would like to convert an ADC 0-5V reading into a percentage value 0-100%. I have tried a couple of attempts below, and also tried in a flat C compiler using printf and I still get zero.

Can you see any errors with my c syntax? I think it does not like typecasting float numbers. I have also tried typecasting into a float variable, and printing in flat c, but this also does not work. Any advice would be gladly accepted.

Thanks,

RocketMan46

Code:
//************* attempt 1 ***********

int adc_value = 255;
unsigned char = result;

result = (unsigned char)((adc_value/1023)*100); // this returns zero

//************* attempt 2 ***********

int adc_value = 255;
unsigned char = result;

result = (unsigned char)(adc_value/1023)*100; // this returns zero

//************* attempt 3 in flat c ***********

int adc_value = 255;
unsigned char = result;

result = (unsigned char)((adc_value/1023)*100);

printf("%d", result); // this returns zero

//************* attempt 4 in flat c ***********

unsigned char = result;

result = (unsigned char)((10/10)*100);

printf("%d", result); // this returns 100 which is correct