1. abeychandran

    Thread Starter New Member

    Feb 7, 2012
    17
    0
    Hi, I'm new in programming. I need help in C programming using ADC in PIC18F4520. i have a sensor and character lcd . i need to indicate the temp in lcd
     
  2. debjit625

    Well-Known Member

    Apr 17, 2010
    790
    186
    Here is how you initialize ADC for 18F4502,I have used HI TECH C compiler...
    Code ( (Unknown Language)):
    1.  
    2. #include "htc.h"
    3. #define Value() ((((unsigned int)ADRESH)<<8)|(ADRESL))
    4. #ifndef _XTAL_FREQ
    5.  #define _XTAL_FREQ 4000000  //Using a 4MHz oscillator
    6. #endif
    7. int result = 0x00;//Variable to store your ADC value.
    8. int main(void)
    9. {
    10.  //Using PORTA's bit 0 i.e.. RA0/AN0  as the ADC input
    11.  PORTA = 0x00;
    12.  TRISA = 0x01;
    13. //Setting up the ADC
    14.  ADCON1 = 0x0E;
    15.  ADCON0 = 0x01;
    16.  ADCON2 = 0x81;
    17. //Reading the ADC
    18. while(1)
    19. {
    20. __delay_us(25);
    21. GODONE = 1;
    22. while(1)
    23. {
    24.  if(GODONE == 0)
    25.  break;
    26. }
    27. result = Value();
    28. //Here goes the rest of your program
    29. }
    30. }
    31.  
    You could get more details on its datasheet

    Good Luck
     
    abeychandran likes this.
  3. abeychandran

    Thread Starter New Member

    Feb 7, 2012
    17
    0
    thanks a lot
     
  4. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Will you be using the HI-Tech C compiler in your project. If so I might have some tip for you
     
  5. abeychandran

    Thread Starter New Member

    Feb 7, 2012
    17
    0
    ya exactly hi tech c compiler and pic16f877a and 18f4520
     
Loading...