Flashing LEDs on FRDM-K22F

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Flashing LEDs on FRDM-K22F

1,158 Views
jverive
Contributor III

The following has been debugged in KDS v1.1.1 with KSDK v1.0.0. It flashes the Green, Red, and Blue LEDs in succession, looping forever. It has been tested on a FRDM-K22F, and is commented to explain operation. It is a very simple program that shows how to use GPIO pins as outputs.

 

#include "fsl_device_registers.h"

#include "board.h"

 

static int i = 0;

 

int main(void)

{

  // LEDs are common-anode, with cathodes connected to port pins.

  // Therefore, logic high (1) turns them off, and logic low

  // (0) turns them on.

 

  short OFF = 1;

  short ON = 0;

  

     hardware_init();

    

     GPIO_DRV_SetPinDir(kGpioLED1, kGpioDigitalOutput); //Green LED

     GPIO_DRV_SetPinDir(kGpioLED2, kGpioDigitalOutput); //Red LED

     GPIO_DRV_SetPinDir(kGpioLED3, kGpioDigitalOutput); //Blue LED

 

 

     GPIO_DRV_WritePinOutput(kGpioLED1, OFF); //Green LED initially off

     GPIO_DRV_WritePinOutput(kGpioLED2, OFF); //Red LED initially off

     GPIO_DRV_WritePinOutput(kGpioLED3, OFF); //Blue LED initially off

 

 

 

 

     while (1)

          {

          for (i = 0; i<0xFFFFFF; i++)

          {

          }

          GPIO_DRV_WritePinOutput(kGpioLED1, ON); //Green LED on

          for (i = 0; i<0xFFFFFF; i++)

          {

          }

          GPIO_DRV_WritePinOutput(kGpioLED1, OFF); //Green LED off

          for (i = 0; i<0xFFFFFF; i++)

          {

          }

          GPIO_DRV_WritePinOutput(kGpioLED2, ON); //Red LED on

          for (i = 0; i<0xFFFFFF; i++)

          {

          }

          GPIO_DRV_WritePinOutput(kGpioLED2, OFF); //Red LED off

          for (i = 0; i<0xFFFFFF; i++)

          {

          };

          GPIO_DRV_WritePinOutput(kGpioLED3, ON); //Blue LED on

          for (i = 0; i<0xFFFFFF; i++)

          {

          }

          GPIO_DRV_WritePinOutput(kGpioLED3, OFF); //Blue LED off

          }

     return 0;

}

Labels (1)
Tags (3)
0 Replies