Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of mbed_shiftreg_2 by
shitreg.cpp@3:1696c69e3109, 2017-01-03 (annotated)
- Committer:
- akverma
- Date:
- Tue Jan 03 17:05:14 2017 +0000
- Revision:
- 3:1696c69e3109
- Parent:
- 2:a07ae6396167
- Child:
- 6:5889eff2e861
After organising it for frequency test.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
akverma | 3:1696c69e3109 | 1 | #include<iostream> |
RahulSitaram | 0:b9fbca7b029d | 2 | #include "mbed.h" |
RahulSitaram | 0:b9fbca7b029d | 3 | //#include <bitset> |
RahulSitaram | 0:b9fbca7b029d | 4 | #include "arduino.h" |
RahulSitaram | 0:b9fbca7b029d | 5 | |
akverma | 3:1696c69e3109 | 6 | #define delay_time 0 |
akverma | 3:1696c69e3109 | 7 | #define outlets 1 |
akverma | 3:1696c69e3109 | 8 | |
RahulSitaram | 0:b9fbca7b029d | 9 | //using namespace mbed::mbed; |
RahulSitaram | 0:b9fbca7b029d | 10 | |
RahulSitaram | 0:b9fbca7b029d | 11 | //DigitalOut lat(P8_11); |
RahulSitaram | 0:b9fbca7b029d | 12 | //DigitalOut dat(P8_13); |
RahulSitaram | 0:b9fbca7b029d | 13 | //DigitalOut clk(P4_4); |
RahulSitaram | 0:b9fbca7b029d | 14 | Serial pc(USBTX, USBRX); // tx, rx |
akverma | 3:1696c69e3109 | 15 | DigitalOut latch = P8_11; |
akverma | 3:1696c69e3109 | 16 | DigitalOut CLK_595 = P8_13; |
akverma | 3:1696c69e3109 | 17 | DigitalOut data_out_pins[outlets][3] = {{P4_4, P4_5, P4_6}}; |
akverma | 3:1696c69e3109 | 18 | DigitalIn data_in_pins[outlets] = {P4_7}; |
akverma | 3:1696c69e3109 | 19 | DigitalOut CLK_165(P2_14); |
akverma | 3:1696c69e3109 | 20 | DigitalOut load(P2_15); |
RahulSitaram | 0:b9fbca7b029d | 21 | |
RahulSitaram | 0:b9fbca7b029d | 22 | uint8_t data_read; |
RahulSitaram | 1:b42fa19eeea8 | 23 | bool c1[4]; |
RahulSitaram | 1:b42fa19eeea8 | 24 | bool c2[4]; |
RahulSitaram | 1:b42fa19eeea8 | 25 | bool c3[4]; |
RahulSitaram | 1:b42fa19eeea8 | 26 | bool c4[4]; |
akverma | 3:1696c69e3109 | 27 | uint8_t data_in[outlets]; |
akverma | 3:1696c69e3109 | 28 | uint8_t data_out[outlets][3] = {{0xC5, 0xB2, 0x68}}; |
RahulSitaram | 1:b42fa19eeea8 | 29 | |
akverma | 3:1696c69e3109 | 30 | void shift(){ |
akverma | 3:1696c69e3109 | 31 | // DigitalOut lat = pins[row_no][0]; |
akverma | 3:1696c69e3109 | 32 | // DigitalOut dat = pins[row_no][1]; |
akverma | 3:1696c69e3109 | 33 | // DigitalOut clk = pins[row_no][2]; |
akverma | 3:1696c69e3109 | 34 | CLK_595 = 0; |
akverma | 3:1696c69e3109 | 35 | latch = 0; |
akverma | 3:1696c69e3109 | 36 | int init = 0x80; |
akverma | 3:1696c69e3109 | 37 | for(int i=0; i<8; i++) |
akverma | 3:1696c69e3109 | 38 | { |
akverma | 3:1696c69e3109 | 39 | for (int j=0; j<outlets; j++) |
akverma | 3:1696c69e3109 | 40 | { |
akverma | 3:1696c69e3109 | 41 | data_out_pins[j][0] = data_out[j][0] & (init>>i); |
akverma | 3:1696c69e3109 | 42 | data_out_pins[j][1] = data_out[j][1] & (init>>i); |
akverma | 3:1696c69e3109 | 43 | data_out_pins[j][2] = data_out[j][2] & (init>>i); |
RahulSitaram | 0:b9fbca7b029d | 44 | } |
akverma | 3:1696c69e3109 | 45 | CLK_595 = 1; |
akverma | 3:1696c69e3109 | 46 | CLK_595 = 0; |
akverma | 3:1696c69e3109 | 47 | } |
akverma | 3:1696c69e3109 | 48 | latch = 1; |
akverma | 3:1696c69e3109 | 49 | latch = 0; |
RahulSitaram | 0:b9fbca7b029d | 50 | } |
RahulSitaram | 0:b9fbca7b029d | 51 | |
akverma | 3:1696c69e3109 | 52 | void shift_read(){ |
akverma | 3:1696c69e3109 | 53 | load = 0; |
akverma | 3:1696c69e3109 | 54 | load = 1; |
akverma | 3:1696c69e3109 | 55 | for (int i=0; i<outlets; i++) |
RahulSitaram | 0:b9fbca7b029d | 56 | { |
akverma | 3:1696c69e3109 | 57 | data_in[i] = (data_in[i]<<1)|data_in_pins[i]; |
RahulSitaram | 0:b9fbca7b029d | 58 | } |
akverma | 3:1696c69e3109 | 59 | for(int i=0; i<8; i++) |
akverma | 3:1696c69e3109 | 60 | { |
akverma | 3:1696c69e3109 | 61 | for (int i=0; i<outlets; i++) |
akverma | 3:1696c69e3109 | 62 | { |
akverma | 3:1696c69e3109 | 63 | data_in[i] = (data_in[i]<<1)|data_in_pins[i]; |
akverma | 3:1696c69e3109 | 64 | } |
akverma | 3:1696c69e3109 | 65 | CLK_165 = 0; |
akverma | 3:1696c69e3109 | 66 | CLK_165 = 1; |
RahulSitaram | 0:b9fbca7b029d | 67 | } |
akverma | 3:1696c69e3109 | 68 | } |
akverma | 3:1696c69e3109 | 69 | |
akverma | 3:1696c69e3109 | 70 | void call(){ |
akverma | 3:1696c69e3109 | 71 | data_out[0][0] = pc.getc(); |
akverma | 3:1696c69e3109 | 72 | shift(); |
akverma | 3:1696c69e3109 | 73 | } |
RahulSitaram | 0:b9fbca7b029d | 74 | |
RahulSitaram | 0:b9fbca7b029d | 75 | int main() { |
RahulSitaram | 2:a07ae6396167 | 76 | pc.attach(&call); |
akverma | 3:1696c69e3109 | 77 | long time_counter1 = 0; |
akverma | 3:1696c69e3109 | 78 | wait_ms(500); |
akverma | 3:1696c69e3109 | 79 | cout<<"Starting: "<<endl; |
RahulSitaram | 0:b9fbca7b029d | 80 | wait_ms(500); |
RahulSitaram | 1:b42fa19eeea8 | 81 | while(1){ |
akverma | 3:1696c69e3109 | 82 | shift(); |
akverma | 3:1696c69e3109 | 83 | shift_read(); |
akverma | 3:1696c69e3109 | 84 | time_counter1++; |
akverma | 3:1696c69e3109 | 85 | if (time_counter1 == 1000000) |
akverma | 3:1696c69e3109 | 86 | { |
akverma | 3:1696c69e3109 | 87 | pc.printf("%X\n", data_in[0]); |
akverma | 3:1696c69e3109 | 88 | time_counter1 = 0; |
RahulSitaram | 1:b42fa19eeea8 | 89 | } |
akverma | 3:1696c69e3109 | 90 | } |
RahulSitaram | 0:b9fbca7b029d | 91 | } |