16F887 (Pickit2), conversor analógico-digital

Hola a todos,

tengo el PICkit2 (16F887), con la Demo Board de 44 pines incluida. Quiero hacer la conversión de una señal analógica (apartir del Potenciómetro 1 que está conectado a la entrada A0), a digital (para mostrarlo en los LEDs, puertos de salida RD0-RD7).

Algo que no debería dar muchos problemas pero que sin embargo me esta dando toda la tarde de quebradero de cabeza... :unsure:

Microchip facilita este código en C que realiza supuestamente esa misma tarea:

Código:
#include <pic.h>
/*  cADC - Display the PICkit Pot Input Value on the built in LEDs

This program samples the voltage on RA0 using the ADC and Displays the 
  value on the 8 LEDs using "cLEDDisp 2" as a base.  

myke predko
04.10.03

*/

__CONFIG(INTIO & WDTDIS & PWRTEN & MCLRDIS & UNPROTECT & UNPROTECT & BORDIS & IESODIS & FCMDIS);


int i, j;
int ADCState = 0;               //  Keep Track of ADC Operation
int ADCValue = 0;
int Dlay = 63;                    //  LED Time on Delay Variable

const char PORTAValue[8] = {0b010000, 0b100000, 0b010000, 0b000100, 0b100000, 0b000100, 0b000100, 0b000010};

const char TRISAValue[8] = {0b001111, 0b001111, 0b101011, 0b101011, 0b011011, 0b011011, 0b111001, 0b111001};                       
const char NOTPORTA[8] = {0, 0, 0, 0, 0, 0, 0, 0};

main()
{

    PORTA = 0;
    CMCON0 = 7;                 //  Turn off Comparators
    ANSEL = 1;                   //  Just RA0 is an Analog Input

    ADCON0 = 0b00000001;        // Turn on the ADC
                                           //  Bit 7 - Left Justified Sample
                                           //  Bit 6 - Use VDD
                                           //  Bit 4:2 - Channel 0
                                          //   Bit 1 - Do not Start
                                          //   Bit 0 - Turn on ADC
    ADCON1 = 0b00010000;       //  Selemct the Clock as Fosc/8

    while(1 == 1)                    //  Loop Forever
    {
        for (i = 0; i < 8; i++ )
        {                                                       //  Loop through Each of the 8 LEDS
            for (j = 0; j < Dlay; j++);                   //  Display "On" Delay Loop
            if ((ADCValue & (1 << i)) == 0)
                PORTA = NOTPORTA[i];
            else
                PORTA = PORTAValue[i];
            TRISA = TRISAValue[i];
        }  

        switch (ADCState)                //  ADC State Machine
        {
            case 0:                          //  Finished, Start Next Sample
                GODONE = 1;
                ADCState++;
                break;

            case 1:                          //  Wait for ADC to complete
                if (!GODONE)
                    ADCState++;          //  Sample Finished
                break;

            case 2:                          //  Save Sample Value in "ADCValue" 
                ADCValue = ADRESH;
                ADCState = 0;
                break;
        }  
    }  
}

Compilo el proyecto con Hi-Tech C (MPLAB), y me da error: undefined identifier "CMCON0"
Mirando el datasheet del 16f887, no existe ningun registro CMCON0, lo más parecido, es el registro CMCON asociado al PORTA, con los siguientes bits:

C2OUT C1OUT C2INV C1INV CIS CM2 CM1 CM0

Pero ahí ya no sé que configurar...

¿Alguien puede echarme una mano? Sé que no es complejo el programa, pero llevo unas semanas aprendiendo a programar en C PICS, y mira que me he googleado toda la red y revisado el datasheet, pero no consigo aclararme, compilar, meterlo en el Pickit y que la placa haga "magia" jeje

muchas gracias!
 
Hola Basalto, gracias por tu respuesta ;)

He borrado esa línea. Sin embargo, compilo correctamente, pero cuando cargo el .hex en el Pickit 2 Programmer, me salta este aviso:

Warning: Some configuration words not in hex file. Ensure default values above right are acceptable.

Aunque el programa se escribe correctamente en el PIC, no funciona... vamos, que giro el potenciómetro y no se encienden LEDs. Tengo activada la VDD a 5V, para que alimente la board.

¿hay algo del código que está mal? quizás está orientado para otro PIC y no el 16F887...
¿qué significa ese aviso?
 
En primer lugar el codigo esta escrito para usar el compilador Hi-Tech y teniendo todas las librerias bien configuradas. Para configurar los bits tienes que darle a configure->configuration bits y desactivar la pestaña de configuracion en el codigo, despues configurar los bits que utilizar y el tipo de reloj
 
Atrás
Arriba