needed for 1620 test code
Fork of ShiftOut by
Embed:
(wiki syntax)
Show/hide line numbers
ShiftOut.h
00001 #ifndef SHIFTOUT_H 00002 #define SHIFTOUT_H 00003 00004 #include <mbed.h> 00005 00006 /** A simple serial driver for a shift register that uses only three digital out pins leaving SPI and i2c free. 00007 * ShiftOut can be configured for any size shift register but defaults to eight bits. 00008 */ 00009 class ShiftOut { 00010 00011 public : 00012 00013 /** Constructs a new ShiftOut with the given three pins. 00014 * @param clk - the pin to use for the shift register clock. 00015 * @param data - the pin to use for the shift register data line. 00016 * @param latch - the pin to use for the shift register latch. 00017 * @param registerCount - the number of registers in the shift register, defaults to eight. 00018 */ 00019 ShiftOut(PinName clk, PinName data, PinName latch, int8_t registerCount = 0x08) { 00020 clkout = new DigitalOut(clk); 00021 dataout = new DigitalOut(data); 00022 latchout = new DigitalOut(latch); 00023 this->registerCount = registerCount; 00024 } 00025 00026 ~ShiftOut() { 00027 delete clkout; 00028 delete dataout; 00029 delete latchout; 00030 } 00031 00032 /** Writes the given integer to the shift register 00033 */ 00034 void write(int data) { 00035 *latchout = 0; 00036 for (int i = registerCount - 1; i >= 0; i--) { 00037 *clkout = 0; 00038 *dataout = (data & (1 << i)) != 0; 00039 *clkout = 1; 00040 } 00041 *latchout = 1; 00042 } 00043 00044 void set_latch (int val){ 00045 *latchout = val; 00046 } 00047 00048 private : 00049 DigitalOut *clkout; 00050 DigitalOut *dataout; 00051 DigitalOut *latchout; 00052 int8_t registerCount; 00053 }; 00054 00055 #endif
Generated on Wed Jul 13 2022 02:30:54 by
1.7.2
