Blue Bird Blinking LED

Blinking LED using Blue Bird Board

How many times can you do a blinking led tutorial.  I guess at least one more time.  I think there are several tutorials on how to blink an LED using a PIC24FJ part on this board.  But, I thought I would add one more to show how to do it with the Blue Bird board.  The Blue Bird board is based on a PIC24FJ64GB002 device.  This device has an integrated USB port in it which gives it some flexibility.  The Blue Bird board also has a boot loader that uses the USB port to allow the board to be programmed without an external programmer.  The board also receives its power through the USB port.  This has proven to be very flexible and there are a lot of ways to get power to the device using USB.  I have even used the portable cell phone charging devices to power this board.  So, there is a built in way to have a battery operated device.

The first issue is connecting the LED to the device.  I like to use one of the port B pins as a lot of these pins are 5 volt tolerant.  Other pins can be used to drive the LED’s but it is nice having the 5 volt tolerance.  The part is a 3 volt part and some of the pins can’t handle a logic level above VCC or 3 volts.  Another thing I would like to point out is that the I/O pins can sync more current than they can source.  So, it is better to take a pin to ground to activate the LED rather than have the pin go high to activate the LED.  So, I will wire the LED to be active low rather than active high.  This inverse logic can sometimes be confusing but you will get use to it.

Here is schematic of the hook up of the LED.

Blue Bird Board Blinking LED Interface

Blue Bird Board Blinking LED Interface

The code would simply look like this using the library found here.

#include <p24fxxxx.h>
#include <string.h>
#include "rtos.h"
#include "pins.h"
#include "initializeSystem.h"

unsigned int on = 0;

//
/******************************************************************************
 * Function void blink(void)
 *
 * This function is called by the RTOS when the delay has expired.  Interesting
 * to note that you have to call the delay routine again to get another delay.
 * The LED is flashed in this routine.
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    blinks the LED and also toggles the on variable between 1 and
 *                  0.
 *
 *****************************************************************************/
void
blink(void)
{
  if (on)
  {
    digitalWrite(16,HIGH);
    on = 0;
  }
  else
  {
    digitalWrite(16,LOW);
    on = 1;
  }
  if (!delayMS(blink,500))
  {
    runNext(); // next item to be run
    // wasn't able to add to the delay queue.  It must be full.
    // Try again.
    while (!delayMS(blink,500))
      runNext();
    // or you could setup an infinite loop to catch the error in
    // a debugger.
    // while (1) 
    //    ;
  }
}

/******************************************************************************
 * Function:        void main(void)
 *
 * PreCondition:    None
 *
 * Input:           None
 *
 * Output:          None
 *
 * Side Effects:    None
 *
 * Overview:        Main program entry point.
 *
 * Note:            None
 *****************************************************************************/
int main(void)
{   
  initializeSystem();

  pinMode(16, OUTPUT);

  while (!delayMS(blink,500))
    runNext();

  while(1)
  {
    runNext();
  }//end while
}//end main