Autor Tema: Inicio con mplabx y xc8...totalmente perdido  (Leído 3496 veces)

0 Usuarios y 2 Visitantes están viendo este tema.

Desconectado raus

  • Colaborador
  • PIC16
  • *****
  • Mensajes: 121
Inicio con mplabx y xc8...totalmente perdido
« en: 28 de Septiembre de 2013, 19:12:30 »
Hola!!!

Despues de mucho tiempo alejado de la programación y de los PICs, he decidido montar algún proyectito y asi adaptarme a las nuevas herramientas.

Tras instalar mplabx y xc8, he montado un proyecto para un pic18f4550 y le he pegado un fragmento de codigo de I2C de otro proyecto que tenía por ahi. He comprobado que las funciones se llaman de la misma manera, y hasta he comprobado en plib/i2c.h para asegurarme de que asi es... pero no hay manera.

El codigo es este:

Código: C
  1. /*
  2.  * File:   main.c
  3.  * Author: Fran
  4.  *
  5.  * Created on 28 de septiembre de 2013, 17:59
  6.  */
  7.  
  8. //****************INCLUDES*****************************
  9.  
  10. #include <xc.h>
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <pic18f4550.h>
  14. #include <plib/i2c.h>
  15. #include <string.h>
  16.  
  17.  
  18.  
  19.  
  20. //****************PRAGMAS******************************
  21.  
  22. #pragma config FOSC=HSPLL_HS, PLLDIV=3, CPUDIV=OSC1_PLL2 //oscilador 12MHz
  23. #pragma config IESO=OFF, FCMEN=OFF
  24. #pragma config PWRT=OFF, BOR=OFF, BORV=3, VREGEN=ON, WDT=OFF
  25. #pragma config MCLRE=ON, XINST=OFF, LVP=OFF, PBADEN=OFF
  26.  
  27.  
  28. //****************DEFINES******************************
  29.  
  30. #define _XTAL_FREQ 48000000
  31.  
  32. //definicion valores displays 16 segmentos
  33.  
  34.  
  35.  
  36. //DECLARACION VARIABLES GLOBALES
  37.  
  38.  
  39.  
  40. void main(void) {
  41.  
  42. OpenI2C( MASTER, SLEW_OFF);    // Initialize I2C module
  43.       SSPADD = 19;                             //100kHz Baud clock @8MHz
  44.  
  45.       StartI2C();                                   // begin I2C communications
  46.           IdleI2C();
  47.       WriteI2C( 0xD0 );                        // addresses the chip
  48.           IdleI2C();
  49.      WriteI2C( 0x01 );                        // access register address for minutes check table 2 above.
  50.          IdleI2C();
  51.     WriteI2C( 0b00010011 );              // write value into minutes register
  52.          IdleI2C();
  53.    StopI2C();                                    // stop condition I2C on bus
  54. }

Pero me tira los siguientes errores al compilar:

Código: [Seleccionar]
CLEAN SUCCESSFUL (total time: 250ms)
make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory `C:/Users/Alexia/MPLABXProjects/UFC_v1_0.X'
make  -f nbproject/Makefile-default.mk dist/default/production/UFC_v1_0.X.production.hex
make[2]: Entering directory `C:/Users/Alexia/MPLABXProjects/UFC_v1_0.X'
"C:\Microchip\xc8\v1.20\bin\xc8.exe" --pass1  --chip=18F4450 -Q -G  --double=24 --float=24 --emi=wordwrite --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib --output=-mcof,+elf "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s"    -obuild/default/production/main.p1  main.c
C:\Microchip\xc8\v1.20\include\pic18f4550.h:9323: warning: redefining preprocessor macro "ADDR0_bit" (C:\Microchip\xc8\v1.20\include\pic18f4450.h: 7676)
C:\Microchip\xc8\v1.20\include\pic18f4550.h:9325: warning: redefining preprocessor macro "ADDR1_bit" (C:\Microchip\xc8\v1.20\include\pic18f4450.h: 7678)
C:\Microchip\xc8\v1.20\include\pic18f4550.h:9327: warning: redefining preprocessor macro "ADDR2_bit" (C:\Microchip\xc8\v1.20\include\pic18f4450.h: 7680)
C:\Microchip\xc8\v1.20\include\pic18f4550.h:9329: warning: redefining preprocessor macro "ADDR3_bit" (C:\Microchip\xc8\v1.20\include\pic18f4450.h: 7682)
C:\Microchip\xc8\v1.20\include\pic18f4550.h:7190: error: struct/union member "GO_NOT_DONE" redefined
C:\Microchip\xc8\v1.20\include\pic18f4550.h:8995: error: struct/union member "INT0IE" redefined
C:\Microchip\xc8\v1.20\include\pic18f4550.h:8995: error: struct/union member "INT0IF" redefined
C:\Microchip\xc8\v1.20\include\pic18f4550.h:8995: error: struct/union member "RBIE" redefined
(908) exit status = 1
C:\Microchip\xc8\v1.20\include\pic18f4550.h:8995: error: struct/union member "TMR0IE" redefined
make[2]: *** [build/default/production/main.p1] Error 1
C:\Microchip\xc8\v1.20\include\pic18f4550.h:8995: error: struct/union member "TMR0IF" redefined
make[1]: *** [.build-conf] Error 2
C:\Microchip\xc8\v1.20\include\pic18f4550.h:9005: error: struct/union member "INT0IE" redefined
C:\Microchip\xc8\v1.20\include\pic18f4550.h:9005: error: struct/union member "INT0IF" redefined
make: *** [.build-impl] Error 2
C:\Microchip\xc8\v1.20\include\pic18f4550.h:9005: error: struct/union member "RBIE" redefined
C:\Microchip\xc8\v1.20\include\pic18f4550.h:9005: error: struct/union member "TMR0IE" redefined
C:\Microchip\xc8\v1.20\include\pic18f4550.h:9005: error: struct/union member "TMR0IF" redefined
C:\Microchip\xc8\v1.20\include\pic18f4550.h:9015: error: struct/union member "PEIE" redefined
C:\Microchip\xc8\v1.20\include\pic18f4550.h:9015: error: struct/union member "GIE" redefined
C:\Microchip\xc8\v1.20\include\pic18f4550.h:9020: error: struct/union member "GIEL" redefined
C:\Microchip\xc8\v1.20\include\pic18f4550.h:9020: error: struct/union member "GIEH" redefined
C:\Microchip\xc8\v1.20\include\pic18f4550.h:9322: error: conflicting declarations for variable "ADDR0" (C:\Microchip\xc8\v1.20\include\pic18f4450.h:7675)
make[2]: Leaving directory `C:/Users/Alexia/MPLABXProjects/UFC_v1_0.X'
make[1]: Leaving directory `C:/Users/Alexia/MPLABXProjects/UFC_v1_0.X'

BUILD FAILED (exit value 2, total time: 5s)

Además, las funciones de I2C, aparecen subrayadas en rojo, pero he comprobado que las rutas son correctas, que el compilador seleccionado es xc8... ya no se que mas mirar!!

Alguna sugerencia de alguien que haya pasado por esto?

Gracias!
Visita mi blog sobre tecnología y marketing:
http://franciscobenito.es

Desconectado AngelGris

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 2480
Re: Inicio con mplabx y xc8...totalmente perdido
« Respuesta #1 en: 28 de Septiembre de 2013, 22:04:26 »
  Hola.
  Una vez incluido XC.H, no es necesario incluir el header correspondiente al pic utilizado. Casi seguro que es por ello los errores de redefinición.

  Pasando al tema de I2C. Primeramente creo que no es necesario agregar la ruta plib en la sentencia include Yo creo que viene por el mismo lado por el cual rseliman tenía problemas con SPI en este topic http://www.todopic.com.ar/foros/index.php?topic=40649.140 Dicho sea de paso, te recomiendo leer todos los mensajes, hay muy buena información allí.

  Puedes probar la solución propuesta por rseliman, pero para tu pic.
  Otra idea que tal vez funcione puede ser que luego del include correspondiente a XC.H, coloque un define __18F4550 en tu código.
Así...

Código: C
  1. #include <xc.h>
  2. #define __18F4550
De vez en cuando la vida
nos besa en la boca
y a colores se despliega
como un atlas

Desconectado raus

  • Colaborador
  • PIC16
  • *****
  • Mensajes: 121
Re: Inicio con mplabx y xc8...totalmente perdido
« Respuesta #2 en: 29 de Septiembre de 2013, 06:00:11 »
Hola AngelGris, gracias por tu respuesta.

La verdad es que estuve probando varias cosas que vi por el foro antes, pero siempre dejaba algun include del pic. Poniendo solo el xc.h, sin embargo, desaparecen las redefiniciones, pero sigue dandome un error, ya que no reconoce el registro SSPADD:

Código: C
  1. make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
  2. make[1]: Entering directory `C:/Users/Alexia/MPLABXProjects/UFC_v1_0.X'
  3. make  -f nbproject/Makefile-default.mk dist/default/production/UFC_v1_0.X.production.hex
  4. make[2]: Entering directory `C:/Users/Alexia/MPLABXProjects/UFC_v1_0.X'
  5. "C:\Microchip\xc8\v1.20\bin\xc8.exe" --pass1  --chip=18F4450 -Q -G  --double=24 --float=24 --emi=wordwrite --opt=default,+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --asmlist --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,+plib --output=-mcof,+elf "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s"    -obuild/default/production/main.p1  main.c
  6. main.c:42: warning: function declared implicit int
  7. main.c:43: error: undefined identifier "SSPADD"
  8. main.c:45: warning: function declared implicit int
  9. main.c:46: warning: function declared implicit int
  10. main.c:47: warning: function declared implicit int
  11. main.c:53: warning: function declared implicit int
  12. (908) exit status = 1
  13. make[2]: Leaving directory `C:/Users/Alexia/MPLABXProjects/UFC_v1_0.X'
  14. make[1]: Leaving directory `C:/Users/Alexia/MPLABXProjects/UFC_v1_0.X'
  15. make[2]: *** [build/default/production/main.p1] Error 1
  16. make[1]: *** [.build-conf] Error 2
  17. make: *** [.build-impl] Error 2
  18.  
  19. BUILD FAILED (exit value 2, total time: 5s)

Ademas, da igual que haga #include <plib/i2c.h> o #include <i2c.h>, las funciones de i2c siguen apareciendo subrayadas, como si no encontrara los identificadores :( Por si sirve de algo, los warning "warning: function declared implicit int" se corresponden a las lineas donde hay una funcion de i2c utilizada.

Seguiré buscando, pero ni en los foros de microchip ni aqui mismo estoy consiguiendo encontrar algo que me ayude.

Ah! Por si acaso, desinstale y volvi a instalar la version mas reciente tanto de mplabx como de xc8
Visita mi blog sobre tecnología y marketing:
http://franciscobenito.es

Desconectado AngelGris

  • Colaborador
  • PIC24H
  • *****
  • Mensajes: 2480
Re: Inicio con mplabx y xc8...totalmente perdido
« Respuesta #3 en: 29 de Septiembre de 2013, 12:42:33 »
  Acabo de compilar el código siguiente y no me arrojó ningún error.

Código: C
  1. /*
  2.  * File:   main.c
  3.  * Author: Fran
  4.  *
  5.  * Created on 28 de septiembre de 2013, 17:59
  6.  */
  7.  
  8. //****************INCLUDES*****************************
  9.  
  10. #include <xc.h>
  11.  
  12. #define __18F4550
  13.  
  14. #include <stdio.h>
  15. #include <stdlib.h>
  16. #include <plib/i2c.h>
  17. #include <string.h>
  18.  
  19.  
  20.  
  21.  
  22. //****************PRAGMAS******************************
  23.  
  24. #pragma config FOSC=HSPLL_HS, PLLDIV=3, CPUDIV=OSC1_PLL2 //oscilador 12MHz
  25. #pragma config IESO=OFF, FCMEN=OFF
  26. #pragma config PWRT=OFF, BOR=OFF, BORV=3, VREGEN=ON, WDT=OFF
  27. #pragma config MCLRE=ON, XINST=OFF, LVP=OFF, PBADEN=OFF
  28.  
  29.  
  30. //****************DEFINES******************************
  31.  
  32. #define _XTAL_FREQ 48000000
  33.  
  34. //definicion valores displays 16 segmentos
  35.  
  36.  
  37.  
  38. //DECLARACION VARIABLES GLOBALES
  39.  
  40.  
  41.  
  42. void main(void) {
  43.  
  44. OpenI2C( MASTER, SLEW_OFF);    // Initialize I2C module
  45.       SSPADD = 19;                             //100kHz Baud clock @8MHz
  46.  
  47.       StartI2C();                                   // begin I2C communications
  48.           IdleI2C();
  49.       WriteI2C( 0xD0 );                        // addresses the chip
  50.           IdleI2C();
  51.      WriteI2C( 0x01 );                        // access register address for minutes check table 2 above.
  52.          IdleI2C();
  53.     WriteI2C( 0b00010011 );              // write value into minutes register
  54.          IdleI2C();
  55.    StopI2C();                                    // stop condition I2C on bus
  56. }

  No me arroja ningún error respecto a SSPADD.
  Y al agregar "#define __18F4550" ya no me subraya las funciones de i2c en rojo.
  Sí da algunos warning indicando que faltan configuraciones de algunos registros de configuración.
De vez en cuando la vida
nos besa en la boca
y a colores se despliega
como un atlas

Desconectado raus

  • Colaborador
  • PIC16
  • *****
  • Mensajes: 121
Re: Inicio con mplabx y xc8...totalmente perdido
« Respuesta #4 en: 30 de Septiembre de 2013, 11:15:06 »
Efectivamente, era un error de rutas. El problema parece ser que yo las tenia definidas como relativas a la raiz del proyecto, y salian unas rutas demasiado largas. Una vez las cambie a absolutas, no hay problema :)
Visita mi blog sobre tecnología y marketing:
http://franciscobenito.es


 

anything