Haz una pregunta
  Foros de Electrónica » Diseño digital » Microcontroladores y sistemas embebidos
Foros Registrarse ¿Olvidaste tu contraseña?

Temas similares

07/06/2013 #1

Avatar de Meta

Probando ejemplos para el XC8
Hola:

Estoy probando los ejemplos que tienen www.Microchip.com bajo PIC16F sobre XC8. Este es uno de los ejemplos.

Código:
/**
 *******************************************************************
 * Lesson 13 - "EEPROM"
 *
 * This lesson will provide code for writing and reading a single byte onto
 * the on-board EEPROM. EEPROM is non-volatile memory, meaning that it does
 * not lose its value when power is shut off. This is unlike RAM, which will
 * lose its value when no power is applied. The EEPROM is useful for storing
 * variables that must still be present during no power.
 * It is also convenient to use if the entire RAM space is used up.
 * Writes and reads to the EEPROM are practically instant and are much faster
 * than program memory operations.

 * Press the switch to save the LED state and then disconnect the power. When
 * power is then applied again, the program will start with that same LED lit.

 * When the lesson is first programmed, no LEDs will light up even with movement
 * of the POT. When the switch is pressed, the corresponding LED will be lit and
 * then the PIC will go to sleep until the switch is pressed again. Each press of
 * the switch saves the ADC value into EEPROM. The PIC uses interrupts to wake up
 * from sleep, take an ADC reading, save to EEPROM, and then goes back to sleep.
 *
 * PIC: 16F1829
 * Compiler: XC8 v1.00
 * IDE: MPLABX v1.10
 *
 * Board: PICkit 3 Low Pin Count Demo Board
 * Date: 6.1.2012
 *
 * *******************************************************************
 * See Low Pin Count Demo Board User's Guide for Lesson Information*
 * ******************************************************************
 */

#include <xc.h>                                     //PIC hardware mapping
#define _XTAL_FREQ 500000                            //Used by the XC8 delay_ms(x) macro

#define DOWN                0
#define UP                  1

#define SWITCH              PORTAbits.RA2


//config bits that are part-specific for the PIC16F1829
#pragma config FOSC=INTOSC, WDTE=OFF, PWRTE=OFF, MCLRE=OFF, CP=OFF, CPD=OFF, BOREN=ON, CLKOUTEN=OFF, IESO=OFF, FCMEN=OFF
#pragma config WRT=OFF, PLLEN=OFF, STVREN=OFF, LVP=OFF

    /* -------------------LATC-----------------
     * Bit#:  -7---6---5---4---3---2---1---0---
     * LED:   ---------------|DS4|DS3|DS2|DS1|-
     *-----------------------------------------
     */

unsigned char adc(void);                            //prototype

void main(void) {
    OSCCON = 0b00111000;                            //500KHz clock speed
    TRISC = 0;                                      //all LED pins are outputs
    LATC = 0;                                       //init all LEDs OFF
    
                                                    //setup switch (SW1)
    TRISAbits.TRISA2 = 1;                           //switch as input
    ANSELAbits.ANSA2 = 0;                           //digital switch

                                                    //setup ADC
    TRISAbits.TRISA4 = 1;                           //Potentiamtor is connected to RA4...set as input
    ANSELAbits.ANSA4 = 1;                           //analog
    ADCON0 = 0b00001101;                            //select RA4 as source of ADC and enable the module (AN3)
    ADCON1 = 0b00010000;                            //left justified - FOSC/8 speed - Vref is Vdd

                                                    //setup interrupt on change for the switch
    INTCONbits.IOCIE = 1;                           //enable interrupt on change global
    IOCANbits.IOCAN2 = 1;                           //when SW1 is pressed/released, enter the ISR

    INTCONbits.GIE = 1;                             //enable global interupts

    while (1) {
       LATC = eeprom_read(0x00);                    //load whatever is in EEPROM to the LATCH
       SLEEP();                                     //sleep until button is pressed

    }

}

unsigned char adc(void) {
    __delay_us(5);                                  //wait for ADC charging cap to settle
    GO = 1;
    while (GO) continue;                            //wait for conversion to be finished

    return ADRESH;                                  //grab the top 8 MSbs

}

void interrupt ISR(void) {
    unsigned char adc_value = 0;

    if (IOCAF) {                                    //SW1 was just pressed
        IOCAF = 0;                                  //must clear the flag in software
        __delay_ms(5);                              //debounce by waiting and seeing if still held down
        if (SWITCH == DOWN) {
            adc_value = adc();                      //get the ADC value from the POT
            adc_value >>= 4;                        //save only the top 4 MSbs

            LATC = adc_value;
                                                    //EEPROM is non-volatile, meaning that it can retain its value when no power is applied
            eeprom_write(0x00, adc_value);          //save the value to EEPROM and go back to sleep
        }
    }
}
Uso el MPLAB X 1.80 y XC8 con Windows 7.

Al compilarlo pulsando en l aimagen de abajo.


Como respuesta obtengo esto.
Código:
make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory `C:/Users/Meta/Desktop/13_EEPROM/eeprom.X'
make  -f nbproject/Makefile-default.mk dist/default/production/eeprom.X.production.hex
make[2]: Entering directory `C:/Users/Meta/Desktop/13_EEPROM/eeprom.X'
"C:\Program Files (x86)\Microchip\xc8\v1.12\bin\xc8.exe" --pass1  --chip=16F1829 -Q -G --asmlist  --double=24 --float=24 --opt=default,+asm,-asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s"  -obuild/default/production/_ext/1472/eeprom.p1  ../eeprom.c 
"C:\Program Files (x86)\Microchip\xc8\v1.12\bin\xc8.exe"  --chip=16F1829 -G --asmlist -mdist/default/production/eeprom.X.production.map  --double=24 --float=24 --opt=default,+asm,-asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s"   -odist/default/production/eeprom.X.production.cof  build/default/production/_ext/1472/eeprom.p1     
Microchip MPLAB XC8 C Compiler V1.12
Copyright (C) 2012 Microchip Technology Inc.
License type: Node Configuration


Memory Summary:
    Program space        used    B4h (   180) of  2000h words   (  2.2%)
    Data space           used     Dh (    13) of   400h bytes   (  1.3%)
    EEPROM space         used     0h (     0) of   100h bytes   (  0.0%)
    Configuration bits   used     2h (     2) of     2h words   (100.0%)
    ID Location space    used     0h (     0) of     4h bytes   (  0.0%)


Running this compiler in PRO mode, with Omniscient Code Generation enabled,
produces code which is typically 40% smaller than in Free mode.
See http://microchip.com for more information.

make[2]: Leaving directory `C:/Users/Meta/Desktop/13_EEPROM/eeprom.X'
make[1]: Leaving directory `C:/Users/Meta/Desktop/13_EEPROM/eeprom.X'

BUILD SUCCESSFUL (total time: 11s)
Loading code from C:/Users/Meta/Desktop/13_EEPROM/eeprom.X/dist/default/production/eeprom.X.production.hex...
Loading symbols from C:/Users/Meta/Desktop/13_EEPROM/eeprom.X/dist/default/production/eeprom.X.production.cof...
Loading completed
Al compilar...

...no compila o eso parece. Muestra mensaje como este:

Launching
No source code lines were found at current PC 0x0
User program stopped


En asm con el PIC16F88 y 16F886 me ocurre lo mismo.

¿Qué es lo que ocurre realmente?

Un saludo.
07/06/2013 #2

Avatar de ByAxel

Los íconos en forma de martillo son para compilar... el que estas usando son para debugger ya sea usando el simulador como MPLAB o algún hardware como el PicKit2/3, ICD, etc...
Configura bien, es posible que estés usando el debug para un hardware, entonces cuando los busca no lo encuentra.

Saludos
07/06/2013 #3

Avatar de Meta

Hola:

Supuestamente lo tengo en el SIM del MPLAB y es el que deseo usar, nada de Hardware por el momento.



A lo mejor no lo tengo bien configurado. Parece estar todo bien. No se.
04/07/2017 #4

Avatar de george.manson.69

Probando ejemplos para el XC8
Buen dia a todos,

Comparto algunas librerias para usar un RTC DS1307, un sensor HCSR04 y un Sensor de Temperatura ds18b20, usando el microcontrolador PIC18F26K80, estoy usando MPLAB XC8 y MCC.
Espero que alguien se le pueda ser util.

Código:
/**
  Generated Main Source File

  Company:
    Microchip Technology Inc.

  File Name:
    main.c

  Summary:
    This is the main file generated using MPLAB(c) Code Configurator

  Description:
    This header file provides implementations for driver APIs for all modules selected in the GUI.
    Generation Information :
        Product Revision  :  MPLAB(c) Code Configurator - 4.15.1
        Device            :  PIC18F26K80
        Driver Version    :  2.00
    The generated drivers are tested against the following:
        Compiler          :  XC8 1.35
        MPLAB             :  MPLAB X 3.40
*/

/*
    (c) 2016 Microchip Technology Inc. and its subsidiaries. You may use this
    software and any derivatives exclusively with Microchip products.

    THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
    EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
    WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
    PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
    WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.

    IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
    INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
    WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
    BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
    FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
    ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
    THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.

    MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
    TERMS.
*/

#include "mcc_generated_files/mcc.h"

#define DISTANCE_PROGR 25

rtc_t rtc;
float distance;
	
sint16 temperature_raw; 
char temperature[8];

void Compare_Distance(float d){

   if(d<DISTANCE_PROGR)
    LED1_SetHigh();
   else
    LED1_SetLow();   

}

float Read_Sensor_HC_SR04(void)
{

    static float count = 0;
    
    TMR1_WriteTimer(0);
    
    TRIGGER_SetHigh();
    __delay_us(10);
    TRIGGER_SetLow();
    
    while(!ECHO_GetValue());
    
    TMR1_StartTimer();
    
    while(!TMR1_HasOverflowOccured() && ECHO_GetValue());
    
    TMR1_StopTimer();
    
    if(TMR1_HasOverflowOccured()){
    
        PIR1bits.TMR1IF = 0;
        count = -1;
    
    }else{
    
        count = TMR1_ReadTimer()/2;
        count = (count/58);
    
    }
    
    return count;

}

/*
                         Main application
 */
void main(void)
{
    // Initialize the device
    SYSTEM_Initialize();
    
    // If using interrupts in PIC18 High/Low Priority Mode you need to enable the Global High and Low Interrupts
    // If using interrupts in PIC Mid-Range Compatibility Mode you need to enable the Global and Peripheral Interrupts
    // Use the following macros to:

    // Enable high priority global interrupts
    //INTERRUPT_GlobalInterruptHighEnable();

    // Enable low priority global interrupts.
    //INTERRUPT_GlobalInterruptLowEnable();

    // Disable high priority global interrupts
    //INTERRUPT_GlobalInterruptHighDisable();

    // Disable low priority global interrupts.
    //INTERRUPT_GlobalInterruptLowDisable();

    // Enable the Global Interrupts
    INTERRUPT_GlobalInterruptEnable();

    // Disable the Global Interrupts
    //INTERRUPT_GlobalInterruptDisable();

    // Enable the Peripheral Interrupts
    INTERRUPT_PeripheralInterruptEnable();

    // Disable the Peripheral Interrupts
    //INTERRUPT_PeripheralInterruptDisable();
    TMR1_StopTimer();
    
    printf("Medicion con HC-SR04 y Temperatura DS1820\r\n");

    rtc.hour = 0x17; //  10:40:20 am
    rtc.min =  0x30;
    rtc.sec =  0x00;

    rtc.date = 0x1; //1st Jan 2016
    rtc.month = 0x07;
    rtc.year = 0x17;
    rtc.weekDay = 6; // Friday: 5th day of week considering monday as first day.    
    
    RTC_Init();
    //RTC_SetDateTime(&rtc);  //  10:40:20 am, 1st Jan 2016
    while(!DS1820_FindFirstDevice());

    while (1)
    {
        
        distance = Read_Sensor_HC_SR04();
        Compare_Distance(distance);
        printf("%0.2f cm\f",Read_Sensor_HC_SR04());
        
		temperature_raw = DS1820_GetTempRaw();
		DS1820_GetTempString(temperature_raw, temperature);
		printf("%s °C\n\r",temperature);
        RTC_GetDateTime(&rtc);
        printf("\n\rtime:%2x:%2x:%2x  \nDate:%2x/%2x/%2x\r\n",(uint16_t)rtc.hour,(uint16_t)rtc.min,(uint16_t)rtc.sec,(uint16_t)rtc.date,(uint16_t)rtc.month,(uint16_t)rtc.year);
        __delay_ms(1000);
        // Add your application code
    }
}
/**
 End of File
*/
Archivos Adjuntos
Tipo de Archivo: zip PIC18.zip (2,34 MB (Megabytes), 2 visitas)
08/07/2017 #5

Avatar de george.manson.69

Esp8266
Hola,

Les comparto un programa hecho en MPLAB X para el microcontrolador PIC18F26K80,
usando el modulo de ESP8266 y realizar una conexion WEB SERVER.

Estoy usando MPLAB X,XC8 Y MCC para la configuracion, les recomiendo abrirlo con la ultima versiones.



Código:
/**
  Generated Main Source File

  Company:
    Microchip Technology Inc.

  File Name:
    main.c

  Summary:
    This is the main file generated using MPLAB(c) Code Configurator

  Description:
    This header file provides implementations for driver APIs for all modules selected in the GUI.
    Generation Information :
        Product Revision  :  MPLAB(c) Code Configurator - 4.0
        Device            :  PIC18F26K80
        Driver Version    :  2.00
    The generated drivers are tested against the following:
        Compiler          :  XC8 1.35
        MPLAB             :  MPLAB X 3.40
*/

/*
    (c) 2016 Microchip Technology Inc. and its subsidiaries. You may use this
    software and any derivatives exclusively with Microchip products.

    THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
    EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
    WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
    PARTICULAR PURPOSE, OR ITS INTERACTION WITH MICROCHIP PRODUCTS, COMBINATION
    WITH ANY OTHER PRODUCTS, OR USE IN ANY APPLICATION.

    IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
    INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
    WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
    BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
    FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
    ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
    THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.

    MICROCHIP PROVIDES THIS SOFTWARE CONDITIONALLY UPON YOUR ACCEPTANCE OF THESE
    TERMS.
*/

#include "mcc_generated_files/mcc.h"

uint8_t DataCount = 0;
char Data[20];

const char page[] = "<!doctype html>\
                     <html> \
                        <h2> ESP8266 Web Server </h2>\
                        <br>\
                        <body>\
                            <tr>\
                                <td><button onclick=\"window.location.href='/led1on'\">LED1 ON</button></td>\
                                <td><button onclick=\"window.location.href='/led1off'\">LED1 OFF</button></td>\
                            </tr>\
                            <tr>\
                                <td><button onclick=\"window.location.href='/led2on'\">LED2 ON</button></td>\
                                <td><button onclick=\"window.location.href='/led2off'\">LED2 OFF</button></td>\
                            </tr>\
                            <tr>\
                                <td><button onclick=\"window.location.href='/led3on'\">LED3 ON</button></td>\
                                <td><button onclick=\"window.location.href='/led3off'\">LED4 OFF</button></td>\
                            </tr>\
                        </body>\
                     </html>";


ESP8266Config MyEsp8266;

char* r;

/*
                         Main application
 */
void main(void)
{
    // Initialize the device
    SYSTEM_Initialize();
    
	//Configuramos Modulos
	
	Dir_Pin_Reset_ESP8266;
	
	MyEsp8266.Ssid="NombreRed";
	MyEsp8266.Password="ContraseñaRed";
	MyEsp8266.MultiConnection=1;
	MyEsp8266.TypeConnection="UDP";
	MyEsp8266.IPConnection="10.0.0.11";
	MyEsp8266.PortConnection="7777";
	MyEsp8266.WifiMode=1;
	MyEsp8266.DataMode=0;
	MyEsp8266.Response="!8266";
    
    // If using interrupts in PIC18 High/Low Priority Mode you need to enable the Global High and Low Interrupts
    // If using interrupts in PIC Mid-Range Compatibility Mode you need to enable the Global and Peripheral Interrupts
    // Use the following macros to:

    // Enable high priority global interrupts
    //INTERRUPT_GlobalInterruptHighEnable();

    // Enable low priority global interrupts.
    //INTERRUPT_GlobalInterruptLowEnable();

    // Disable high priority global interrupts
    //INTERRUPT_GlobalInterruptHighDisable();

    // Disable low priority global interrupts.
    //INTERRUPT_GlobalInterruptLowDisable();

    // Enable the Global Interrupts
    INTERRUPT_GlobalInterruptEnable();

    // Enable the Peripheral Interrupts
    INTERRUPT_PeripheralInterruptEnable();

    // Disable the Global Interrupts
    //INTERRUPT_GlobalInterruptDisable();

    // Disable the Peripheral Interrupts
    //INTERRUPT_PeripheralInterruptDisable();
    
	//*Habilitamos la interrupcion por recepcion de datos UART
	//Para trabajar con el modulo ESP8266

	//Inicializamos el Modulo ESP8266
	
	if(ESP8266_InitWebServer(MyEsp8266)){
        
        WriteString("Error 1\r\n");

		while(ESP8266_InitWebServer(MyEsp8266)){WriteString("Error Counting");}

	}

	
	while(1){

		if(!ESP8266_SendPage(&page,sizeof(page)-1,&r)){
    
            PIE1bits.RC1IE = 0;
            WriteString(r);
            r=strstr(r,"GET");
            if(!strncmp("GET /led1off",r,12)){
            
                PORTBbits.RB0 = 0;
            
            
            }else if(!strncmp("GET /led1on",r,11)){

                PORTBbits.RB0 = 1;
            
            }
            
            if(!strncmp("GET /led2off",r,12)){
            
                PORTBbits.RB1 = 0;
            
            
            }else if(!strncmp("GET /led2on",r,11)){

                PORTBbits.RB1 = 1;
            
            }
            
            if(!strncmp("GET /led3off",r,12)){
            
                PORTBbits.RB2 = 0;
            
            
            }else if(!strncmp("GET /led3on",r,11)){

                PORTBbits.RB2 = 1;
            
            }
        
            PIE1bits.RC1IE = 1;
        
        }else{
        
            WriteString("Error 2\r\n");
            while(ESP8266_InitWebServer(MyEsp8266)){WriteString("Error Counting");}
        }

	}
}
/**
 End of File
*/
Imágenes Adjuntas
Tipo de Archivo: jpg Web server.jpg (29,8 KB (Kilobytes), 3 visitas)
Tipo de Archivo: jpg Diagrama web server.jpg (60,1 KB (Kilobytes), 3 visitas)
Archivos Adjuntos
Tipo de Archivo: zip IoT p1.X.zip (1,14 MB (Megabytes), 2 visitas)
Respuesta
¿Tienes una mejor respuesta a este tema? ¿Quieres hacerle una pregunta a nuestra comunidad y sus expertos? Registrate

Foros de Electrónica » Diseño digital » Microcontroladores y sistemas embebidos

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2011, Crawlability, Inc.