Actions

EmSys

CCS Add files to your project

From EdWiki

Add files to your project

New C Source File

We need to add main.c to the project.

► Select File → New → Source File







New C Source File

► In the Next Dialog box :

  • Source file : main.c
  • Template : choose Default C source template
  • Click Finish.







► Copy the following code and paste it into the newly created main.c file.

Blinky Program

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