Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

any sample program (HTC pro) for ADC in pic16f877a

Status
Not open for further replies.

vinodstanur

New Member
could any 1 give me a sample program for ADC in pic16f877a in HTC?

I checked the data sheet but i couldn't make out anything. If i get a sample program then am sure i could learn it from that .
 
Here a sample
Here a good site to check out https://www.microchipc.com/sourcecode/
Code:
#include    <pic.h>
#include    "adc.h"


void
adc_read(unsigned char channel)
{

    ADCON0 = (channel << 3) + 0xC1;        // enable ADC, RC osc.
    ADGO = 1;
    while(ADGO)
        continue;    // wait for conversion complete
}

If I had that kind of money I would pay some one to show me how LOL
Part Number: SW500010 - HI-TECH C compiler for PIC10/12/16 MCUs (PRO) $1,195
 
Last edited:
could u make it little more clear

its not working. could u give an example such that, if input >2v then rb0=1 else rb0=0
 
You didn't say write you a program what I posted will get you a adc reading if you set your chip right but this part worried me
I checked the data sheet but i couldn't make out anything.

This is not for your chip I'm not going to read the data sheet and set it up for you you'll have the do that your self

Code:
main()
{

    PORTA = 0;
    CMCON0 = 7;                 //  Turn off Comparators
    ANSEL = 1;                  //  Just RA0 is an Analog Input

    ADCON0 = 0b00000001;        //  Turn on the ADC
                                //   Bit 7 - Left Justified Sample
                                //   Bit 6 - Use VDD
                                //   Bit 4:2 - Channel 0
                                //   Bit 1 - Do not Start
                                //   Bit 0 - Turn on ADC
    ADCON1 = 0b00010000;        //  Selemct the Clock as Fosc/8

    while(1 == 1)               //  Loop Forever
    {
        for (i = 0; i < 8; i++ )
        {                       //  Loop through Each of the 8 LEDS
            for (j = 0; j < Dlay; j++);  //  Display "On" Delay Loop
            if ((ADCValue & (1 << i)) == 0)
                PORTA = NOTPORTA[i];
            else
                PORTA = PORTAValue[i];
            TRISA = TRISAValue[i];
        }  //  rof
        switch (ADCState)       //  ADC State Machine
        {
            case 0:             //  Finished, Start Next Sample
                GODONE = 1;
                ADCState++;
                break;
            case 1:             //  Wait for ADC to complete
                if (!GODONE)
                    ADCState++; //  Sample Finished
                break;
            case 2:             //  Save Sample Value in "ADCValue" 
                ADCValue = ADRESH;
                ADCState = 0;
                break;
        }  // hctiws
    }  //  elihw
}  //  End
 
Last edited:
It figures I don't have time for that LOL It not that hard I can do it and I'm 47 never had any learning for this in school learn it on my own


You start reading on page 129 here https://www.electro-tech-online.com/custompdfs/2010/10/39582b.pdf

Then ask and you'll get some real good help I'm sure mike would post a good example

Like if adc_read << 2 volts jump over here and do this what good would it do to write it for him I don't even no that he trying to do

OP read this pdf it will help you learn how to do this . https://www.electro-tech-online.com/custompdfs/2010/10/PIC_Mid_C_8.pdf
 
Last edited:
Status
Not open for further replies.

Latest threads

Back
Top