I am New in this Forum and PIC Programming. I need a little help.
I am using PIC16F676 MCU with Internal Oscillator clock and internal MCLR Voltage in MikroC Compiler. I want to read two analog inputs of 5K potentiometer connected at RA4 and RA3 to calculate the LED on/off Delay. I have connected a LED on RA0 (Pin 13) of PIC16f676 MCU. I want to limit its time from 1 second to 10 seconds with respect to 5k Potentiometer.
I have pasted my code below, But it gives me some error. I don't know where i was doing wrong:
Code:
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;
Delay_ms(VR1_Value);
LED = 1;
Delay_ms(VR2_Value);
}
This is my Proteus Simulation Design:
And Below is my MikroC compiler Configuration Bit Settings:
Yes sir, Now program ins working with VDelay_ms() , But please guide me a little more that how i can adjust the calculation for 5k potentiometer for 1s to 10s delay?
Yep I have Attached the GND now ... and replace VDD to U1_VDD. Now code is working with VDelay_ms(VR1_Value); , But now how i can do calculation for 1s to 10s delay for 5k potentiometer?
If you need maximum 10 second delay then use this assuming 10 bit ADC.
Code:
unsigned int VR1_Value, VR2_Value;
VR1_Value = (unsigned int)ADC_Read(4) * 10000 / 1024; // LED OFF Time
VR2_Value = (unsigned int)ADC_Read(3) * 10000 / 1024;// LED ON Time
LED = 0;
VDelay_ms(VR1_Value);
LED = 1;
VDelay_ms(VR2_Value);
It doesn't matter whether you use 5K or 10k pot. It only limits the current. The voltage out of pot should be in the range of 0-5V.