IC 165 serial input IN by Abhinav

Dependencies:   mbed

Committer:
akverma
Date:
Sat Dec 03 07:27:42 2016 +0000
Revision:
0:9b87785841ab
Serial read via IC165

Who changed what in which revision?

UserRevisionLine numberNew contents of line
akverma 0:9b87785841ab 1 #include "mbed.h"
akverma 0:9b87785841ab 2 #include <bitset>
akverma 0:9b87785841ab 3
akverma 0:9b87785841ab 4 //DigitalOut lat(P8_11);
akverma 0:9b87785841ab 5 //DigitalOut dat(P8_13);
akverma 0:9b87785841ab 6 //DigitalOut clk(P4_4);
akverma 0:9b87785841ab 7 DigitalOut pins[1][3] = {{P8_11,P8_13,P4_4}};
akverma 0:9b87785841ab 8 DigitalIn ser(P2_14);
akverma 0:9b87785841ab 9 DigitalOut clk_inh(P4_5);
akverma 0:9b87785841ab 10 DigitalOut clk_2(P4_7);
akverma 0:9b87785841ab 11 DigitalOut SH_LD(P4_6);
akverma 0:9b87785841ab 12
akverma 0:9b87785841ab 13 int delay_time;
akverma 0:9b87785841ab 14 uint8_t data_read = 0x00;
akverma 0:9b87785841ab 15
akverma 0:9b87785841ab 16 void shift(uint8_t data, int delay_time,int row_no){
akverma 0:9b87785841ab 17 DigitalOut lat = pins[row_no][0];
akverma 0:9b87785841ab 18 DigitalOut dat = pins[row_no][1];
akverma 0:9b87785841ab 19 DigitalOut clk = pins[row_no][2];
akverma 0:9b87785841ab 20 clk = 0;
akverma 0:9b87785841ab 21 dat = 0;
akverma 0:9b87785841ab 22 lat = 0;
akverma 0:9b87785841ab 23 SH_LD = 1;
akverma 0:9b87785841ab 24 clk_inh = 1;
akverma 0:9b87785841ab 25 clk_2 = 1;
akverma 0:9b87785841ab 26 data_read = 0x00;
akverma 0:9b87785841ab 27
akverma 0:9b87785841ab 28 dat = data & 0x80;
akverma 0:9b87785841ab 29 clk = 1;
akverma 0:9b87785841ab 30 // wait_us(delay_time);
akverma 0:9b87785841ab 31 clk = 0;
akverma 0:9b87785841ab 32
akverma 0:9b87785841ab 33 dat = data & 0x40;
akverma 0:9b87785841ab 34 clk = 1;
akverma 0:9b87785841ab 35 // wait_us(delay_time);
akverma 0:9b87785841ab 36 clk = 0;
akverma 0:9b87785841ab 37
akverma 0:9b87785841ab 38 dat = data & 0x20;
akverma 0:9b87785841ab 39 clk = 1;
akverma 0:9b87785841ab 40 // wait_us(delay_time);
akverma 0:9b87785841ab 41 clk = 0;
akverma 0:9b87785841ab 42
akverma 0:9b87785841ab 43 dat = data & 0x10;
akverma 0:9b87785841ab 44 clk = 1;
akverma 0:9b87785841ab 45 // wait_us(delay_time);
akverma 0:9b87785841ab 46 clk = 0;
akverma 0:9b87785841ab 47
akverma 0:9b87785841ab 48 dat = data & 0x08;
akverma 0:9b87785841ab 49 clk = 1;
akverma 0:9b87785841ab 50 // wait_us(delay_time);
akverma 0:9b87785841ab 51 clk = 0;
akverma 0:9b87785841ab 52
akverma 0:9b87785841ab 53 dat = data & 0x04;
akverma 0:9b87785841ab 54 clk = 1;
akverma 0:9b87785841ab 55 // wait_us(delay_time);
akverma 0:9b87785841ab 56 clk = 0;
akverma 0:9b87785841ab 57
akverma 0:9b87785841ab 58 dat = data & 0x02;
akverma 0:9b87785841ab 59 clk = 1;
akverma 0:9b87785841ab 60 // wait_us(delay_time);
akverma 0:9b87785841ab 61 clk = 0;
akverma 0:9b87785841ab 62
akverma 0:9b87785841ab 63 dat = data & 0x01;
akverma 0:9b87785841ab 64 clk = 1;
akverma 0:9b87785841ab 65 // wait_us(delay_time);
akverma 0:9b87785841ab 66 clk = 0;
akverma 0:9b87785841ab 67
akverma 0:9b87785841ab 68 lat = 1;
akverma 0:9b87785841ab 69 // wait(delay_time);
akverma 0:9b87785841ab 70 lat = 0;
akverma 0:9b87785841ab 71
akverma 0:9b87785841ab 72 SH_LD = 0;
akverma 0:9b87785841ab 73 wait_ms(100);
akverma 0:9b87785841ab 74 SH_LD = 1;
akverma 0:9b87785841ab 75 wait_ms(500);
akverma 0:9b87785841ab 76 clk_inh = 0;
akverma 0:9b87785841ab 77
akverma 0:9b87785841ab 78 wait_ms(500);
akverma 0:9b87785841ab 79 clk_2 = 0;
akverma 0:9b87785841ab 80 data_read = (data_read<<1)|ser;
akverma 0:9b87785841ab 81 wait_ms(500);
akverma 0:9b87785841ab 82 clk_2 = 1;
akverma 0:9b87785841ab 83
akverma 0:9b87785841ab 84 wait_ms(500);
akverma 0:9b87785841ab 85 clk_2 = 0;
akverma 0:9b87785841ab 86 data_read = (data_read<<1)|ser;
akverma 0:9b87785841ab 87 wait_ms(500);
akverma 0:9b87785841ab 88 clk_2 = 1;
akverma 0:9b87785841ab 89
akverma 0:9b87785841ab 90 wait_ms(500);
akverma 0:9b87785841ab 91 clk_2 = 0;
akverma 0:9b87785841ab 92 data_read = (data_read<<1)|ser;
akverma 0:9b87785841ab 93 wait_ms(500);
akverma 0:9b87785841ab 94 clk_2 = 1;
akverma 0:9b87785841ab 95
akverma 0:9b87785841ab 96 wait_ms(500);
akverma 0:9b87785841ab 97 clk_2 = 0;
akverma 0:9b87785841ab 98 data_read = (data_read<<1)|ser;
akverma 0:9b87785841ab 99 wait_ms(500);
akverma 0:9b87785841ab 100 clk_2 = 1;
akverma 0:9b87785841ab 101
akverma 0:9b87785841ab 102 wait_ms(500);
akverma 0:9b87785841ab 103 clk_2 = 0;
akverma 0:9b87785841ab 104 data_read = (data_read<<1)|ser;
akverma 0:9b87785841ab 105 wait_ms(500);
akverma 0:9b87785841ab 106 clk_2 = 1;
akverma 0:9b87785841ab 107
akverma 0:9b87785841ab 108 wait_ms(500);
akverma 0:9b87785841ab 109 clk_2 = 0;
akverma 0:9b87785841ab 110 data_read = (data_read<<1)|ser;
akverma 0:9b87785841ab 111 wait_ms(500);
akverma 0:9b87785841ab 112 clk_2 = 1;
akverma 0:9b87785841ab 113
akverma 0:9b87785841ab 114 wait_ms(500);
akverma 0:9b87785841ab 115 clk_2 = 0;
akverma 0:9b87785841ab 116 data_read = (data_read<<1)|ser;
akverma 0:9b87785841ab 117 wait_ms(500);
akverma 0:9b87785841ab 118 clk_2 = 1;
akverma 0:9b87785841ab 119
akverma 0:9b87785841ab 120 wait_ms(500);
akverma 0:9b87785841ab 121 clk_2 = 0;
akverma 0:9b87785841ab 122 data_read = (data_read<<1)|ser;
akverma 0:9b87785841ab 123 wait_ms(500);
akverma 0:9b87785841ab 124 clk_2 = 1;
akverma 0:9b87785841ab 125 }
akverma 0:9b87785841ab 126
akverma 0:9b87785841ab 127 int main() {
akverma 0:9b87785841ab 128
akverma 0:9b87785841ab 129 shift(0x35, 0.001, 0);
akverma 0:9b87785841ab 130 wait(2);
akverma 0:9b87785841ab 131 shift(~data_read, 0.001, 0);
akverma 0:9b87785841ab 132 }