-
Notifications
You must be signed in to change notification settings - Fork 163
/
Copy pathmain.c
37 lines (29 loc) · 1.13 KB
/
main.c
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
#include "tm4c.h" // the same as "lm4f120h5qr.h" in the video
#define LED_RED (1U << 1)
#define LED_BLUE (1U << 2)
#define LED_GREEN (1U << 3)
int main(void) {
SYSCTL_GPIOHBCTL_R |= (1U << 5); /* enable AHB for GPIOF */
SYSCTL_RCGCGPIO_R |= (1U << 5); /* enable clock for GPIOF */
GPIO_PORTF_AHB_DIR_R |= (LED_RED | LED_BLUE | LED_GREEN);
GPIO_PORTF_AHB_DEN_R |= (LED_RED | LED_BLUE | LED_GREEN);
/* start with turning all LEDs off (note the use of array []) */
GPIO_PORTF_AHB_DATA_BITS_R[LED_RED | LED_BLUE | LED_GREEN] = 0;
GPIO_PORTF_AHB_DATA_BITS_R[LED_BLUE] = LED_BLUE;
while (1) {
//*((unsigned long volatile *)(0x40025000 + (LED_RED << 2))) = LED_RED;
//*(GPIO_PORTF_DATA_BITS_R + LED_RED) = LED_RED;
GPIO_PORTF_AHB_DATA_BITS_R[LED_RED] = LED_RED;
int volatile counter;
counter = 0;
while (counter < 1000000) { // delay loop
++counter;
}
GPIO_PORTF_AHB_DATA_BITS_R[LED_RED] = 0;
counter = 0;
while (counter < 1000000) { // delay loop
++counter;
}
}
//return 0; // unreachable code
}