Maker Pro
Maker Pro

A/D conversion - pic18f4550

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);
    }
}
 
Also your ADCON2 reg will need the correct values for the sys. clock you are using if different from the original code.
M.
 
Top