TM4C123GH6PM | Blinking LED through Push button | Blinking LED through Switch | GPIO Switch | TIVAC Series

Blinking LED through Push button using TM4C Launch Pad

Programs

1)Program for TM4CGH6PM, to turn ON the RED LED when the button is pressed and turn OFF when it is released.


#include<stdint.h>
#include<stdbool.h>
#include"inc/hw_types.h"
#include"inc/hw_memmap.h"
#include"driverlib/sysctl.h"
#include"driverlib/gpio.h"
int main(void) {
    SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1);
    GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_4);
    GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_4, GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD_WPU);

    while (1) 
{
        if (!GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_4))

        {
            GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, 0x02);
        } 
else
{
            GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, 0x00);
        }
    }
}


2) Program for TM4CGH6PM,to turn ON the RED LED when the button is pressed and turn ON the GREEN LED when it is released

#include<stdint.h>
#include<stdbool.h>
#include"inc/hw_types.h"
#include"inc/hw_memmap.h"
#include"driverlib/sysctl.h"
#include"driverlib/gpio.h"
int main(void) {
    SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ| SYSCTL_OSC_MAIN);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_3);
    GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_4);
    GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_4, GPIO_STRENGTH_4MA,GPIO_PIN_TYPE_STD_WPU);

    while (1) {
        if (!GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_4))

        {
            GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_3,0x02);
        } 
else 
{
            GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_3,0x08);
        }
    }
}


3)Program for TM4CGH6PM  to make the GREEN LED stay ON for around 1sec every time when the button is pressed.

#include<stdint.h>
#include<stdbool.h>
#include"inc/hw_types.h"
#include"inc/hw_memmap.h"
#include"driverlib/sysctl.h"
#include"driverlib/gpio.h"
int main(void) {
    SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ| SYSCTL_OSC_MAIN);
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_3);
    GPIOPinTypeGPIOInput(GPIO_PORTF_BASE, GPIO_PIN_4);
    GPIOPadConfigSet(GPIO_PORTF_BASE, GPIO_PIN_4, GPIO_STRENGTH_4MA,GPIO_PIN_TYPE_STD_WPU);

    while (1) {
        if (GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_4))

        {
        GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3,0x00);
        } 
else 
{
            GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_3,0x08);
                        SysCtlDelay(13000000);
        }
    }
}



Procedure

1. Create a new folder on desktop location.

2. Open ccstudio on desktop.

3. Browse the workspace location

    Click on browseàdesktopàselect created folderàok button.

4. ccs wizard is opened

5.  Click on projectànew ccs projectàtarget [select Tiva c series]   select the micro controller “Tiva MC4123GH6PM” then connection as “Stellaris in-circuit debug interface”. Then type the project name and click the finish button in new CCS project.

6. Open restore on the left side and enter the program and click save button.

7. Click the GPIO in project explorer.

8.Click the GPIO project and right click then go to properties and select the include options then click add button and select browse.

9. Unfold the computer, open the local disk (c:) to select ‘ti’ and tivaware_c_series_2.1.2.111 after selecting click the ok button.

10. During the compilation process to import peripheral library files process, select the ok button and click on the ok button.

11. In order to add files to project select the project and click on the add files. Now by giving double click select the following,
local disc (c:)
àtiàTivaware_c_series_2.1.2.111àdriverlibàccsàdebug.

12. After debug, select & open the driverlib.lib and then click on the ok button and build the program.

13. Connect the switch in debug mode to Tiva series launch pad and connect the USB output then debug the program into launch pad and click resume button and observe the output.


TM4C123GH6PM Overall Documentation in video description

Video 👇







Comments