Tamas Titusz Ban
/
ELEC1620_ExamTemplate_2019
Template for the ELEC1620 End of year exam
ShiftReg/ShiftReg.cpp@0:54721f063ac8, 2019-03-22 (annotated)
- Committer:
- el16ttb
- Date:
- Fri Mar 22 13:11:07 2019 +0000
- Revision:
- 0:54721f063ac8
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el16ttb | 0:54721f063ac8 | 1 | #include "ShiftReg.h" |
el16ttb | 0:54721f063ac8 | 2 | |
el16ttb | 0:54721f063ac8 | 3 | ShiftReg::ShiftReg() |
el16ttb | 0:54721f063ac8 | 4 | { |
el16ttb | 0:54721f063ac8 | 5 | clkout = new DigitalOut(p7); |
el16ttb | 0:54721f063ac8 | 6 | dataout = new DigitalOut(p5); |
el16ttb | 0:54721f063ac8 | 7 | latchout = new DigitalOut(p30); |
el16ttb | 0:54721f063ac8 | 8 | } |
el16ttb | 0:54721f063ac8 | 9 | |
el16ttb | 0:54721f063ac8 | 10 | ShiftReg::~ShiftReg() |
el16ttb | 0:54721f063ac8 | 11 | { |
el16ttb | 0:54721f063ac8 | 12 | delete clkout; |
el16ttb | 0:54721f063ac8 | 13 | delete dataout; |
el16ttb | 0:54721f063ac8 | 14 | delete latchout; |
el16ttb | 0:54721f063ac8 | 15 | } |
el16ttb | 0:54721f063ac8 | 16 | |
el16ttb | 0:54721f063ac8 | 17 | void ShiftReg::write(int data) |
el16ttb | 0:54721f063ac8 | 18 | { |
el16ttb | 0:54721f063ac8 | 19 | *latchout = 0; |
el16ttb | 0:54721f063ac8 | 20 | for (int i = 7; i >= 0; i--) { |
el16ttb | 0:54721f063ac8 | 21 | *clkout = 0; |
el16ttb | 0:54721f063ac8 | 22 | *dataout = (data & (1 << i)) != 0; |
el16ttb | 0:54721f063ac8 | 23 | *clkout = 1; |
el16ttb | 0:54721f063ac8 | 24 | wait_us(20); |
el16ttb | 0:54721f063ac8 | 25 | } |
el16ttb | 0:54721f063ac8 | 26 | *latchout = 1; |
el16ttb | 0:54721f063ac8 | 27 | } |
el16ttb | 0:54721f063ac8 | 28 |