Question: Come up with additional code for the code below: lThe microcontroller-based traffic control will also now use sensors to provide information about waiting cars at

Come up with additional code for the code below: lThe microcontroller-based traffic control will also now use sensors to provide information about waiting cars at the intersection. This can be accomplished using external pushbuttons as sensors or the ADC10 module (tricky part). For example, if there are more than 12 cars waiting before the 20 second RED signal has expired, the traffic lights should therefore switch signal directions and allow the waiting traffic to proceed. 3. Output the crosswalk time as a countdown to a BCD display using serial communication. #include #define RED_LED BIT0 #define YELLOW_LED BIT1 #define GREEN_LED BIT2 #define BUTTON_PIN BIT3 #define ONE_SECOND 32768 #define GREEN_DURATION 30 #define YELLOW_DURATION 4 #define RED_DURATION 20 #define CROSSWALK_DURATION 10 #define a BIT4 #define b BIT5 #define c BIT6 #define d BIT7 #define e BIT8 #define f BIT9 #define g BITA typedef enum { STATE_GREEN, STATE_YELLOW, STATE_RED, STATE_CROSSWALK } traffic_state_t; volatile traffic_state_t current_state = STATE_GREEN; volatile unsigned int timer_count = 0; volatile unsigned char crosswalk_request = 0; volatile unsigned int crosswalk_timer = 0; volatile unsigned char visual_signal_on = 0; int n = 9; int display[10]={a+b+c+d+e+f, b+c, a+b+g+e+d, a+b+g+c+d, f+g+b+c, a+f+g+c+d, a+f+e+d+c+g, a+b+c, a+b+c+d+e+f+g, a+b+c+d+f+g}; void initialize_ports(); void initialize_timer(); void process_traffic_light(); void process_crosswalk(); void flash_visual_signal(); void crosswalk_countdown(); #pragma vector=TIMER0_A0_VECTOR __interrupt void Timer_A0_ISR() { timer_count++; if (crosswalk_request) { crosswalk_timer++; } } #pragma vector=PORT1_VECTOR __interrupt void Port_1_ISR() { if (P1IFG & BUTTON_PIN) { __delay_cycles(10000); if (!(P1IN & BUTTON_PIN)) { crosswalk_request = 1; P1OUT |= RED_LED; } P1IFG &= ~BUTTON_PIN; } } void main() { WDTCTL = WDTPW | WDTHOLD; P1DIR = a+b+c+d+e+f+g; initialize_ports(); initialize_timer(); __enable_interrupt(); while (1) { process_traffic_light(); process_crosswalk(); } } void initialize_ports() { P1DIR |= RED_LED | YELLOW_LED | GREEN_LED; P1OUT &= ~(RED_LED | YELLOW_LED | GREEN_LED); P1DIR &= ~BUTTON_PIN; P1REN |= BUTTON_PIN; P1OUT |= BUTTON_PIN; P1IES |= BUTTON_PIN; P1IFG &= ~BUTTON_PIN; P1IE |= BUTTON_PIN; } void initialize_timer() { TA0CTL |= TASSEL_1 | MC_1 | ID_0; TA0CCR0 = ONE_SECOND - 1; TA0CCTL0 |= CCIE; } void process_traffic_light() { switch (current_state) { case STATE_GREEN: P1OUT = GREEN_LED; if (timer_count >= GREEN_DURATION) { current_state = STATE_YELLOW; timer_count = 0; } break; case STATE_YELLOW: P1OUT = YELLOW_LED; if (timer_count >= YELLOW_DURATION) { current_state = STATE_RED; timer_count = 0; } break; case STATE_RED: P1OUT = RED_LED; if (!crosswalk_request && timer_count >= RED_DURATION) { current_state = STATE_GREEN; timer_count = 0; } break; case STATE_CROSSWALK: P1OUT = RED_LED; flash_visual_signal(); if (crosswalk_timer >= CROSSWALK_DURATION) { crosswalk_request = 0; crosswalk_timer = 0; visual_signal_on = 0; current_state = STATE_GREEN; timer_count = 0; } break; default: current_state = STATE_GREEN; timer_count = 0; break; } } void process_crosswalk() { if (crosswalk_request && current_state != STATE_CROSSWALK) { current_state = STATE_CROSSWALK; timer_count = 0; crosswalk_timer = 0; visual_signal_on = 1; } } void flash_visual_signal() { if (visual_signal_on) { if (crosswalk_timer % (ONE_SECOND / 2) == 0) { P1OUT ^= YELLOW_LED; } } else { P1OUT &= ~YELLOW_LED; } } void crosswalk_countdown() { while(1); { P1OUT = display[n]; __delay_cycles(500000); n--; if(n

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock