mplabx e xc8 problemi con libreria adc
Ciao a tutti,
finalmente ho fatto il grande passo a convertirmi con l'ambiente di sviluppo MPLAB X installando il compilatore xc8. Dopo la corretta installazione dei software IDE e IPE ho fatto le seguenti configurazioni:
1) Tools --> option --> embedded: ho cliccato scanfor bulid tools ed ha aggiunto il compilatore xc8 quando creo il nuovo programma.
2) Ho creato il primo progetto e ho messo la path delle librerie in: File --> Project property --> Xc8 Compiler --> Include directories --> messo la path C:\Program Files (x86)\Microchip\xc8\v1.34\include\plib --> ok --> apply.
Con questa ultima modifica riesco ad importare correttamente la liberia adc.h, ma quando provo a usare uno dei suoi metodi dichiarati e compilo viene fuori l'errore che non può trovare il metodo anche se esso è dichiarato nel file adc.h. Non contento ho provato lo stesso ad usare il metodo "OpenADC(ADC_FOSC_2 & ADC_RIGHT_JUST & ADC_20_TAD, ADC_CH0 & ADC_INT_ON & ADC_VREFPLUS_VDD & ADC_VREFMINUS_VSS, ADC_0ANA);" ma ottengo una bellissima sottolineatura rossa per tutto ad ecezzione della costante "ADC_RIGHT_JUST".
Ad ogni modo allego il mio progetto:
MAIN
USER
SYSTEM
CONFIGURATION BIT
Sapete se c'è qualche altro settaggio che ignoro da qualche parte?
Come posso risolvere senza dovermi fare la libreria da capo?
Grazie a tutti,
ciao lcua31989
finalmente ho fatto il grande passo a convertirmi con l'ambiente di sviluppo MPLAB X installando il compilatore xc8. Dopo la corretta installazione dei software IDE e IPE ho fatto le seguenti configurazioni:
1) Tools --> option --> embedded: ho cliccato scanfor bulid tools ed ha aggiunto il compilatore xc8 quando creo il nuovo programma.
2) Ho creato il primo progetto e ho messo la path delle librerie in: File --> Project property --> Xc8 Compiler --> Include directories --> messo la path C:\Program Files (x86)\Microchip\xc8\v1.34\include\plib --> ok --> apply.
Con questa ultima modifica riesco ad importare correttamente la liberia adc.h, ma quando provo a usare uno dei suoi metodi dichiarati e compilo viene fuori l'errore che non può trovare il metodo anche se esso è dichiarato nel file adc.h. Non contento ho provato lo stesso ad usare il metodo "OpenADC(ADC_FOSC_2 & ADC_RIGHT_JUST & ADC_20_TAD, ADC_CH0 & ADC_INT_ON & ADC_VREFPLUS_VDD & ADC_VREFMINUS_VSS, ADC_0ANA);" ma ottengo una bellissima sottolineatura rossa per tutto ad ecezzione della costante "ADC_RIGHT_JUST".
Ad ogni modo allego il mio progetto:
MAIN
- Codice: Seleziona tutto
/******************************************************************************/
/* Files to Include */
/******************************************************************************/
#include <xc.h> /* XC8 General Include File */
#include "system.h" /* System funct/params, like osc/peripheral config */
#include "user.h" /* User funct/params, such as InitApp */
#include <stdint.h> /* For uint8_t definition */
#include <stdbool.h> /* For true/false definition */
#include <adc.h>
/******************************************************************************/
/* User Global Variable Declaration */
/******************************************************************************/
/* i.e. uint8_t <variable_name>; */
/******************************************************************************/
/* Main Program */
/******************************************************************************/
void main(void)
{
/* Configure the oscillator for the device */
ConfigureOscillator();
/* Initialize I/O and Peripherals for application */
InitApp();
OpenADC(ADC_FOSC_2 & ADC_RIGHT_JUST & ADC_20_TAD, ADC_CH0 & ADC_INT_ON & ADC_VREFPLUS_VDD & ADC_VREFMINUS_VSS, ADC_0ANA);
while(1)
{
;
}
}
USER
- Codice: Seleziona tutto
/******************************************************************************/
/* Files to Include */
/******************************************************************************/
#include <xc.h> /* XC8 General Include File */
#include <stdint.h> /* For uint8_t definition */
#include <stdbool.h> /* For true/false definition */
#include "user.h"
/******************************************************************************/
/* User Functions */
/******************************************************************************/
/* <Initialize variables in user.h and insert code for user algorithms.> */
void InitApp(void)
{
APFCON = 0B00100001; //RX=RA1, CWGOUTA=RA2, CWGOUTB=RA4, T1G=RA3, TX=RA0,
//P2SEL=RA0, P1SEL=RA5
OPTION_REG = 0B11000000;
TRISA = 0B00000100; //Program all pins as output except the RA2 as input
ODCONA = 0B00000000; //No open drain pins are required
SLRCONA = 0B00000000; //No baud rate limits are required
INLVLA = 0B00000000; //TTL imputs are enabled when on change interrupt match
ANSELA = 0B00000100; //Program RA2 as analog input
WPUA = 0B00000000; //No pull up resistors are required
PORTA = 0B00000000; // Clear PortA
LATA = 0B00000000; // Clear LatA
INTCON = 0B00000000; //Disable all interrupts
IOCAP = 0B00000000; //Interrupt on change are disable of all imputs pins
IOCAN = 0B00000000; //Interrupt disable for the associated pin
IOCAF = 0B00000000; //Clear interrupts request
FVRCON = 0B11000010; //FVR = enabled, DAC = disable, ADFVR = 2.048 V
ADCON0 = 0B00001001; //ADC from AN2, adc not in progress, adc module en.
ADCON1 = 0B10000011; //ADRSEH = 8 bit significant, FOSC/2,
//FVR = selected for ADC module
ADCON2 = 0B00000000; //As default to the datasheet
DACCON0 = 0B00000000; //DAC is disabled
CM1CON0 = 0B00000000; //Comparators are disabled
CM1CON1 = 0B00000000; //As default
TXSTA = 0B00000000; //As default
RCSTA = 0B00000000; //Disable EUSART module
PWM1CON = 0B00000000; //Disable PWM 1 modules
PWM2CON = 0B00000000; //Disable PWM 2 modules
PWM3CON = 0B00000000; //Disable PWM 3 modules
CWG1CON0 = 0B00000000; //Disable CWG modules
}
SYSTEM
- Codice: Seleziona tutto
/******************************************************************************/
/* Files to Include */
/******************************************************************************/
#include <xc.h> /* XC8 General Include File */
#include <stdint.h> /* For uint8_t definition */
#include <stdbool.h> /* For true/false definition */
#include "system.h"
/* Refer to the device datasheet for information about available
oscillator configurations and to compiler documentation for macro details. */
void ConfigureOscillator(void)
{
/*If the PIC12 device has an OSCCAL value, the HiTech Compiler provides
a macro called _READ_OSCCAL_DATA which can be loaded using this: */
/* TODO Configure OSCCAL if the device has an OSCCAL register */
#if 0
OSCCAL=_READ_OSCCAL_DATA(); /* _READ_OSCCAL_DATA macro unloads cal memory */
#endif
/*Not all PIC12 devices require this.
/* TODO Add clock switching code if appropriate. */
/* Typical actions in this function are to tweak the oscillator tuning
register, select new clock sources, and to wait until new clock sources
are stable before resuming execution of the main project. */
OSCCON = 0B01111000; //PLL = disable, clock = 16 MHz, Internal block en.
OSCTUNE = 0B00000000; //Oscillator is running as factory calibration
OSCSTAT = 0B00000000; //They are control bits, as well see datasheet
}
CONFIGURATION BIT
- Codice: Seleziona tutto
/******************************************************************************/
/* Main Files to Include */
/******************************************************************************/
#include <htc.h> /* HiTech General Include File */
/******************************************************************************/
/* Configuration Bits */
/* */
/* Refer to your Hi-Tech User Manual in the PICC installation directory */
/* /doc folder for more information on filling in configuration bits. */
/* In addition, configuration bit mnemonics can be found in your */
/* PICC\version\include\<processor name>.h file for your device. The XC8 */
/* compiler contains documentation on the configuration bit macros within */
/* the compiler installation /docs folder in a file called */
/* pic18_chipinfo.html. */
/* */
/* For additional information about what the hardware configurations mean in */
/* terms of device operation, refer to the device datasheet. */
/* */
/* A feature of MPLAB X is the 'Generate Source Code to Output' utility in */
/* the Configuration Bits window. Under Window > PIC Memory Views > */
/* Configuration Bits, a user controllable configuration bits window is */
/* available to Generate Configuration Bits source code which the user can */
/* paste into this project. */
/* */
/******************************************************************************/
/* TODO Fill in your config bits here. Use the configuration bits generator. */
// CONFIG1
#pragma config FOSC = INTOSC // (INTOSC oscillator; I/O function on CLKIN pin)
#pragma config WDTE = OFF // Watchdog Timer Enable (WDT disabled)
#pragma config PWRTE = OFF // Power-up Timer Enable (PWRT disabled)
#pragma config MCLRE = ON // MCLR Pin Function Select (MCLR/VPP pin function is MCLR)
#pragma config CP = OFF // Flash Program Memory Code Protection (Program memory code protection is disabled)
#pragma config BOREN = ON // Brown-out Reset Enable (Brown-out Reset enabled)
#pragma config CLKOUTEN = OFF // Clock Out Enable (CLKOUT function is disabled. I/O or oscillator function on the CLKOUT pin)
// CONFIG2
#pragma config WRT = OFF // Flash Memory Self-Write Protection (Write protection off)
#pragma config PLLEN = OFF // PLL Enable (4x PLL disabled)
#pragma config STVREN = ON // Stack Overflow/Underflow Reset Enable (Stack Overflow or Underflow will cause a Reset)
#pragma config BORV = LO // Brown-out Reset Voltage Selection (Brown-out Reset Voltage (Vbor), low trip point selected.)
#pragma config LPBOREN = OFF // Low Power Brown-out Reset enable bit (LPBOR is disabled)
#pragma config LVP = ON // Low-Voltage Programming Enable (Low-voltage programming enabled)
Sapete se c'è qualche altro settaggio che ignoro da qualche parte?
Come posso risolvere senza dovermi fare la libreria da capo?
Grazie a tutti,
ciao lcua31989