I am not goot at programing texas tiva c series in Keil. But I want to make that If switch is pressed(PF4=0), PF2 toggle(flip bit from 0 to 1, or from 1 to 0), If the switch is not pressed(PF4=1), set PF2(LED is on)
I have already written something. But it does not work.
#include "TExaS.h"
#define PF4 (*((volatile unsigned long *)0x40025040))
#define PF2 (*((volatile unsigned long *)0x40025010))
#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
unsigned long In;
unsigned long Out;
// basic functions defined at end of startup.s
void DisableInterrupts(void); // Disable interrupts
void EnableInterrupts(void); // Enable interrupts
void delay(void){unsigned long volatile time;
unsigned long i;
while(time > 0){
i = 1333333;
while(i > 0) {
i = i-1;
}
time = time-1;
}
}
int main(void){
TExaS_Init(SW_PIN_PF4, LED_PIN_PF2); // activate grader and set system clock to 80 MHz
SYSCTL_RCGC2_R |= 0x00000020; // activate clock for Port F
GPIO_PORTF_AMSEL_R = 0x00; //disable analog on PF
GPIO_PORTF_PCTL_R = 0x00000000; //PCTL GPIO on PF4-0
GPIO_PORTF_DIR_R = 0x04;
GPIO_PORTF_AFSEL_R = 0x00;
GPIO_PORTF_DEN_R = 0x14;
GPIO_PORTF_PUR_R = 0x10;
GPIO_PORTF_DATA_R|=0x04;
EnableInterrupts(); // enable interrupts for the grader
while(1)
{
delay();
In=GPIO_PORTF_DATA_R&0x10;
if ( In ==0){
while(In==0)
{
Out=GPIO_PORTF_DATA_R=(~0x04);
Out=Out^0x04;
GPIO_PORTF_DATA_R=Out;
delay();
}
}
else {
GPIO_PORTF_DATA_R=(0x04);
}
}
}