Saturday, January 22, 2022

Sw1 Press [On] Red LED (w/ Video)

 


/*

    
Testing Board #1

*/

#include "TM4C123GH6PM.h"


int main(void)

{

   unsigned int state;

   SYSCTL->RCGCGPIO |= 0x20;   /* enable clock to GPIOF */

   GPIOF->LOCK = 0x4C4F434B;   // unlockGPIOCR register

   GPIOF->CR = 0x01;           // Enable GPIOPUR register enable to commit

   GPIOF->PUR |= 0x10;        // Enable Pull Up resistor PF4

   GPIOF->DIR |= 0x02;          //set PF1 as an output and PF4 as an input pin

   GPIOF->DEN |= 0x12;         // Enable PF1 and PF4 as a digital GPIO pins 


    while(1)

    {   

        state = GPIOF->DATA & 0x10;

        GPIOF->DATA = (~state>>3);    /* put it on red LED */

    }

}


Friday, January 21, 2022

Blinking Red LED (w/ Video)



 /* Defines boolean and integer data types */

#include <stdbool.h>

#include <stdint.h>

#include "inc/tm4c123gh6pm.h"


#define delay_value 100000000 // change blink speed here


int main(void)

{

/* Delay Loop variable */

volatile unsigned long ulLoop;

/* Enable the GPIO port that is used for the onboard LED */

SYSCTL_RCGC2_R = SYSCTL_RCGC2_GPIOF;

/* Do a dummy read to insert a few cycles after peripheral enable */

ulLoop = SYSCTL_RCGC2_R;

/* Enable the GPIO pin for the LED (PF1)

* Set the direction as output, and enable the GPIO pin for

* digital function. Care is taken to not disrupt the

* operation of the JTAG pins on PC0-PC3 */

GPIO_PORTF_DIR_R |= 0x02;  //set PF1 as an output and PF4 as an input pin

GPIO_PORTF_DEN_R |= 0x02;

GPIO_PORTF_AFSEL_R = 0x00;

/* Loop forever */

while(1)

{

/* Turn on the LED */

GPIO_PORTF_DATA_R |= 0x02;

/* Delay for a 100ms */

for(ulLoop = 0; ulLoop < delay_value; ulLoop++)

{

}

/* Turn off the LED */

GPIO_PORTF_DATA_R &=~ 0x02; // &= ˜(0x02) <-- Incorrect

/* Delay for a 100ms */

for(ulLoop = 0; ulLoop < delay_value; ulLoop++)

{

}

}

}