0% found this document useful (0 votes)
60 views4 pages

LED Blinking and Ring Counter Code Examples

The document describes four programs to blink LEDs using different ports on an LPC17xx microcontroller. The first program blinks a single LED connected to port P2 pin 11. The second program blinks three LEDs connected to port P2 pins 11, 12, and 13 using byte access. The third program blinks eight LEDs connected to port P0 pins 21 through 28 using half word registers. The fourth program implements a ring counter using six bits and eight ports to sequentially turn on the LEDs. All programs use delays to blink the LEDs in a continuous loop.

Uploaded by

Vignesh Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views4 pages

LED Blinking and Ring Counter Code Examples

The document describes four programs to blink LEDs using different ports on an LPC17xx microcontroller. The first program blinks a single LED connected to port P2 pin 11. The second program blinks three LEDs connected to port P2 pins 11, 12, and 13 using byte access. The third program blinks eight LEDs connected to port P0 pins 21 through 28 using half word registers. The fourth program implements a ring counter using six bits and eight ports to sequentially turn on the LEDs. All programs use delays to blink the LEDs in a continuous loop.

Uploaded by

Vignesh Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

1- To make an LED blink continuously at port P2 (11):

#include <LPC17xx.H>

void delay(unsigned long int x);

int main()
{
SystemInit();
LPC_SC->PCONP&=0X00008000;
LPC_GPIO2->FIOMASK=0XFFFFF7FF;
LPC_GPIO2->FIODIR=0X00000800;

while(1)
{
LPC_GPIO2->FIOSET=0X00000800;
delay(0x2000000);
LPC_GPIO2->FIOCLR=0X00000800;
delay(0x2000000);

}
}

void delay(unsigned long int x)


{
unsigned long int i=0;
for(i=0;i<x;i++);
}
2- To blink 3 LEDs continuously connected at port P2 (11, 12 & 13), use ports with byte access:

#include <LPC17xx.H>

void delay(unsigned long int x);

int main()
{
SystemInit();
LPC_SC->PCONP&=0X00008000;
LPC_GPIO2->FIOMASK1=0XC7;
LPC_GPIO2->FIODIR1=0X38;

while(1)
{
LPC_GPIO2->FIOSETH=0X38;
delay(0x2000000);
LPC_GPIO2->FIOCLRH=0X38;
delay(0x2000000);

}
}

void delay(unsigned long int x)


{
unsigned long int i=0;
for(i=0;i<x;i++);
}
3- To blink 8 LEDs continuously connected at port P0 (21 to 28), use all the registers of GPIO as half
word size:

#include <LPC17xx.H>

void delay(unsigned long int x);

int main()
{
SystemInit();
LPC_SC->PCONP&=0X00008000;
LPC_GPIO0->FIOMASKH=0XE01F;
LPC_GPIO0->FIODIRH=0X1FE0;

while(1)
{
LPC_GPIO0->FIOSETH=0X1FE0;
delay(0x500000);
LPC_GPIO0->FIOCLRH=0X1FE0;
delay(0x500000);

}
}

void delay(unsigned long int x)


{
unsigned long int i=0;
for(i=0;i<x;i++);
}
4- Using 8 ports, design a Ring Counter using 6-bit counter:

#include <LPC17xx.H>

void delay(unsigned long int x);

int main()
{
SystemInit();
LPC_SC->PCONP&=0X00008000;
LPC_GPIO2->FIOMASKH=0XF81F;
LPC_GPIO2->FIODIRH=0X07E0;

while(1)
{
LPC_GPIO2->FIOSETH=0X0400;
delay(0x500000);
LPC_GPIO2->FIOCLRH=0X0200;
delay(0x500000);
LPC_GPIO2->FIOCLRH=0X0100;
delay(0x500000);
LPC_GPIO2->FIOCLRH=0X0080;
delay(0x500000);
LPC_GPIO2->FIOCLRH=0X0040;
delay(0x500000);
LPC_GPIO2->FIOCLRH=0X0020;
delay(0x500000);

}
}

void delay(unsigned long int x)


{
unsigned long int i=0;
for(i=0;i<x;i++);
}

You might also like