2017-06-07 4 views
-4

Je suis un débutant en programmation PIC. This video J'ai utilisé pour coder mon premier programme.PIC18F2220 Erreur de programme de clignotement de DEL

C'est le code que je l'ai écrit:

#include <stdio.h> 
#include <stdlib.h> 
#include "XC8.h" 

void main(void) 
{ 
    TRISBbits.RB0 = 0; 
    OSCCON = 0x76; 

    while(1) 
    { 
     LATBbits.LATB0 = ~LATBbits.LATB0; 

     for (int countDelay=0; countDelay<20; countDelay++) __delay_ms(50); 
    } 
} 

Et mon fichier d'en-tête XC8.h est:

// PIC18F2220 Configuration Bit Settings 

// 'C' source line config statements 

// CONFIG1H 
#pragma config OSC = RC   // Oscillator Selection bits (External RC oscillator, CLKO function on RA6) 
#pragma config FSCM = OFF  // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled) 
#pragma config IESO = OFF  // Internal/External Switchover bit (Internal/External Switchover mode disabled) 

// CONFIG2L 
#pragma config PWRT = OFF  // Power-up Timer enable bit (PWRT disabled) 
#pragma config BOR = OFF  // Brown-out Reset enable bit (Brown-out Reset disabled) 
#pragma config BORV = 20  // Brown-out Reset Voltage bits (VBOR set to 2.0V) 

// CONFIG2H 
#pragma config WDT = ON   // Watchdog Timer Enable bit (WDT enabled) 
#pragma config WDTPS = 32768 // Watchdog Timer Postscale Select bits (1:32768) 

// CONFIG3H 
#pragma config CCP2MX = ON  // CCP2 MUX bit (CCP2 input/output is multiplexed with RC1) 
#pragma config PBAD = ANA  // PORTB A/D Enable bit (PORTB<4:0> pins are configured as analog input channels on Reset) 
#pragma config MCLRE = OFF  // MCLR Pin Enable bit (MCLR disabled; RE3 input is enabled in 40-pin devices only (PIC18F4X20)) 

// CONFIG4L 
#pragma config STVR = ON  // Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset) 
#pragma config LVP = ON   // Single-Supply ICSP Enable bit (Single-Supply ICSP enabled) 

// CONFIG5L 
#pragma config CP0 = OFF  // Code Protection bit (Block 0 (000200-0007FFh) not code-protected) 
#pragma config CP1 = OFF  // Code Protection bit (Block 1 (000800-000FFFh) not code-protected) 

// CONFIG5H 
#pragma config CPB = OFF  // Boot Block Code Protection bit (Boot block (000000-0001FFh) is not code-protected) 
#pragma config CPD = OFF  // Data EEPROM Code Protection bit (Data EEPROM is not code-protected) 

// CONFIG6L 
#pragma config WRT0 = OFF  // Write Protection bit (Block 0 (000200-0007FFh) not write-protected) 
#pragma config WRT1 = OFF  // Write Protection bit (Block 1 (000800-000FFFh) not write-protected) 

// CONFIG6H 
#pragma config WRTC = OFF  // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) are not write-protected) 
#pragma config WRTB = OFF  // Boot Block Write Protection bit (Boot block (000000-0001FFh) is not write-protected) 
#pragma config WRTD = OFF  // Data EEPROM Write Protection bit (Data EEPROM is not write-protected) 

// CONFIG7L 
#pragma config EBTR0 = OFF  // Table Read Protection bit (Block 0 (000200-0007FFh) not protected from table reads executed in other blocks) 
#pragma config EBTR1 = OFF  // Table Read Protection bit (Block 1 (000800-000FFFh) not protected from table reads executed in other blocks) 

// CONFIG7H 
#pragma config EBTRB = OFF  // Boot Block Table Read Protection bit (Boot block (000000-0001FFh) is not protected from table reads executed in other blocks) 

// #pragma config statements should precede project file includes. 
// Use project enums instead of #define for ON and OFF. 

#define _XTAL_FREQ 8000000 

J'ai suivi toutes les étapes prévues dans le tutoriel mais je reçois ce qui suit erreur lorsque j'essaye de construire le programme.

make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf 
make[1]: Entering directory 'E:/Projects/Coding/MPLABX/Programming/XC8/XC8.X' 
make -f nbproject/Makefile-default.mk dist/default/production/XC8.X.production.hex 
make[2]: Entering directory 'E:/Projects/Coding/MPLABX/Programming/XC8/XC8.X' 
"C:\Program Files (x86)\Microchip\xc8\v1.42\bin\xc8.exe" --pass1 --chip=18F2220 -Q -G --double=24 --float=24 --emi=wordwrite --opt=+asm,+asmfile,-speed,+space,-debug --addrqual=ignore --mode=free -P -N255 --warn=-3 --asmlist -DXPRJ_default=default --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,-download,+config,+clib,-plib --output=-mcof,+elf:multilocs --stack=compiled:auto:auto:auto "--errformat=%f:%l: error: (%n) %s" "--warnformat=%f:%l: warning: (%n) %s" "--msgformat=%f:%l: advisory: (%n) %s" -obuild/default/production/XC8.p1 XC8.c 
XC8.c:15: error: (192) undefined identifier "TRISBbits" 
XC8.c:15: error: (196) struct/union required 
XC8.c:16: error: (192) undefined identifier "OSCCON" 
XC8.c:20: error: (192) undefined identifier "LATBbits" 
XC8.c:20: error: (196) struct/union required 
XC8.c:20: error: (196) struct/union required 
XC8.c:22: warning: (361) function declared implicit int 
(908) exit status = 1 
nbproject/Makefile-default.mk:100: recipe for target 'build/default/production/XC8.p1' failed 
make[2]: Leaving directory 'E:/Projects/Coding/MPLABX/Programming/XC8/XC8.X' 
nbproject/Makefile-default.mk:84: recipe for target '.build-conf' failed 
make[1]: Leaving directory 'E:/Projects/Coding/MPLABX/Programming/XC8/XC8.X' 
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed 
make[2]: *** [build/default/production/XC8.p1] Error 1 
make[1]: *** [.build-conf] Error 2 
make: *** [.build-impl] Error 2 

BUILD FAILED (exit value 2, total time: 467ms) 

Espérons que j'ai ajouté suffisamment de données pour la requête. Puisque je suis nouveau dans cette section, n'hésitez pas à demander de plus amples informations.

Répondre

3

Vous manquez d'inclure #include <xc.h>, au lieu de simplement définir vos bits de configuration. Le xc.h est le fichier d'en-tête principal qui comprendra beaucoup d'autres fichiers d'en-tête qui pointent finalement vers le fichier d'en-tête de votre contrôleur spécial #include <pic18f2220.h>. Cela se fait avec les constructions #ifdef que votre IDE MPLAB devrait fournir car vous avez initialement défini le contrôleur lors de la création d'un nouveau projet.

Cette guide from Microchip est très utile car elle commence par beaucoup.

Si vous n'incluez pas le fichier d'en-tête <xc.h>, les noms de registre de votre contrôleur ne sont pas connus du compilateur. C'est la raison de vos erreurs.

+0

mis à jour le code et son fonctionnement. Merci beaucoup – vt673

+0

@AndreKampling Considérons [n'est pas non plus poli ...] (https://meta.stackoverflow.com/a/266312/2410359) – chux

+0

@chuc: Merci pour votre indice. Je ne le sais pas avant et je ne le ferai plus. –