IC 165 serial input IN by Abhinav

Dependencies:   mbed

main.cpp

Committer:
akverma
Date:
2016-12-03
Revision:
0:9b87785841ab

File content as of revision 0:9b87785841ab:

#include "mbed.h"
#include <bitset>

//DigitalOut lat(P8_11);
//DigitalOut dat(P8_13);
//DigitalOut clk(P4_4);
DigitalOut pins[1][3] = {{P8_11,P8_13,P4_4}};
DigitalIn ser(P2_14);
DigitalOut clk_inh(P4_5);
DigitalOut clk_2(P4_7);
DigitalOut SH_LD(P4_6); 

int delay_time;
uint8_t data_read = 0x00;

void shift(uint8_t data, int delay_time,int row_no){
    DigitalOut lat = pins[row_no][0];
    DigitalOut dat = pins[row_no][1];
    DigitalOut clk = pins[row_no][2];
    clk = 0;
    dat = 0;
    lat = 0; 
    SH_LD = 1;
    clk_inh = 1;
    clk_2 = 1;
    data_read = 0x00;

    dat = data & 0x80;
    clk = 1;
//    wait_us(delay_time);
    clk = 0;
    
    dat = data & 0x40;
    clk = 1;
//    wait_us(delay_time);
    clk = 0;
    
    dat = data & 0x20;
    clk = 1;
 //   wait_us(delay_time);
    clk = 0;
    
    dat = data & 0x10;
    clk = 1;
//    wait_us(delay_time);
    clk = 0;
    
    dat = data & 0x08;
    clk = 1;
//    wait_us(delay_time);
    clk = 0;
    
    dat = data & 0x04;
    clk = 1;
//    wait_us(delay_time);
    clk = 0;
    
    dat = data & 0x02;
    clk = 1;
//    wait_us(delay_time);
    clk = 0;
    
    dat = data & 0x01;
    clk = 1;
//    wait_us(delay_time);
    clk = 0;
    
    lat = 1;
//    wait(delay_time);
    lat = 0;
    
    SH_LD = 0;
    wait_ms(100);
    SH_LD = 1;
    wait_ms(500);
    clk_inh = 0;
    
    wait_ms(500);
    clk_2 = 0;
    data_read = (data_read<<1)|ser;
    wait_ms(500);
    clk_2 = 1;
    
    wait_ms(500);
    clk_2 = 0;
    data_read = (data_read<<1)|ser;
    wait_ms(500);
    clk_2 = 1;
    
    wait_ms(500);
    clk_2 = 0;
    data_read = (data_read<<1)|ser;
    wait_ms(500);
    clk_2 = 1;
    
    wait_ms(500);
    clk_2 = 0;
    data_read = (data_read<<1)|ser;    
    wait_ms(500);
    clk_2 = 1;
    
    wait_ms(500);
    clk_2 = 0;
    data_read = (data_read<<1)|ser;
    wait_ms(500);
    clk_2 = 1;
    
    wait_ms(500);
    clk_2 = 0;
    data_read = (data_read<<1)|ser;
    wait_ms(500);
    clk_2 = 1;
    
    wait_ms(500);
    clk_2 = 0;
    data_read = (data_read<<1)|ser;
    wait_ms(500);
    clk_2 = 1;
    
    wait_ms(500);
    clk_2 = 0;
    data_read = (data_read<<1)|ser;
    wait_ms(500);
    clk_2 = 1;
}

int main() {
    
    shift(0x35, 0.001, 0);
    wait(2);
    shift(~data_read, 0.001, 0);
}