/* * Copyright 2016-2021 NXP * All rights reserved. * * This is a very simple example. * It is a loop cheecking the button, if pushed it turns the * red LED ON if not pushed it turns it off * button is connected to pin 8, LED to pin 9 * I used define to define 8 and 9 * * @file ex1.c * @brief Application entry point. */ #include #include "board.h" #include "peripherals.h" #include "pin_mux.h" #include "clock_config.h" #include "LPC802.h" #include "fsl_debug_console.h" /* TODO: insert other include files here. */ #define LED (9) #define BUTTON (8) /* TODO: insert other definitions and declarations here. */ /* * @brief Application entry point. */ int main(void) { /* Init board hardware. */ BOARD_InitBootPins(); BOARD_InitBootClocks(); BOARD_InitBootPeripherals(); /* Init FSL debug console. */ BOARD_InitDebugConsole(); //Connect the clock to the ports,, a must if you want to use any port SYSCON->SYSAHBCLKCTRL0 |= SYSCON_SYSAHBCLKCTRL0_GPIO0_MASK; PRINTF("Hello World\n"); /* Force the counter to be placed into memory. */ volatile static int i = 0 ; /* Enter an infinite loop, just incrementing a counter. */ //make pio 8 as input (set direction register to 0 or clear it GPIO->DIRCLR[0] = (1UL <DIRSET[0] = (1UL <CLR[0]=(1UL << LED); while(1) { // do forever //continuously check the input if 1 turn the LED ON //read the value of pin 8, specifically the least significant bit /*******************************/ i= GPIO->B[0][BUTTON] & 1; // if ( i == 1) { // Is it high. Not pushed Then Turn LED OFF GPIO->SET[0] = (1UL << LED); // Turn RED LED OFF } else {// it is 0, pushed GPIO->CLR[0]=(1UL<