In this tutorial we will see how read a switch and trun ON/OFF the LED/Buzzer/Relay using the explore Embedded bare metal libraries. The libraries can be used on different platforms like Keil, ARM GCC, GCC And Eclipse etc.


Prerequisites

Please check this tutorial for detailed explanation on lpc1768 Gpio configuration.
If you are doing it for the first time, then check the below links to setup the project for generating the .bin file.

  1. Keil4 Setup
  2. Keil5 Setup
  3. ARM GCC Setup
  4. Eclipse & ARM GCC Setup



Hardware Connection

ExploreM3 comes with an USB_BOOT switch and on board led connected to pin 13.


Code

Below is the sample code to read the switch status and turn ON/OFF the LED.

#include "delay.h"
#include "gpio.h"
#include "stdutils.h"
#define LED 13 //LED is connected to pin 13 on Explore M3 board
int main()
{
SystemInit(); //Clock and PLL configuration
GPIO_PinFunction(LED,PINFUN_GPIO); // Configure Pin for Gpio
GPIO_PinDirection(LED,OUTPUT); // Configure the pin as OUTPUT
while(1)
{
GPIO_PinWrite(LED,HIGH); // Turn ON the Led
DELAY_ms(100); // Wait for some time
GPIO_PinWrite(LED,LOW); // Turn OFF the Led
DELAY_ms(100); // Wait for some time
}
}


Demo