This is a GR peach project demonstrating shift registers 595 and 165
Fork of mbed_shiftreg_2 by
shitreg.cpp
- Committer:
- akverma
- Date:
- 2017-01-04
- Revision:
- 7:2c0917fbf656
- Parent:
- 6:5889eff2e861
- Child:
- 8:6930a00ba8ba
File content as of revision 7:2c0917fbf656:
#include<iostream> #include "mbed.h" #include "arduino.h" #define delay_time 0 #define outlets 11 #define TOTAL_NODES 88 Serial pc(USBTX, USBRX); // tx, rx DigitalOut latch = P8_11; DigitalOut CLK_595 = P8_13; DigitalOut data_out_pins[outlets][3] = { {P4_4, P4_5, P4_6}, {P1_2, P1_3, P10_12}, {P10_14, P10_13, P8_14}, {P1_8, P1_9, P1_10}, {P1_13, P1_15, P1_7}, {P10_0, P1_1, P1_0}, {P2_7, P2_6, P2_5}, {P2_3, P2_2, P2_1}, {P7_15, P8_1, P2_9}, {P4_0, P2_13, P5_7}, {P5_3, P5_2, P5_1},}; DigitalIn data_in_pins[outlets] = {P4_7,P10_15,P8_15,P1_11,P1_6,P1_12,P2_4,P2_0,P2_10,P5_6,P5_0}; DigitalOut CLK_165(P2_14); DigitalOut load(P2_15); uint8_t data_read; //uint8_t data_in[outlets]; //uint8_t data_out[outlets][3][8] = {{0xC5, 0xB2, 0x68}}; //First column is output A (PNP), second column is output B (NPN) and third column is output C. bool c1[TOTAL_NODES]; bool c2[TOTAL_NODES]; bool c3[TOTAL_NODES]; bool A[TOTAL_NODES]; bool B[TOTAL_NODES]; bool C[TOTAL_NODES]; bool cm[TOTAL_NODES][TOTAL_NODES]; bool so[TOTAL_NODES]; bool sov[TOTAL_NODES]; bool o[TOTAL_NODES]; bool ov[TOTAL_NODES]; void shift(){ // DigitalOut lat = pins[row_no][0]; // DigitalOut dat = pins[row_no][1]; // DigitalOut clk = pins[row_no][2]; CLK_595 = 0; latch = 0; for(int i=7; i>=0; i--) { for (int j=0; j<outlets; j++) { data_out_pins[j][0] = A[8*j + i]; data_out_pins[j][1] = B[8*j + i]; data_out_pins[j][2] = C[8*j + i]; } CLK_595 = 1; CLK_595 = 0; } latch = 1; latch = 0; } void shift_read1(){ load = 0; load = 1; for(int i=7; i>=0; i--) { for (int j=0; j<outlets; j++) { c2[j*8 + i] = data_in_pins[i]; } CLK_165 = 0; CLK_165 = 1; } } void shift_read2(){ load = 0; load = 1; for(int i=7; i>=0; i--) { for (int j=0; j<outlets; j++) { c2[j*8 + i] = data_in_pins[i]; } CLK_165 = 0; CLK_165 = 1; } } void value_calculator() { for (int i=0; i<TOTAL_NODES; i++) { c3[i] = c1[i]^c2[i]; C[i] = ~(c1[i]|c2[i]); } for (int i=0; i<TOTAL_NODES; i++) { o[i] = 0; ov[i] = 0; for (int j=0; j<TOTAL_NODES; j++) { o[i] = o[i] | (cm[i][j] & c3[j]); ov[i] = ov[i] | (cm[i][j] & c3[j] & c1[j]); } ov[i] = ((~so[i]) & ov[i]) | (so[i] & sov[i]); A[i] = ~(o[i] & ov[i]); B[i] = o[i] & ~ov[i]; } } void call(){ char data_out = pc.getc(); shift(); } int main() { pc.attach(&call); long time_counter1 = 0; wait_ms(500); cout<<"Starting: "<<endl; wait_ms(500); for (int i=0; i<TOTAL_NODES; i++) { c1[i] = 0; c2[i] = 1; } while(1){ value_calculator(); shift(); shift_read1(); value_calculator(); shift(); shift_read2(); time_counter1++; if (time_counter1 == 1000000) { pc.printf("%X\n", 'B'); time_counter1 = 0; } } }