NXP Freescale Kinetis KEA128 Study Notes 3--GPIO Module (Part 2)

Publisher:stampieLatest update time:2021-04-06 Source: eefocusKeywords:Freescale Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Control the light on and off through IO.


//============================================================================

//File name: light.h

//Functional overview: small light component header file

//Copyright: Freescale Embedded Center, Soochow University (sumcu.suda.edu.cn)

//Version update: 2014-12-10 V1.0

//Chip type: KEA128

//============================================================================

 

#ifndef _LIGHT_H //Prevent duplicate definition (starting with _LIGHT_H)

#define _LIGHT_H

 

//Header file includes

#include "common.h" //Includes common element header files

#include "gpio.h" //Use gpio components

 

//Indicator port and pin definition

#define LIGHT_0 (PORTC|0) //Port/pin used by light 0

#define LIGHT_1 (PORTC|1) //Port/pin used by light 1

#define LIGHT_2 (PORTC|2) //Port/pin used by light 2

#define LIGHT_3 (PORTC|3) //Port/pin used by light 3

 

//Light status macro definition (the physical level corresponding to light on and light off is determined by the hardware connection)

#define LIGHT_ON 1 //Light on

#define LIGHT_OFF 0 //Light off

 

 

//================Interface function declaration===============================================

//============================================================================

//Function name: light_init

//Function parameters: port_pin: (port number)|(pin number) (e.g. (PORTB)|(5) means pin 5 of port B)

// state: Set the state of the small light. Defined by macro.

//Function returns: None

//Function summary: indicator light driver initialization.

//============================================================================

void light_init(uint_16 port_pin, uint_8 state);

 

//============================================================================

//Function name: light_control

//Function parameters: port_pin: (port number)|(pin number) (e.g. (PORTB)|(5) means pin 5 of port B)

// state: Set the state of the small light. Defined by macro.

//Function returns: None

//Function summary: Control the brightness of the indicator light.

//============================================================================

void light_control(uint_16 port_pin, uint_8 state);

 

//============================================================================

//Function name: light_change

//Function parameters: port_pin: (port number)|(pin number) (e.g. (PORTB)|(5) means pin 5 of port B)

//Function returns: None

//Function summary: switch the indicator light on or off.

//============================================================================

void light_change(uint_16 port_pin);

 

#endif //Prevent duplicate definition (ending with _LIGHT_H)

 

 

//===========================================================================

//statement:

//(1)The source code we developed has passed the test of the hardware system provided by our center. We sincerely contribute it to the society. If there are any shortcomings, please feel free to point them out.

//(2) For users who use hardware systems other than those of our center, please carefully match the system according to your own hardware when porting the code.

//

//Freescale Embedded Center, Suzhou University

//Technical consultation: 0512-65214835 http://sumcu.suda.edu.cn

 


//===========================================================================

//File name: light.c

//Functional overview: small light component source file

//Copyright: Freescale Embedded Center, Soochow University (sumcu.suda.edu.cn)

//Version update: 2014-12-10 V1.0

//Chip type: KEA128

//===========================================================================

 

#include "light.h"

 

//===========================================================================

//Function name: light_init

//Function parameters: port_pin: (port number)|(pin number) (e.g. (PORTB)|(5) means pin 5 of port B)

// state: Set the state of the small light. Defined by the macro in light.h.

//Function returns: None

//Function summary: indicator light driver initialization.

//===========================================================================

void light_init(uint_16 port_pin, uint_8 state)

{

gpio_init(port_pin, 1, state);

}

 

//===========================================================================

//Function name: light_control

//Function parameters: port_pin: (port number)|(pin number) (e.g. (PORTB)|(5) means pin 5 of port B)

// state: Set the state of the small light. Defined by the macro in light.h.

//Function returns: None

//Function summary: Control the brightness of the indicator light.

//===========================================================================

void light_control(uint_16 port_pin, uint_8 state)

{

gpio_set(port_pin, state);

}

 

//===========================================================================

//Function name: light_change

//Function parameters: port_pin: (port number)|(pin number) (e.g. (PORTB)|(5) means pin 5 of port B)

//Function returns: None

//Function summary: switch the indicator light on or off.

//===========================================================================

void light_change(uint_16 port_pin)

{

gpio_reverse(port_pin);

}

Main program header file


//============================================================================

//File name: includes.h

//Functional summary: project header file

//Copyright: Freescale Embedded Center, Soochow University (sumcu.suda.edu.cn)

//Version update: 2014-12-10 V1.0

//Chip type: KEA128

//============================================================================

 

#ifndef _INCLUDES_H //Prevent duplicate definitions (at the beginning)

#define _INCLUDES_H

 

//Contains the component header file used

#include "common.h"

#include "gpio.h"

#include "light.h"

 

//Preventing duplicate declarations of global variables using prefix processing

#ifdef GLOBLE_VAR //GLOBLE_VAR macro definition in main.c file

#define G_VAR_PREFIX //Use global variables in main.c file without "extern" prefix

#else

#define G_VAR_PREFIX extern //Global variables used in other files are automatically prefixed with "extern"

#endif

//Declare global variables (global variable types are always prefixed with G_VAR_PREFIX)

G_VAR_PREFIX char g_uart_num;

 

//Define macro constants

#define RUN_COUNTER_MAX 1500000ul //Flashing frequency of the small light

 

#endif //Prevent duplicate definition (end)

c file


//For instructions, see the Readme.txt file in the Doc folder under the project folder

#define GLOBLE_VAR //Only need to be defined once in main.c to prevent duplicate definition of global variables

 

#include "includes.h"

 

int main(void)

 {

    //1. Declare variables used by the main function

    uint_32 mRuncount; //Main loop counter

    //2. Turn off the general interrupt

    DISABLE_INTERRUPTS; //Disable total interrupt

    //3. Initialize peripheral modules

    light_init(LIGHT_0, LIGHT_OFF); //Initialize light 0

    light_init(LIGHT_1, LIGHT_OFF); //Initialize light 1

    light_init(LIGHT_2, LIGHT_OFF); //Initialize light 2

    light_init(LIGHT_3, LIGHT_OFF); //Initialize light 3

    //4. Initialization of local variables used in main

    mRuncount = 0; //Main loop counter

    //5. Global variable initialization

    //6. Enable module interrupt

    //7. Enable general interrupt

    ENABLE_INTERRUPTS; //Enable total interrupt

 

    //Enter the main loop

    //Main loop starts= ...

    for (;;)

    {

        //Running indicator light flashes----------------------------------------------------------

        mRuncount++; //Main loop count counter + 1

        if (mRuncount >= RUN_COUNTER_MAX) //The main loop count counter is greater than the set macro constant

        {

            mRuncount = 0; // Clear the main loop count counter

            light_change(LIGHT_0); //Light 0 (LIGHT_0) status change

            light_change(LIGHT_1); //Light 1 (LIGHT_1) status change

            light_change(LIGHT_2); //Light 2 (LIGHT_2) status change

            light_change(LIGHT_3); //Light 3 (LIGHT_3) status change

        }

        //The following user program is added--------------------------------------------------------

 

    } //Main loop end_for

 

    //End of main loop= ...

    return 0;

}

Keywords:Freescale Reference address:NXP Freescale Kinetis KEA128 Study Notes 3--GPIO Module (Part 2)

Previous article:NXP Freescale Kinetis KEA128 Study Notes 3--GPIO Module (I)
Next article:NXP Freescale Kinetis KEA128 Study Notes 3 - Watchdog

Recommended ReadingLatest update time:2024-11-16 20:51

Freescale HCS12 series MCU bootloader detailed explanation (Part 3)
After finishing the memory mapping, we will move on to the actual design of a simple Bootloader. In the first section, we have briefly introduced the role of the bootlaoder, which is actually a step in the microcontroller restart process: if there is a bootloader start signal, it will enter the bootloader mode to star
[Microcontroller]
Freescale MC9S12G64 serial port send and receive driver
Because I just joined the company and don't know much about serial port debugging, I will sort out the serial port program in the book. Portability is relatively strong Instructions: There are two ways to query the serial port of the MC9S12 series                1》Use interrupt mode to query                2》Use
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号