FUN WITH LINUX

Running LED on a Tiva-Board TM4C1294XL

1 October 2015

For my studies I have to work with the Tiva-Board TM4C1294XL. I was quite lost when I tried to find examples in the internet. For all the poor souls who have to work with the tiva-board TM4C1294XL, I am going to publish the code I have to write on it. Here is some simple code for a runnig LED-light. If you push the USR1-button, it will change it’s direction.

#include 
#include  
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "drivers/pinout.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/rom_map.h"
#include "driverlib/sysctl.h"
#include "inc/tm4c1294ncpdt.h"

void WriteOut(uint8_t bitmask)
{

		GPIOPinWrite(GPIO_PORTN_BASE,GPIO_PIN_0 | GPIO_PIN_1,0x0);
		GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_0 | GPIO_PIN_4,0x0);

	if(bitmask == 0)
		return;


	if( (bitmask & 1) || (bitmask & 16) )
	{
		GPIOPinWrite(GPIO_PORTN_BASE,GPIO_PIN_0 | GPIO_PIN_1,0x2);
	}

	if( (bitmask & 2) || (bitmask & 32) )
	{
		GPIOPinWrite(GPIO_PORTN_BASE,GPIO_PIN_0 | GPIO_PIN_1,0x1);
	}

	if( (bitmask & 4) || (bitmask & 64) )
	{
		GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_0 | GPIO_PIN_4,0x10);
	}

	if( (bitmask & 8) || (bitmask & 128) )
	{
		GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_0 | GPIO_PIN_4,0x1);
	}
}


int
main(void)
{
	volatile int delay = 700000;
	volatile int direction = 1;
	volatile uint8_t runner = 1;
	uint32_t config_strength, config_type;

	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ);


	GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE,GPIO_PIN_0 | GPIO_PIN_1);
	GPIOPinWrite(GPIO_PORTN_BASE,GPIO_PIN_0 | GPIO_PIN_1,0x0);

	GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE,GPIO_PIN_0 | GPIO_PIN_4);
	GPIOPinWrite(GPIO_PORTF_BASE,GPIO_PIN_0 | GPIO_PIN_4,0x0);

	GPIOPinTypeGPIOInput(GPIO_PORTJ_BASE,GPIO_PIN_0);
	GPIOPadConfigGet(GPIO_PORTJ_BASE,GPIO_PIN_0,&config_strength,&config_type);
	GPIOPadConfigSet(GPIO_PORTJ_BASE,GPIO_PIN_0,config_strength,GPIO_PIN_TYPE_STD_WPU);

	if(direction == 1)
		runner = 0;


	WriteOut(0);

    while(1)
    {
    	if(GPIOPinRead(GPIO_PORTJ_BASE,GPIO_PIN_0) == 0)
    	{
    		if(direction == 0)
    			direction = 1;
    		else
    			richtung = 0;
    	}

        WriteOut(runner);

        SysCtlDelay(delay);

        if(direction == 0)
        {
        	if(runner == 0)
        		runner = 1;
        	else
        		runner = runner << 1;
        }
        else
        {
        	if(runner == 0)
        	       runner = 0x8;
        	else
        	       runner = runner >> 1;

        }

    }
}
[ Programming  C  TM4C1294XL  Hardware  Electronic  Microcontroller  ]
Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution 3.0 Unported License.

Copyright 2015-present Hoti