Shift registers working
ShiftReg.cpp@1:9cc13bd590df, 2019-05-07 (annotated)
- Committer:
- mwthewsey
- Date:
- Tue May 07 13:19:27 2019 +0000
- Revision:
- 1:9cc13bd590df
- Parent:
- 0:a0e3fd47970f
arse bicuits
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
yoonghm | 0:a0e3fd47970f | 1 | #include "mbed.h" |
yoonghm | 0:a0e3fd47970f | 2 | #include "ShiftReg.h" |
yoonghm | 0:a0e3fd47970f | 3 | |
mwthewsey | 1:9cc13bd590df | 4 | ShiftReg::ShiftReg(PinName data, PinName store, PinName clock ): _ds(data), _st(store), _sh(clock){}//Constructor |
mwthewsey | 1:9cc13bd590df | 5 | void ShiftReg::ShiftByte (uint16_t data, BitOrd ord ) |
yoonghm | 0:a0e3fd47970f | 6 | { |
mwthewsey | 1:9cc13bd590df | 7 | uint16_t mask; |
mwthewsey | 1:9cc13bd590df | 8 | if (ord == MSBFirst) |
mwthewsey | 1:9cc13bd590df | 9 | { |
mwthewsey | 1:9cc13bd590df | 10 | mask = 0x8000; |
mwthewsey | 1:9cc13bd590df | 11 | } |
mwthewsey | 1:9cc13bd590df | 12 | else |
mwthewsey | 1:9cc13bd590df | 13 | { |
mwthewsey | 1:9cc13bd590df | 14 | mask = 0x0001; |
mwthewsey | 1:9cc13bd590df | 15 | } |
mwthewsey | 1:9cc13bd590df | 16 | for (uint8_t i = 0; i < 16; i++) |
yoonghm | 0:a0e3fd47970f | 17 | { |
mwthewsey | 1:9cc13bd590df | 18 | //_ds = data; |
yoonghm | 0:a0e3fd47970f | 19 | |
mwthewsey | 1:9cc13bd590df | 20 | if (data & mask) |
mwthewsey | 1:9cc13bd590df | 21 | { |
mwthewsey | 1:9cc13bd590df | 22 | _ds = 1; |
mwthewsey | 1:9cc13bd590df | 23 | } |
mwthewsey | 1:9cc13bd590df | 24 | else |
mwthewsey | 1:9cc13bd590df | 25 | { |
mwthewsey | 1:9cc13bd590df | 26 | _ds = 0; |
mwthewsey | 1:9cc13bd590df | 27 | } |
mwthewsey | 1:9cc13bd590df | 28 | if (ord == MSBFirst) |
mwthewsey | 1:9cc13bd590df | 29 | { |
mwthewsey | 1:9cc13bd590df | 30 | mask = mask >> 1; |
mwthewsey | 1:9cc13bd590df | 31 | } |
mwthewsey | 1:9cc13bd590df | 32 | else |
mwthewsey | 1:9cc13bd590df | 33 | { |
mwthewsey | 1:9cc13bd590df | 34 | mask = mask << 1; |
mwthewsey | 1:9cc13bd590df | 35 | } |
yoonghm | 0:a0e3fd47970f | 36 | _sh = 0; |
yoonghm | 0:a0e3fd47970f | 37 | _sh = 1; |
yoonghm | 0:a0e3fd47970f | 38 | } |
yoonghm | 0:a0e3fd47970f | 39 | } |
mwthewsey | 1:9cc13bd590df | 40 | void ShiftReg::ShiftBit(int8_t data) |
yoonghm | 0:a0e3fd47970f | 41 | { |
yoonghm | 0:a0e3fd47970f | 42 | _ds = data; |
yoonghm | 0:a0e3fd47970f | 43 | _sh = 0; |
yoonghm | 0:a0e3fd47970f | 44 | _sh = 1; |
yoonghm | 0:a0e3fd47970f | 45 | } |
yoonghm | 0:a0e3fd47970f | 46 | |
mwthewsey | 1:9cc13bd590df | 47 | void ShiftReg::Latch() |
yoonghm | 0:a0e3fd47970f | 48 | { |
yoonghm | 0:a0e3fd47970f | 49 | _st = 1; |
yoonghm | 0:a0e3fd47970f | 50 | _st = 0; |
yoonghm | 0:a0e3fd47970f | 51 | } |