0% found this document useful (0 votes)
18 views5 pages

ARMexp

The document contains five programs written in C for the LPC214X microcontroller, each demonstrating different LED control techniques. The programs include blinking a single LED, toggling multiple LEDs, alternating LED patterns, creating a Knight Rider effect, and implementing a binary counter with LEDs. Each program uses specific GPIO configurations and delay functions to achieve the desired LED behaviors.

Uploaded by

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

ARMexp

The document contains five programs written in C for the LPC214X microcontroller, each demonstrating different LED control techniques. The programs include blinking a single LED, toggling multiple LEDs, alternating LED patterns, creating a Knight Rider effect, and implementing a binary counter with LEDs. Each program uses specific GPIO configurations and delay functions to achieve the desired LED behaviors.

Uploaded by

subtlybeige
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

‭Program 1: Blinking a Single LED‬

‭#include<LPC214X.h>‬

‭void delay(unsigned int);‬

‭int main()‬
‭{‬
‭IODIR0 = 0X0010000; // Configure P0.16 as output‬
‭while(1)‬
‭{‬
‭IOSET0 = 0X0010000; // Set P0.16 (LED ON)‬
‭delay(20); // Delay‬
‭IOCLR0 = 0X0010000; // Clear P0.16 (LED OFF)‬
‭delay(20); // Delay‬
‭}‬
‭}‬

‭void delay(unsigned int i) {‬


‭int j, k;‬
‭for(j = 0; j < i; j++) // Outer delay loop‬
‭for(k = 0; k < 1275; k++); // Inner delay loop‬
‭}‬
‭Program 2: Toggling 8 LEDs‬

‭#include<LPC214X.h>‬

‭void wait (void) {‬


‭int d;‬
‭for (d = 0; d < 1000000; d++); // Software delay loop‬
‭}‬

‭int main() {‬
‭IODIR1 = 0x00FF0000; // Configure P1.16 to P1.23 as outputs‬
‭while(1)‬
‭{‬
‭IOSET1 = 0x00FF0000; // Set P1.16 to P1.23 (Turn all LEDs ON)‬
‭wait();‬
‭IOCLR1 = 0x00FF0000; // Clear P1.16 to P1.23 (Turn all LEDs OFF)‬
‭wait();‬
‭}‬
‭}‬
‭Program 3: Toggling Alternate LEDs‬

‭#include<LPC214X.h>‬

‭void delay(unsigned int);‬

‭int main() {‬
‭IODIR1 = 0X00FF0000; // Configure P1.16 to P1.23 as outputs‬
‭while(1)‬
‭{‬
‭IOSET0 = 0X00AA0000; // Turn ON alternate LEDs (binary 10101010)‬
‭IOCLR0 = 0X00550000; // Turn OFF alternate LEDs (binary 01010101)‬
‭delay(20);‬
‭IOSET0 = 0X00550000; // Turn ON alternate LEDs (binary 01010101)‬
‭IOCLR0 = 0X00AA0000; // Turn OFF alternate LEDs (binary 10101010)‬
‭delay(20);‬
‭}‬
‭}‬

‭void delay(unsigned int i) {‬


‭int j, k;‬
‭for(j = 0; j < i; j++)‬
‭for(k = 0; k < 1275; k++);‬
‭}‬
‭Program 4: LED Knight Rider Effect‬

‭#include <LPC21xx.H>‬

‭void wait (void) {‬


‭int d;‬
‭for (d = 0; d < 1000000; d++);‬
‭}‬

‭int main (void) {‬


‭unsigned int i;‬
‭IODIR1 = 0x00FF0000; // Configure P1.16 to P1.23 as outputs‬
‭while (1)‬
‭{‬
‭for (i = 1<<16; i < 1<<23; i <<= 1) // Shift LED ON from P1.16 to P1.23‬
‭{‬
‭IOSET1 = i;‬
‭wait();‬
‭IOCLR1 = i;‬
‭}‬
‭for (i = 1<<23; i > 1<<16; i >>=1) // Shift LED ON from P1.23 to P1.16‬
‭{‬
‭IOSET1 = i;‬
‭wait();‬
‭IOCLR1 = i;‬
‭}‬
‭}‬
‭}‬
‭Program 5: LED Binary Counter on ARM LPC2148‬

‭#include<LPC214X.h>‬

‭void delay(unsigned int);‬

‭int main() {‬
‭unsigned char count = 0; // Initialize counter variable‬
‭IODIR0 = 0x00FF0000; // Configure P0.16 to P0.23 as outputs‬
‭while(1)‬
‭{‬
‭IOSET0 = (count << 16); // Send counter value to LEDs‬
‭delay(20); // Delay‬
‭IOCLR0 = 0x00FF0000; // Clear LEDs‬
‭count++; // Increment the counter‬
‭if(count > 255) // Reset counter after 255‬
‭count = 0;‬
‭}‬
‭}‬

‭void delay(unsigned int i) {‬


‭int j, k;‬
‭for(j = 0; j < i; j++)‬
‭for(k = 0; k < 1275; k++);‬
‭}‬

You might also like