Lecture_14_15
Lecture_14_15
System and
Design
D R M A N OJ TO LA N I ( P H D -IIIT A L L A H A BA D )
A S S I STAN T P RO F E S S OR ( D E PA RTME NT O F I CT )
GPIO Programming & Examples
Lets say we want to set PIN 3 on Port 0 as output. It can be done in following ways:
GPIO Programming & Examples
Lets say we want to set PIN 3 on Port 0 as output. It can be done in following ways:
Example #1)
Consider that we want to configure Pin 4 of Port 0 i.e P0.4 as Ouput and want to drive it High(Logic
1). This can be done as :
Example #1)
Consider that we want to configure Pin 4 of Port 0 i.e P0.4 as Ouput and want to drive it High(Logic
1). This can be done as :
Example #2)
Making output configured Pin 17 High of Port 0 i.e P0.17 and then Low can be does as follows:
Example #2)
Making output configured Pin 17 High of Port 0 i.e P0.17 and then Low can be does as follows:
Example #3)
Configuring P0.5 and P0.11 as Ouput and Setting them High:
Example #3)
Configuring P0.5 and P0.11 as Ouput and Setting them High:
Example #4)
Configuring 1st 8 Pins of Port 0 (P0.0 to P0.7) as Output and Setting them High:
Example #4)
Configuring 1st 8 Pins of Port 0 (P0.0 to P0.7) as Ouput and Setting them High:
GPIO (General Purpose Input/Output)
Ex: Send 0xA5 to P0.15-P0.8 without affecting values on the remaining pins.
This can be accomplished in several ways
Configure P0.1 with Function-01 and P0.15 with Function-02, Value to be loaded to PINSEL
Configure P0.17 with Function-03 and P0.30 with Function-01, Value to be loaded to PINSEL
Configure P2.3 with Function-01 and P2.14 with Function-02, Value to be loaded to PINSEL
Configure P2.17 with Function-03 and P2.5 with Function-01, Value to be loaded to PINSEL
Answer: PINSEL5=3<<2
PINSEL4=1<<10
Send 0xA5 to P0.15-P0.8 without affecting values on the remaining pins. Use FIOMASK and FIOPIN
Answer: FIOMASK=0xFFFF00FF;
FIOPIN=0x0000A500;
Initial pins instruction 0x78560743. Send 0xA5 to P0.23-P0.16 without affecting values on the remaining pins (Instructions). Use
FIOMASK and FIOPIN and find the value of the pins instruction after execution
Answer: FIOMASK=0xFF00FFFF;
FIOPIN=0x00A50000;
Pin o/p after instruction 0x78A50743
LPC_GPIO0->FIOPIN | = 3F<<20
0 0 1 1 1 1 1 1
LPC_GPIO0->FIOPIN | = 2E<<4
0 0 1 0 1 1 1 0
Write an embedded C program to turn ON and OFF LEDs P0.11
connected to P0.11 – P0.4
P0.10
#include <LPC17xx.h>
L P0.9
Variable Initialization
P
int main(void) C P0.8
{
1
i/o Pin selection and Pin Direction 7 P0.7
6
while(1)
{
8 P0.6
} P0.4
}
GPIO (General Purpose Input/Output)
P0.11
Write an embedded C program to turn ON and OFF LEDs connected to P0.11 – P0.4
#include <LPC17xx.h>
unsigned int j; P0.10
unsigned long LED = 0x00000FF0;
LED<<=1
OR
LED=LED<<1
After Execution
LED = 0x00000020
for(j=0;j<10000;j++);
LED <<= 1;
}
LED = 0x00000010;
}
}