#include<stdio.h> #include<stdlib.h> #include<stdint.h> #include<stdbool.h> #inc
ID: 2248192 • Letter: #
Question
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<stdbool.h>
#include<TM4C123GH6PM.h>
void Delay(int t)
{
volatile long time;
int i;
for (i=0; i<t; ++i)
{
time = 3020200;
while(time)
time--;
}
}
int main(){
SYSCTL->RCGCGPIO = 0x20; // 1) activate clock for Port F
while((SYSCTL->PRGPIO & 0x20) != 0x20){}; // allow time for clock to start
GPIOF->LOCK = 0x4C4F434B;
GPIOF->CR = 0x1F;
GPIOF->AMSEL= 0x00; // 3) disable analog on PF
GPIOF->PCTL = 0x00000000; // 4) PCTL GPIO on PF4-0
GPIOF->DIR = 0x0E; // 5) PF4,PF0 in, PF3-1 out
GPIOF->AFSEL = 0x00; // 6) disable alt funct on PF7-0
GPIOF->PUR = 0x11; // enable pull-up on PF0 and PF4
GPIOF->DEN = 0x1F; // 7) enable digital I/O on PF4-0
unsigned long In, Out;
while(1)
{
In = GPIOF->DATA & 0x10; //read portF pin4
if( !In )
{
Out = 0x02; //making portF pin1 high
GPIOF->DATA = Out; //write the data on portF and Red LED ON
Delay(3); //call the delay function for 2s delay
GPIOF->DATA= 0x00; //making the Red LED off
}
In = GPIOF->DATA & 0x01; //read port F pin0
if( !In )
{
Out = 0x08; //making portF pin3 high
GPIOF->DATA = Out; //write the data on portF and Green LED ON
Delay(3); //call the delay function for 2s delay
GPIOF->DATA = 0x00; //making the Green LED off
}
}
}
here is my code, the button 1 and 2 are working, I need help for press both button to turn on the blue Led. thank you
EK-TM4C123GXL LaunchPad TM4C123GHGPM PA1 PAR PB1 PDS PD4 Serial PF4 PF3 PF2 PF1 PF0 USB PO1 ePB7 Table 1: User Switches and RGB LED Signals GPIO Pin Pin Function PF4 PFO PF1 PF2 PF3 GPIO GPIO GPIO GPIO GPIO User Device SW1 SW2 RGB LED (Red) RGB LED (Blue) RGB LED (Green)Explanation / Answer
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<stdbool.h>
#include<TM4C123GH6PM.h>
void Delay(int t)
{
volatile long time;
int i;
for (i=0; i<t; ++i)
{
time = 3020200;
while(time)
time--;
}
}
int main(){
SYSCTL->RCGCGPIO = 0x20; // 1) activate clock for Port F
while((SYSCTL->PRGPIO & 0x20) != 0x20){}; // allow time for clock to start
GPIOF->LOCK = 0x4C4F434B;
GPIOF->CR = 0x1F;
GPIOF->AMSEL= 0x00; // 3) disable analog on PF
GPIOF->PCTL = 0x00000000; // 4) PCTL GPIO on PF4-0
GPIOF->DIR = 0x0E; // 5) PF4,PF0 in, PF3-1 out
GPIOF->AFSEL = 0x00; // 6) disable alt funct on PF7-0
GPIOF->PUR = 0x11; // enable pull-up on PF0 and PF4
GPIOF->DEN = 0x1F; // 7) enable digital I/O on PF4-0
unsigned long In, Out;
while(1)
{
In1 = GPIOF->DATA & 0x10; //read portF pin4
in2 = GPIOF->DATA & 0x00; //Read PortF pin 0
if( !In1 && !in2 )
{
Out = 0x04; //making portF pin1 high
GPIOF->DATA = Out; //write the data on portF and Blue LED ON
Delay(3); //call the delay function for 2s delay
GPIOF->DATA= 0x00; //making the Blue LED off
}
else if( !In2 )
{
Out = 0x02; //making portF pin1 high
GPIOF->DATA = Out; //write the data on portF and Red LED ON
Delay(3); //call the delay function for 2s delay
GPIOF->DATA= 0x00; //making the Red LED off
}
In = GPIOF->DATA & 0x01; //read port F pin0
else if( !In1 )
{
Out = 0x08; //making portF pin3 high
GPIOF->DATA = Out; //write the data on portF and Green LED ON
Delay(3); //call the delay function for 2s delay
GPIOF->DATA = 0x00; //making the Green LED off
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.