PIC16f676 5k Potentiometer Analog Read Problem

Thread Starter


Joined Jan 7, 2016
Hello Respected All Members,

I am new in this forum and in PIC Programming field. I need a little help in my small assignment.
I am using PIC16F676 MCU and MikroC compiler with internal Oscillator and internal MCLR voltage settings. In my circuit two 5k Potentiometer are connected with RA4 and RA3 for analog read input. One led connected on (Pin 13) RA0 of MCU for output. I want to adjust the time from 1 second to 10 seconds delay with respect to potentiometer for LED off/on. Means I wanna use RA4 potentiometer to set LED OFF delay and RA3 potentiometer to set LED ON delay.
This is my code written in Mikro C
sbit LED at RA0_bit;

unsigned int VR1_Value = 0;
unsigned int VR2_Value = 0;

void main(void)

CMCON = 0x07;   //Turn off Comparators
ANSEL = 0x18;  //AN3 and AN4 as Analog Input
ADCON1 = 0x10;  /* set FOSC/8 as ADC clock source */
ADCON0 = 0x00;  /* select channel 0 and turn off ADC */

TRISA3_bit = 1;   //Analog VR2 input
TRISA4_bit = 1;   // VR1 input

TRISA0_bit = 0; // Led pin as an output

LED = 0;

VR1_Value = ADC_Read(4);  // LED OFF Time
VR2_Value = ADC_Read(3);    // LED ON Time

LED = 0;
LED = 1;

This is my Proteus Simulation Snap

And this is my MikroC configuration Bit Settings:


Joined Jun 4, 2013
Can you print out your variables VR1_Value and VR2_Value, please?
Also, your Delay function is for milliseconds, but you said that you want it to be seconds. Could that be the problem?
Last edited:


Joined Apr 24, 2011
You need to create a loop where you read the pots and make the delays.

Also you need to convert the A2D reading range. You read zero to 1023 and need to output 1,000 to 10,000 milliseconds to the delay routine. See if you can make that equation. Also check your variables are large enough to hold the results.