Convert output of ADC to ASCII value in PIC16F877

Discussion in 'Embedded Systems and Microcontrollers' started by ecaits, Feb 6, 2014.

  1. ecaits

    Thread Starter Member

    Jan 6, 2014
    52
    0
    I dont have logic that how to convert hex value of ADC result (10 bit) to ascii value in PIC16F877 using hitech compiler....
     
  2. Ian Rogers

    Member

    Dec 12, 2012
    158
    29
    Look up itoa().... or printf()...
     
  3. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    The printf is an option(and also itoa of course). But in free version using printf sucks up 2K of ROM alone
     
  4. ecaits

    Thread Starter Member

    Jan 6, 2014
    52
    0
    can u give me in programming form???
     
  5. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    It is mentioned in the manual. Start at that end. You will find the manual in the compiler install folder like this ".....\HI-TECH Software\PICC\9.83\docs" You are of course free to ask for any help if you are stuck later in the coding process for this question
     
  6. Ian Rogers

    Member

    Dec 12, 2012
    158
    29
    If you cant afford the code space.. then write your own

    Take the number 12345... Add 48 to make it ascii..

    number / 10000 + 48 = ascii '1'
    (number % 10000) / 1000 + 48 = ascii '2'
    (number % 1000) / 100 + 48 = ascii '3'
    (number % 100) / 10 + 48 = ascii '4'
    number % 10 + 48 = ascii '5'
     
  7. Brownout

    Well-Known Member

    Jan 10, 2012
    2,375
    998
    Not using Hi-Tech, but here's how I did it in MPLAB. dec1 and dec2 are the 1st and 2nd decimal places in the reading. voltstring is the character which is printed.

    Code ( (Unknown Language)):
    1.  
    2. voltage = ADC_Convert();
    3. voltage = (voltage*3);
    4. dec1 = (voltage%255)*10;
    5. dec2 = (dec1%255)*10;
    6. voltage = voltage/255;
    7. dec1 = dec1/255;
    8. dec2 = dec2/255;
    9.  
    10. itoa(voltage, voltstring, 10);
    11. WriteCmdXLCD(0x87);
    12. WriteStringXldc(voltstring);
    13. WriteDataXLCD_local('.');
    14. itoa(dec1, voltstring, 10);
    15. WriteStringXldc(voltstring);
    16. itoa(dec2, voltstring, 10);
    17. WriteStringXldc(voltstring);
    18.  
     
Loading...