Flashing LEDs on FRDM-K22F

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Flashing LEDs on FRDM-K22F

1,653 次查看
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;

}

标签 (1)
标记 (3)
0 回复数