291 static inline void lkm_display_hex (byte display, byte hex) |
294 static inline void lkm_display_hex (byte display, byte hex) |
292 { |
295 { |
293 lkm_display(display, LKM_DISPLAY_FONT[hex]); |
296 lkm_display(display, LKM_DISPLAY_FONT[hex]); |
294 } |
297 } |
295 |
298 |
|
299 static inline void lkm_display_dec (byte display, byte dec, byte decimal) |
|
300 { |
|
301 byte raw; |
|
302 |
|
303 if (dec < 10) |
|
304 raw = LKM_DISPLAY_FONT[dec]; |
|
305 else |
|
306 raw = 0x00; |
|
307 |
|
308 if (decimal) |
|
309 raw |= LKM_DISPLAY_DECIMAL; |
|
310 |
|
311 lkm_display(display, raw); |
|
312 } |
|
313 |
296 /* |
314 /* |
297 * Read the 8-bit key states |
315 * Read the 8-bit key states |
298 */ |
316 */ |
299 byte lkm_buttons () |
317 byte lkm_buttons () |
300 { |
318 { |
330 |
348 |
331 return k3; |
349 return k3; |
332 } |
350 } |
333 |
351 |
334 /* |
352 /* |
|
353 * Set 8-bit hexadecimal output on displays n..n+1 |
|
354 */ |
|
355 void lkm_display_hh (byte display, byte hex) |
|
356 { |
|
357 lkm_display_hex(display + 0, ((hex >> 4) & 0xF)); |
|
358 lkm_display_hex(display + 1, ((hex >> 0) & 0xF)); |
|
359 } |
|
360 |
|
361 /* |
335 * Set 16-bit hexadecimal output on displays 4..7 |
362 * Set 16-bit hexadecimal output on displays 4..7 |
336 */ |
363 */ |
337 void lkm_display_hex16 (short hex) |
364 void lkm_display_hhhh (short hex) |
338 { |
365 { |
339 lkm_display_hex(7, ((hex >> 0) & 0xF)); |
366 lkm_display_hex(7, ((hex >> 0) & 0xF)); |
340 lkm_display_hex(6, ((hex >> 4) & 0xF)); |
367 lkm_display_hex(6, ((hex >> 4) & 0xF)); |
341 lkm_display_hex(5, ((hex >> 8) & 0xF)); |
368 lkm_display_hex(5, ((hex >> 8) & 0xF)); |
342 lkm_display_hex(4, ((hex >> 12) & 0xF)); |
369 lkm_display_hex(4, ((hex >> 12) & 0xF)); |
343 } |
370 } |
344 |
371 |
|
372 /* |
|
373 * Set 2-digit decimal output on displays n..n+1 |
|
374 */ |
|
375 void lkm_display_dd (byte display, byte dec) |
|
376 { |
|
377 byte d = dec / 10; |
|
378 byte u = dec % 10; |
|
379 |
|
380 byte c = d / 10; |
|
381 d = d % 10; |
|
382 |
|
383 lkm_display_dec(display + 0, d, c > 1); |
|
384 lkm_display_dec(display + 1, u, c > 0); |
|
385 } |
|
386 |
345 // debug |
387 // debug |
346 #define DEBUG_DDR DDRB |
388 #define DEBUG_DDR DDRB |
347 #define DEBUG_PORT PORTB |
389 #define DEBUG_PORT PORTB |
348 #define DEBUG_LED 0 |
390 #define DEBUG_LED 0 |
349 |
391 |
359 |
401 |
360 // setup display |
402 // setup display |
361 lkm_clear(); |
403 lkm_clear(); |
362 lkm_control(LKM_CONTROL_DISPLAY_ON, LKM_CONTROL_INTENSITY_MAX); |
404 lkm_control(LKM_CONTROL_DISPLAY_ON, LKM_CONTROL_INTENSITY_MAX); |
363 |
405 |
|
406 /* |
|
407 // test |
|
408 lkm_led(0, LKM_LED_OFF); |
|
409 lkm_led(1, LKM_LED_RED); |
|
410 lkm_led(2, LKM_LED_GREEN); |
|
411 lkm_led(3, LKM_LED_ORANGE); |
|
412 |
|
413 return 0; |
|
414 */ |
|
415 |
364 // start |
416 // start |
365 byte state[8] = { }; |
417 byte channels[4] = { }; |
366 char i; |
418 char c; |
367 |
419 |
368 while (true) { |
420 while (true) { |
369 // scan input |
421 // scan input |
370 byte buttons = lkm_buttons(); |
422 byte buttons = lkm_buttons(); |
371 |
423 |
372 for (i = 0; i < 8; i++) { |
424 for (c = 0; c < 4; c++) { |
373 if (!(buttons & (1 << i))) { |
425 if (buttons & 0b1) { |
374 continue; |
426 channels[c]++; |
375 } else if (state[i] >= 0xF) { |
427 lkm_led(c * 2 + 0, LKM_LED_GREEN); |
376 state[i] = 0; |
428 lkm_led(c * 2 + 1, LKM_LED_OFF); |
|
429 } else if (buttons & 0b10) { |
|
430 channels[c]--; |
|
431 lkm_led(c * 2 + 0, LKM_LED_OFF); |
|
432 lkm_led(c * 2 + 1, LKM_LED_RED); |
377 } else { |
433 } else { |
378 state[i]++; |
434 lkm_led(c * 2 + 0, LKM_LED_OFF); |
|
435 lkm_led(c * 2 + 1, LKM_LED_OFF); |
379 } |
436 } |
380 |
437 |
381 lkm_display_hex(i, state[i]); |
438 buttons >>= 2; |
382 lkm_led(i, state[i]); |
439 |
|
440 lkm_display_hh(c * 2, channels[c]); |
383 |
441 |
384 xbi(&DEBUG_PORT, DEBUG_LED); |
442 xbi(&DEBUG_PORT, DEBUG_LED); |
385 } |
443 } |
386 |
444 |
387 timer_sleep(16000); |
445 timer_sleep(1000); |
388 } |
446 } |
389 } |
447 } |