PIC16f compilador xc8: pragma desconocido "código", "interrupción", "chk_isr"

0

Últimamente he intentado conectar la interfaz HC-SR04 con PIC16F877A utilizando el modo de captura e interrupción, pero recibo "Advertencias" y pegué el código a continuación:

Salida de compilación:

"C:\Program Files (x86)\Microchip\xc8\v1.10\bin\xc8.exe" --pass1  --chip=16F877A -Q -G --asmlist  --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,-speed,+space,-debug,9 --addrqual=ignore -P -N31 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,-config,+clib,-plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s"  -obuild/default/production/Ultrasonic.p1  Ultrasonic.c 

Ultrasonic.c:23: warning: unknown pragma "code"
Ultrasonic.c:29: warning: unknown pragma "interrupt"
Ultrasonic.c:36: warning: unknown pragma "code"
Ultrasonic.c:64: warning: illegal conversion between pointer types
pointer to const unsigned char -> pointer to unsigned char
Ultrasonic.c:66: warning: illegal conversion between pointer types
pointer to const unsigned char -> pointer to unsigned char
Ultrasonic.c:83: warning: implicit conversion of float to integer
Ultrasonic.c:88: warning: illegal conversion between pointer types
pointer to const unsigned char -> pointer to unsigned char
Ultrasonic.c:92: warning: illegal conversion between pointer types
pointer to const unsigned char -> pointer to unsigned char
"C:\Program Files (x86)\Microchip\xc8\v1.10\bin\xc8.exe"  --chip=16F877A -G --asmlist -mdist/default/production/Ultrasonic.X.production.map  --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,-speed,+space,-debug,9 --addrqual=ignore -P -N31 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,-config,+clib,-plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s"   -odist/default/production/Ultrasonic.X.production.cof  build/default/production/Ultrasonic.p1     
Microchip MPLAB XC8 C Compiler (PRO Mode)  V1.10
Copyright (C) 2012 Microchip Technology Inc.
Ultrasonic.c:21: warning: variable "_rf" is not used

Memory Summary:
    Program space        used   3F1h (  1009) of  2000h words   ( 12.3%)
    Data space           used    3Ch (    60) of   170h bytes   ( 16.3%)
    EEPROM space         used     0h (     0) of   100h bytes   (  0.0%)
    Configuration bits   used     0h (     0) of     1h word    (  0.0%)
    ID Location space    used     0h (     0) of     4h bytes   (  0.0%)

make[2]: Leaving directory 'E:/MPLAB Projects/Ultrasonic/Ultrasonic.X'
make[1]: Leaving directory 'E:/MPLAB Projects/Ultrasonic/Ultrasonic.X'

BUILD SUCCESSFUL (total time: 6s)
Loading code from E:/MPLAB Projects/Ultrasonic/Ultrasonic.X/dist/default/production/Ultrasonic.X.production.hex...
Loading symbols from E:/MPLAB Projects/Ultrasonic/Ultrasonic.X/dist/default/production/Ultrasonic.X.production.cof...
Loading completed

He leído tus publicaciones anteriores pero aún no he podido resolver el problema y Nunca he usado la directiva #pragma antes, ayúdame a resolver este problema. He pegado el código y cualquier ayuda será apreciada mucho.

Código

#include <pic.h>
#include <htc.h>
#define TRIG RB7
#define PD PORTD
#define RS RE0
#define RW RE1
#define E RE2
void cmdwrite(unsigned char);
void datawrite(unsigned char);
void strdis(unsigned char *str);
void MSDelay(unsigned int itime);
void ms_delay();
/*void msd();*/
void dis4digit(unsigned int var);
void CCP1_ISR(void);
void rising(void);
void falling(void);
void chk_isr();
void My_HiPrio_Int();
unsigned char disp=0;
unsigned char rf=0;

#pragma code My_HiPrio_Int=0x0008
void My_HiPrio_Int(void)
{
    chk_isr();
}

#pragma interrupt chk_isr
void chk_isr(void)
{
     if(CCP1IF==1)
       CCP1_ISR();
}

#pragma code
void main()
{
unsigned long int distance_in_cm;
unsigned long int distance_in_inches;
unsigned long int F_byte;
unsigned char H_byte,L_byte;

      ADCON1=0x0F;
      GIE=1;
      PEIE=1;
      CCP1IE=1;
      TRISD=0;
      TRISE=0;
      TRISB7=0;
      TRISC2=1;
      CCP1CON=0x05;
      T1CON=0x00;
      CCPR1L=0x00;
      CCPR1H=0x00;
      TRIG=0;
      E=0;
      cmdwrite(0x01);
      cmdwrite(0x38);
      cmdwrite(0x38);
      cmdwrite(0x38);
      cmdwrite(0x0C);
      cmdwrite(0x83);
      strdis("Ultrasonic");
      cmdwrite(0xC0);
      strdis("Distance Sensor");
      MSDelay(2000);
          while(1)
          {
              H_byte=0; L_byte=0; F_byte=0;
              TRIG=1;
              TRIG=0;
              TMR1H=0x00;
              TMR1L=0x00;
              while(disp==0);
              disp=0;

              H_byte=CCPR1H;
              L_byte=CCPR1L;
              CCPR1L=0x00; CCPR1H=0x00;
              F_byte=(H_byte * 256);
              F_byte=F_byte + L_byte;
              F_byte=(F_byte * 0.5);
              distance_in_cm=F_byte/58;
              distance_in_inches=F_byte/148;
              cmdwrite(0x01);
              cmdwrite(0x80);
              strdis("Dist.cm:");
              cmdwrite(0x88);
              dis4digit(distance_in_cm);
              cmdwrite(0xC0);
              strdis("Dist.in:");
              cmdwrite(0xC8);
              dis4digit(distance_in_inches);
              MSDelay(6000);
              cmdwrite(0x01);
          }
}

void cmdwrite(unsigned char var1)
{
PD=var1;
RS=0;
RW=0;
E=1;
ms_delay();
E=0;
}
void datawrite(unsigned char var2)
{
PD=var2;
RS=1;
RW=0;
E=1;
ms_delay();
E=0;
}
void strdis(unsigned char *str)
{
        while(*str!='
"C:\Program Files (x86)\Microchip\xc8\v1.10\bin\xc8.exe" --pass1  --chip=16F877A -Q -G --asmlist  --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,-speed,+space,-debug,9 --addrqual=ignore -P -N31 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,-config,+clib,-plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s"  -obuild/default/production/Ultrasonic.p1  Ultrasonic.c 

Ultrasonic.c:23: warning: unknown pragma "code"
Ultrasonic.c:29: warning: unknown pragma "interrupt"
Ultrasonic.c:36: warning: unknown pragma "code"
Ultrasonic.c:64: warning: illegal conversion between pointer types
pointer to const unsigned char -> pointer to unsigned char
Ultrasonic.c:66: warning: illegal conversion between pointer types
pointer to const unsigned char -> pointer to unsigned char
Ultrasonic.c:83: warning: implicit conversion of float to integer
Ultrasonic.c:88: warning: illegal conversion between pointer types
pointer to const unsigned char -> pointer to unsigned char
Ultrasonic.c:92: warning: illegal conversion between pointer types
pointer to const unsigned char -> pointer to unsigned char
"C:\Program Files (x86)\Microchip\xc8\v1.10\bin\xc8.exe"  --chip=16F877A -G --asmlist -mdist/default/production/Ultrasonic.X.production.map  --double=24 --float=24 --emi=wordwrite --opt=default,+asm,-asmfile,-speed,+space,-debug,9 --addrqual=ignore -P -N31 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,-config,+clib,-plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s"   -odist/default/production/Ultrasonic.X.production.cof  build/default/production/Ultrasonic.p1     
Microchip MPLAB XC8 C Compiler (PRO Mode)  V1.10
Copyright (C) 2012 Microchip Technology Inc.
Ultrasonic.c:21: warning: variable "_rf" is not used

Memory Summary:
    Program space        used   3F1h (  1009) of  2000h words   ( 12.3%)
    Data space           used    3Ch (    60) of   170h bytes   ( 16.3%)
    EEPROM space         used     0h (     0) of   100h bytes   (  0.0%)
    Configuration bits   used     0h (     0) of     1h word    (  0.0%)
    ID Location space    used     0h (     0) of     4h bytes   (  0.0%)

make[2]: Leaving directory 'E:/MPLAB Projects/Ultrasonic/Ultrasonic.X'
make[1]: Leaving directory 'E:/MPLAB Projects/Ultrasonic/Ultrasonic.X'

BUILD SUCCESSFUL (total time: 6s)
Loading code from E:/MPLAB Projects/Ultrasonic/Ultrasonic.X/dist/default/production/Ultrasonic.X.production.hex...
Loading symbols from E:/MPLAB Projects/Ultrasonic/Ultrasonic.X/dist/default/production/Ultrasonic.X.production.cof...
Loading completed
') { datawrite(*str); str++; } } void dis4digit(unsigned int var) { unsigned char thp,hp,up,tp,w,x,y; w=var/10; x=w/10; y=x/10; thp=y; hp=x%10; tp=w%10; up=var%10; datawrite(thp+48); datawrite(hp+48); datawrite(tp+48); datawrite(up+48); } void ms_delay() { T1CON = 0x30; TMR1H=0xC2; TMR1L=0xF7; TMR1ON=1; while(TMR1IF==0); TMR1ON=0; TMR1IF=0; } /*void msd() { T1CON = 0x30; TMR1H=0xFF; TMR1L=0xFE; T1CON.TMR1ON=1; while(PIR1.TMR1IF==0); T1CON.TMR1ON=0; PIR1.TMR1IF=0; } */ void MSDelay(unsigned int itime) { unsigned int i; unsigned int j; for(i=0;i<itime;i++) for(j=0;j<165;j++); } void CCP1_ISR() { if(rf==0) rising(); else falling(); } void rising() { TMR1ON=1; rf=1; CCP1M0=0; CCP1IF=0; } void falling() { TMR1ON=0; disp=1; rf=0; CCP1CON=0x00; CCP1M0=1; CCP1IF=0; }
    
pregunta Kulbir Singh

1 respuesta

2

Incluso si usas MPLab IDE, el código que estás escribiendo sigue siendo C.

xC8, xc16 y xc32 El XC8, XC16 y XC32 son compiladores para los procesadores PIC de Microchip. XC8 se utiliza para MCU de 8 bits, XC16 para MCU de 16 bits y XC32 para MCU de 32 bits. Aquí obtendrá una visión general clara de los compiladores

El C18 era un antiguo compilador para MCU de 8 bits. Si recién comienza a programar los PIC, use el equivalente a XC :-)

Advertencias de Pragma

Ya te mostré la Guía de migración . Para obtener la advertencia en la línea 23 de distancia, escriba

void My_HiPrio_Int @ 0x0008 (void)

en lugar de

#pragma code My_HiPrio_Int=0x0008
void My_HiPrio_Int(void)

¡Echa un vistazo claro a la página 34 para esto!

La declaración pragma en la línea 36 ya no es necesaria cuando se compila con XC8 en lugar de C18.

Para evitar la advertencia en la línea 30, puede escribir

 void interrupt chk_isr(void)

en lugar de

 #pragma interrupt chk_isr
 void chk_isr(void)

La página 32 te ayudará con esto ;-)

conversión de puntero ilegal

Intentas enviar un const -String con la función strdis() . Escribe

 void strdis(unsigned char const  *str)

para mostrar al compilador que los valores del puntero no se sobrescribirán en la función (espero que esto funcione, no tengo el compilador XC8 con nosotros, lo siento). De lo contrario, puede hacer una conversión de tipo al llamar a strdis() . Por ejemplo:

 strdis((unsigned char *)"Hello")

¡Pero no lo recomendaré! ¡Incluso si sabes lo que haces!

Último en la línea 83 que escribes

 F_byte=(F_byte * 0.5);

En su lugar, escribe lo siguiente

 F_byte=(F_byte / 2);

Al calcular con números flotantes, el compilador hará una conversión de tipo por sí mismo. Así que convierte F_byte a un flotador y luego se multiplica con 0.5 . float -calculación es mucho más lento que integer -cálculo, por lo tanto, evite esto siempre que sea posible.

Si encuentra algo como F_byte=(F_byte >> 1); en cualquier lugar de la www, puede estar seguro de que cada compilador, que está casi actualizado, hará la optimización de este código mientras compila.

Código completo

Con XC8 v1.33 este código se compila sin ningún error o advertencia:

#include<xc.h>

#define TRIG RB7
#define PD PORTD
#define RS RE0
#define RW RE1
#define E RE2

void cmdwrite(unsigned char);
void datawrite(unsigned char);
void strdis(unsigned char const *str);
void MSDelay(unsigned int itime);
void ms_delay();
void dis4digit(unsigned int var);
void CCP1_ISR(void);
void rising(void);
void falling(void);
void interrupt chk_isr();
unsigned char disp = 0;
unsigned char rf = 0;

void interrupt chk_isr(void) {
    if (CCP1IF == 1)
        CCP1_ISR();
}

void main() {
    unsigned long int distance_in_cm;
    unsigned long int distance_in_inches;
    unsigned long int F_byte;
    unsigned char H_byte, L_byte;

    ADCON1 = 0x0F;
    GIE = 1;
    PEIE = 1;
    CCP1IE = 1;
    TRISD = 0;
    TRISE = 0;
    TRISB7 = 0;
    TRISC2 = 1;
    CCP1CON = 0x05;
    T1CON = 0x00;
    CCPR1L = 0x00;
    CCPR1H = 0x00;
    TRIG = 0;
    E = 0;
    cmdwrite(0x01);
    cmdwrite(0x38);
    cmdwrite(0x38);
    cmdwrite(0x38);
    cmdwrite(0x0C);
    cmdwrite(0x83);
    strdis("Ultrasonic");
    cmdwrite(0xC0);
    strdis("Distance Sensor");
    MSDelay(2000);
    while (1) {
        H_byte = 0;
        L_byte = 0;
        F_byte = 0;
        TRIG = 1;
        TRIG = 0;
        TMR1H = 0x00;
        TMR1L = 0x00;
        while (disp == 0);
        disp = 0;

        H_byte = CCPR1H;
        L_byte = CCPR1L;
        CCPR1L = 0x00;
        CCPR1H = 0x00;
        F_byte = (H_byte * 256);
        F_byte = F_byte + L_byte;
        F_byte = (F_byte / 2);
        distance_in_cm = F_byte / 58;
        distance_in_inches = F_byte / 148;
        cmdwrite(0x01);
        cmdwrite(0x80);
        strdis("Dist.cm:");
        cmdwrite(0x88);
        dis4digit(distance_in_cm);
        cmdwrite(0xC0);
        strdis("Dist.in:");
        cmdwrite(0xC8);
        dis4digit(distance_in_inches);
        MSDelay(6000);
        cmdwrite(0x01);
    }
}

void cmdwrite(unsigned char var1) {
    PD = var1;
    RS = 0;
    RW = 0;
    E = 1;
    ms_delay();
    E = 0;
}

void datawrite(unsigned char var2) {
    PD = var2;
    RS = 1;
    RW = 0;
    E = 1;
    ms_delay();
    E = 0;
}

void strdis(unsigned char const *str) {
    while (*str != '
make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory 'C:/Users/x.x/VirtualBox VMs/KT/test.X'
make  -f nbproject/Makefile-default.mk dist/default/production/test.X.production.hex
make[2]: Entering directory 'C:/Users/x.x/VirtualBox VMs/KT/test.X'
"C:\Program Files (x86)\Microchip\xc8\v1.33\bin\xc8.exe" --pass1  --chip=16F877A -Q -G  --double=24 --float=24 --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,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%%f:%%l: error: (%%n) %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s"    -obuild/default/production/main.p1  main.c 
"C:\Program Files (x86)\Microchip\xc8\v1.33\bin\xc8.exe"  --chip=16F877A -G -mdist/default/production/test.X.production.map  --double=24 --float=24 --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,+osccal,-resetbits,-download,-stackcall,+clib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: (%%n) %%s" "--msgformat=%%f:%%l: advisory: (%%n) %%s"     -odist/default/production/test.X.production.elf  build/default/production/main.p1     
Microchip MPLAB XC8 C Compiler (Free Mode) V1.33
Part Support Version: 1.33 (A)
Copyright (C) 2014 Microchip Technology Inc.
License type: Node Configuration

:: warning: (1273) Omniscient Code Generation not available in Free mode

Memory Summary:
    Program space        used   46Ch (  1132) of  2000h words   ( 13.8%)
    Data space           used    33h (    51) of   170h bytes   ( 13.9%)
    EEPROM space         used     0h (     0) of   100h bytes   (  0.0%)
    Data stack space     used     0h (     0) of    60h bytes   (  0.0%)
    Configuration bits   used     0h (     0) of     1h word    (  0.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.
The MPLAB XC8 PRO compiler output for this code could be 432 words smaller.
See http://microchip.com for more information.

make[2]: Leaving directory 'C:/Users/x.x/VirtualBox VMs/KT/test.X'
make[1]: Leaving directory 'C:/Users/x.x/VirtualBox VMs/KT/test.X'

BUILD SUCCESSFUL (total time: 1s)
Loading code from C:/Users/x.x/VirtualBox VMs/KT/test.X/dist/default/production/test.X.production.hex...
Loading symbols from C:/Users/x.x/VirtualBox VMs/KT/test.X/dist/default/production/test.X.production.elf...
Loading completed
') { datawrite(*str); str++; } } void dis4digit(unsigned int var) { unsigned char thp, hp, up, tp, w, x, y; w = var / 10; x = w / 10; y = x / 10; thp = y; hp = x % 10; tp = w % 10; up = var % 10; datawrite(thp + 48); datawrite(hp + 48); datawrite(tp + 48); datawrite(up + 48); } void ms_delay() { T1CON = 0x30; TMR1H = 0xC2; TMR1L = 0xF7; TMR1ON = 1; while (TMR1IF == 0); TMR1ON = 0; TMR1IF = 0; } void MSDelay(unsigned int itime) { unsigned int i; unsigned int j; for (i = 0; i < itime; i++) for (j = 0; j < 165; j++); } void CCP1_ISR() { if (rf == 0) rising(); else falling(); } void rising() { TMR1ON = 1; rf = 1; CCP1M0 = 0; CCP1IF = 0; } void falling() { TMR1ON = 0; disp = 1; rf = 0; CCP1CON = 0x00; CCP1M0 = 1; CCP1IF = 0; }

Aquí está mi registro de compilación:

void My_HiPrio_Int @ 0x0008 (void)

Los errores y advertencias que recibe no son específicos de MPLab ... Considere leer un BUEN libro sobre programación en C (por ejemplo, K & R ) y busque los errores en google al principio.

    
respondido por el GER_Moki

Lea otras preguntas en las etiquetas