Very simple class for interacting with the CD40147 Priority Encoder chip
CD40147.h
- Committer:
- marmer
- Date:
- 2017-03-21
- Revision:
- 0:41932be18e2f
- Child:
- 1:84213005a5d8
File content as of revision 0:41932be18e2f:
#ifndef CD40147_H #define CD40147_H /** * Handles the CD40147 chip and clones. These are 10-4 line BCD Priority Encoders. * This simple interface lets you know which of the 10 pins, if any, is * connected to ground. As per spec, the result can only tell you about the * highest valued pin which is grounded. Note that pull-up resistors should * be connected to each pin so they are not left floating, which will lead to * unpredictable results. */ class CD40147 { public: /** * Create an instance * * @param a Data input line for least significat bit (bit 0) * @param b Data input line for bit 1 * @param c Data input line for bit 2 * @param d Data input line for most significat bit (bit 3) */ inline CD40147(PinName a, PinName b, PinName c, PinName d) : _in(a,b,c,d) {} /** * Provides the highest valued input that was set, as this is a priority * encoder chip. The value 0x0f means no pin is connected to ground. * Otherwise a value of 0-9 refers to pins 0-9 being grounded. */ inline uint8_t read() {return (~_in.read()) & 0x0f;} protected: BusIn _in; }; #endif