Template for the ELEC1620 End of year exam

Dependencies:   mbed

Committer:
el16ttb
Date:
Fri Mar 22 13:11:07 2019 +0000
Revision:
0:54721f063ac8
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew 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