HD44780 compatible 16x2 character LCD driver with HC595 shiftregister
Embed:
(wiki syntax)
Show/hide line numbers
ShiftOut.h
00001 #ifndef SHIFTOUT_H 00002 #define SHIFTOUT_H 00003 00004 #include <mbed.h> 00005 00006 class ShiftOut 00007 { 00008 00009 public : 00010 00011 ShiftOut(PinName data, PinName clk, PinName latch, int8_t registerCount = 8) { 00012 dataout = new DigitalOut(data); 00013 clkout = new DigitalOut(clk); 00014 latchout = new DigitalOut(latch); 00015 this->registerCount = registerCount; 00016 } 00017 00018 ~ShiftOut() { 00019 delete clkout; 00020 delete dataout; 00021 delete latchout; 00022 } 00023 00024 void write(int8_t data) { 00025 *latchout = 0; 00026 for(int i = registerCount - 1; i >= 0; i--) { 00027 *clkout = 0; 00028 wait_us(0.01); 00029 *dataout = (data & (1 << i)) != 0; // 1 or 0 00030 *clkout = 1; 00031 wait_us(0.01); 00032 } 00033 *latchout = 1; 00034 } 00035 00036 private : 00037 DigitalOut *clkout; 00038 DigitalOut *dataout; 00039 DigitalOut *latchout; 00040 int8_t registerCount; 00041 }; 00042 00043 #endif
Generated on Thu Jul 14 2022 03:30:42 by 1.7.2