m
m
Line 5: Line 5:
 
=Basics=
 
=Basics=
 
===lpc17xx header file===
 
===lpc17xx header file===
 +
This is peripheral access header file for NXP LPC17xx device series. It contains all required register and peripheral definitions which one requires in order to access any peripheral.
  
 
===PINSEL and GPIO===
 
===PINSEL and GPIO===

Revision as of 12:05, 17 March 2015

Amruta (talk) 11:24, 17 March 2015 (IST)


Basics

lpc17xx header file

This is peripheral access header file for NXP LPC17xx device series. It contains all required register and peripheral definitions which one requires in order to access any peripheral.

PINSEL and GPIO

Schematic

Code

  1. #include "lpc17xx.h" // NXP Library containing all port abd register definations
  2. #include "stdutils.h" // Explore Embedded library
  3.  
  4. #define LED 29 //P1.29
  5. #define SWITCH 28 //P1.28
  6. int main()
  7. {
  8. SystemInit();
  9.  
  10. LPC_PINCON->PINSEL3 = 0x00; // Configure Pin as GPIO
  11. util_BitSet(LPC_GPIO1->FIODIR,LED); // Set pin direction as output
  12. util_BitClear (LPC_GPIO1->FIODIR,SWITCH); // Set pin direction as input
  13.  
  14. while(1)
  15. {
  16. if (util_IsBitCleared (LPC_GPIO1->FIOPIN,SWITCH)) // check if switch is pressed
  17. util_BitSet (LPC_GPIO1->FIOSET,LED); // turn on LED
  18. else
  19. util_BitSet (LPC_GPIO1->FIOCLR,LED); // turn off LED
  20. }
  21. }