Difference between revisions of "IO Operations"
| m | m | ||
| Line 18: | Line 18: | ||
|          SystemInit(); |          SystemInit(); | ||
| − | 	LPC_PINCON->PINSEL3 = 0x00;	 | + | 	LPC_PINCON->PINSEL3 = 0x00;			   // Configure Pin as GPIO | 
| − | 	util_BitSet(LPC_GPIO1->FIODIR,LED);	 | + | 	util_BitSet(LPC_GPIO1->FIODIR,LED);	   	   // Set pin direction as output | 
| − | 	util_BitClear (LPC_GPIO1->FIODIR,SWITCH);	// Set pin direction as input | + | 	util_BitClear (LPC_GPIO1->FIODIR,SWITCH);	   // Set pin direction as input | 
| 	while(1) | 	while(1) | ||
| 	{		 | 	{		 | ||
| 		if (util_IsBitCleared (LPC_GPIO1->FIOPIN,SWITCH))	// check if switch is pressed | 		if (util_IsBitCleared (LPC_GPIO1->FIOPIN,SWITCH))	// check if switch is pressed | ||
| − | 			util_BitSet (LPC_GPIO1->FIOSET,LED);	 | + | 			util_BitSet (LPC_GPIO1->FIOSET,LED);	   // turn on LED	 | 
| 		else | 		else | ||
| − | 			util_BitSet (LPC_GPIO1->FIOCLR,LED);	 | + | 			util_BitSet (LPC_GPIO1->FIOCLR,LED);	// turn off LED	 | 
| 	} | 	} | ||
| } | } | ||
Revision as of 11:55, 17 March 2015
Amruta (talk) 11:24, 17 March 2015 (IST)
Basics
Code
#include "lpc17xx.h" // NXP Library containing all port abd register definations #include "stdutils.h" // Explore Embedded library #define LED 29 //P1.29 #define SWITCH 28 //P1.28 int main() { SystemInit(); LPC_PINCON->PINSEL3 = 0x00; // Configure Pin as GPIO util_BitSet(LPC_GPIO1->FIODIR,LED); // Set pin direction as output util_BitClear (LPC_GPIO1->FIODIR,SWITCH); // Set pin direction as input while(1) { if (util_IsBitCleared (LPC_GPIO1->FIOPIN,SWITCH)) // check if switch is pressed util_BitSet (LPC_GPIO1->FIOSET,LED); // turn on LED else util_BitSet (LPC_GPIO1->FIOCLR,LED); // turn off LED } }
