38 #define CONFIG_LED1() CONFIG_RB14_AS_DIG_OUTPUT()
39 #define LED1 _LATB14 //led1 state
43 CONFIG_RB13_AS_DIG_INPUT();
46 #define SW1 _RB13 //switch state
47 #define SW1_PRESSED() (SW1==0) //switch test
48 #define SW1_RELEASED() (SW1==1) //switch test
52 CONFIG_RB12_AS_DIG_INPUT();
56 #define SW2 _RB12 //switch state
61 STATE_WAIT_FOR_PRESS1,
62 STATE_WAIT_FOR_RELEASE1,
63 STATE_WAIT_FOR_PRESS2,
64 STATE_WAIT_FOR_RELEASE2,
66 STATE_WAIT_FOR_RELEASE3
69 STATE e_LastState = STATE_RESET;
71 void printNewState (STATE e_currentState) {
72 if (e_LastState != e_currentState) {
73 switch (e_currentState) {
74 case STATE_WAIT_FOR_PRESS1:
75 outString(
"STATE_WAIT_FOR_PRESS1 - LED is off\n");
77 case STATE_WAIT_FOR_RELEASE1:
80 case STATE_WAIT_FOR_PRESS2:
81 outString(
"STATE_WAIT_FOR_PRESS2 - LED is on\n");
83 case STATE_WAIT_FOR_RELEASE2:
84 outString(
"STATE_WAIT_FOR_RELEASE2 - SW2 on goes to blink else go to PRESS1\n");
87 outString(
"STATE_BLINK - LED blinks, waiting for SW1 press\n");
89 case STATE_WAIT_FOR_RELEASE3:
90 outString(
"STATE_WAIT_FOR_RELEASE3 - LED is on\n");
97 e_LastState = e_currentState;
111 e_mystate = STATE_WAIT_FOR_PRESS1;
114 printNewState(e_mystate);
116 case STATE_WAIT_FOR_PRESS1:
118 if (SW1_PRESSED()) e_mystate = STATE_WAIT_FOR_RELEASE1;
120 case STATE_WAIT_FOR_RELEASE1:
121 if (SW1_RELEASED()) e_mystate = STATE_WAIT_FOR_PRESS2;
123 case STATE_WAIT_FOR_PRESS2:
125 if (SW1_PRESSED()) e_mystate = STATE_WAIT_FOR_RELEASE2;
127 case STATE_WAIT_FOR_RELEASE2:
128 if (SW1_RELEASED()) {
130 if (SW2) e_mystate = STATE_BLINK;
131 else e_mystate = STATE_WAIT_FOR_PRESS1;
137 if (SW1_PRESSED()) e_mystate = STATE_WAIT_FOR_RELEASE3;
139 case STATE_WAIT_FOR_RELEASE3:
141 if (SW1_RELEASED()) e_mystate = STATE_WAIT_FOR_PRESS1;
144 e_mystate = STATE_WAIT_FOR_PRESS1;