Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Help me set AN5 as analog in PIC16f877a

Status
Not open for further replies.

yoannes

Junior Member level 1
Joined
Jan 28, 2012
Messages
17
Helped
1
Reputation
2
Reaction score
1
Trophy points
1,283
Activity points
1,395
Hi everyone,

I need some help. I am beginner with microcontrollers and had some problems..

I'm trying to make an simple code with PIC16F877A and mikroc to learn to use microcontrollers.

I want to set the AN5 as analog, but I can't do it, I tried to look for but couldn't find the answer. When all the ports were digital was fine, but now.. Could anyone help me please?

I just want to turn on the LEDs when input 2,5V on the RE0 for exemple

Code:
  unsigned asd;
void main() {

  ADCON1 = 0x08;

  TRISA = 0x00; 
  TRISB = 0x00;
  TRISC = 0x00; 
  TRISD = 0x00; 
  TRISE = 0xFF;

  while(1){
        PORTB = 0x00;
        PORTC = 0x00;
        PORTD = 0x00;
  
  asd = ADC_Read(5);
  
  if(asd >= 200){
        PORTB = 0xFF;
        PORTC = 0xFF;
        PORTD = 0xFF;
        delay_ms(1000);
  }

  }
}
 

Re: Help with Pic16f877a

I don't specifically know MikroC but with the PIC micros you normally need to set the ANSEL register to define an input as analog before you can use the ADC.

Keith
 

Re: Help with Pic16f877a

I don't specifically know MikroC but with the PIC micros you normally need to set the ANSEL register to define an input as analog before you can use the ADC.

Keith

Thankyou for your help. ANSEL doesn't work for the 877A... I've tried.
 

Re: Help with Pic16f877a

Ok. You don't don't seem to have set up the ADCON0 register.

Keith

---------- Post added at 23:17 ---------- Previous post was at 23:12 ----------

Also, your ADCON1 value requires external VREF+/- are you doing that? If not, try 0x09

Keith
 

Re: Help with Pic16f877a

I don't use MikroC and I was use PIC16F877A long time ago. Now I'm use PIC16F887.

1. ANSEL is only use in 887 not 877A.
2. I'm not sure about MikroC ADC_Read() function, so maybe in the function is set the ADCON0.
3. You set ADCON1=0x08, then you need to connect voltage at pin VREF+(RA3) and VREF-(RA2). If you not connect that pin, then try change to ADCON1=0x00 to make all analog pin and VREF from VDD and VSS.
 

Re: Help with Pic16f877a

Ok. You don't don't seem to have set up the ADCON0 register.

Keith

---------- Post added at 23:17 ---------- Previous post was at 23:12 ----------

Also, your ADCON1 value requires external VREF+/- are you doing that? If not, try 0x09

Keith

I made some changes to set the VREF+, so I'm using now the AN0 as input
ADCON0 = 0b10000001;
ADCON1 = 0b10000101;

How can I read the result?
Thank-you
 

Re: Help with Pic16f877a

I made some changes to set the VREF+, so I'm using now the AN0 as input
ADCON0 = 0b10000001;
ADCON1 = 0b10000101;

How can I read the result?
Thank-you

I can't recalled 3 yrs ago. It was found in mikroc and css and mplab. But u can do in search google....battery monitor adc in mikroc.

Check it out in mikroc:
News - Car battery voltage monitor written in mikroC PRO for PIC - July 19 2011 05:38:36 AM EDT


source code and schematic including:
PIC-based Digital Voltmeter (DVM) :Embedded Lab


check it out with bar leds/ pic16f887:
mikroElektronika • View topic - adc proteus 7.6 sp4 pic 16f887
 
Last edited:

Re: Help with Pic16f877a

I can't recalled 3 yrs ago. It was found in mikroc and css and mplab. But u can do in search google....battery monitor adc in mikroc.

Check it out in mikroc:
News - Car battery voltage monitor written in mikroC PRO for PIC - July 19 2011 05:38:36 AM EDT


source code and schematic including:
PIC-based Digital Voltmeter (DVM) :Embedded Lab


check it out with bar leds/ pic16f887:
mikroElektronika • View topic - adc proteus 7.6 sp4 pic 16f887



Thank-you, these links helped a lot!!
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top