CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Error in Adc Pic 16F886

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
jose_pic16f887



Joined: 06 Sep 2018
Posts: 11

View user's profile Send private message

Error in Adc Pic 16F886
PostPosted: Thu Sep 06, 2018 1:18 pm     Reply with quote

Friends, best regards, I am commenting on a digital voltmeter with pic 16f886 to use the ADC but when compiling I get an error, this is a part of the code, well I am using the internal oscillator of the pic.
Code:

#include <16f886.h>
#fuses intrc,nowdt
#use delay(clock=4Mhz)
#device ADC=10
#define use_portb_lcd TRUE
#include <LCD.C>                   
#include <math.h>                 
#use standard_io (All)
float t;                           
float s;
   
 void med_ir ()                   
{                                 
  setup_adc_ports (AN0);           
  setup_adc (ADC_CLOCK_DIV_32);   
                                   
  set_adc_channel (0);
  delay_us (20);                 
  t = read_adc();                       
  s= 5.0 *t / 1024;     
}                 

the compiler is located in Instruction # Device ADC = 10
and this is the mistakes:
Quote:
Compiling I:\Proyecto CCs Compiler\Volt3 on 06-sept.-18 at 14:09
*** Error 23 "Volt3.c" Line 4(9,15): Can not set this option this far into the code
*** Error 12 "Volt3.c" Line 14(20,23): Undefined identifier AN0
2 Errors, 0 Warnings.
Build Failed.

I hope you can help me friends and thanks.
Confused
fernandokestering



Joined: 03 Sep 2018
Posts: 21

View user's profile Send private message MSN Messenger

PostPosted: Thu Sep 06, 2018 2:19 pm     Reply with quote

Correct code:
Code:

#include <16f886.h>
#device adc=10
#fuses intrc,nowdt
#use delay(clock=4Mhz)

#define use_portb_lcd TRUE
#include <LCD.C>
#include <math.h>
#use standard_io (All)
float t;
float s;

void main ()
{

setup_adc_ports (sAN0);
setup_adc (ADC_CLOCK_DIV_32);

set_adc_channel (0);
delay_us (20);
t = read_adc();
s= 5.0 *t / 1024;

}
jose_pic16f887



Joined: 06 Sep 2018
Posts: 11

View user's profile Send private message

PostPosted: Fri Sep 07, 2018 7:57 am     Reply with quote

thank you very much friend for helping me, the code compiled without any error, can you please tell me what were my errors in my code and thanks Question
dyeatman



Joined: 06 Sep 2003
Posts: 1934
Location: Norman, OK

View user's profile Send private message

PostPosted: Sat Sep 08, 2018 6:19 am     Reply with quote

Processor include and #device lines have to always come first, then the fuses.
_________________
Google and Forum Search are some of your best tools!!!!
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group