Hello guys i wanted to map adc value (0-1023) to 0-255 range. But the code did not working on proteus 8.6.I have created a map function for this.Here is my code.But can not guess where is my fault?

Code:
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
float map(unsigned int value, unsigned int min, unsigned int max)//function definition
{
return(((max - min)/1023)*value);
}
char Txt[15];
void main()
{
unsigned int adc_value;
float d;
PORTA = 0b00000000;
TRISA = 0xFF;
ADC_Init();
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
while(1)
{
adc_value = ADC_read(0);
d = map(adc_value,0,255);
FloatToStr(d,Txt); // Convert voltage to string
Lcd_Out(2,1,"d =");
Lcd_Out(2,5,Txt);
Delay_ms(300);
}
}

Last edited: