Question: PLEASE HELP WITH THIS CODE IT IS NOT TURN ON THE LIGHTS AS STATE BELOW NOTE SW3 IS A SWITCH /* Created on September 12,
PLEASE HELP WITH THIS CODE IT IS NOT TURN ON THE LIGHTS AS STATE BELOW NOTE SW3 IS A SWITCH
/* Created on September 12, 2018, 8:49 AM */
/* Insert any include files appropriate */
#include "xc.h"
#include "../EE3310_2188_header.h"
/* Insert your #define values here */
#define LED1 _RB15
#define SW3 _RA4
#define LED0Gn _RA0
#define LED1Gn _RA1
#define LED2Rd _RA2
#define LED0Rd _RA3
#define LED3Rd _RB0
#define LED1Bl _RB3
#define LED2Bl _RB2
/* Declare Global Variables here */
int i, j, state;
/* Insert Subroutines (Function Calls here */ void ConfigIO(void)
{ TRISA = 0b10000; ANSELA = 0;
LATA = 0b00000;
LATB = 0x0000;
TRISB = 0x0000;
ANSELB = 0;
_CNPDA4 = 1;
int main(void) {
/* Declare Local Variables here */
int k = 0;
int state;
/* Call the initialization functions */
ConfigIO();
/* Here's the while loop that executes all operations.*/
//HERE IS MY PROBLEM
1. Press and Release the switch (SW3) one time. LED0-Green ON.
2. Press and Release SW3 again. LED0-Green OFF.
3. Press and Release SW3 LED1-Green ON.
4. Press and Release SW3 LED1-Green OFF.
5. Press SW3 LED2-Red ON.
6. Release SW3 LED2-Red OFF and LED0-Red ON.
7. Press SW3 LED3-Red ON.
8. Release SW3 LED0-Red OFF and LED1-Blue ON.
9. Press SW3 LED2-Blue ON and LED3-Red OFF.
10. Release SW3 LED2-Blue OFF and LED1-Blue OFF.
11. Return to Step 1 and repeat
switch (state) {
case 0:
(SW3 == 1);
state = 1;
break;
case 1:
(SW3 == 0);
LED0Gn = 1;
state = 2;
break;
case 2:
(SW3 == 0)
state = 3;
break;
case 3:
(SW3 == 1)
LED0Gn = 0;
state = 4;
break;
case 4:
(SW3 == 0)
state = 5;
break;
case 5:
(SW3 == 1)
LED1Gn = 1;
state = 6;
break;
case 6:
(SW3 == 0)
state = 7;
break;
case 7:
(SW3 == 1)
LED1Gn = 0;
state = 8;
break;
case 8:
(SW3 == 0)
LED2Rd = 1;
state = 9;
break;
case 9:
(SW3 == 1)
LED2Rd = 0;
LED0Rd = 1;
state = 10;
break;
case 10:
(SW3 == 0)
LED3Rd = 1;
state = 11;
break;
case 11:
(SW3 == 1)
LED0Rd = 0;
LED1Bl = 1;
state = 12;
break;
case 12:
(SW3 == 0)
LED2Bl = 1;
LED3Rd = 0;
state = 13;
break;
case 13:
(SW3 == 1)
LED2Bl = 0;
LED1Bl = 0;
state = 0;
break;
}
return 0;
} // end main
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
