Simple shift register library
Dependents: 1620_App_Board_Shift_Register 1620_App_Board_UART_getc 1620_Project_Template 1620_Project_Template ... more
ShiftReg.cpp@1:33b34e0ed72c, 2017-02-20 (annotated)
- Committer:
- eencae
- Date:
- Mon Feb 20 20:38:39 2017 +0000
- Revision:
- 1:33b34e0ed72c
- Parent:
- 0:4922f5f8bfa9
Test change
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
eencae | 0:4922f5f8bfa9 | 1 | #include "ShiftReg.h" |
eencae | 0:4922f5f8bfa9 | 2 | |
eencae | 0:4922f5f8bfa9 | 3 | ShiftReg::ShiftReg() |
eencae | 0:4922f5f8bfa9 | 4 | { |
eencae | 0:4922f5f8bfa9 | 5 | clkout = new DigitalOut(p7); |
eencae | 0:4922f5f8bfa9 | 6 | dataout = new DigitalOut(p5); |
eencae | 0:4922f5f8bfa9 | 7 | latchout = new DigitalOut(p30); |
eencae | 0:4922f5f8bfa9 | 8 | } |
eencae | 0:4922f5f8bfa9 | 9 | |
eencae | 0:4922f5f8bfa9 | 10 | ShiftReg::~ShiftReg() |
eencae | 0:4922f5f8bfa9 | 11 | { |
eencae | 0:4922f5f8bfa9 | 12 | delete clkout; |
eencae | 0:4922f5f8bfa9 | 13 | delete dataout; |
eencae | 0:4922f5f8bfa9 | 14 | delete latchout; |
eencae | 0:4922f5f8bfa9 | 15 | } |
eencae | 0:4922f5f8bfa9 | 16 | |
eencae | 0:4922f5f8bfa9 | 17 | void ShiftReg::write(int data) |
eencae | 0:4922f5f8bfa9 | 18 | { |
eencae | 0:4922f5f8bfa9 | 19 | *latchout = 0; |
eencae | 0:4922f5f8bfa9 | 20 | for (int i = 7; i >= 0; i--) { |
eencae | 0:4922f5f8bfa9 | 21 | *clkout = 0; |
eencae | 0:4922f5f8bfa9 | 22 | *dataout = (data & (1 << i)) != 0; |
eencae | 0:4922f5f8bfa9 | 23 | *clkout = 1; |
eencae | 0:4922f5f8bfa9 | 24 | } |
eencae | 0:4922f5f8bfa9 | 25 | *latchout = 1; |
eencae | 0:4922f5f8bfa9 | 26 | } |