/* Copyright 2022, Laboratorio de Microprocesadores * Facultad de Ciencias Exactas y TecnologĂ­a * Universidad Nacional de Tucuman * http://www.microprocesadores.unt.edu.ar/ * Copyright 2022, Esteban Volentini * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ /** \brief Simple sample of use LPC HAL gpio functions ** ** \addtogroup samples Sample projects ** \brief Sample projects to use as a starting point ** @{ */ /* === Headers files inclusions =============================================================== */ #include "chip.h" #include /* === Macros definitions ====================================================================== */ #define LED_R_PORT 2 #define LED_R_PIN 0 #define LED_R_FUNC SCU_MODE_FUNC4 #define LED_R_GPIO 5 #define LED_R_BIT 0 #define LED_G_PORT 2 #define LED_G_PIN 1 #define LED_G_FUNC SCU_MODE_FUNC4 #define LED_G_GPIO 5 #define LED_G_BIT 1 #define LED_B_PORT 2 #define LED_B_PIN 2 #define LED_B_FUNC SCU_MODE_FUNC4 #define LED_B_GPIO 5 #define LED_B_BIT 2 #define LED_1_PORT 2 #define LED_1_PIN 10 #define LED_1_FUNC SCU_MODE_FUNC0 #define LED_1_GPIO 0 #define LED_1_BIT 14 #define LED_2_PORT 2 #define LED_2_PIN 11 #define LED_2_FUNC SCU_MODE_FUNC0 #define LED_2_GPIO 1 #define LED_2_BIT 11 #define LED_3_PORT 2 #define LED_3_PIN 12 #define LED_3_FUNC SCU_MODE_FUNC0 #define LED_3_GPIO 1 #define LED_3_BIT 12 #define TEC_1_PORT 1 #define TEC_1_PIN 0 #define TEC_1_FUNC SCU_MODE_FUNC0 #define TEC_1_GPIO 0 #define TEC_1_BIT 4 #define TEC_2_PORT 1 #define TEC_2_PIN 1 #define TEC_2_FUNC SCU_MODE_FUNC0 #define TEC_2_GPIO 0 #define TEC_2_BIT 8 #define TEC_3_PORT 1 #define TEC_3_PIN 2 #define TEC_3_FUNC SCU_MODE_FUNC0 #define TEC_3_GPIO 0 #define TEC_3_BIT 9 #define TEC_4_PORT 1 #define TEC_4_PIN 6 #define TEC_4_FUNC SCU_MODE_FUNC0 #define TEC_4_GPIO 1 #define TEC_4_BIT 9 /* === Private data type declarations ========================================================== */ /* === Private variable declarations =========================================================== */ /* === Private function declarations =========================================================== */ /* === Public variable definitions ============================================================= */ /* === Private variable definitions ============================================================ */ /* === Private function implementation ========================================================= */ /* === Public function implementation ========================================================= */ int main(void) { int divisor = 0; bool current_state, last_state = false; Chip_SCU_PinMuxSet(LED_R_PORT, LED_R_PIN, SCU_MODE_INBUFF_EN | SCU_MODE_INACT | LED_R_FUNC); Chip_GPIO_SetPinState(LPC_GPIO_PORT, LED_R_GPIO, LED_R_BIT, false); Chip_GPIO_SetPinDIR(LPC_GPIO_PORT, LED_R_GPIO, LED_R_BIT, true); Chip_SCU_PinMuxSet(LED_G_PORT, LED_G_PIN, SCU_MODE_INBUFF_EN | SCU_MODE_INACT | LED_G_FUNC); Chip_GPIO_SetPinState(LPC_GPIO_PORT, LED_G_GPIO, LED_G_BIT, false); Chip_GPIO_SetPinDIR(LPC_GPIO_PORT, LED_G_GPIO, LED_G_BIT, true); Chip_SCU_PinMuxSet(LED_B_PORT, LED_B_PIN, SCU_MODE_INBUFF_EN | SCU_MODE_INACT | LED_B_FUNC); Chip_GPIO_SetPinState(LPC_GPIO_PORT, LED_B_GPIO, LED_B_BIT, false); Chip_GPIO_SetPinDIR(LPC_GPIO_PORT, LED_B_GPIO, LED_B_BIT, true); /******************/ Chip_SCU_PinMuxSet(LED_1_PORT, LED_1_PIN, SCU_MODE_INBUFF_EN | SCU_MODE_INACT | LED_1_FUNC); Chip_GPIO_SetPinState(LPC_GPIO_PORT, LED_1_GPIO, LED_1_BIT, false); Chip_GPIO_SetPinDIR(LPC_GPIO_PORT, LED_1_GPIO, LED_1_BIT, true); Chip_SCU_PinMuxSet(LED_2_PORT, LED_2_PIN, SCU_MODE_INBUFF_EN | SCU_MODE_INACT | LED_2_FUNC); Chip_GPIO_SetPinState(LPC_GPIO_PORT, LED_2_GPIO, LED_2_BIT, false); Chip_GPIO_SetPinDIR(LPC_GPIO_PORT, LED_2_GPIO, LED_2_BIT, true); Chip_SCU_PinMuxSet(LED_3_PORT, LED_3_PIN, SCU_MODE_INBUFF_EN | SCU_MODE_INACT | LED_3_FUNC); Chip_GPIO_SetPinState(LPC_GPIO_PORT, LED_3_GPIO, LED_3_BIT, false); Chip_GPIO_SetPinDIR(LPC_GPIO_PORT, LED_3_GPIO, LED_3_BIT, true); /******************/ Chip_SCU_PinMuxSet(TEC_1_PORT, TEC_1_PIN, SCU_MODE_INBUFF_EN | SCU_MODE_PULLUP | TEC_1_FUNC); Chip_GPIO_SetPinDIR(LPC_GPIO_PORT, TEC_1_GPIO, TEC_1_BIT, false); Chip_SCU_PinMuxSet(TEC_2_PORT, TEC_2_PIN, SCU_MODE_INBUFF_EN | SCU_MODE_PULLUP | TEC_2_FUNC); Chip_GPIO_SetPinDIR(LPC_GPIO_PORT, TEC_2_GPIO, TEC_2_BIT, false); Chip_SCU_PinMuxSet(TEC_3_PORT, TEC_3_PIN, SCU_MODE_INBUFF_EN | SCU_MODE_PULLUP | TEC_3_FUNC); Chip_GPIO_SetPinDIR(LPC_GPIO_PORT, TEC_3_GPIO, TEC_3_BIT, false); Chip_SCU_PinMuxSet(TEC_4_PORT, TEC_4_PIN, SCU_MODE_INBUFF_EN | SCU_MODE_PULLUP | TEC_4_FUNC); Chip_GPIO_SetPinDIR(LPC_GPIO_PORT, TEC_4_GPIO, TEC_4_BIT, false); while (true) { if (Chip_GPIO_ReadPortBit(LPC_GPIO_PORT, TEC_1_GPIO, TEC_1_BIT) == 0) { Chip_GPIO_SetPinState(LPC_GPIO_PORT, LED_B_GPIO, LED_B_BIT, true); } else { Chip_GPIO_SetPinState(LPC_GPIO_PORT, LED_B_GPIO, LED_B_BIT, false); } current_state = (Chip_GPIO_ReadPortBit(LPC_GPIO_PORT, TEC_2_GPIO, TEC_2_BIT) == 0); if ((current_state) && (!last_state)) { Chip_GPIO_SetPinToggle(LPC_GPIO_PORT, LED_1_GPIO, LED_1_BIT); } last_state = current_state; if (Chip_GPIO_ReadPortBit(LPC_GPIO_PORT, TEC_3_GPIO, TEC_3_BIT) == 0) { Chip_GPIO_SetPinState(LPC_GPIO_PORT, LED_2_GPIO, LED_2_BIT, true); } if (Chip_GPIO_ReadPortBit(LPC_GPIO_PORT, TEC_4_GPIO, TEC_4_BIT) == 0) { Chip_GPIO_SetPinState(LPC_GPIO_PORT, LED_2_GPIO, LED_2_BIT, false); } divisor++; if (divisor == 5) { divisor = 0; Chip_GPIO_SetPinToggle(LPC_GPIO_PORT, LED_3_GPIO, LED_3_BIT); } for (int index = 0; index < 100; index++) { for (int delay = 0; delay < 25000; delay++) { __asm("NOP"); } } } } /* === End of documentation ==================================================================== */ /** @} End of module definition for doxygen */