shift register
Dependents: Enrico_newproject_copy Enrico_copy Enrico_copy2 Project_ORBE
Fork of Shifter by
Revision 3:4511084b5546, committed 2018-05-30
- Comitter:
- billycorgan123
- Date:
- Wed May 30 14:57:03 2018 +0000
- Parent:
- 1:b6a66e7e1947
- Commit message:
- changed timing
Changed in this revision
Shifter.cpp | Show annotated file Show diff for this revision Revisions of this file |
Shifter.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r b6a66e7e1947 -r 4511084b5546 Shifter.cpp --- a/Shifter.cpp Wed Mar 07 21:10:59 2018 +0000 +++ b/Shifter.cpp Wed May 30 14:57:03 2018 +0000 @@ -4,34 +4,38 @@ #define LOW 0 #define HIGH 1 DigitalOut SER_Pin(D4); //pin 14 su 595 -DigitalOut RCLK_Pin(D3); //pin 1x su 595 -DigitalOut SRCLK_Pin(D2); //pin 1x su 595 +DigitalOut RCLK_Pin(D3); //pin 11 su 595 +DigitalOut SRCLK_Pin(D2); //pin 12 su 595 int Number_of_Registers=2; void Shifter::write() { //Set and display registers //Only call AFTER all values are set how you would like (slow otherwise) -RCLK_Pin.write(LOW); - - //iterate through the registers - for(int i = Number_of_Registers - 1; i >= 0; i--) - { - //iterate through the bits in each registers - for(int j = 8 - 1; j >= 0; j--) - { - SRCLK_Pin.write(LOW); - wait_us(1); - int val = shiftRegisters[i] & (1 << j); - SER_Pin.write(val); - wait_us(1); - SRCLK_Pin.write(HIGH); - } - - } - RCLK_Pin.write(HIGH); + RCLK_Pin.write(LOW); + SRCLK_Pin.write(LOW); + wait_us(10); + //iterate through the registers + for(int i = Number_of_Registers - 1; i >= 0; i--) { + //iterate through the bits in each registers + for(int j = 8 - 1; j >= 0; j--) { + SRCLK_Pin.write(LOW); + wait_us(4); + int val = shiftRegisters[i] & (1 << j); + SER_Pin.write(val); + wait_us(1); //wait_us(10); + SRCLK_Pin.write(HIGH); + wait_us(10); //wait_us(10); + SRCLK_Pin.write(LOW); + wait_us(6); //wait_us(10); + } + } + RCLK_Pin.write(HIGH); + wait_us(10); + RCLK_Pin.write(LOW); + wait_us(10); } - + void Shifter::setPin(int index, bool val) { int byteIndex = index/8; @@ -44,12 +48,16 @@ void Shifter::setAll(bool val) { -//set all register pins to LOW - for(int i = Number_of_Registers * 8 - 1; i >= 0; i--){ setPin(i, val); } +//set all register pins to val + for(int i = Number_of_Registers * 8 - 1; i >= 0; i--) { + setPin(i, val); + } } void Shifter::clear() { -//set all register pins to LOW - for(int i = Number_of_Registers * 8 - 1; i >= 0; i--){ setPin(i, LOW); } +//set all register pins to LOW + for(int i = Number_of_Registers * 8 - 1; i >= 0; i--) { + setPin(i, HIGH); + } } \ No newline at end of file
diff -r b6a66e7e1947 -r 4511084b5546 Shifter.h --- a/Shifter.h Wed Mar 07 21:10:59 2018 +0000 +++ b/Shifter.h Wed May 30 14:57:03 2018 +0000 @@ -13,7 +13,7 @@ void setAll(bool); void clear(); private: - char shiftRegisters[25]; + char shiftRegisters[16]; }; #endif \ No newline at end of file