Akash Ravichandran
Published © GPL3+

FRDM K82F-Play X-0 Game

Play X-O game, in this 9 LED setup which I did using Frdm-K82f. Type in the LED that you like to light and it will glow.

IntermediateFull instructions provided5 hours773
FRDM K82F-Play X-0 Game

Things used in this project

Hardware components

Solderless Breadboard Half Size
Solderless Breadboard Half Size
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Male-Header 36 Position 1 Row- Long (0.1")
Male-Header 36 Position 1 Row- Long (0.1")
×1
Kinetis Freedom Board with FlexIO
NXP Kinetis Freedom Board with FlexIO
×1
9V battery (generic)
9V battery (generic)
×1
9V Battery Clip
9V Battery Clip
×1
Resistor 330 ohm
Resistor 330 ohm
×1
RGB Diffused Common Cathode
RGB Diffused Common Cathode
×1

Software apps and online services

Kinetis Design Studio

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Soldered Surface.

I have made every LED connect to a male header for me to easily fit it to the FRDM board and made every ground as common.

Code

PinMux Code:That should be given to pinmux.c

C/C++
It defines the pins that defines the LED.
#include "fsl_common.h"
#include "fsl_port.h"
#include "pin_mux.h"

void BOARD_InitPins(void)
{
    CLOCK_EnableClock(kCLOCK_PortC);
    CLOCK_EnableClock(kCLOCK_PortB);
    CLOCK_EnableClock(kCLOCK_PortA);
    CLOCK_EnableClock(kCLOCK_PortD);


    PORT_SetPinMux(PORTC, 14U, kPORT_MuxAlt3);

    PORT_SetPinMux(PORTC, 15U, kPORT_MuxAlt3);

    PORT_SetPinMux(PORTA, 15U, kPORT_MuxAsGpio);  //1 R
    PORT_SetPinMux(PORTA, 16U, kPORT_MuxAsGpio);  //1 G
    PORT_SetPinMux(PORTC, 7U, kPORT_MuxAsGpio);   //2 R
    PORT_SetPinMux(PORTA, 14U, kPORT_MuxAsGpio);  //2 G
    PORT_SetPinMux(PORTA, 17U, kPORT_MuxAsGpio);  //3 R
    PORT_SetPinMux(PORTA, 12U, kPORT_MuxAsGpio);  //3 G
    PORT_SetPinMux(PORTA, 13U, kPORT_MuxAsGpio);  //4 R
    PORT_SetPinMux(PORTA, 5U, kPORT_MuxAsGpio);   //4 G
    PORT_SetPinMux(PORTB, 23U, kPORT_MuxAsGpio);  //5 R
    PORT_SetPinMux(PORTB, 22U, kPORT_MuxAsGpio);  //5 G
    PORT_SetPinMux(PORTB, 21U, kPORT_MuxAsGpio);  //6 R
    PORT_SetPinMux(PORTB, 20U, kPORT_MuxAsGpio);  //6 G
    PORT_SetPinMux(PORTC, 12U, kPORT_MuxAsGpio);   //7 R
    PORT_SetPinMux(PORTB, 17U, kPORT_MuxAsGpio);   //7 G
    PORT_SetPinMux(PORTB, 16U, kPORT_MuxAsGpio);   //8 R
    PORT_SetPinMux(PORTC, 11U, kPORT_MuxAsGpio);   //8 G
    PORT_SetPinMux(PORTC, 5U, kPORT_MuxAsGpio);   //9 R
    PORT_SetPinMux(PORTC, 3U, kPORT_MuxAsGpio);   //9 G
}

Main Code: This is the code that goes into main.c

C/C++
It defines the functionality to switch on/off the Led.
#include "board.h"
#include "fsl_debug_console.h"
#include "fsl_gpio.h"

#include "clock_config.h"
#include "pin_mux.h"

#include <stdlib.h>
#include <stdio.h>

#define High 1

static char g_StrMenu[] =
    "\r\n"
    "#################\r\n"
    "## 1 ## 2 ## 3 ##\r\n"
    "## 4 ## 5 ## 6 ##\r\n"
    "## 7 ## 8 ## 9 ##\r\n"
    "#################\r\n"
        "\r\n"
		"\r\n1 Red a  1 Green b"
		"\r\n2 Red c  2 Green d"
		"\r\n3 Red e  3 Green f"
		"\r\n4 Red g  4 Green h"
		"\r\n5 Red i  5 Green j"
		"\r\n6 Red k  6 Green l"
		"\r\n7 Red m  7 Green n"
		"\r\n8 Red o  8 Green p"
		"\r\n9 Red q  9 Green r";

static char g_StrNewline[] = "\r\n";


int main(void)
{
	uint8_t index;

    gpio_pin_config_t led_config = {
        kGPIO_DigitalOutput, 0,
    };

    /* Board pin, clock, debug console init */
    BOARD_InitPins();
    BOARD_BootClockRUN();
    BOARD_InitDebugConsole();



    GPIO_PinInit(GPIOA, 15U, &led_config);  //1 R a
    GPIO_PinInit(GPIOA, 16U, &led_config);  //1 G b
    GPIO_PinInit(GPIOC, 7U, &led_config);   //2 R c
    GPIO_PinInit(GPIOA, 14U, &led_config);  //2 G d
    GPIO_PinInit(GPIOA, 17U, &led_config);  //3 R e
    GPIO_PinInit(GPIOA, 12U, &led_config);  //3 G f
    GPIO_PinInit(GPIOA, 13U, &led_config);  //4 R g
    GPIO_PinInit(GPIOA, 5U, &led_config);   //4 G h
    GPIO_PinInit(GPIOB, 23U, &led_config);  //5 R i
    GPIO_PinInit(GPIOB, 22U, &led_config);  //5 G j
    GPIO_PinInit(GPIOB, 21U, &led_config);  //6 R k
    GPIO_PinInit(GPIOB, 20U, &led_config);  //6 G l
    GPIO_PinInit(GPIOC, 12U, &led_config);   //7 R m
    GPIO_PinInit(GPIOB, 17U, &led_config);   //7 G n
    GPIO_PinInit(GPIOB, 16U, &led_config);  //8 R o
    GPIO_PinInit(GPIOC, 11U, &led_config);  //8 G p
    GPIO_PinInit(GPIOC, 5U, &led_config);   //9 R q
    GPIO_PinInit(GPIOC, 3U, &led_config);   //9 G r



    while (1)
    {

        PRINTF(g_StrMenu);
        PRINTF("\r\nSelect:");

        index = GETCHAR();
        PUTCHAR(index);
        PRINTF(g_StrNewline);

        switch (index)
        {
            case 'a':
                GPIO_WritePinOutput (GPIOA, 15U, High);
                break;
            case 'b':
                GPIO_WritePinOutput (GPIOA, 16U, High);
                break;
            case 'c':
                GPIO_WritePinOutput (GPIOC, 7U, High);
                break;
            case 'd':
                GPIO_WritePinOutput (GPIOA, 14U, High);
                break;
            case 'e':
                GPIO_WritePinOutput (GPIOA, 17U, High);
                break;
            case 'f':
                GPIO_WritePinOutput (GPIOA, 12U, High);
                break;
            case 'g':
                GPIO_WritePinOutput (GPIOA, 13U, High);
                break;
            case 'h':
                GPIO_WritePinOutput (GPIOA, 5U, High);
                break;

            case 'i':
                GPIO_WritePinOutput (GPIOB, 23U, High);
                break;
            case 'j':
                GPIO_WritePinOutput (GPIOB, 22U, High);
                break;
            case 'k':
                GPIO_WritePinOutput (GPIOB, 21U, High);
                break;
            case 'l':
                GPIO_WritePinOutput (GPIOB, 20U, High);
                break;

            case 'm':
                GPIO_WritePinOutput (GPIOC, 12U, High);
                break;
            case 'n':
                GPIO_WritePinOutput (GPIOB, 17U, High);
                break;
            case 'o':
                GPIO_WritePinOutput (GPIOB, 16U, High);
                break;
            case 'p':
                GPIO_WritePinOutput (GPIOC, 11U, High);
                break;

            case 'q':
                GPIO_WritePinOutput (GPIOC, 5U, High);
                break;
            case 'r':
                GPIO_WritePinOutput (GPIOC, 3U, High);
                break;
            default:
                break;
        }
    }
}

Credits

Akash Ravichandran

Akash Ravichandran

15 projects • 98 followers
Developer and a Learner

Comments