Skip to content

Commit a491062

Browse files
committed
0.2.0 74HC154
1 parent 23f77f5 commit a491062

File tree

6 files changed

+75
-18
lines changed

6 files changed

+75
-18
lines changed

libraries/74HC154/74HC154.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
// FILE: 74HC154.h
44
// AUTHOR: Rob Tillaart
55
// DATE: 2024-02-22
6-
// VERSION: 0.1.0
6+
// VERSION: 0.2.0
77
// PURPOSE: Arduino library for the 74HC154 4-to-16 line decoder/demultiplexer.
88
// URL: https://github.com/RobTillaart/74HC154
99

1010

1111
#include "Arduino.h"
1212

13-
#define LIB_74HC154_VERSION (F("0.1.0"))
13+
#define LIB_74HC154_VERSION (F("0.2.0"))
1414

1515

1616

@@ -86,16 +86,19 @@ class DEV_74HC154
8686

8787
void enable()
8888
{
89+
// if (_enable == 255) return;
8990
digitalWrite(_enable, LOW);
9091
}
9192

9293
void disable()
9394
{
95+
// if (_enable == 255) return;
9496
digitalWrite(_enable, HIGH);
9597
}
9698

9799
bool isEnabled()
98100
{
101+
// if (_enable == 255) return false???;
99102
return digitalRead(_enable);
100103
}
101104

@@ -107,13 +110,14 @@ class DEV_74HC154
107110

108111
void _setLine()
109112
{
110-
digitalWrite(_pin[0], _line & 0x01);
111-
digitalWrite(_pin[1], _line & 0x02);
112-
digitalWrite(_pin[2], _line & 0x04);
113-
digitalWrite(_pin[3], _line & 0x08);
113+
digitalWrite(_pin[0], (_line >> 0) & 0x01);
114+
digitalWrite(_pin[1], (_line >> 1) & 0x01);
115+
digitalWrite(_pin[2], (_line >> 2) & 0x01);
116+
digitalWrite(_pin[3], (_line >> 3) & 0x01);
114117
}
115118

116119
/*
120+
// read from the pins instead of from cache
117121
uint8_t getLine()
118122
{
119123
uint8_t value = digitalRead(_pin[0]);

libraries/74HC154/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

88

9+
## [0.2.0] - 2025-06-03
10+
- fix #2, support for ATtiny402 (kudos to trent-lane)
11+
- update readme.md
12+
- minor edits
13+
14+
----
15+
916
## [0.1.0] - 2024-02-23
1017
- initial version
1118

libraries/74HC154/LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2024-2024 Rob Tillaart
3+
Copyright (c) 2024-2025 Rob Tillaart
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

libraries/74HC154/README.md

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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)**
4268
set the 4 selection IO lines from pin numbers.
4369
Optionally 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)**
4571
set the 4 selection IO lines from an array.
4672
The pins array should have at least 4 elements.
4773
Optionally 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

6086
Works 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

libraries/74HC154/library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"type": "git",
1616
"url": "https://github.com/RobTillaart/74HC154.git"
1717
},
18-
"version": "0.1.0",
18+
"version": "0.2.0",
1919
"license": "MIT",
2020
"frameworks": "*",
2121
"platforms": "*",

libraries/74HC154/library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=74HC154
2-
version=0.1.0
2+
version=0.2.0
33
author=Rob Tillaart <[email protected]>
44
maintainer=Rob Tillaart <[email protected]>
55
sentence=Arduino library for the 74HC154 4 to 16 line decoder/demultiplexer.

0 commit comments

Comments
 (0)