dopo qualche anno passato a scrivere FW in mikrobasic ho deciso di imparare il C.
Ho installato MPLAB X con XC8 e dopo aver creato un progetto mi sono messo a fare un po' di pratica ma riscontro un problema strano.
in pratica faccio lampeggiare banalmente la PORTB e non riscontro problemi ma se aggiungo un ritardo il PIC sembra morto...
Il PIC è un 18F4620 e utilizzo il seguente codice:
- Codice: Seleziona tutto
// PIC18F4620 Configuration Bit Settings
#include <xc.h>
#include <pic18f4620.h>
// CONFIG1H
#pragma config OSC = HSPLL // Oscillator Selection bits (HS oscillator, PLL enabled (Clock Frequency = 4 x FOSC1))
#pragma config FCMEN = OFF // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled)
#pragma config IESO = OFF // Internal/External Oscillator Switchover bit (Oscillator Switchover mode disabled)
// CONFIG2L
#pragma config PWRT = OFF // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = SBORDIS // Brown-out Reset Enable bits (Brown-out Reset enabled in hardware only (SBOREN is disabled))
#pragma config BORV = 3 // Brown Out Reset Voltage bits (Minimum setting)
// CONFIG2H
#pragma config WDT = OFF // Watchdog Timer Enable bit (WDT disabled (control is placed on the SWDTEN bit))
#pragma config WDTPS = 32768 // Watchdog Timer Postscale Select bits (1:32768)
// CONFIG3H
#pragma config CCP2MX = PORTC // CCP2 MUX bit (CCP2 input/output is multiplexed with RC1)
#pragma config PBADEN = OFF // PORTB A/D Enable bit (PORTB<4:0> pins are configured as digital I/O on Reset)
#pragma config LPT1OSC = OFF // Low-Power Timer1 Oscillator Enable bit (Timer1 configured for higher power operation)
#pragma config MCLRE = ON // MCLR Pin Enable bit (MCLR pin enabled; RE3 input pin disabled)
// CONFIG4L
#pragma config STVREN = 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)
#pragma config XINST = OFF // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode))
// CONFIG5L
#pragma config CP0 = OFF // Code Protection bit (Block 0 (000800-003FFFh) not code-protected)
#pragma config CP1 = OFF // Code Protection bit (Block 1 (004000-007FFFh) not code-protected)
#pragma config CP2 = OFF // Code Protection bit (Block 2 (008000-00BFFFh) not code-protected)
#pragma config CP3 = OFF // Code Protection bit (Block 3 (00C000-00FFFFh) not code-protected)
// CONFIG5H
#pragma config CPB = OFF // Boot Block Code Protection bit (Boot block (000000-0007FFh) not code-protected)
#pragma config CPD = OFF // Data EEPROM Code Protection bit (Data EEPROM not code-protected)
// CONFIG6L
#pragma config WRT0 = OFF // Write Protection bit (Block 0 (000800-003FFFh) not write-protected)
#pragma config WRT1 = OFF // Write Protection bit (Block 1 (004000-007FFFh) not write-protected)
#pragma config WRT2 = OFF // Write Protection bit (Block 2 (008000-00BFFFh) not write-protected)
#pragma config WRT3 = OFF // Write Protection bit (Block 3 (00C000-00FFFFh) not write-protected)
// CONFIG6H
#pragma config WRTC = OFF // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) not write-protected)
#pragma config WRTB = OFF // Boot Block Write Protection bit (Boot Block (000000-0007FFh) not write-protected)
#pragma config WRTD = OFF // Data EEPROM Write Protection bit (Data EEPROM not write-protected)
// CONFIG7L
#pragma config EBTR0 = OFF // Table Read Protection bit (Block 0 (000800-003FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR1 = OFF // Table Read Protection bit (Block 1 (004000-007FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR2 = OFF // Table Read Protection bit (Block 2 (008000-00BFFFh) not protected from table reads executed in other blocks)
#pragma config EBTR3 = OFF // Table Read Protection bit (Block 3 (00C000-00FFFFh) not protected from table reads executed in other blocks)
// CONFIG7H
#pragma config EBTRB = OFF // Boot Block Table Read Protection bit (Boot Block (000000-0007FFh) not protected from table reads executed in other blocks)
#define _XTAL_FREQ 40000000
void delay_s(unsigned int count);
void delay_s(unsigned int count){
unsigned int k;
for (k=0; k=count; k++)
{
__delay_ms(10);
}
}
void main(void){
TRISA = 0x00;
TRISB = 0x00;
TRISC = 0x00;
TRISD = 0x00;
TRISE = 0x00;
PORTA = 0X00;
PORTB = 0X00;
PORTC = 0X00;
PORTD = 0X00;
PORTE = 0X00;
ADCON1 = 0b1111;
CMCON = 0b111;
while(1){
PORTB = 0;
delay_s(100);
PORTB = 255;
}
}
Se io tolgo l'istruzione delay_s(100); il PIC lavora correttamente (controllo l'uscita sia con un led che con l'oscilloscopio) se invece inserisco tale istruzione tutto sembra morto.
Ho provato a sostituire il ciclo FOR con un ciclo WHILE(1) ma con il medesimo risultato.
Qualcuno potrebbe gentilmente spiegarmi perché non funziona?
Non ci sono problemi HW in quanto sto usando una scheda di sviluppo easypic6.
quando compilo il compilatore restituisce i seguenti messaggi:
- Codice: Seleziona tutto
make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory `C:/Users/Nicola/MPLABXProjects/Test led.X'
make -f nbproject/Makefile-default.mk dist/default/production/Test_led.X.production.hex
make[2]: Entering directory `C:/Users/Nicola/MPLABXProjects/Test led.X'
"C:\Program Files\Microchip\xc8\v1.12\bin\xc8.exe" --pass1 --chip=18F4620 -Q -G --asmlist --double=24 --float=24 --emi=wordwrite --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,-download,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -obuild/default/production/Main.p1 Main.c
"C:\Program Files\Microchip\xc8\v1.12\bin\xc8.exe" --chip=18F4620 -G --asmlist -mdist/default/production/Test_led.X.production.map --double=24 --float=24 --emi=wordwrite --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,-download,+config,+clib,+plib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s" -odist/default/production/Test_led.X.production.cof build/default/production/Main.p1
Microchip MPLAB XC8 C Compiler V1.12
Copyright (C) 2012 Microchip Technology Inc.
License type: Node Configuration
:: advisory: Employing 18F4620 errata work-arounds:
:: advisory: * Corrupted fast interrupt shadow registers
:: advisory: * Data in RAM location can be corrupted if async. reset occurs during write
:: warning: Omniscient Code Generation not available in Free mode
Memory Summary:
Program space used 8Ah ( 138) of 10000h bytes ( 0.2%)
Data space used 5h ( 5) of F80h bytes ( 0.1%)
Configuration bits used 7h ( 7) of 7h words (100.0%)
EEPROM space used 0h ( 0) of 400h bytes ( 0.0%)
ID Location space used 8h ( 8) of 8h nibbles (100.0%)
Running this compiler in PRO mode, with Omniscient Code Generation enabled,
often produces code which is 60% smaller and at least 400% faster than in
Free mode. The MPLAB XC8 PRO compiler output for this code could be
76 bytes smaller and run 4 times faster.
See http://www.microchip.com for more information.
make[2]: Leaving directory `C:/Users/Nicola/MPLABXProjects/Test led.X'
make[1]: Leaving directory `C:/Users/Nicola/MPLABXProjects/Test led.X'
BUILD SUCCESSFUL (total time: 9s)
Loading code from C:/Users/Nicola/MPLABXProjects/Test led.X/dist/default/production/Test_led.X.production.hex...
Loading symbols from C:/Users/Nicola/MPLABXProjects/Test led.X/dist/default/production/Test_led.X.production.cof...
Loading completed
Ringrazio chiunque riesce a darmi delucidazioni in merito!

Elettrotecnica e non solo (admin)
Un gatto tra gli elettroni (IsidoroKZ)
Esperienza e simulazioni (g.schgor)
Moleskine di un idraulico (RenzoDF)
Il Blog di ElectroYou (webmaster)
Idee microcontrollate (TardoFreak)
PICcoli grandi PICMicro (Paolino)
Il blog elettrico di carloc (carloc)
DirtEYblooog (dirtydeeds)
Di tutto... un po' (jordan20)
AK47 (lillo)
Esperienze elettroniche (marco438)
Telecomunicazioni musicali (clavicordo)
Automazione ed Elettronica (gustavo)
Direttive per la sicurezza (ErnestoCappelletti)
EYnfo dall'Alaska (mir)
Apriamo il quadro! (attilio)
H7-25 (asdf)
Passione Elettrica (massimob)
Elettroni a spasso (guidob)
Bloguerra (guerra)





