Question
Write a program that simulates a pedestrian controlled traffic light. The light flashes green with an interval of a half second. If the SW1 button
- Write a program that simulates a pedestrian controlled traffic light. The light flashes green with an interval
of a half second. If the SW1 button is pressed, the light changes to yellow for 1 second, then turns solid red
for 5 seconds. After the 5 seconds, the light returns to the default state of flashing green. Note that if you
quickly press the button while the LED is flashing green it may not detect the button press and activate the
signal. Why do you think that is? What is the minimum length of time you must hold the button down to
guarantee that the button press is detected?Note that SW1 will work as expected, however, bit 0 of Port F is “locked” and you will need to add
the following two lines of code before you initialize the Port F registers for SW2:
GPIO_PORTF_LOCK_R = GPIO_LOCK_KEY;
GPIO_PORTF_CR_R |= SW2;Please modify the code below to work with question 1
#include "tm4c123gh6pm.h" // device specific include file
#define YELLOW 0XA //BIT 2 or 0x5 is blue, BIT1 or 0x3 is red, BIT3 or 0x8 is green, yellow is 0xA
#define RED 0x3
#define GREEN 0x8
#define WHITE 0xE
#define DELAY_LOOPS 2000000
#define BRIEF_PAUSE 500000int main(void)
{
int loopCount; // counter to generate delayvolatile int temp; // temporary variable to force peripheral bus read
// activate clock for GPIO Port F
SYSCTL_RCGC2_R |= SYSCTL_RCGC2_GPIOF;// allow a few cycles for clock to start
temp = SYSCTL_RCGC2_R;// enable Port F Bit 2 connected to white LED as digital output. For full colour spectrum
GPIO_PORTF_DIR_R |= WHITE;
GPIO_PORTF_DEN_R |= WHITE;while(1) {
// generate delay
GPIO_PORTF_DATA_R ^= GREEN; // toggle ON GREEN LED
for(loopCount = 0; loopCount < DELAY_LOOPS; loopCount++) {} //Stays on for about 2 seconds
GPIO_PORTF_DATA_R ^= GREEN; // toggle OFF GREEN LED
GPIO_PORTF_DATA_R ^=YELLOW; // toggle ON YELLOW LED
for(loopCount = 0; loopCount < BRIEF_PAUSE; loopCount++) {} // Stays on for about 0.5 seconds
GPIO_PORTF_DATA_R ^=YELLOW; // toggle OFF YELLOW LED
GPIO_PORTF_DATA_R ^=RED; // toggle ON RED LED
for(loopCount = 0; loopCount < DELAY_LOOPS; loopCount++) {} // Stays on for about 2 seconds
GPIO_PORTF_DATA_R ^=RED; // toggle OFF RED LED
}
}
DEBUGA.COM GPIO PA2 PA3 PA4 PA5 PA6 PA7 PC4 PC5 PC6 PC71 PEO PE1 PF2 PE3 PE4 PE5 PAO/UORX VCP TXD PA1/UOTX VCP RXD DEBUG PCO/TCK/SWCLK DEBUG PC1/TMS/SWDIO DEBUG PC2/TDI DEBUG PC3/TDO/SWO COCO Hot test +8+ 17 18 19 20 21 22 23 24 16 15 14 13 PAO PA1 9 8 7 6 59 60 PA2 PA3 PA4 PA5 52 PC0 51 PC1 50 PC2 49 PA6 PA7 PC3 PC4 PC5 PC6 PC7 PE1 PE2 PE3 PE4 PE5 U1-A PB0 PB1 PB2 PB3 PB4 PB5 PB6 PB7 PFO PF1 PF2 PF3 PF4 45 46 61 PDO PD1 62 63 PD2 64 PD3 PD4 PD5 PD6 PD7 TM4C123G 47 48 58 57 1 4 43 44 53 10 28 29 30 31 5 18 USB DM USB DP PBO PB1 PB2 PB3 PB4 PB5 PB6 PB7 PDO PD1 PD2 IPD3 PD6 PD7 IPFO PF1 PF2 PF3 PF4 R1 R11 R12 R13 ww ww www ww GPIO PBO USR SW2 LED R LED B LED G USR SW1 USB DP USB DM 9 8 ww R25 J9 CON-USB-MICROAB 5 OOOOO 0 6 d 4 3 N T 7 PD1 PDO 0 ww R14 +USB VBUS 0 ww R29 0 ww R9 0 ww R10 PB1 PB6 PB7
Step by Step Solution
3.44 Rating (170 Votes )
There are 3 Steps involved in it
Step: 1
include tm4c123gh6pmh device specific include file define YELLOW 0XA BIT 2 or 0x5 is blue BIT1 or 0x3 is red BIT3 or 0x8 is green yellow is 0xA define RED 0x3 define GREEN 0x8 define WHITE 0xE define ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started