-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsing_all_LEDs.c
More file actions
58 lines (46 loc) · 1.35 KB
/
Using_all_LEDs.c
File metadata and controls
58 lines (46 loc) · 1.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Including LPC17xx header file for LPC1768 microcontroller
#include <LPC17xx.h>
// Including standard integer types for uint32_t
#include <stdint.h>
// Define macro for all LED pins from P1.19 to P1.26
#define ALL_LED_PINS (0xFF << 19)
// Function prototype for delay function
void delay(uint32_t );
// Main function
int main(void)
{
// Set pins P1.19 to P1.26 as outputs for LEDs
LPC_GPIO1 -> FIODIR |= ALL_LED_PINS;
// Infinite loop for toggling all LEDs
while(1)
{
// Set all LED pins high to turn on all LEDs
LPC_GPIO1 -> FIOSET = ALL_LED_PINS;
// Call delay function to create delay
delay(500);
// Clear all LED pins to turn off all LEDs
LPC_GPIO1 -> FIOCLR = ALL_LED_PINS;
// Call delay function to create delay
delay(500);
}
// Return 0 to indicate successful completion
return 0;
}
// Function to create delay
void delay(uint32_t ms)
{
// Declare variables for loop iteration
uint32_t i, j, k;
// Loop for the given number of milliseconds
for(i = 0 ; i < ms ; i++)
{
// Nested loop for delay
k = 0 ;
for(j = 0 ; j < 3000 ; j++)
{
k++ ;
}
}
// Return from the function
return ;
}