Very simple class for interacting with the CD40147 Priority Encoder chip

Committer:
marmer
Date:
Tue Mar 21 22:04:08 2017 +0000
Revision:
0:41932be18e2f
Child:
1:84213005a5d8
Initial revision

Who changed what in which revision?

UserRevisionLine numberNew contents of line
marmer 0:41932be18e2f 1 #ifndef CD40147_H
marmer 0:41932be18e2f 2 #define CD40147_H
marmer 0:41932be18e2f 3
marmer 0:41932be18e2f 4 /**
marmer 0:41932be18e2f 5 * Handles the CD40147 chip and clones. These are 10-4 line BCD Priority Encoders.
marmer 0:41932be18e2f 6 * This simple interface lets you know which of the 10 pins, if any, is
marmer 0:41932be18e2f 7 * connected to ground. As per spec, the result can only tell you about the
marmer 0:41932be18e2f 8 * highest valued pin which is grounded. Note that pull-up resistors should
marmer 0:41932be18e2f 9 * be connected to each pin so they are not left floating, which will lead to
marmer 0:41932be18e2f 10 * unpredictable results.
marmer 0:41932be18e2f 11 */
marmer 0:41932be18e2f 12 class CD40147 {
marmer 0:41932be18e2f 13 public:
marmer 0:41932be18e2f 14 /**
marmer 0:41932be18e2f 15 * Create an instance
marmer 0:41932be18e2f 16 *
marmer 0:41932be18e2f 17 * @param a Data input line for least significat bit (bit 0)
marmer 0:41932be18e2f 18 * @param b Data input line for bit 1
marmer 0:41932be18e2f 19 * @param c Data input line for bit 2
marmer 0:41932be18e2f 20 * @param d Data input line for most significat bit (bit 3)
marmer 0:41932be18e2f 21 */
marmer 0:41932be18e2f 22 inline CD40147(PinName a, PinName b, PinName c, PinName d) : _in(a,b,c,d) {}
marmer 0:41932be18e2f 23
marmer 0:41932be18e2f 24 /**
marmer 0:41932be18e2f 25 * Provides the highest valued input that was set, as this is a priority
marmer 0:41932be18e2f 26 * encoder chip. The value 0x0f means no pin is connected to ground.
marmer 0:41932be18e2f 27 * Otherwise a value of 0-9 refers to pins 0-9 being grounded.
marmer 0:41932be18e2f 28 */
marmer 0:41932be18e2f 29 inline uint8_t read() {return (~_in.read()) & 0x0f;}
marmer 0:41932be18e2f 30
marmer 0:41932be18e2f 31 protected:
marmer 0:41932be18e2f 32 BusIn _in;
marmer 0:41932be18e2f 33 };
marmer 0:41932be18e2f 34
marmer 0:41932be18e2f 35 #endif