# ADC generation using PIC16f72 microcontroller.

Status
Not open for further replies.

#### djc

Hi,
Here is the code for ADC using 16f72.
Code:
/****************************************************************
1) RA3 is selected as input channel
2) Knob is connected to RA3 pin on kit, by varying it we can have ADC result which is displayed on PORTB.
3) GO/DONE bit must be set before monitoring it for going low.
******************************************************************/

void main() {
unsigned int temp,i;
//TRISA = 0xff;      //Set port A direction as i/p
TRISA = 0x00;        //Port A as output
PORTA = 0X00;        //ALL BITS OFF
ADCON0 = 0X18;       //CLOCK SELECTION AND ANALOG CHANNEL SELECTION channel RA3 as input
TRISB = 0x00;        //Set port B as output
TRISC = 0x00;
//ADCON1 = 0x00;     //Vref is VDD
TRISA3_bit = 0;      //Port A 0th bit as input
TRISA2_bit = 0;
TRISA1_bit = 1;
TRISA0_bit = 1;

PORTB = 0xFF;
Delay_ms(1000);
PORTB = 0x00;
Delay_ms(1000);
PORTC = 0x00;
while(1)

{
//while((ADCON0 & 0x04)==1);    // Wait till conversion is going on
Delay_us(2);    //Call delay 2 microseconds;
}

}

#### AbdulMoeez

##### Newbie level 6
If you study datasheet of pic16F72, they mentioned that only following adc configuration you can use. use cannot make only AN3 for adc use have to use following group configuration.

1- NO_ANALOGS 7 // None
2- ALL_ANALOG 0 // A0 A1 A2 A3 A5
3- AN0_AN1_AN2_AN4_VSS_VREF 1 // A0 A1 A2 A5 VRefh=A3
4- AN0_AN1_AN3 4 // A0 A1 A3
5- AN0_AN1_VSS_VREF 5 // A0 A1 VRefh=A3

- - - Updated - - -

ccs compiler code // tested code
***************************************************************************************
1) RA3 is selected as input channel
2) Knob is connected to RA3 pin on kit, by varying it we can have ADC result which is displayed on PORTB.
***************************************************************************************

#include <pic16f72.h>

#FUSES NOWDT,NOBROWNOUT,NOLVP,HS,PUT

#use delay(clock=20000000)

void main(){

set_tris_b(0x00);
set_tris_a(0xff);

delay_ms(10);
while(1){
delay_ms(2);
}

}

#### djc

Hi,

Thanx for the suggestions sir. The program has been modified for other application using ADC. Though we have to use group of channels as input but we will get input for ADC on certain specific channel right? Correct me if I am wrong.

Thanking You

- - - Updated - - -

Hi,

Thanx for the suggestions sir. The program has been modified for other application using ADC. Though we have to use group of channels as input but we will get input for ADC on certain specific channel right? Correct me if I am wrong.

Thanking You

#### AbdulMoeez

##### Newbie level 6
yes, you are correct..... Though we have to use group of channels as input but we will get input for ADC on certain specific channel.....

Status
Not open for further replies.