Hola Amigos, les escribo porque quiero hacerles una consulta y quería ver si me pueden ayudar, el problema es el siguiente: estoy realizando pruebas con mi nuevo ICD3 y resulta que tengo algunos inconvenientes con mi código, si debugueo el código y no coloco ciertos breakpoints, hay pines de mi pic que no cambian el estado, si le coloco los breakpoints los tomo y el programa funciona casi normalmente.
Esta es la primera vez que trabajo con este micro, había probado unos ejemplos hace un tiempo en el develpment kit, pero ahora cuando paso a trabajar sobre el diseño de mi circuito me encuentro con estos problemas. Una vez detectado el inconveniente con el debug, asumí que quizas el problema era el debug en si x lo q trate de programar el pic, el icd3 me dice que se programo en forma correcta, pero el programa no corre, les dejo adjuntado el código que en su mayoria está sacado del libro de pic32 que se puede bajar en forma gratuita. Cualquir ayuda es bienvenida. Les detallo a continuación los breakpoints que debo colocar para que funcione, estan marcados con
![redhot :5]](http://www.todopic.com.ar/foros/Smileys/default/redhot.gif)
, que sería la carita en llamas jaja:
/*
** SEE Library test
*/
#pragma config FPLLMUL = MUL_20, FPLLIDIV = DIV_2, FPLLODIV = DIV_1, FWDTEN = OFF
#pragma config POSCMOD = HS, FNOSC = PRIPLL, FPBDIV = DIV_1
#include <p32xxxx.h>
#include <plib.h>
#include <math.h>
#include "see.h"
#define SYS_FREQ (80000000L)
#define DESIRED_BAUDRATE (115200)
#define FPB 80000000L
#define RESET _RD1
#define TRESET _TRISD1
#define PIN_A _RB3
#define TPIN_A _TRISB3
#define PIN_B _RD7
#define TPIN_B _TRISD7
#define PIN_C _RD6
#define TPIN_C _TRISD6
#define PIN_D _RD5
#define TPIN_D _TRISD5
#define PIN_E _RB6
#define TPIN_E _TRISB6
#define READY _RF1
#define TREADY _TRISF1
#define PIN_F _RD8
#define TPIN_F _TRISD8
void DelayUS(WORD us)
{
DWORD start = _CP0_GET_COUNT();
DWORD end = start + SYS_FREQ / 1000000 / 2 * us;
if (end > start) while (_CP0_GET_COUNT() < end);
else while (_CP0_GET_COUNT() > start || _CP0_GET_COUNT() < end);
}
void DelayMS(WORD ms)
{
DWORD start = _CP0_GET_COUNT();
DWORD end = start + SYS_FREQ / 1000 / 2 * ms;
if (end > start) while (_CP0_GET_COUNT() < end);
else while (_CP0_GET_COUNT() > start || _CP0_GET_COUNT() < end);
}
void initGRAL()
{
DDPCONbits.JTAGEN = 0;
AD1PCFG = 0xffff;
T1CON = 0x8030;
PR1 = 0xFFFF;
TRISB = 0x07C0;
TRISC = 0xF000;
TRISD = 0x0F14;
TRISE = 0x00FF;
TRISF = 0x0013;
TRISG = 0x028C;
PORTB = 0;
PORTC = 0;
PORTD = 0;
//PORTE = 0;
PORTF = 0;
PORTG = 0;
}
void initSPI2( void)
{
// init the SPI2 peripheral
TRESET = 0;
TPIN_A = 0;
TPIN_B = 0; // make SSEE pin output
TPIN_C = 0;
TPIN_D = 0;
TPIN_E = 1;
TREADY = 1;
TPIN_F = 1;
DelayUS(100);
:5] RESET = 1;
PIN_B = 1; // de-select the Serial EEPROM
PIN_C = 1;
PIN_D = 1;
PIN_A = 0;
SPI2ACON = 0x8920; // enable the peripheral
SPI2ABRG = 23; // select clock speed
}
void initUART()
{
int pbClk;
pbClk=SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);
OpenUART1(UART_EN, UART_RX_ENABLE | UART_TX_ENABLE, pbClk/16/DESIRED_BAUDRATE-1);
}
void initCLK( int samplerate)
{
OpenOC1( OC_ON | OC_TIMER2_SRC | OC_PWM_FAULT_PIN_DISABLE, 0, 0);
OpenTimer2( T2_ON | T2_PS_1_1 | T2_SOURCE_INT, FPB/samplerate);
PR2 = FPB/samplerate-1;
mT2SetIntPriority(4);
mT2ClearIntFlag();
mT2IntEnable(1);
SetDCOC1PWM(PR2/2);
}
int writeSPI2( int i)
{
SPI2ABUF = i; // write to buffer for TX
while( !SPI2ASTATbits.SPIRBF); // wait for transfer complete
return SPI2ABUF; // read the received value
}
void __ISR(_TIMER_2_VECTOR, ipl4) T2Interrupt( void)
{
mT2ClearIntFlag();
}
main()
{
int data;
unsigned char datin = 30;
unsigned char F_PIN_E = 0;
int i;
// initialize the SPI2 port and CS to access the 25LC256
initGRAL();
initSEE();
initUART();
initSPI2();
initCLK(1000000);
// main loop
:5] putsUART1("*** UART Simple Application Example ***\r\n");
:5] putsUART1("*** Type some characters and observe echo and RA7 LED toggle ***\r\n");
:5] putcUART1('a');
while ( 1)
{
datin++;
// read current content of memory location
data = readSEE( 16);
// increment current value
data++; // <-set brkpt here
// write back the new value
writeSEE( 16, data);
putcUART1(datin);
//address++;
if ((PIN_E == 1) && (F_PIN_E == 0))
{
PIN_A = 1;
for (i=0;i<10240;i++)
{
if (F_PIN_E != 0)
{
while (READY == 1);
}
DelayUS(1);
PIN_C = 0;
PIN_B = 1;
writeSPI2(0xffffffff);
writeSPI2(0xffffffff);
DelayUS(1);
PIN_C = 1;
DelayUS(1);
PIN_B = 0;
writeSPI2(0xffffffff);
writeSPI2(0xffffffff);
DelayUS(1);
PIN_B = 1;
while (READY == 0);
PIN_D = 0;
DelayUS(20);
PIN_D = 1;
F_PIN_E = 1;
}
PIN_A = 0;
}
if ((PIN_E == 0) && (F_PIN_E == 1))
{
F_PIN_E = 0;
}
}
}