ledflash_nomacros.c - Flashes an LED, does not use I/O macros.

A simple program that flashes the power LED, does not use I/O macros. RB15 is configured as an open drain output, and drives an LED at the junction between the LED and a pullup resistor to VDD. When RB15 is driven low, the LED is off. When RB15 is driven high, the RB15 output floats because of the open drain, and so the LED is turned on by the pullup resistor to VDD. This allows the power LED to function as a ‘blinky’ LED in addition to serving as a power indicator.

 
#include "pic24_all.h"
 
 

A naive software delay function.

void a_delay(void) {
  uint16_t u16_i;
  uint16_t u16_k;

change count values to alter delay

  for (u16_k = 1800; u16_k > 0; --u16_k) {
    for (u16_i = 1200; u16_i > 0; --u16_i) {
    }
  }
}


int main(void) {
  configClock();    //clock configuration

  /********** GPIO config **********************************
  ** determine which, if any SFR bit exists that enables
  ** opendrain on RB15.  If no SRB bit is defined, make
  ** RB15 a normal CMOS digital output
  *********************************************************/

#ifdef _ODB15          //PIC24F CPU header files define this instead of ODCB15
  _ODB15 = 1;         //enable open drain with _ODB15 bit (if it exists)
#endif
#ifdef _ODCB15
  _ODCB15 = 1;        //enable open drain with _ODCB15 bit (if it exists)
#endif
  _TRISB15 = 0;       //Config RB15 as output
  _LATB15 = 0;        //RB15 initially low

  /************** LOOP **************/
  while (1) {           //infinite while loop
    a_delay();          //call delay function
    _LATB15 = !_LATB15;  //Toggle LED attached to RB15
  } // end while (1)
}