@@ -16,11 +16,37 @@ Arduino library for the 74HC154 4-to-16 line decoder/demultiplexer.
1616
1717## Description
1818
19- This library controls the 74HC154 4 to 6 line decoder.
20- With 4 IO lines one can select one of 16 output lines.
19+ This library controls the 74HC154 4 to 16 line decoder.
20+ With 4 IO lines one can select one of 16 output lines to go LOW.
21+ The other lines are HIGH.
2122
23+ The 74HC154 device has two input enable lines E0 and E1.
24+ If one or both enable lines are HIGH all outputs are HIGH and there
25+ is no line LOW.
26+ If both enable lines are LOW, there is one line LOW (defined by the
27+ address pins) and all others are HIGH.
2228
23- #### Related
29+ The library supports only one ENABLE pin which is sufficient to control
30+ the device. Set the other pin permanent LOW if not needed, however
31+ never let the enable line(s) float.
32+
33+ One can use one of the enable inputs as the multiplexed data input.
34+ Keep the other enable input LOW and the addressed output will follow
35+ the state of the applied data.
36+
37+
38+ ### SetLine
39+
40+ When changing a line, not all address lines are set simultaneously as
41+ individual digitalWrite()'s are used.
42+ This might cause other lines be selected for a few microseconds which
43+ might affect the working of your project.
44+ To prevent this behaviour one can ** disable()** the device before
45+ ** setLine()** and ** enable()** the device afterwards.
46+ This only works if the enablePin is set in the constructor.
47+
48+
49+ ### Related
2450
2551- https://github.com/RobTillaart/74HC138 (3 to 8 selector)
2652- https://github.com/RobTillaart/74HC154 (4 to 16 selector)
@@ -36,26 +62,26 @@ With 4 IO lines one can select one of 16 output lines.
3662#include " 74HC154.h"
3763```
3864
39- #### Constructor
65+ ### Constructor
4066
41- - ** 74HC154(uint8_t pin0, uint8_t pin1, uint8_t pin2, uint8_t pin3, uint8_t pinEnable = 255)**
67+ - ** 74HC154(uint8_t pin0, uint8_t pin1, uint8_t pin2, uint8_t pin3, uint8_t pinEnable = 255)**
4268set the 4 selection IO lines from pin numbers.
4369Optionally set the enable pin, connect to E1 or E2, see datasheet.
44- - ** 74HC154(uint8_t \* pins, uint8_t pinEnable = 255)**
70+ - ** 74HC154(uint8_t \* pins, uint8_t pinEnable = 255)**
4571set the 4 selection IO lines from an array.
4672The pins array should have at least 4 elements.
4773Optionally set the enable pin, connect to E1, see datasheet.
4874
4975
50- #### Select line
76+ ### Select line
5177
5278- ** bool setLine(uint8_t line)** set line 0 .. 15. Returns false if out of range.
53- - ** uint8_t getLine()** returns 0 .. 15
79+ - ** uint8_t getLine()** returns 0 .. 15, default line selected = 0.
5480- ** void nextLine()** selects the next line, wraps back to 0 if needed.
5581- ** void prevLine()** selects the previous line, wraps to 15 if needed.
5682
5783
58- #### Enable
84+ ### Enable
5985
6086Works only if enable line is set in constructor.
6187
@@ -76,9 +102,29 @@ Works only if enable line is set in constructor.
76102
77103#### Could
78104
105+ - AVR optimize digitalWrite() as pins are known.
106+ - investigate performance gain setLine by using a changed mask.
107+ - will decrease if all 4 lines change
108+
109+ ``` cpp
110+ void _setLine ()
111+ {
112+ uint8_t changed = _oldLine ^ _line;
113+ for (int i = 0; i < 4; i++)
114+ {
115+ if (changed & 0x01) digitalWrite(_pin[i], (_line >> i) & 0x01);
116+ changed >>= 1;
117+ }
118+ }
119+ ```
120+
121+ - let next/prevLine() return the new line selected?
122+ - optimize the enable functions by checking pin nr.?
123+
79124
80125#### Wont
81126
127+ - set default line in constructor?
82128
83129## Support
84130
0 commit comments