1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

urgent help in Code!!!!

Discussion in 'Microcontrollers' started by engkhlaif, Mar 15, 2008.

  1. caddybran1977

    caddybran1977 New Member

    Joined:
    Apr 7, 2009
    Messages:
    4
    Likes:
    0
    we are using 8 bits and we tried
    voltage = (x/255)*(5.0) and we got much larger numbers that had negative signs in front.
    our range on x is 71 - 81
    the original code is


    while(1)
    {
    lcd_init();

    lcd_goto(0) ;
    lcd_puts("welcome " ) ;
    lcd_goto(0x40);
    x=read_a2d(1);
    voltage=(x/255.0)*(5.0);
    sprintf(outString,"A2D = %d.%d volts",voltage);
    lcd_puts(outString);

    }

    }
    so if i comment out voltage and display x my range is 71-81
     
  2. binzer

    binzer Member

    Joined:
    Apr 16, 2008
    Messages:
    197
    Likes:
    4
    Location:
    Oxford, Ct USA

    So what is your input voltage when you did that?? If I calculate it out it's about 1.3 - 1.5 volts.

    Where did you get your calculation info??

    Here is a snippet from one of my programs, no guarantee it will help.
    {

    ConvertADC();
    while( BusyADC() );
    reslta0 = ReadADC();
    reslts0 = (reslta0+1)* .488; // Scale for 5Volts
    // reslts0 = (reslta0+1)* 2.44; // Scale for 25Volts
    }
     
    Last edited: Apr 13, 2009

Share This Page