A/D Conversion PIC 16F

😕 Hi guys,
For a project I am trying to implement the A/D converter on a PIC 16F877A by using it to read in 4 voltage values and convert them to their digital values but am having difficulties in understanding the operation of the A/D converter, I have been reading through the datasheet and also the reference manual. If anybody has any information or links to tutorials that would help it would be greatly appreciated.

Thanks.

Replies

  • shahrul
    shahrul
    For program ADC, you need to setup ADCON0 and ADCON1 address. For read the channel, just use function
    int read_a2d(unsigned char channel)
    {ADCON0=0b00000001; //Turn on A/D module
    ADCON1=0b10000000; //configures analog and voltage reference pins
    ADCON0=(ADCON0&0xC7)|(channel<<3); //select analog input channel
    __delay_ms(2);
    ADGO=1; //initiate conversion on the selected channel
    while(ADGO==1) continue; //wait until conversion done
    return(256*ADRESH+ADRESL);}
    Full program, you can see here, #-Link-Snipped-#
  • tejasgadaria
    tejasgadaria
    sbit start_stop at ADCON0.B2;

    void Init_Adc()
    {
    ADCON0 = 0x81;
    ADCON1 = 0x80;
    TRISA = 0x01;
    }
    void delay()
    {
    int i;
    for(i=0;i<40000;i++) ;
    }
    void lcdcmd(unsigned char c)
    {
    PORTD =c;
    PORTB=0x10;
    delay();
    PORTB=0x00;
    }
    void lcddata(unsigned char c)
    {
    PORTD=c;
    PORTB=0x14;
    delay();
    PORTB=0x04;
    }

    void Lcd_Init()
    {
    lcdcmd(0x38);
    delay();
    lcdcmd(0x0C);
    delay();
    lcdcmd(0x06);
    delay();
    lcdcmd(0x01);
    delay();
    }

    void read_disp_adc()
    {
    int x,x2,x3,x4,x1;
    float b,a;
    int d1,d2,d3,d4,d5;

    unsigned char arr[20]="0123456789";

    x = ADRESL ;
    x2 = ADRESH;

    x1 = x;
    x3=(x2>>8);
    x4=x3|x;


    b=x4*5;
    a = b/255;

    d1 = (long)a;
    d1+=0x30;

    d2= a*10;
    d2%=10;
    d2+=0x30;

    d3= a*100;
    d3%=10;
    d3+=0x30;

    d4= a*1000;
    d4%=10;
    d4+=0x30;

    lcdcmd(0x80);
    lcddata(d1);
    delay();
    lcddata('.');
    delay();
    lcddata(d2);
    delay();
    lcddata(d3);
    delay();
    lcddata(d4);
    delay();
    }

    void main()
    {
    TRISB = 0x00;
    TRISD = 0x00;

    Init_Adc();
    Lcd_Init();

    while (1)
    {
    start_stop = 1;
    while (start_stop == 1);
    read_disp_adc();
    }
    }
    ;-) Enjoy.......!!
  • sanks85
    sanks85
    hey gr8 work ....
  • HEMSHAH
    HEMSHAH
    Hi,

    i am interested in a/d converter programming ,
    want 5 channel i/p (0-5v)
    and want o/p 30 channels.
    1 i/p channel converts to 6 digital o/p (0-5v => 6 channel )

    pls suggest which microcontroller to use and how

You are reading an archived discussion.

Related Posts

hi.... can anybody give me a link where completeness of metric spaces is explained well....or can somebody please explain me??😕
Can you give me 100 by just pressing 3 buttons on a standard calculator ? condition you can't press 0 at any time
could one tell me the latest online paper presentation contest dates?.
Is the this possible that we made. aroplane in to much small size; but? It can take our load. I mean our Body load What happen if we fit aroplane...
Hi cean's, I want to create a small project in java .But in my curriculum i have learned java from "teach yourself java" and in that i created java programs...