Watch the video and/or get the code below.
Relevant Links:
- Stellaris LM4F120H5QR Microcontroller Data Sheet
- Stellaris LM4F120 LaunchPad Evaluation Board User Manual
Blink The Red LED Code:
#include <lm4f120h5qr.h> void wait(void); int main() { // General-Purpose Input/Output Run Mode Clock Gating Control (RCGCGPIO), pg. 315 SYSCTL_RCGCGPIO_R |= 0x20U; // activate the clock for port f // GPIO Lock (GPIOLOCK), pg. 645 GPIO_PORTF_LOCK_R = 0x4C4F434BU; // unlock the lock register // GPIO Commit (GPIOCR), pg. 646 GPIO_PORTF_CR_R = 0xFF; // enable commit for PORT F // GPIO Analog Mode Select (GPIOASMSEL), pg. 648 GPIO_PORTF_AMSEL_R = 0x00U; // disable analog functionality // GPIO Port Control (GPIOPCTL), pg. 649 GPIO_PORTF_PCTL_R = 0x00000000U; // configure port f as GPIO // GPIO Direction (GPIODIR), pg. 624 GPIO_PORTF_DIR_R = 0x0EU; // 0xE = 01110 make PF3, PF2, and PF1 output // GPIO Alternate Function Select (GPIOAFSEL), pg. 633 GPIO_PORTF_AFSEL_R = 0x00U; // disable alternate functions // GPIO Digital Enable (GPIODEN), pg. 643 GPIO_PORTF_DEN_R = 0xFFU; // enable digital on all pins in PORTF while(1) { GPIO_PORTF_DATA_R &= ~0x0E; // 0E = 00001110, so ~0E = 11110001 turn off the three leds wait(); GPIO_PORTF_DATA_R |= 0x02; // turn on the red led wait(); } return 0; } void wait(void) { for(int i=0;i<1000000;i++); }