Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
ShiftReg.cpp
- Committer:
- mwthewsey
- Date:
- 2019-05-07
- Revision:
- 1:9cc13bd590df
- Parent:
- 0:a0e3fd47970f
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;
}