Connect with us

A/D conversion - pic18f4550

Discussion in 'Microcontrollers, Programming and IoT' started by Jack41, Nov 2, 2015.

Scroll to continue with content
  1. Jack41

    Jack41

    5
    0
    Nov 2, 2015
    Hello
    I'm trying to make an A/D conversion and I am trying to adapt this code for a PIC18F4550 in MPLAB IDE, but I’m having troubles. I’m programming in C and trying to read the value of a sensor on AN0. How can I adapt this code for my needs?

    Code:
    #include <xc.h>
    #include <stdio.h>
    #include "lcd.h"
    #endif
    
    int main(void){
       
        int x;
        int v;
        char d[10];
       
      __delay_ms(2000);
       
        ADCON0=0b00000001;
        ADCON1=0b00001110;
        ADCON2=0b10011110;
    
       Lcd8_Config(&PORTE,&PORTD,2,1,0,7,6,5,4,3,2,1,0);
       Lcd8_Init(&PORTE,&PORTD);
       
        TRISD=0x00;
        TRISB=0x0F;
       
        __delay_ms(10);
        lcd_init();
       
        while(1)
        {
            ADCON0.GO_DONE=1;
            while(ADCON0.GODONE);
            tensaohum=((ADRESH<<8)+ ADRES1)* 4.88;
            inttostr(v,d);
            strcat(d,"mV");
            lcd8_out(2,4,d);
            delay_ms(10);
        }
    }
    
     
  2. Harald Kapp

    Harald Kapp Moderator Moderator

    11,310
    2,588
    Nov 17, 2011
    Which troubles? Please explain.

    What are your needs?
     
  3. Minder

    Minder

    3,066
    657
    Apr 24, 2015
    Also your ADCON2 reg will need the correct values for the sys. clock you are using if different from the original code.
    M.
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-