|
|
(68 intermediate revisions by 3 users not shown) |
Line 1: |
Line 1: |
− | [[category: ARM Tutorials]] | + | #REDIRECT [[LPC1768: Led Blinking]] |
− | [[User:Amruta|Amruta]] ([[User talk: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.
| + | |
− | | + | |
− | If you take look at this header file, you will notice that all registers associated with a peripheral are clubbed together in a structure. So to access a register we need to use the respective structure
| + | |
− | | + | |
− | e.g. LPC_PINCON->PINSELx for PINSEL register,
| + | |
− | | + | |
− | LPC_GPIO1->FIOSET for GPIO register, etc.
| + | |
− | | + | |
− | ====PINSEL and GPIO====
| + | |
− | | + | |
− | =Schematic=
| + | |
− | =Code=
| + | |
− | | + | |
− | In this code, we will demonstrate LED and Switch interfacing with the LPC1768.
| + | |
− | We will monitor the switch condition and will glow LED when switch is pressed.
| + | |
− | | + | |
− | <syntaxhighlight>
| + | |
− | | + | |
− | #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
| + | |
− | }
| + | |
− | }
| + | |
− | | + | |
− | | + | |
− | {{DISQUS}}
| + | |