ShiftReg library (74HC595, NUJ3711)

ShiftReg.cpp

Committer:
kysiki
Date:
2015-10-24
Revision:
0:5f1670338bef
Child:
1:3741bc0fbba8

File content as of revision 0:5f1670338bef:

#include "ShiftReg.h"
#include "mbed.h"
 
ShiftReg::ShiftReg(PinName dataPin, PinName stbPin, 
                   PinName clkPin, PinName clrPin)
: 
    DATA(dataPin),
    STB(stbPin),
    CLK(clkPin),
    CLR(clrPin)
{
    DATA = 1;
    STB  = 1;
    CLK  = 1;
    CLR  = 1;
}
 
void ShiftReg::send_data(uint8_t data) {
    shiftOut(data);
    wait_us(1);
#ifdef HC595
    STB = 0;
    wait_us(1);
    STB = 1;
#elif NJU3711
    STB = 1;
    wait_us(1);
    STB = 0;
#else
    printf("not support\n");
#endif
    wait_us(1);
}

void ShiftReg::shiftOut(uint8_t data) {
    for(int i = 0; i < 8; i++) {
        DATA = (data & (1 << i));
        CLK = 0;
        CLK = 1;
    }
}