author | Tero Marttila <terom@paivola.fi> |
Sat, 05 Apr 2014 01:50:26 +0300 | |
changeset 59 | 7090f61e5e17 |
parent 58 | a445e08b63e0 |
child 60 | b9648067e9d7 |
permissions | -rw-r--r-- |
58
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
1 |
/* |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
2 |
* Control the JY-LKM1638 LED display module. |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
3 |
*/ |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
4 |
|
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
5 |
#include <avr/io.h> |
59 | 6 |
#include <util/delay.h> |
58
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
7 |
|
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
8 |
#include "stdlib.h" |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
9 |
|
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
10 |
// XXX |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
11 |
#include "timer.c" |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
12 |
|
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
13 |
#define LKM_DDR DDRC |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
14 |
#define LKM_PORT PORTC |
59 | 15 |
#define LKM_PIN PINC |
58
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
16 |
#define LKM_CLK 0 |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
17 |
#define LKM_DIO 1 |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
18 |
#define LKM_STB 2 |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
19 |
|
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
20 |
enum lkm_cmd { |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
21 |
LKM_CMD_DATA = 0b01000000, |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
22 |
LKM_CMD_CONTROL = 0b10000000, |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
23 |
LKM_CMD_ADDRESS = 0b11000000, |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
24 |
|
59 | 25 |
LKM_DATA_WRITE = 0b00000000, |
26 |
LKM_DATA_READ = 0b00000010, |
|
58
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
27 |
|
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
28 |
LKM_DATA_ADDR_AUTO = 0b00000000, |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
29 |
LKM_DATA_ADDR_FIXED = 0b00000100, |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
30 |
|
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
31 |
LKM_DATA_TEST_NORMAL = 0b00000000, |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
32 |
LKM_DATA_TEST_TEST = 0b00001000, |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
33 |
|
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
34 |
LKM_ADDRESS = 0b00001111, |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
35 |
|
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
36 |
LKM_CONTROL_INTENSITY = 0b00000111, |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
37 |
LKM_CONTROL_INTENSITY_MIN = 0b00000000, |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
38 |
LKM_CONTROL_INTENSITY_MAX = 0b00000111, |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
39 |
|
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
40 |
LKM_CONTROL_DISPLAY_OFF = 0b00000000, |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
41 |
LKM_CONTROL_DISPLAY_ON = 0b00001000, |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
42 |
}; |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
43 |
|
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
44 |
static const uint8_t LKM_DISPLAY_FONT[] = { |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
45 |
0b00111111, // 0 |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
46 |
0b00000110, // 1 |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
47 |
0b01011011, // 2 |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
48 |
0b01001111, // 3 |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
49 |
0b01100110, // 4 |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
50 |
0b01101101, // 5 |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
51 |
0b01111101, // 6 |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
52 |
0b00000111, // 7 |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
53 |
0b01111111, // 8 |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
54 |
0b01100111, // 9 |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
55 |
0b01110111, // A |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
56 |
0b01111100, // B |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
57 |
0b00111001, // C |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
58 |
0b01011110, // D |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
59 |
0b01111001, // E |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
60 |
0b01110001, // F |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
61 |
}; |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
62 |
|
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
63 |
enum { |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
64 |
LKM_DISPLAY_DOT = 0b10000000, |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
65 |
}; |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
66 |
|
59 | 67 |
enum { |
68 |
LKM_LED_OFF = 0b00, |
|
69 |
LKM_LED_RED = 0b01, |
|
70 |
LKM_LED_GREEN = 0b10, |
|
71 |
LKM_LED_ORANGE = 0b11, |
|
72 |
}; |
|
73 |
||
74 |
/* |
|
75 |
* Button bitfields. |
|
76 |
* |
|
77 |
* The JY-LKM1638 uses K3 |
|
78 |
*/ |
|
79 |
enum { |
|
80 |
LKM_BUTTON_K1L = 0b00000100, |
|
81 |
LKM_BUTTON_K2L = 0b00000010, |
|
82 |
LKM_BUTTON_K3L = 0b00000001, |
|
83 |
||
84 |
LKM_BUTTON_K1H = 0b01000000, |
|
85 |
LKM_BUTTON_K2H = 0b00100000, |
|
86 |
LKM_BUTTON_K3H = 0b00010000, |
|
87 |
}; |
|
88 |
||
58
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
89 |
void lkm_init () |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
90 |
{ |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
91 |
// strobe off: high output |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
92 |
// XXX: should use an external pull-up resistor? |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
93 |
sbi(&LKM_PORT, LKM_STB); |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
94 |
sbi(&LKM_DDR, LKM_STB); |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
95 |
|
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
96 |
// clock low |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
97 |
sbi(&LKM_DDR, LKM_CLK); |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
98 |
cbi(&LKM_PORT, LKM_CLK); |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
99 |
|
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
100 |
// data tri-state |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
101 |
cbi(&LKM_DDR, LKM_DIO); |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
102 |
cbi(&LKM_DDR, LKM_DIO); |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
103 |
} |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
104 |
|
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
105 |
/* |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
106 |
* Select the LKM for write. |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
107 |
*/ |
59 | 108 |
void lkm_out () |
58
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
109 |
{ |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
110 |
// clock low |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
111 |
cbi(&LKM_PORT, LKM_CLK); |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
112 |
|
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
113 |
// data out |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
114 |
sbi(&LKM_DDR, LKM_DIO); |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
115 |
|
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
116 |
// select on: low |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
117 |
cbi(&LKM_PORT, LKM_STB); |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
118 |
} |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
119 |
|
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
120 |
/* |
59 | 121 |
* Select the LKM for read. |
122 |
*/ |
|
123 |
void lkm_in () |
|
124 |
{ |
|
125 |
// data in |
|
126 |
cbi(&LKM_DDR, LKM_DIO); |
|
127 |
cbi(&LKM_PORT, LKM_DIO); |
|
128 |
||
129 |
// select on: low |
|
130 |
cbi(&LKM_PORT, LKM_STB); |
|
131 |
||
132 |
// clock high |
|
133 |
sbi(&LKM_PORT, LKM_CLK); |
|
134 |
||
135 |
// pause |
|
136 |
_delay_us(1); |
|
137 |
} |
|
138 |
||
139 |
/* |
|
58
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
140 |
* Write out one byte |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
141 |
*/ |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
142 |
void lkm_write (byte b) |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
143 |
{ |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
144 |
char i; |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
145 |
|
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
146 |
for (i = 0; i < 8; i++) { |
59 | 147 |
// clock read: low |
58
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
148 |
cbi(&LKM_PORT, LKM_CLK); |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
149 |
|
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
150 |
// set output |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
151 |
if (b & 1) |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
152 |
sbi(&LKM_PORT, LKM_DIO); |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
153 |
else |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
154 |
cbi(&LKM_PORT, LKM_DIO); |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
155 |
|
59 | 156 |
// clock write: high |
58
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
157 |
sbi(&LKM_PORT, LKM_CLK); |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
158 |
|
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
159 |
// next bit |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
160 |
b >>= 1; |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
161 |
} |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
162 |
} |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
163 |
|
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
164 |
/* |
59 | 165 |
* Read in one byte. |
166 |
*/ |
|
167 |
byte lkm_read () |
|
168 |
{ |
|
169 |
byte b = 0; |
|
170 |
char i; |
|
171 |
||
172 |
// XXX: this loop is timing-critical; we must allow the signal to settle betwen clocks |
|
173 |
for (i = 0; i < 8; i++) { |
|
174 |
// next bit |
|
175 |
b >>= 1; |
|
176 |
||
177 |
// clock read: low |
|
178 |
cbi(&LKM_PORT, LKM_CLK); |
|
179 |
||
180 |
// pause |
|
181 |
_delay_us(1); |
|
182 |
||
183 |
// read input |
|
184 |
if (tbi(&LKM_PIN, LKM_DIO)) |
|
185 |
b |= 0x80; |
|
186 |
||
187 |
// pause |
|
188 |
_delay_us(1); |
|
189 |
||
190 |
// clock write: high |
|
191 |
sbi(&LKM_PORT, LKM_CLK); |
|
192 |
||
193 |
// pause |
|
194 |
_delay_us(1); |
|
195 |
} |
|
196 |
||
197 |
return b; |
|
198 |
} |
|
199 |
||
200 |
/* |
|
58
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
201 |
* End command. |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
202 |
*/ |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
203 |
void lkm_end () |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
204 |
{ |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
205 |
// select off: high |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
206 |
sbi(&LKM_PORT, LKM_STB); |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
207 |
|
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
208 |
// tristate data |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
209 |
cbi(&LKM_DDR, LKM_DIO); |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
210 |
} |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
211 |
|
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
212 |
void lkm_cmd (byte cmd) |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
213 |
{ |
59 | 214 |
lkm_out(); |
58
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
215 |
lkm_write(cmd); |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
216 |
lkm_end(); |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
217 |
} |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
218 |
|
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
219 |
void lkm_cmd1 (byte cmd, byte arg) |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
220 |
{ |
59 | 221 |
lkm_out(); |
58
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
222 |
lkm_write(cmd); |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
223 |
lkm_write(arg); |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
224 |
lkm_end(); |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
225 |
} |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
226 |
|
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
227 |
static inline void lkm_control (byte display, byte intensity) |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
228 |
{ |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
229 |
lkm_cmd(LKM_CMD_CONTROL |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
230 |
| (display ? LKM_CONTROL_DISPLAY_ON : LKM_CONTROL_DISPLAY_OFF) |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
231 |
| (intensity & LKM_CONTROL_INTENSITY) |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
232 |
); |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
233 |
} |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
234 |
|
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
235 |
/* |
59 | 236 |
* Blank display/LEDs |
58
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
237 |
*/ |
59 | 238 |
static void lkm_clear () |
58
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
239 |
{ |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
240 |
char i; |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
241 |
|
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
242 |
lkm_cmd(LKM_CMD_DATA |
59 | 243 |
| LKM_DATA_TEST_NORMAL |
244 |
| LKM_DATA_ADDR_AUTO |
|
58
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
245 |
| LKM_DATA_WRITE |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
246 |
); |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
247 |
|
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
248 |
// write out all 16 bytes of 0x00 |
59 | 249 |
lkm_out(); |
58
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
250 |
lkm_write(LKM_CMD_ADDRESS | (0x0) & LKM_ADDRESS); |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
251 |
for (i = 0; i < 16; i++) { |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
252 |
lkm_write(0x00); |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
253 |
} |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
254 |
lkm_end(); |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
255 |
|
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
256 |
} |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
257 |
|
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
258 |
/* |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
259 |
* Set raw output mask for given display 0..7 |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
260 |
*/ |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
261 |
static inline void lkm_display (byte display, byte value) |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
262 |
{ |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
263 |
lkm_cmd(LKM_CMD_DATA |
59 | 264 |
| LKM_DATA_TEST_NORMAL |
265 |
| LKM_DATA_ADDR_AUTO |
|
58
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
266 |
| LKM_DATA_WRITE |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
267 |
); |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
268 |
lkm_cmd1(LKM_CMD_ADDRESS | ((display * 2 + 0) & LKM_ADDRESS), |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
269 |
value |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
270 |
); |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
271 |
} |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
272 |
|
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
273 |
/* |
59 | 274 |
* Set raw output mask for given led 0..7 |
275 |
*/ |
|
276 |
static inline void lkm_led (byte led, byte value) |
|
277 |
{ |
|
278 |
lkm_cmd(LKM_CMD_DATA |
|
279 |
| LKM_DATA_TEST_NORMAL |
|
280 |
| LKM_DATA_ADDR_AUTO |
|
281 |
| LKM_DATA_WRITE |
|
282 |
); |
|
283 |
lkm_cmd1(LKM_CMD_ADDRESS | ((led * 2 + 1) & LKM_ADDRESS), |
|
284 |
value |
|
285 |
); |
|
286 |
} |
|
287 |
||
288 |
/* |
|
58
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
289 |
* Set 4-bit hexadecimal output for given display 0..7 |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
290 |
*/ |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
291 |
static inline void lkm_display_hex (byte display, byte hex) |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
292 |
{ |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
293 |
lkm_display(display, LKM_DISPLAY_FONT[hex]); |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
294 |
} |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
295 |
|
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
296 |
/* |
59 | 297 |
* Read the 8-bit key states |
298 |
*/ |
|
299 |
byte lkm_buttons () |
|
300 |
{ |
|
301 |
byte k3 = 0; |
|
302 |
char i; |
|
303 |
||
304 |
lkm_out(); |
|
305 |
lkm_write(LKM_CMD_DATA |
|
306 |
| LKM_DATA_TEST_NORMAL |
|
307 |
| LKM_DATA_ADDR_AUTO |
|
308 |
| LKM_DATA_READ |
|
309 |
); |
|
310 |
lkm_in(); |
|
311 |
for (i = 0; i < 4; i++) { |
|
312 |
/* |
|
313 |
* The ordering of keys used is weird; it seems to go 04 15 26 37 |
|
314 |
*/ |
|
315 |
k3 |= lkm_read() << i; |
|
316 |
||
317 |
/* |
|
318 |
k3 >>= 1; |
|
319 |
||
320 |
byte b = lkm_read(); |
|
321 |
||
322 |
if (b & LKM_BUTTON_K3L) |
|
323 |
k3 |= 0b00001000; |
|
324 |
||
325 |
if (b & LKM_BUTTON_K3H) |
|
326 |
k3 |= 0b10000000; |
|
327 |
*/ |
|
328 |
} |
|
329 |
lkm_end(); |
|
330 |
||
331 |
return k3; |
|
332 |
} |
|
333 |
||
334 |
/* |
|
58
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
335 |
* Set 16-bit hexadecimal output on displays 4..7 |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
336 |
*/ |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
337 |
void lkm_display_hex16 (short hex) |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
338 |
{ |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
339 |
lkm_display_hex(7, ((hex >> 0) & 0xF)); |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
340 |
lkm_display_hex(6, ((hex >> 4) & 0xF)); |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
341 |
lkm_display_hex(5, ((hex >> 8) & 0xF)); |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
342 |
lkm_display_hex(4, ((hex >> 12) & 0xF)); |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
343 |
} |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
344 |
|
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
345 |
// debug |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
346 |
#define DEBUG_DDR DDRB |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
347 |
#define DEBUG_PORT PORTB |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
348 |
#define DEBUG_LED 0 |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
349 |
|
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
350 |
int main (void) |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
351 |
{ |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
352 |
// led_init(); |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
353 |
sbi(&DEBUG_DDR, DEBUG_LED); |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
354 |
|
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
355 |
timer_init(); |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
356 |
lkm_init(); |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
357 |
|
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
358 |
sei(); |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
359 |
|
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
360 |
// setup display |
59 | 361 |
lkm_clear(); |
58
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
362 |
lkm_control(LKM_CONTROL_DISPLAY_ON, LKM_CONTROL_INTENSITY_MAX); |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
363 |
|
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
364 |
// start |
59 | 365 |
byte state[8] = { }; |
366 |
char i; |
|
58
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
367 |
|
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
368 |
while (true) { |
59 | 369 |
// scan input |
370 |
byte buttons = lkm_buttons(); |
|
371 |
||
372 |
for (i = 0; i < 8; i++) { |
|
373 |
if (!(buttons & (1 << i))) { |
|
374 |
continue; |
|
375 |
} else if (state[i] >= 0xF) { |
|
376 |
state[i] = 0; |
|
377 |
} else { |
|
378 |
state[i]++; |
|
379 |
} |
|
58
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
380 |
|
59 | 381 |
lkm_display_hex(i, state[i]); |
382 |
lkm_led(i, state[i]); |
|
383 |
||
384 |
xbi(&DEBUG_PORT, DEBUG_LED); |
|
385 |
} |
|
386 |
||
387 |
timer_sleep(16000); |
|
58
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
388 |
} |
a445e08b63e0
hello-lkm: Control the JY-LKM1638 LED 7-segment display module
Tero Marttila <terom@paivola.fi>
parents:
diff
changeset
|
389 |
} |