Greetings
I have a very basic program to toggle the led for every 100ms if switch 1 ( PW 4 ) is pressed
other wise the led should remain on
*Im sorry about the inconvenience caused by incomplete info, Will make things clearer from now (sorry, firstpost) *
The entire code is here :
// BranchingFunctionsDelays.c Lab 6
// Runs on LM4F120/TM4C123
// Use simple programming structures in C to
// toggle an LED while a button is pressed and
// turn the LED on when the button is released.
// This lab will use the hardware already built into the LaunchPad.
// Daniel Valvano, Jonathan Valvano
// January 15, 2016
// built-in connection: PF0 connected to negative logic momentary switch, SW2
// built-in connection: PF1 connected to red LED
// built-in connection: PF2 connected to blue LED
// built-in connection: PF3 connected to green LED
// built-in connection: PF4 connected to negative logic momentary switch, SW1
#include "TExaS.h"
#define GPIO_PORTF_DATA_R (*((volatile unsigned long *)0x400253FC))
#define GPIO_PORTF_DIR_R (*((volatile unsigned long *)0x40025400))
#define GPIO_PORTF_AFSEL_R (*((volatile unsigned long *)0x40025420))
#define GPIO_PORTF_PUR_R (*((volatile unsigned long *)0x40025510))
#define GPIO_PORTF_DEN_R (*((volatile unsigned long *)0x4002551C))
#define GPIO_PORTF_AMSEL_R (*((volatile unsigned long *)0x40025528))
#define GPIO_PORTF_PCTL_R (*((volatile unsigned long *)0x4002552C))
#define SYSCTL_RCGC2_R (*((volatile unsigned long *)0x400FE108))
#define SYSCTL_RCGC2_GPIOF 0x00000020 // port F Clock Gating Control
// basic functions defined at end of startup.s
void DisableInterrupts(void); // Disable interrupts
void EnableInterrupts(void); // Enable interrupts
// function to delay for 100ms
void Delay100ms()
{
unsigned long i;
i = 1333333;
while(i > 0)
i = i - 1;
}
int main(void){ unsigned long volatile delay;
TExaS_Init(SW_PIN_PF4, LED_PIN_PF2); // activate grader and set system clock to 80 MHz
// initialization goes here
SYSCTL_RCGC2_R |= 0x00000020; // 1) activate clock for Port F
delay = SYSCTL_RCGC2_R; // allow time for clock to start
GPIO_PORTF_AMSEL_R = 0x00; // 3) disable analog on PF
GPIO_PORTF_PCTL_R = 0x40004050; // clear PF 4 n PF 2 clear pctl to set as GPIO
GPIO_PORTF_DIR_R = 0x04; // setting dir reg for PF4 - 0 n PF2 1
GPIO_PORTF_AFSEL_R = 0x00; // clear afsel for disabling alternate func
GPIO_PORTF_DEN_R = 0x14; // enable digital I/O on PF4 & PF2
GPIO_PORTF_PUR_R = 0x11; // enable pull-up on PF0 and PF4
GPIO_PORTF_DATA_R = 0X01; // set pf2 bit high for led to be on
EnableInterrupts(); // enable interrupts for the grader
while(1)
{
Delay100ms(1); // delay for 100ms
Delay100ms(1); // delay for 100ms
Delay100ms(1); // delay for 100ms
Delay100ms(1); // delay for 100ms
Delay100ms(1); // delay for 100ms
Delay100ms(1); // delay for 100ms
Delay100ms(1); // delay for 100ms
Delay100ms(1); // delay for 100ms
Delay100ms(1); // delay for 100ms
if (GPIO_PORTF_DATA_R ==0X00)
{
GPIO_PORTF_DATA_R ^= 0X04;
}
else
GPIO_PORTF_DATA_R = 0X04;
}
}