Shift registers working
ShiftReg.cpp
- Committer:
- mwthewsey
- Date:
- 2019-05-07
- Revision:
- 1:9cc13bd590df
- Parent:
- 0:a0e3fd47970f
- Child:
- 2:b565b6a8f612
File content as of revision 1:9cc13bd590df:
#include "mbed.h" #include "ShiftReg.h" ShiftReg::ShiftReg(PinName data, PinName store, PinName clock ): _ds(data), _st(store), _sh(clock){}//Constructor void ShiftReg::ShiftByte (uint16_t data, BitOrd ord ) { uint16_t mask; if (ord == MSBFirst) { mask = 0x8000; } else { mask = 0x0001; } for (uint8_t i = 0; i < 16; i++) { //_ds = data; if (data & mask) { _ds = 1; } else { _ds = 0; } if (ord == MSBFirst) { mask = mask >> 1; } else { mask = mask << 1; } _sh = 0; _sh = 1; } } void ShiftReg::ShiftBit(int8_t data) { _ds = data; _sh = 0; _sh = 1; } void ShiftReg::Latch() { _st = 1; _st = 0; }