how to get analog inputs PIC 18F in mikro C ?

Discussion in 'Embedded Systems and Microcontrollers' started by pw123, Mar 7, 2010.

  1. pw123

    Thread Starter New Member

    Mar 7, 2010
    1
    0
    hi all,

    i want to get Anlog inputs in to a PIC 18 F,im new in mikro C.

    and i want to convert these anlog inputs into digital .please advice me.

    and please provide me a learning PDF link for mikro c for PIC 18 f.

    THANKS.
     
  2. spinnaker

    AAC Fanatic!

    Oct 29, 2009
    4,884
    1,002
  3. symqwerty

    Member

    Feb 22, 2010
    31
    0
    MikroC have built-in function for that purpose ( ADC )

    From mikroC menubar -> goto help

    From the help page, read ADC chapter


    Sample code:
    Code ( (Unknown Language)):
    1. unsigned short adc_val ;  // use to store digital value
    2. void main ()
    3. {
    4.  ADCON1 = 0x00;    // check PIC18 datasheet and set particular bits for ADC
    5.  ADCON0 = 0x00;    // same as above  
    6. TRISA = 0xff ;       // set portA as input
    7.  TRISB = 0;
    8.  while (1)
    9.      {
    10.           adc_val = adc_read(0) ; //adc_read(x) is mikroC built-in func while x is
    11.                                  // port number. Eg, read from AD0 pin
    12.          portb =adc_val ;           // for you to figure out:)
    13.      }
    14. }
     
Loading...