Todd Dale
/
SPI_Project_Master
SPI transmission of an array, Master device.
main.cpp@1:c573caf40864, 2018-02-19 (annotated)
- Committer:
- el15tcd
- Date:
- Mon Feb 19 13:09:13 2018 +0000
- Revision:
- 1:c573caf40864
- Parent:
- 0:8a61e3541a5e
- Child:
- 2:b95b33894176
Matrix Demonstration (2x2)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el15tcd | 0:8a61e3541a5e | 1 | #include "mbed.h" |
el15tcd | 0:8a61e3541a5e | 2 | |
el15tcd | 0:8a61e3541a5e | 3 | //DigitalIn trigger(p22); |
el15tcd | 0:8a61e3541a5e | 4 | //DigitalOut transmit(p28); |
el15tcd | 0:8a61e3541a5e | 5 | |
el15tcd | 0:8a61e3541a5e | 6 | DigitalIn tl(p17); //change to correct board |
el15tcd | 0:8a61e3541a5e | 7 | DigitalIn tr(p18); |
el15tcd | 0:8a61e3541a5e | 8 | DigitalIn bl(p19); |
el15tcd | 0:8a61e3541a5e | 9 | DigitalIn br(p20); |
el15tcd | 0:8a61e3541a5e | 10 | |
el15tcd | 0:8a61e3541a5e | 11 | Serial device(p28,p27); //tx,rx |
el15tcd | 0:8a61e3541a5e | 12 | |
el15tcd | 0:8a61e3541a5e | 13 | BusOut myleds(LED4, LED3, LED2, LED1); |
el15tcd | 0:8a61e3541a5e | 14 | |
el15tcd | 0:8a61e3541a5e | 15 | int buffer[4]; |
el15tcd | 0:8a61e3541a5e | 16 | int temp1; |
el15tcd | 0:8a61e3541a5e | 17 | |
el15tcd | 0:8a61e3541a5e | 18 | int row; |
el15tcd | 0:8a61e3541a5e | 19 | int columns; |
el15tcd | 0:8a61e3541a5e | 20 | |
el15tcd | 0:8a61e3541a5e | 21 | char array[4]; |
el15tcd | 1:c573caf40864 | 22 | char matrix[2][2]; |
el15tcd | 0:8a61e3541a5e | 23 | int i; |
el15tcd | 1:c573caf40864 | 24 | int j; |
el15tcd | 0:8a61e3541a5e | 25 | |
el15tcd | 0:8a61e3541a5e | 26 | void Array(); |
el15tcd | 1:c573caf40864 | 27 | void Matrix(); |
el15tcd | 0:8a61e3541a5e | 28 | |
el15tcd | 0:8a61e3541a5e | 29 | int main() |
el15tcd | 0:8a61e3541a5e | 30 | { |
el15tcd | 0:8a61e3541a5e | 31 | |
el15tcd | 0:8a61e3541a5e | 32 | myleds = 0; |
el15tcd | 0:8a61e3541a5e | 33 | |
el15tcd | 0:8a61e3541a5e | 34 | device.baud(19200); |
el15tcd | 0:8a61e3541a5e | 35 | buffer[0] = 1; |
el15tcd | 0:8a61e3541a5e | 36 | buffer[1] = 0; |
el15tcd | 0:8a61e3541a5e | 37 | buffer[2] = 1; |
el15tcd | 0:8a61e3541a5e | 38 | buffer[3] = 0; |
el15tcd | 0:8a61e3541a5e | 39 | // buffer[4] = 0; |
el15tcd | 0:8a61e3541a5e | 40 | // buffer[5] = 0; |
el15tcd | 0:8a61e3541a5e | 41 | // buffer[6] = 1; |
el15tcd | 0:8a61e3541a5e | 42 | // buffer[7] = 0; |
el15tcd | 0:8a61e3541a5e | 43 | |
el15tcd | 0:8a61e3541a5e | 44 | array[0] = 0; |
el15tcd | 0:8a61e3541a5e | 45 | array[1] = 0; |
el15tcd | 0:8a61e3541a5e | 46 | array[2] = 0; |
el15tcd | 0:8a61e3541a5e | 47 | array[3] = 0; |
el15tcd | 0:8a61e3541a5e | 48 | |
el15tcd | 0:8a61e3541a5e | 49 | while(1) { |
el15tcd | 0:8a61e3541a5e | 50 | |
el15tcd | 0:8a61e3541a5e | 51 | if (tl > 0) { |
el15tcd | 0:8a61e3541a5e | 52 | myleds = 1; |
el15tcd | 0:8a61e3541a5e | 53 | } else { |
el15tcd | 0:8a61e3541a5e | 54 | myleds = 0; |
el15tcd | 0:8a61e3541a5e | 55 | } |
el15tcd | 0:8a61e3541a5e | 56 | |
el15tcd | 1:c573caf40864 | 57 | //Array(); |
el15tcd | 1:c573caf40864 | 58 | |
el15tcd | 1:c573caf40864 | 59 | Matrix(); |
el15tcd | 0:8a61e3541a5e | 60 | |
el15tcd | 1:c573caf40864 | 61 | device.putc(1); |
el15tcd | 1:c573caf40864 | 62 | for (int i=0; i<2; i++) { |
el15tcd | 1:c573caf40864 | 63 | for (int j=0; j<2; j++) { |
el15tcd | 0:8a61e3541a5e | 64 | |
el15tcd | 1:c573caf40864 | 65 | //device.printf("%i",buffer[i]); |
el15tcd | 1:c573caf40864 | 66 | |
el15tcd | 1:c573caf40864 | 67 | //device.putc(buffer[i]); |
el15tcd | 1:c573caf40864 | 68 | device.putc(matrix[i][j]); |
el15tcd | 1:c573caf40864 | 69 | } |
el15tcd | 0:8a61e3541a5e | 70 | } |
el15tcd | 0:8a61e3541a5e | 71 | //wait(1); |
el15tcd | 0:8a61e3541a5e | 72 | } |
el15tcd | 0:8a61e3541a5e | 73 | |
el15tcd | 0:8a61e3541a5e | 74 | } |
el15tcd | 0:8a61e3541a5e | 75 | |
el15tcd | 0:8a61e3541a5e | 76 | void Array() |
el15tcd | 0:8a61e3541a5e | 77 | { |
el15tcd | 0:8a61e3541a5e | 78 | for(i=0; i<=1 ; i=i+1) { |
el15tcd | 0:8a61e3541a5e | 79 | if (i == 0) { |
el15tcd | 0:8a61e3541a5e | 80 | if (tl > 0) { |
el15tcd | 0:8a61e3541a5e | 81 | array[0] = 1; |
el15tcd | 0:8a61e3541a5e | 82 | } else { |
el15tcd | 0:8a61e3541a5e | 83 | array[0] = 0; |
el15tcd | 0:8a61e3541a5e | 84 | } |
el15tcd | 0:8a61e3541a5e | 85 | } else if (i == 1) { |
el15tcd | 0:8a61e3541a5e | 86 | if (tr > 0) { |
el15tcd | 0:8a61e3541a5e | 87 | array[1] = 1; |
el15tcd | 0:8a61e3541a5e | 88 | } else { |
el15tcd | 0:8a61e3541a5e | 89 | array[1] = 0; |
el15tcd | 0:8a61e3541a5e | 90 | } |
el15tcd | 0:8a61e3541a5e | 91 | } |
el15tcd | 0:8a61e3541a5e | 92 | } |
el15tcd | 0:8a61e3541a5e | 93 | for(i=0; i<=1 ; i=i+1) { |
el15tcd | 0:8a61e3541a5e | 94 | if (i == 0) { |
el15tcd | 0:8a61e3541a5e | 95 | if (bl > 0) { |
el15tcd | 0:8a61e3541a5e | 96 | array[2] = 1; |
el15tcd | 0:8a61e3541a5e | 97 | } else { |
el15tcd | 0:8a61e3541a5e | 98 | array[2] = 0; |
el15tcd | 0:8a61e3541a5e | 99 | } |
el15tcd | 0:8a61e3541a5e | 100 | } else if (i == 1) { |
el15tcd | 0:8a61e3541a5e | 101 | if (br > 0) { |
el15tcd | 0:8a61e3541a5e | 102 | array[3] = 1; |
el15tcd | 0:8a61e3541a5e | 103 | } else { |
el15tcd | 0:8a61e3541a5e | 104 | array[3] = 0; |
el15tcd | 0:8a61e3541a5e | 105 | } |
el15tcd | 0:8a61e3541a5e | 106 | } |
el15tcd | 0:8a61e3541a5e | 107 | } |
el15tcd | 0:8a61e3541a5e | 108 | /* |
el15tcd | 0:8a61e3541a5e | 109 | for (row=0; row<2; row++) { |
el15tcd | 0:8a61e3541a5e | 110 | for(columns=0; columns<2; columns++) { |
el15tcd | 0:8a61e3541a5e | 111 | printf("%d ", array[row][columns]); |
el15tcd | 0:8a61e3541a5e | 112 | } |
el15tcd | 0:8a61e3541a5e | 113 | printf("\n"); |
el15tcd | 0:8a61e3541a5e | 114 | }*/ |
el15tcd | 0:8a61e3541a5e | 115 | //printf("\n"); |
el15tcd | 0:8a61e3541a5e | 116 | } |
el15tcd | 1:c573caf40864 | 117 | |
el15tcd | 1:c573caf40864 | 118 | void Matrix() |
el15tcd | 1:c573caf40864 | 119 | { |
el15tcd | 1:c573caf40864 | 120 | |
el15tcd | 1:c573caf40864 | 121 | if (tl > 0) { |
el15tcd | 1:c573caf40864 | 122 | matrix[0][0] = 1; |
el15tcd | 1:c573caf40864 | 123 | } else { |
el15tcd | 1:c573caf40864 | 124 | matrix[0][0] = 0; |
el15tcd | 1:c573caf40864 | 125 | } |
el15tcd | 1:c573caf40864 | 126 | if (tr > 0) { |
el15tcd | 1:c573caf40864 | 127 | matrix[0][1] = 1; |
el15tcd | 1:c573caf40864 | 128 | } else { |
el15tcd | 1:c573caf40864 | 129 | matrix[0][1] = 0; |
el15tcd | 1:c573caf40864 | 130 | } |
el15tcd | 1:c573caf40864 | 131 | if (bl > 0) { |
el15tcd | 1:c573caf40864 | 132 | matrix[1][0] = 1; |
el15tcd | 1:c573caf40864 | 133 | } else { |
el15tcd | 1:c573caf40864 | 134 | matrix[1][0] = 0; |
el15tcd | 1:c573caf40864 | 135 | } |
el15tcd | 1:c573caf40864 | 136 | if (br > 0) { |
el15tcd | 1:c573caf40864 | 137 | matrix[1][1] = 1; |
el15tcd | 1:c573caf40864 | 138 | } else { |
el15tcd | 1:c573caf40864 | 139 | matrix[1][1] = 0; |
el15tcd | 1:c573caf40864 | 140 | } |
el15tcd | 1:c573caf40864 | 141 | |
el15tcd | 1:c573caf40864 | 142 | } |