View previous topic :: View next topic |
Author |
Message |
jose_pic16f887
Joined: 06 Sep 2018 Posts: 11
|
Error in Adc Pic 16F886 |
Posted: Thu Sep 06, 2018 1:18 pm |
|
|
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.
|
|
|
fernandokestering
Joined: 03 Sep 2018 Posts: 21
|
|
Posted: Thu Sep 06, 2018 2:19 pm |
|
|
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
|
|
Posted: Fri Sep 07, 2018 7:57 am |
|
|
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 |
|
|
dyeatman
Joined: 06 Sep 2003 Posts: 1934 Location: Norman, OK
|
|
Posted: Sat Sep 08, 2018 6:19 am |
|
|
Processor include and #device lines have to always come first, then the fuses. _________________ Google and Forum Search are some of your best tools!!!! |
|
|
|