Question

I am trying to get started with pic24's, specifically the PIC24FJ64GA002, and I have looked in the datasheet at the registers and whatnot, but I still cannot get it to blink the leds. When I run it via debug it runs correctly, but when I try to actually run it on the pic it seems to not run at all.

I am using an external Oscillator, a 8MHZ Oscillator specifically, connected to pins 9(OSCI) and 10 (OSCO). Compiler is C30 in Mplab.

Datasheet link is: http://ww1.microchip.com/downloads/en/DeviceDoc/39881D.pdf

The code is below

//include basic header definition
#include <p24FJ64GA002.h>

//config
_CONFIG2(0x0200);
_CONFIG1(0x0800);

int i;

//main loop
int main(void)
{

   OSCCON = 0x2280;  //select external OSC, no PLL
   AD1PCFG      = 0xFFFF;  //set to all digital I/O
   TRISA = 0x0000;  //configure all PortA as output

   while(1)    //Loop forever
   {
  LATAbits.LATA0 = 1; //RA0 = 1
  Wait();
  LATAbits.LATA0 = 1; //RA0 = 1
  Wait(); 
   }

}


int Wait(void) // gives me a nice delay of 1/3rd a second or so
{
for (int i = 0; i < 30000; i++)
 { 
  for (int i = 0; i < 30; i++);
    }

}

Was it helpful?

Solution 3

Thank you guys for all your help, but it was that I set the config bits wrong, when I set them in the config editor in mplab all works well.

Thank you for all your help!

OTHER TIPS

You need to go hi, wait, then lo, wait... you are just going hi, wait, hi, wait.

   while(1)    //Loop forever
   {
  LATAbits.LATA0 = 1; //RA0 = 1
  Wait();
  LATAbits.LATA0 = 0; //RA0 = 1
  Wait(); 
   }

What optimization level are you compiling with? If it's only working in debug, it's possible the optimizer is reducing the whole Wait() function to a no-op. Try declaring `volatile int i'.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top