HD44780 compatible 16x2 character LCD driver with HC595 shiftregister
ShiftOut.h
- Committer:
- k4zuki
- Date:
- 2014-06-20
- Revision:
- 0:9cf8e8a3a8d6
File content as of revision 0:9cf8e8a3a8d6:
#ifndef SHIFTOUT_H #define SHIFTOUT_H #include <mbed.h> class ShiftOut { public : ShiftOut(PinName data, PinName clk, PinName latch, int8_t registerCount = 8) { dataout = new DigitalOut(data); clkout = new DigitalOut(clk); latchout = new DigitalOut(latch); this->registerCount = registerCount; } ~ShiftOut() { delete clkout; delete dataout; delete latchout; } void write(int8_t data) { *latchout = 0; for(int i = registerCount - 1; i >= 0; i--) { *clkout = 0; wait_us(0.01); *dataout = (data & (1 << i)) != 0; // 1 or 0 *clkout = 1; wait_us(0.01); } *latchout = 1; } private : DigitalOut *clkout; DigitalOut *dataout; DigitalOut *latchout; int8_t registerCount; }; #endif