Subversion Repositories group.electronics

Rev

Rev 127 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 127 Rev 128
Line 91... Line 91...
91
        PD7     - Input, Pullup		- * Button
91
        PD7     - Input, Pullup		- * Button
92
  */
92
  */
93
  DDRD          = 0B01000000;
93
  DDRD          = 0B01000000;
94
  PORTD         = 0B10000000;
94
  PORTD         = 0B10000000;
95
 
95
 
-
 
96
  PCMSK1 |= (( 1 << PCINT8 ) | ( 1 << PCINT9 )| ( 1 << PCINT10 )| ( 1 << PCINT11 ));
-
 
97
  PCICR |= ( 1 << PCIE1 );
-
 
98
 
-
 
99
  pcInt[1].last = PINC;
-
 
100
  pcInt[1].current = pcInt[1].last;
-
 
101
  pcInt[1].mask = 0;
-
 
102
 
96
  	systime = 0;
103
  	systime = 0;
97
    sysclockInit();
104
    sysclockInit();
98
 
105
 
99
    uart_init( UART_BAUD_SELECT(UART_BAUD_RATE,F_CPU) );
106
    uart_init( UART_BAUD_SELECT(UART_BAUD_RATE,F_CPU) );
100
 
107
 
Line 129... Line 136...
129
		lmd_decodemode(c, 0xff);
136
		lmd_decodemode(c, 0xff);
130
		lmd_dp(c, 0x04);
137
		lmd_dp(c, 0x04);
131
		lmd_print_u16(c, comm1[c]);
138
		lmd_print_u16(c, comm1[c]);
132
    }
139
    }
133
 
140
 
134
    //PORTC |= (( 1 << PCINT8 ) | ( 1 << PCINT9 )| ( 1 << PCINT10 )| ( 1 << PCINT11 ));
-
 
135
    PCMSK1 |= (( 1 << PCINT8 ) | ( 1 << PCINT9 )| ( 1 << PCINT10 )| ( 1 << PCINT11 ));
-
 
136
    PCICR |= ( 1 << PCIE1 );
-
 
137
 
-
 
138
    for(;;){
141
    for(;;){
139
    	 wdt_reset();
142
    	 wdt_reset();
140
 
143
 
141
    	 if (doInt) {
144
    	 if (doInt) {
-
 
145
    		 pcInterrupt(doInt);
142
    		 doInt = 0;
146
    		 doInt = 0;
143
    		 pcInterrupt(1);
-
 
144
    	 }
147
    	 }
145
 
148
 
146
 
149
#ifdef _DEBUG_
147
		if (!lcdTimer) {
150
		if (!lcdTimer) {
148
		  ultoa(systime, display, 10);
151
		  ultoa(systime, display, 10);
149
		  lcd_overprint_right(display, 10, 6, 1);
152
		  lcd_overprint_right(display, 10, 6, 1);
150
 
153
 
151
		  lcdTimer = LCD_SEND_DELAY;
154
		  lcdTimer = LCD_SEND_DELAY;
152
		}
155
		}
-
 
156
#endif
153
 
157
 
154
		if (!oledTimer && !rbi(PIND, PD7)) {
158
		if (!oledTimer && !rbi(PIND, PD7)) {
155
			cli();
159
			cli();
156
			statusLed(ON);
160
			statusLed(ON);
157
 
161
 
Line 166... Line 170...
166
			oledTimer = OLED_SEND_DELAY;
170
			oledTimer = OLED_SEND_DELAY;
167
 
171
 
168
			lmd_print_u16(0, comm1[0]);
172
			lmd_print_u16(0, comm1[0]);
169
			lmd_print_u16(1, comm1[1]);
173
			lmd_print_u16(1, comm1[1]);
170
 
174
 
-
 
175
#ifdef _DEBUG_
171
			uart_puts("Swap: ");
176
			uart_puts("Swap: ");
172
			utoa(systime, display, 10);
177
			utoa(systime, display, 10);
173
			uart_puts(display);
178
			uart_puts(display);
174
			uart_puts("\r\n");
179
			uart_puts("\r\n");
-
 
180
#endif
175
		}
181
		}
176
 
182
 
177
		if (input.inner != 0 || input.outer != 0) {
183
		if (input.inner != 0 || input.outer != 0) {
178
 
184
 
179
			int16_t delta = 0;
185
			int16_t delta = 0;
Line 200... Line 206...
200
    return 0;
206
    return 0;
201
}
207
}
202
 
208
 
203
void pcInterrupt(uint8_t pcint) {
209
void pcInterrupt(uint8_t pcint) {
204
		wdt_reset();
210
		wdt_reset();
-
 
211
 
-
 
212
		pcInt[pcint].mask = pcInt[pcint].current ^ pcInt[pcint].last;
-
 
213
 
-
 
214
#ifdef _DEBUG_
-
 
215
        utoa(pcInt[pcint].last, display, 2);
-
 
216
        uart_puts(display);
205
        switch (pcint) {
217
        uart_puts("\r\n");
206
                case 1: pcInt[pcint].current = PINC; break;
218
        utoa(pcInt[pcint].current, display, 2);
-
 
219
        uart_puts(display);
207
        }
220
        uart_puts("\r\n");
208
        pcInt[pcint].mask = pcInt[pcint].current ^ pcInt[pcint].last;
221
        utoa(pcInt[pcint].mask, display, 2);
-
 
222
        uart_puts(display);
-
 
223
        uart_puts("\r\n");
-
 
224
#endif
-
 
225
 
209
        pcInt[pcint].last = pcInt[pcint].current;
226
        pcInt[pcint].last = pcInt[pcint].current;
210
 
227
 
211
        if (pcInt[pcint].mask == 0)
228
        if (pcInt[pcint].mask == 0)
212
        		return;
229
                		return;
213
 
230
 
214
        // Check which pin caused the interrupt. If they both
231
        // Check which pin caused the interrupt. If they both
215
        //  equal 0 || 1, the pin that interrupted is the direction
232
        //  equal 0 || 1, the pin that interrupted is the direction
216
        if ((
233
        if ((
217
        	(rbi(pcInt[pcint].current, PCINT8) == 1 &&
234
        	(rbi(pcInt[pcint].current, PCINT8) == 1 &&
218
             rbi(pcInt[pcint].current, PCINT9) == 1) ||
235
             rbi(pcInt[pcint].current, PCINT9) == 1) ||
219
             (rbi(pcInt[pcint].current, PCINT8) == 0 &&
236
             (rbi(pcInt[pcint].current, PCINT8) == 0 &&
220
              rbi(pcInt[pcint].current, PCINT9) == 0)) &&
237
              rbi(pcInt[pcint].current, PCINT9) == 0))) {
221
            rbi(pcInt[pcint].mask, PCINT8) ) {
-
 
222
 
238
 
-
 
239
              if (rbi(pcInt[pcint].mask, PCINT8) ) {
223
        		input.outer += 1;
240
        		input.outer += 1;
224
        } else if ((
-
 
225
        		(rbi(pcInt[pcint].current, PCINT8) == 1 &&
241
        		uart_puts("+Outer\r\n");
226
                 rbi(pcInt[pcint].current, PCINT9) == 1) ||
242
              } else if (rbi(pcInt[pcint].mask, PCINT9) ) {
227
                (rbi(pcInt[pcint].current, PCINT8) == 0 &&
243
            	input.outer -= 1;
228
                 rbi(pcInt[pcint].current, PCINT9) == 0)) &&
244
            	uart_puts("-Outer\r\n");
229
               rbi(pcInt[pcint].mask, PCINT9) ) {
245
              }
230
 
246
 
231
        		input.outer -= 1;
247
        }
-
 
248
 
232
        } else if ((
249
        if ((
233
        		(rbi(pcInt[pcint].current, PCINT10) == 1 &&
250
        		(rbi(pcInt[pcint].current, PCINT10) == 1 &&
234
                rbi(pcInt[pcint].current, PCINT11) == 1) ||
251
                rbi(pcInt[pcint].current, PCINT11) == 1) ||
235
                (rbi(pcInt[pcint].current, PCINT10) == 0 &&
252
                (rbi(pcInt[pcint].current, PCINT10) == 0 &&
236
                 rbi(pcInt[pcint].current, PCINT11) == 0)) &&
253
                 rbi(pcInt[pcint].current, PCINT11) == 0))) {
237
               rbi(pcInt[pcint].mask, PCINT10) ) {
-
 
238
 
254
 
-
 
255
        	if (rbi(pcInt[pcint].mask, PCINT10) ) {
239
        		input.inner += 1;
256
        		input.inner += 1;
240
        } else if ((
-
 
241
        		(rbi(pcInt[pcint].current, PCINT10) == 1 &&
-
 
242
        		 rbi(pcInt[pcint].current, PCINT11) == 1) ||
-
 
243
        			(rbi(pcInt[pcint].current, PCINT10) == 0 &&
257
        		uart_puts("+Inner\r\n");
244
        			 rbi(pcInt[pcint].current, PCINT11) == 0)) &&
-
 
245
                   rbi(pcInt[pcint].mask, PCINT11) ) {
258
        	} else if (rbi(pcInt[pcint].mask, PCINT11) ) {
246
 
-
 
247
        		input.inner -= 1;
259
        		input.inner -= 1;
-
 
260
        		uart_puts("-Inner\r\n");
-
 
261
        	}
248
        }
262
        }
249
 
263
 
250
        // Clear the mask so we know we've delth with it
264
        // Clear the mask so we know we've dealt with it
251
        pcInt[pcint].mask = 0;
265
        pcInt[pcint].mask = 0;
252
 
266
 
253
}
267
}
254
 
268
 
255
ISR(PCINT0_vect) {
-
 
256
	doInt = 1;
-
 
257
}
-
 
258
ISR(PCINT1_vect) {
269
ISR(PCINT1_vect) {
259
	doInt = 1;
270
	pcInt[1].current = PINC;
260
}
-
 
261
ISR(PCINT2_vect) {
271
	if (!doInt) {
262
	doInt = 1;
272
		doInt = 1;
-
 
273
	}
263
}
274
}
264
 
275
 
265
 
276
 
266
ISR(TIMER0_OVF_vect) {
277
ISR(TIMER0_OVF_vect) {
267
        tmr0_ovf++;
278
        tmr0_ovf++;