He codificado un ejemplo simple de parpadeo para un dsPIC30F2020. Creo que el esquema es correcto, pero no estoy seguro de los bits de configuración.
Herramientas:
- MCU: dsPIC30F2020
- Programador: PICKit 2
- IDE: MPLAB X IDE v3.60
Aquí está el código:
#include "xc.h"
#include "libpic30.h"
#include "stdio.h"
#include "stdlib.h"
#include "p30F2020.h"
// xtal
#define _XTAL_FREQ 16000000
// DSPIC30F2020 Configuration Bit Settings
// 'C' source line config statements
// FBS
#pragma config BWRP = BWRP_OFF // Boot Segment Write Protect (Boot Segment may be written)
#pragma config BSS = NO_BOOT_CODE // Boot Segment Program Flash Code Protection (No Boot Segment)
// FGS
#pragma config GWRP = GWRP_OFF // General Code Segment Write Protect (General Segment may be written)
#pragma config GSS = GSS_OFF // General Segment Code Protection (Disabled)
// FOSCSEL
#pragma config FNOSC = PRIOSC // Oscillator Mode (Primary Oscillator (HS, EC))
// FOSC
#pragma config POSCMD = HS // Primary Oscillator Source (HS Oscillator Mode)
#pragma config OSCIOFNC = OSC2_CLKO // OSCI/OSCO Pin Function (OSCO pin has clock out function)
#pragma config FRANGE = FRC_HI_RANGE // Frequency Range Select (High Range)
#pragma config FCKSM = CSW_FSCM_OFF // Clock Switching and Monitor (Sw Disabled, Mon Disabled)
// FWDT
#pragma config WDTPS = WDTPOST_PS32768 // Watchdog Timer Postscaler (1:32,768)
#pragma config FWPSA0 = WDTPRE_PR128 // WDT Prescaler (1:128)
#pragma config WWDTEN = WINDIS_OFF // Watchdog Timer Window (Non-Window mode)
#pragma config FWDTEN = FWDTEN_OFF // Watchdog Timer Enable (Disable)
// FPOR
#pragma config FPWRT = PWRT_128 // POR Timer Value (128ms)
// FICD
#pragma config ICS = ICS_PGD // Comm Channel Select (Use PGC/EMUC and PGD/EMUD)
int main(){
_TRISD0 = 0x00;
while(1){
_RD0 = 0xff;
__delay32(150000000);
_RD0 = 0x00;
__delay32(150000000);
}
return 0;
}
CapturadepantalladePickit2:
Cuando conecto el LED a RD0 (pin 15), el LED se ilumina todo el tiempo; no parpadea.
¿Qué podría estar mal?
[ACTUALIZACIÓN]
Creo que el __delay32() es el problema. ¿Alguna idea?
