ShiftReg library (74HC595, NUJ3711)
Diff: ShiftReg.cpp
- Revision:
- 0:5f1670338bef
- Child:
- 1:3741bc0fbba8
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ShiftReg.cpp Sat Oct 24 16:30:11 2015 +0000 @@ -0,0 +1,41 @@ +#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; + } +} \ No newline at end of file