Interfacing LED and Switch
with ARM LPC2148
Dr. P. T. Karule
Professor
Department of Electronics Engineering,
Yeshwantrao Chavan College of Engineering,
Nagpur – 441 110
4-Oct-21 [email protected] 1
Q. Write program to blink LED connected to P0.10
XTAL 1
12MHz
XTAL 2
22pF
3.3 V VDD
VSS
P0.10
ARM
LPC 2148
4-Oct-21 [email protected] 2
Q. Write program to blink LED connected to P0.10
#include <lpc214x.h> //include header files for LPC-214x series
void delay_ms(unsigned int count)
{
unsigned int j=0,i=0;
for(j=0;j<count;j++) //For loop to create delay
{
for(i=0;i<3000;i++);
}
}
4-Oct-21 [email protected] 3
Q. Write program to blink LED connected to P0.10
main ()
{
IO0DIR = (1<<10); //Configure the pin P0.10 as OUTPUT;
while(1) // While loop to execute program continueously
{
IO0SET = (1<<10) ; // Make the pin P0.10 HIGH (LED ON)
delay_ms(1000);
IO0CLR = (1<<10); // Make the pin P0.10 LOW (LED OFF)
delay_ms(1000);
}
}
4-Oct-21 [email protected] 4
Q. Write program to turn ON LED if Switch is pressed, LED is 3.3 V
Connected to P1.16 and Switch is connected to P0.16
XTAL 1
12MHz
P0.16
XTAL 2
22pF
Key
3.3 V VDD
VSS
P1.16
ARM
LPC 2148
4-Oct-21 [email protected] 5
Q. Write program to turn ON LED if Switch is pressed, LED is connected to P1.16 and
Switch is connected to P0.16
#include<lpc214x.h>
void main()
{
IO1DIR =0X00010000; //Port 1.16 is now acting as a output pin
IO0DIR = 0xFFFEFFFF; //Port 0.16 is now acting as a input pin
while(1)
{
if((IO0PIN & (1<<16)) ==0) //Checking 16th pin of Port 0 (P0.16=0)
IO1SET =0X00010000; //Port 1.16 high now (LED is glowing)
else
IO1CLR =0X00010000; //Port 1.16 low now (LED is OFF)
}
}
4-Oct-21 [email protected] 6
Q. Interface 8 LED to P0.0 to P0.7 and write program to blink
LED
XTAL 1
P0.0
P0.1
P0.2
XTAL 2
P0.3
P0.4
P0.5
3.3 V VDD P0.6
VSS
P0.7
ARM
LPC 2148
7
Q. Interface 8 LED to P0.0 to P0.7 and write program to blink
#include<lpc214x.h>
void delay();
void main()
{
IO0DIR |=0X000000FF; //Port 0 is now acting as a output pin
while(1)
{
IOSET0 |=0X000000FF; //Port 0's all pins are high now (LED is glowing)
delay();
IOCLR0 |=0X000000FF; //Port 0's all pins are low now (LED is OFF)
delay();
}
}
void delay()
{
unsigned int i;
for(i=0;i<90000;i++);
}
4-Oct-21 [email protected] 8
Q. Interface 8 LED to P0.0 to P0.7 and write program to blink alternate LED
#include<lpc214x.h>
void delay();
void main()
{
IO0DIR |=0X000000FF; //Port 0 is now acting as a output pin
while(1)
{
IOSET0 |=0X000000AA; //Port 0's alternate pins are high now (LED is glowing)
delay();
IOCLR0 |=0X000000FF; //Port 0's all pins are low now (LED is OFF)
IOSET0 |=0X00000055; //Port 0's alternate pins are high now (LED is glowing)
delay();
IOCLR0 |=0X000000FF; //Port 0's all pins are low now (LED is OFF)
}
}
void delay()
{
unsigned int i;
for(i=0;i<90000;i++);
}
4-Oct-21 [email protected] 9
C1
U1
22p 62 19
XTAL1 P0.0/TxD0/PWM1
Q. Interface 8 LED to X1 61 21
XTAL2 P0.1/RxD0/PWM3/EINT0
CRYSTAL 22
C2 3
P0.2/SCL0/CAP0.0
26
RTXC1 P0.3/SDA0/MAT0..0/EINT1
P0.0 to P0.7 and
5 27
RTXC2 P0.4/SCK0/CAP0.1/AD0.6
29
P0.5/MISO0/MAT0.1/AD0.7
22p 57 30
RST P0.6/MOSI0/CAP0.2/AD1.0
write program to blink
31
P0.7/SSEL0/PWM2/EINT2
33
P0.8/TxD1/PWM4/AD1.1
34
P0.9/RxD1/PWM6/EINT3
alternate LED
35
P0.10/RTS1/CAP1.0/AD1.2
R1 P0.11/CTS1/CAP1.1/SCL1
37
10k 38
P0.12/DSR1/MAT1.0/AD1.3
39
P0.13/DTR1/MAT1.1/AD1.4
41
P0.14/DCD1/EINT1/SDA1
45
P0.15/RI1/EINT2/AD1.5
46
P0.16/EINT0/MAT0.2/CAP0.2
47
P0.17/CAP1.2/SCK1/MAT1.2
53
P0.18/CAP1.3/MISO1/MAT1.3
54
P0.19/MAT1.2/MOSI1/CAP1.2
55
P0.20/MAT1.3/SSEL1/EINT3
Simulation using SW1
SW-SPST
P0.21/PWM5/AD1.6/CAP1.3
P0.22/AD1.7/CAP0.0/MAT0.0
P0.23
1
2
58
Proteus SW P0.25/AD0.4/AOUT
P0.26/AD0.5
9
10
11
P0.27/AD0.0/CAP0.1/MAT0.1
13
P0.28/AD0.1/CAP0.2/MAT0.2
14
P0.29/AD0.2/CAP0.3/MAT0.3
15
P0.30/AD0.3/EINT3/CAP0.0
17
P0.31
16
P1.16/TRACEPKT0
12
P1.17/TRACEPKT1
49 8
VBAT P1.18/TRACEPKT2
4
P1.19/TRACEPKT3
63 48
VREF P1.20/TRACESYNC
7 44
V3A P1.21/PIPESTAT0
51 40
V3 P1.22/PIPESTAT1
43 36
V3 P1.23/PIPESTAT2
23 32
V3 P1.24/TRACECLK
28
P1.25/EXTIN0
59 24
VSSA P1.26/RTCK
BAT1 50
VSS P1.27/TDO
64
3.3V 42 60
VSS P1.28/TDI
25 56
VSS P1.29/TCK
18 52
VSS P1.30/TMS
6 20
VSS P1.31/TRST
4-Oct-21 [email protected] 10
LPC2138
Q. Interface 8 LED to P0.0 to P0.7 and Switch to P1.16
LED
XTAL 1
P0.0
P0.1
P0.2
XTAL 2
P0.3
P0.4
P0.5
3.3 V VDD P0.6
VSS
P0.7
3.3 V
P1.16
Switch
ARM
LPC 2148
11
Q. Write program to turn ON LED’s if Switch is pressed, 8 LED are connected to P0.0 to
P0.7 and Switch is connected to P1.16
#include<lpc214x.h>
void main()
{
IO1DIR =0XFFFEFFFF; //Port 1.16 is now acting as a input pin
IO0DIR = 0x000000FF; //P0.0 to P0.7 are now acting as an output pins
while(1)
{
if((IO1PIN & (1<<16)) ==0) //Checking 16th pin of Port 1 (P1.16=0)
IO0SET =0X000000FF; // P0.0 to P0.7 high now (LED is glowing)
else
IO0CLR = 0X000000FF; // P0.0 to P0.7 low now (LED is OFF)
}
}
4-Oct-21 [email protected] 12
C1
U1
Q. Write program to turn 22p
X1
62
61
XTAL1
XTAL2
P0.0/TxD0/PWM1
P0.1/RxD0/PW M3/EINT0
19
21
22
CRYSTAL
ON LED’s if Switch is C2 P0.2/SCL0/CAP0.0
3 26
RTXC1 P0.3/SDA0/MAT0..0/EINT1
5 27
RTXC2 P0.4/SCK0/CAP0.1/AD0.6
29
pressed, 8 LED are
P0.5/MISO0/MAT0.1/AD0.7
22p 57 30
RST P0.6/MOSI0/CAP0.2/AD1.0
31
P0.7/SSEL0/PW M2/EINT2
33
connected to
P0.8/TxD1/PW M4/AD1.1
34
P0.9/RxD1/PW M6/EINT3
35
P0.10/RTS1/CAP1.0/AD1.2
R1 37
P0.0 to P0.7 and Switch
P0.11/CTS1/CAP1.1/SCL1
10k 38
P0.12/DSR1/MAT1.0/AD1.3
39
P0.13/DTR1/MAT1.1/AD1.4
41
is connected to P1.16
P0.14/DCD1/EINT1/SDA1
45
P0.15/RI1/EINT2/AD1.5
46
P0.16/EINT0/MAT0.2/CAP0.2
47
P0.17/CAP1.2/SCK1/MAT1.2
53
P0.18/CAP1.3/MISO1/MAT1.3
54
P0.19/MAT1.2/MOSI1/CAP1.2
55
Simulation using
P0.20/MAT1.3/SSEL1/EINT3
1
P0.21/PWM5/AD1.6/CAP1.3
SW1 P0.22/AD1.7/CAP0.0/MAT0.0
2
58
Proteus SW
SW-SPST P0.23
9
P0.25/AD0.4/AOUT
10
P0.26/AD0.5
11
P0.27/AD0.0/CAP0.1/MAT0.1
13
P0.28/AD0.1/CAP0.2/MAT0.2
14
P0.29/AD0.2/CAP0.3/MAT0.3
15
P0.30/AD0.3/EINT3/CAP0.0
17
P0.31 SW2
16
P1.16/TRACEPKT0
12 SW-SPST
P1.17/TRACEPKT1
49 8
VBAT P1.18/TRACEPKT2
4
P1.19/TRACEPKT3
63 48
VREF P1.20/TRACESYNC
7 44
V3A P1.21/PIPESTAT0
51 40
V3 P1.22/PIPESTAT1
43 36
V3 P1.23/PIPESTAT2
23 32
V3 P1.24/TRACECLK
28
P1.25/EXTIN0
59 24
VSSA P1.26/RTCK
BAT1 50
VSS P1.27/TDO
64
3.3V 42 60
VSS P1.28/TDI
25 56
VSS P1.29/TCK
18 52
VSS P1.30/TMS
4-Oct-21 [email protected] VSS P1.31/TRST
20 13
LPC2138