39 #define CONFIG_LED1() CONFIG_RB14_AS_DIG_OUTPUT()
40 #define LED1 _LATB14 //led1 state
44 CONFIG_RB13_AS_DIG_INPUT();
48 #define SW1_RAW _RB13 //raw switch value
49 #define SW1 u8_valueSW1 //switch state
50 #define SW1_PRESSED() (SW1==0) //switch test
51 #define SW1_RELEASED() (SW1==1) //switch test
55 CONFIG_RB12_AS_DIG_INPUT();
59 #define SW2 _RB12 //switch state
64 STATE_WAIT_FOR_PRESS1,
65 STATE_WAIT_FOR_RELEASE1,
66 STATE_WAIT_FOR_PRESS2,
67 STATE_WAIT_FOR_RELEASE2,
69 STATE_WAIT_FOR_RELEASE3
73 volatile uint8_t u8_valueSW1 = 1;
75 volatile STATE e_mystate;
78 void _ISR _T3Interrupt (
void) {
79 u8_valueSW1 = SW1_RAW;
81 case STATE_WAIT_FOR_PRESS1:
83 if (SW1_PRESSED()) e_mystate = STATE_WAIT_FOR_RELEASE1;
85 case STATE_WAIT_FOR_RELEASE1:
86 if (SW1_RELEASED()) e_mystate = STATE_WAIT_FOR_PRESS2;
88 case STATE_WAIT_FOR_PRESS2:
90 if (SW1_PRESSED()) e_mystate = STATE_WAIT_FOR_RELEASE2;
92 case STATE_WAIT_FOR_RELEASE2:
95 if (SW2) e_mystate = STATE_BLINK;
96 else e_mystate = STATE_WAIT_FOR_PRESS1;
103 e_mystate = STATE_WAIT_FOR_RELEASE3;
106 case STATE_WAIT_FOR_RELEASE3:
108 if (SW1_RELEASED()) e_mystate = STATE_WAIT_FOR_PRESS1;
111 e_mystate = STATE_WAIT_FOR_PRESS1;
120 void printNewState (STATE e_currentState) {
121 static STATE e_LastState = STATE_RESET;
122 if (e_LastState != e_currentState) {
123 switch (e_currentState) {
124 case STATE_WAIT_FOR_PRESS1:
125 outString(
"STATE_WAIT_FOR_PRESS1 - LED is off\n");
127 case STATE_WAIT_FOR_RELEASE1:
130 case STATE_WAIT_FOR_PRESS2:
131 outString(
"STATE_WAIT_FOR_PRESS2 - LED is on\n");
133 case STATE_WAIT_FOR_RELEASE2:
134 outString(
"STATE_WAIT_FOR_RELEASE2 - SW2 on goes to blink else go to PRESS1\n");
137 outString(
"STATE_BLINK - LED blinks, waiting for SW1 press\n");
139 case STATE_WAIT_FOR_RELEASE3:
140 outString(
"STATE_WAIT_FOR_RELEASE3 - LED is on\n");
146 e_LastState = e_currentState;
150 #define ISR_PERIOD 15 // in ms
151 void configTimer3(
void) {
156 T3CON = T3_OFF |T3_IDLE_CON | T3_GATE_OFF
176 e_mystate = STATE_WAIT_FOR_PRESS1;
179 printNewState(e_mystate);