A library interface to shift register such as NXP 74HCT595
Dependents: DiscoTech filter_implement System_Project_V6 LM35functionshield ... more
ShiftReg Class Reference
A interface to drive shifter register as such 74HCT595. More...
#include <ShiftReg.h>
Public Types | |
enum | BitOrd { MSBFirst = 0x80, LSBFirst = 0x01 } |
Bit order out format. More... | |
Public Member Functions | |
ShiftReg (PinName data, PinName store, PinName clock) | |
Create a ShiftReg interface to shift register. | |
void | ShiftByte (int8_t data, BitOrd ord=MSBFirst) |
Shift out 8-bit data via the serial pin. | |
void | ShiftBit (int8_t data=0) |
Shift out 1-bit data via the serial pin. | |
void | Latch () |
Latch data out. |
Detailed Description
A interface to drive shifter register as such 74HCT595.
#include "mbed.h" #include "ShiftReg.h" ShiftReg HC595(p21, p22, p23); int main() { // clear shift and store registers initially HC595.ShiftByte(0x00, ShiftReg::MSBFirst); HC595.Latch(); wait(0.2); while(1) { // Demostrate to shift in bit by bit HC595.ShiftBit(1); HC595.Latch(); wait(0.2); for (int i = 0; i < 8; i++) { HC595.ShiftBit(0); HC595.Latch(); wait(0.2); } // Demostrate to shift in byte-by-byte // HC595.ShiftByte(0x80, ShiftReg::MSBFirst); HC595.Latch(); wait(0.2); HC595.ShiftByte(0x40, ShiftReg::MSBFirst); HC595.Latch(); wait(0.2); HC595.ShiftByte(0x20, ShiftReg::MSBFirst); HC595.Latch(); wait(0.2); HC595.ShiftByte(0x10, ShiftReg::MSBFirst); HC595.Latch(); wait(0.2); HC595.ShiftByte(0x08, ShiftReg::MSBFirst); HC595.Latch(); wait(0.2); HC595.ShiftByte(0x04, ShiftReg::MSBFirst); HC595.Latch(); wait(0.2); HC595.ShiftByte(0x02, ShiftReg::MSBFirst); HC595.Latch(); wait(0.2); HC595.ShiftByte(0x01, ShiftReg::MSBFirst); HC595.Latch(); wait(0.2); HC595.ShiftByte(0x00, ShiftReg::MSBFirst); HC595.Latch(); wait(0.2); } }
Definition at line 62 of file ShiftReg.h.
Member Enumeration Documentation
enum BitOrd |
Bit order out format.
Definition at line 66 of file ShiftReg.h.
Constructor & Destructor Documentation
ShiftReg | ( | PinName | data, |
PinName | store, | ||
PinName | clock | ||
) |
Create a ShiftReg interface to shift register.
- Parameters:
-
data Pin to serial input to shift register store Pin to store register clock Pin to shift into register
Definition at line 7 of file ShiftReg.cpp.
Member Function Documentation
void Latch | ( | ) |
Latch data out.
Definition at line 59 of file ShiftReg.cpp.
void ShiftBit | ( | int8_t | data = 0 ) |
Shift out 1-bit data via the serial pin.
- Parameters:
-
data Data to be shifted out via the serial pin
Definition at line 49 of file ShiftReg.cpp.
void ShiftByte | ( | int8_t | data, |
BitOrd | ord = MSBFirst |
||
) |
Shift out 8-bit data via the serial pin.
- Parameters:
-
data Data to be shifted out via the serial pin order Bit order to shift out data. Default is MSBFirst
Definition at line 16 of file ShiftReg.cpp.
Generated on Tue Jul 12 2022 19:29:32 by 1.7.2