GPIO Interface

From Embedded Systems Learning Academy
Revision as of 01:37, 17 November 2012 by Preet (talk | contribs) (Created page with "This article shows how to use one of the pins on the SJ-One board as either an INPUT or OUTPUT pin. == Steps == Check to see if you have '''gpio.hpp''' in your project's ''...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This article shows how to use one of the pins on the SJ-One board as either an INPUT or OUTPUT pin.

Steps

Check to see if you have gpio.hpp in your project's L4_IO directory, if not, follow these steps :

  • Grab the GPIO header file from SourceForge SourceForge SJ-One Project
    You will get the gpio.hpp file
  • Put this in your Project's L4_IO directory


To use a pin for GPIO, see the source code example below :

/// Include the GPIO file
#include "gpio.hpp"

int main(void)
{
   /**
    * Locate a pin on your board that you'd 
    * like to use either as INPUT or OUTPUT
    * Let's use P1.19 (as labeled on the Board)
    *
    * You can use any other pins as defined by
    * LPC1758_GPIO enumeration at gpio.hpp file.
    */
    GPIO myPin(P1_19);   // Control P1.19
    myPin.setAsOutput(); // Use the pin as output pin

    // Let's blink an LED on P1.19 :
    while(1) {
        myPin.setHigh();     // Pin will now be at 3.3v
        delay_ms(100);

        myPin.setLow();      // Pin will now be at 0.0v
        delay_ms(100);
    }

    return 0;
}