Select Page

Blinky

EK-TM4C123GXL Blinky Program

  1. /* 
  2. Toggling LEDs using special function registers by their names defined in the TivaWare header file
  3. Runs on TI EK-TM4C123GXl LaunchPad Board
  4. */
  5. 
    
  6. 
    
  7. #include <stdint.h>
  8. #include "inc/tm4c123gh6pm.h"
  9. 
    
  10. void delayMs(int n);
  11. 
    
  12. int main(void)
  13. {
  14.     SYSCTL_RCGC2_R |= 0x00000020;     /* enable clock to GPIOF at clock gating control register */
  15. 
    
  16.     GPIO_PORTF_DIR_R = 0x0E;          /* enable the GPIO pins for the LED (PF3, 2, 1) as output */
  17.     GPIO_PORTF_DEN_R = 0x0E;         /* enable the GPIO pins for digital function */
  18. 
    
  19.     while(1) {
  20.         GPIO_PORTF_DATA_R = 0x0E;     /* turn on all LEDs */
  21.         delayMs(500);
  22.         GPIO_PORTF_DATA_R = 0;        /* turn off all LEDs */
  23.         delayMs(500);
  24.     }
  25. }
  26. 
    
  27. /* delay n milliseconds (16 MHz CPU clock) */
  28. void delayMs(int n)
  29. {
  30.     int i, j;
  31.     for(i = 0 ; i < n; i++)
  32.         for(j = 0; j < 3180; j++) {}   /* do nothing for 1 ms */
  33. }
    

    See Also

    1. TM4C123GH6PM GPIO Programming
    2. EK-TM4C123GXL LaunchPad Board
    3. Switch Inputs and LED Outputs in TM4C123