HD44780 compatible 16x2 character LCD driver with HC595 shiftregister

Dependents:   mbed_3pinLCD

Committer:
k4zuki
Date:
Fri Jun 20 01:07:06 2014 +0000
Revision:
0:9cf8e8a3a8d6
porting from arduino library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
k4zuki 0:9cf8e8a3a8d6 1 #ifndef SHIFTOUT_H
k4zuki 0:9cf8e8a3a8d6 2 #define SHIFTOUT_H
k4zuki 0:9cf8e8a3a8d6 3
k4zuki 0:9cf8e8a3a8d6 4 #include <mbed.h>
k4zuki 0:9cf8e8a3a8d6 5
k4zuki 0:9cf8e8a3a8d6 6 class ShiftOut
k4zuki 0:9cf8e8a3a8d6 7 {
k4zuki 0:9cf8e8a3a8d6 8
k4zuki 0:9cf8e8a3a8d6 9 public :
k4zuki 0:9cf8e8a3a8d6 10
k4zuki 0:9cf8e8a3a8d6 11 ShiftOut(PinName data, PinName clk, PinName latch, int8_t registerCount = 8) {
k4zuki 0:9cf8e8a3a8d6 12 dataout = new DigitalOut(data);
k4zuki 0:9cf8e8a3a8d6 13 clkout = new DigitalOut(clk);
k4zuki 0:9cf8e8a3a8d6 14 latchout = new DigitalOut(latch);
k4zuki 0:9cf8e8a3a8d6 15 this->registerCount = registerCount;
k4zuki 0:9cf8e8a3a8d6 16 }
k4zuki 0:9cf8e8a3a8d6 17
k4zuki 0:9cf8e8a3a8d6 18 ~ShiftOut() {
k4zuki 0:9cf8e8a3a8d6 19 delete clkout;
k4zuki 0:9cf8e8a3a8d6 20 delete dataout;
k4zuki 0:9cf8e8a3a8d6 21 delete latchout;
k4zuki 0:9cf8e8a3a8d6 22 }
k4zuki 0:9cf8e8a3a8d6 23
k4zuki 0:9cf8e8a3a8d6 24 void write(int8_t data) {
k4zuki 0:9cf8e8a3a8d6 25 *latchout = 0;
k4zuki 0:9cf8e8a3a8d6 26 for(int i = registerCount - 1; i >= 0; i--) {
k4zuki 0:9cf8e8a3a8d6 27 *clkout = 0;
k4zuki 0:9cf8e8a3a8d6 28 wait_us(0.01);
k4zuki 0:9cf8e8a3a8d6 29 *dataout = (data & (1 << i)) != 0; // 1 or 0
k4zuki 0:9cf8e8a3a8d6 30 *clkout = 1;
k4zuki 0:9cf8e8a3a8d6 31 wait_us(0.01);
k4zuki 0:9cf8e8a3a8d6 32 }
k4zuki 0:9cf8e8a3a8d6 33 *latchout = 1;
k4zuki 0:9cf8e8a3a8d6 34 }
k4zuki 0:9cf8e8a3a8d6 35
k4zuki 0:9cf8e8a3a8d6 36 private :
k4zuki 0:9cf8e8a3a8d6 37 DigitalOut *clkout;
k4zuki 0:9cf8e8a3a8d6 38 DigitalOut *dataout;
k4zuki 0:9cf8e8a3a8d6 39 DigitalOut *latchout;
k4zuki 0:9cf8e8a3a8d6 40 int8_t registerCount;
k4zuki 0:9cf8e8a3a8d6 41 };
k4zuki 0:9cf8e8a3a8d6 42
k4zuki 0:9cf8e8a3a8d6 43 #endif