RadioLocman.com Electronics ru
Advanced Search +
  
Go Back   RadioLocman Forum > Electronics and ... > Microcontrollers (MCU)

Microcontrollers (MCU) Application and programming of MCUs, Evaluation Kits and Demonstration Boards, Programmers.

Reply
 
Thread Tools Search this Thread
Old 01-07-2016, 10:16 AM   #1
Ali_Ahmer
Junior Member
 
Join Date: Jan 2016
Posts: 5
Ali_Ahmer is on a distinguished road
Default PIC16F676 5k Potentiometer Analog Read

Hello Respected All Members,

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:
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);


}
Ali_Ahmer is offline   Reply With Quote
Old 01-09-2016, 03:50 PM   #2
Rocketman46
Junior Member
 
Join Date: Dec 2015
Posts: 4
Rocketman46 is on a distinguished road
Default

You can't pass non constant value to
Code:
Code:
Delay_ms() function
It expects a const integer value. Use VDelay_ms() instead.
Rocketman46 is offline   Reply With Quote
Old 01-10-2016, 07:10 PM   #3
Ali_Ahmer
Junior Member
 
Join Date: Jan 2016
Posts: 5
Ali_Ahmer is on a distinguished road
Default

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?
Ali_Ahmer is offline   Reply With Quote
Old 01-15-2016, 06:26 PM   #4
symbol
Senior Member
 
Join Date: Oct 2013
Posts: 129
symbol is on a distinguished road
Default

Also, there is no ground connected on your schematic.
And where is infinity loop at the end of main?
symbol is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Analog wifi repeater - possible? DRN_231 Beginners 1 11-09-2015 05:46 PM
Discussion: Read 10 or more switches using only two I/O pins of a microcontroller Radiolocman Robot Projects and Advices 1 03-17-2014 02:07 PM

All times are GMT. The time now is 08:08 AM.




Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2018, vBulletin Solutions, Inc.
Slices ↓
Radiolocman facebook Radiolocman twitter Radiolocman google plus