Projektseminar 3
/
GrundansteuerungDisplay
example marix 8x8
Fork of 00_LAB_matrix8x8_SPI by
main.cpp@4:8f0d7520027d, 2017-11-06 (annotated)
- Committer:
- burked01
- Date:
- Mon Nov 06 11:57:05 2017 +0000
- Revision:
- 4:8f0d7520027d
- Parent:
- 3:4a8de2f71ed0
h
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fabeltranm | 0:61199d9d0aed | 1 | |
fabeltranm | 0:61199d9d0aed | 2 | #include "mbed.h" |
burked01 | 4:8f0d7520027d | 3 | #include "max7219.h" |
fabeltranm | 0:61199d9d0aed | 4 | |
fabeltranm | 0:61199d9d0aed | 5 | // *************************************************************************** |
fabeltranm | 0:61199d9d0aed | 6 | // option 1 : use SPI |
fabeltranm | 0:61199d9d0aed | 7 | // *************************************************************************** |
burked01 | 4:8f0d7520027d | 8 | /*SPI deviceM(PA_7, PA_6, PA_5); |
fabeltranm | 0:61199d9d0aed | 9 | DigitalOut ssel (PB_12); |
fabeltranm | 0:61199d9d0aed | 10 | |
fabeltranm | 0:61199d9d0aed | 11 | #define uint8_t unsigned char |
fabeltranm | 2:414129d953dd | 12 | uint8_t vcol2[8]={0,0,0,0,0,0,0,0}; |
fabeltranm | 1:b732136485e0 | 13 | |
fabeltranm | 0:61199d9d0aed | 14 | |
fabeltranm | 0:61199d9d0aed | 15 | void sendSPI(uint8_t d1, uint8_t d2) |
fabeltranm | 0:61199d9d0aed | 16 | { |
fabeltranm | 0:61199d9d0aed | 17 | deviceM.unlock(); |
fabeltranm | 0:61199d9d0aed | 18 | ssel=0; |
fabeltranm | 0:61199d9d0aed | 19 | deviceM.write(d1); |
fabeltranm | 0:61199d9d0aed | 20 | deviceM.write(d2); |
fabeltranm | 0:61199d9d0aed | 21 | ssel=1; |
fabeltranm | 0:61199d9d0aed | 22 | deviceM.lock(); |
fabeltranm | 0:61199d9d0aed | 23 | }; |
fabeltranm | 0:61199d9d0aed | 24 | |
fabeltranm | 0:61199d9d0aed | 25 | |
fabeltranm | 0:61199d9d0aed | 26 | void printMatrix(uint8_t* vC) |
fabeltranm | 0:61199d9d0aed | 27 | |
fabeltranm | 0:61199d9d0aed | 28 | { |
fabeltranm | 0:61199d9d0aed | 29 | uint8_t i =0; |
fabeltranm | 0:61199d9d0aed | 30 | for (i=1;i<9;i++){ |
fabeltranm | 0:61199d9d0aed | 31 | sendSPI(i,*(vC+i)); |
fabeltranm | 0:61199d9d0aed | 32 | } |
fabeltranm | 0:61199d9d0aed | 33 | |
fabeltranm | 0:61199d9d0aed | 34 | }; |
fabeltranm | 2:414129d953dd | 35 | |
fabeltranm | 3:4a8de2f71ed0 | 36 | void clr_vcol() |
fabeltranm | 2:414129d953dd | 37 | { |
fabeltranm | 3:4a8de2f71ed0 | 38 | for (int i=0; i<8;i++){ |
fabeltranm | 2:414129d953dd | 39 | vcol2[i]=0; |
fabeltranm | 2:414129d953dd | 40 | } |
fabeltranm | 0:61199d9d0aed | 41 | |
fabeltranm | 2:414129d953dd | 42 | } |
fabeltranm | 2:414129d953dd | 43 | |
fabeltranm | 2:414129d953dd | 44 | void print_Snake2() |
fabeltranm | 2:414129d953dd | 45 | { |
fabeltranm | 2:414129d953dd | 46 | |
fabeltranm | 2:414129d953dd | 47 | int j, i; |
fabeltranm | 2:414129d953dd | 48 | //reset |
fabeltranm | 3:4a8de2f71ed0 | 49 | |
fabeltranm | 2:414129d953dd | 50 | for (j=0; j<8;j++){ |
fabeltranm | 3:4a8de2f71ed0 | 51 | clr_vcol(); |
fabeltranm | 3:4a8de2f71ed0 | 52 | if(j % 2 == 0) |
fabeltranm | 3:4a8de2f71ed0 | 53 | vcol2[j]=1; |
fabeltranm | 3:4a8de2f71ed0 | 54 | else |
fabeltranm | 3:4a8de2f71ed0 | 55 | vcol2[j]=0b10000000; |
fabeltranm | 3:4a8de2f71ed0 | 56 | |
fabeltranm | 2:414129d953dd | 57 | for (i=0; i<8;i++){ |
fabeltranm | 2:414129d953dd | 58 | if(j % 2 == 0){ |
fabeltranm | 3:4a8de2f71ed0 | 59 | vcol2[j]=3<<i; |
fabeltranm | 2:414129d953dd | 60 | } |
fabeltranm | 2:414129d953dd | 61 | else{ |
fabeltranm | 3:4a8de2f71ed0 | 62 | vcol2[j]=0b1100000000>>i; |
fabeltranm | 2:414129d953dd | 63 | } |
fabeltranm | 2:414129d953dd | 64 | printMatrix(vcol2); |
fabeltranm | 2:414129d953dd | 65 | wait_ms(5); |
fabeltranm | 2:414129d953dd | 66 | } |
fabeltranm | 2:414129d953dd | 67 | } |
fabeltranm | 2:414129d953dd | 68 | } |
fabeltranm | 2:414129d953dd | 69 | |
fabeltranm | 1:b732136485e0 | 70 | void print_Snake() |
fabeltranm | 1:b732136485e0 | 71 | { |
fabeltranm | 2:414129d953dd | 72 | |
fabeltranm | 2:414129d953dd | 73 | uint8_t vt1[8]={1,3,7,0xf,0x1f,0x3f, 0x7f,0xff}; |
fabeltranm | 2:414129d953dd | 74 | uint8_t vt2[8]={0b10000000,0b11000000,0b11100000,0b11110000,0b11111000,0b11111100,0b11111110,0b11111111}; |
fabeltranm | 0:61199d9d0aed | 75 | |
fabeltranm | 2:414129d953dd | 76 | |
fabeltranm | 1:b732136485e0 | 77 | int j, i; |
fabeltranm | 2:414129d953dd | 78 | //reset |
fabeltranm | 3:4a8de2f71ed0 | 79 | clr_vcol(); |
fabeltranm | 1:b732136485e0 | 80 | for (j=0; j<8;j++){ |
fabeltranm | 1:b732136485e0 | 81 | for (i=0; i<8;i++){ |
fabeltranm | 2:414129d953dd | 82 | if(j % 2 == 0){ |
fabeltranm | 2:414129d953dd | 83 | vcol2[j]=vt1[i]; |
fabeltranm | 2:414129d953dd | 84 | }else{ |
fabeltranm | 2:414129d953dd | 85 | vcol2[j]=vt2[i]; |
fabeltranm | 2:414129d953dd | 86 | } |
fabeltranm | 1:b732136485e0 | 87 | printMatrix(vcol2); |
fabeltranm | 1:b732136485e0 | 88 | wait_ms(5); |
fabeltranm | 1:b732136485e0 | 89 | } |
fabeltranm | 1:b732136485e0 | 90 | } |
fabeltranm | 1:b732136485e0 | 91 | } |
fabeltranm | 0:61199d9d0aed | 92 | int main() { |
fabeltranm | 1:b732136485e0 | 93 | uint8_t vcol[8]={0,0,0,0,0,0,0,0}; |
fabeltranm | 0:61199d9d0aed | 94 | sendSPI(0x0c,1); |
fabeltranm | 0:61199d9d0aed | 95 | sendSPI(0x0F,1); |
fabeltranm | 1:b732136485e0 | 96 | wait (0.1); |
fabeltranm | 0:61199d9d0aed | 97 | sendSPI(0x0f,0); |
fabeltranm | 1:b732136485e0 | 98 | wait (0.1); |
fabeltranm | 0:61199d9d0aed | 99 | int i =0; |
fabeltranm | 0:61199d9d0aed | 100 | while(1){ |
fabeltranm | 1:b732136485e0 | 101 | print_Snake(); |
fabeltranm | 0:61199d9d0aed | 102 | } |
burked01 | 4:8f0d7520027d | 103 | }*/ |
fabeltranm | 0:61199d9d0aed | 104 | // *************************************************************************** |
burked01 | 4:8f0d7520027d | 105 | // option two: use max7219 library |
fabeltranm | 0:61199d9d0aed | 106 | |
fabeltranm | 0:61199d9d0aed | 107 | // *************************************************************************** |
burked01 | 4:8f0d7520027d | 108 | |
burked01 | 4:8f0d7520027d | 109 | |
burked01 | 4:8f0d7520027d | 110 | Max7219 max7219(PA_7, PA_6, PA_5, D2); |
burked01 | 4:8f0d7520027d | 111 | |
burked01 | 4:8f0d7520027d | 112 | int main() |
burked01 | 4:8f0d7520027d | 113 | { |
burked01 | 4:8f0d7520027d | 114 | max7219_configuration_t cfg = { |
burked01 | 4:8f0d7520027d | 115 | .device_number = 1, |
burked01 | 4:8f0d7520027d | 116 | .decode_mode = 3, |
burked01 | 4:8f0d7520027d | 117 | .intensity = Max7219::MAX7219_INTENSITY_5, |
burked01 | 4:8f0d7520027d | 118 | .scan_limit = Max7219::MAX7219_SCAN_8 |
burked01 | 4:8f0d7520027d | 119 | }; |
burked01 | 4:8f0d7520027d | 120 | |
burked01 | 4:8f0d7520027d | 121 | max7219.init_device(cfg); |
burked01 | 4:8f0d7520027d | 122 | max7219.enable_device(1); |
burked01 | 4:8f0d7520027d | 123 | max7219.set_display_test(); |
burked01 | 4:8f0d7520027d | 124 | wait(1); |
burked01 | 4:8f0d7520027d | 125 | max7219.clear_display_test(); |
burked01 | 4:8f0d7520027d | 126 | |
burked01 | 4:8f0d7520027d | 127 | |
burked01 | 4:8f0d7520027d | 128 | |
burked01 | 4:8f0d7520027d | 129 | |
fabeltranm | 0:61199d9d0aed | 130 | |
fabeltranm | 0:61199d9d0aed | 131 | |
burked01 | 4:8f0d7520027d | 132 | |
fabeltranm | 0:61199d9d0aed | 133 | while(1){ |
burked01 | 4:8f0d7520027d | 134 | |
burked01 | 4:8f0d7520027d | 135 | max7219.write_digit(1,1,0b01010101); |
burked01 | 4:8f0d7520027d | 136 | max7219.write_digit(1,2,0b10101010); |
burked01 | 4:8f0d7520027d | 137 | max7219.write_digit(1,3,0b01010101); |
burked01 | 4:8f0d7520027d | 138 | max7219.write_digit(1,4,0b10101010); |
burked01 | 4:8f0d7520027d | 139 | max7219.write_digit(1,5,0b01010101); |
burked01 | 4:8f0d7520027d | 140 | max7219.write_digit(1,6,0b10101010); |
burked01 | 4:8f0d7520027d | 141 | max7219.write_digit(1,7,0b01010101); |
burked01 | 4:8f0d7520027d | 142 | max7219.write_digit(1,8,0b11001100); |
burked01 | 4:8f0d7520027d | 143 | |
burked01 | 4:8f0d7520027d | 144 | |
burked01 | 4:8f0d7520027d | 145 | max7219.write_digit(2,1,0b01010101); |
burked01 | 4:8f0d7520027d | 146 | max7219.write_digit(2,2,0b10101010); |
burked01 | 4:8f0d7520027d | 147 | max7219.write_digit(2,3,0b01010101); |
burked01 | 4:8f0d7520027d | 148 | max7219.write_digit(2,4,0b10101010); |
burked01 | 4:8f0d7520027d | 149 | max7219.write_digit(2,5,0b01010101); |
burked01 | 4:8f0d7520027d | 150 | max7219.write_digit(2,6,0b10101010); |
burked01 | 4:8f0d7520027d | 151 | max7219.write_digit(2,7,0b01010101); |
burked01 | 4:8f0d7520027d | 152 | max7219.write_digit(2,8,0b11001100); |
burked01 | 4:8f0d7520027d | 153 | |
burked01 | 4:8f0d7520027d | 154 | |
burked01 | 4:8f0d7520027d | 155 | max7219.write_digit(3,1,0b01010101); |
burked01 | 4:8f0d7520027d | 156 | max7219.write_digit(3,2,0b10101010); |
burked01 | 4:8f0d7520027d | 157 | max7219.write_digit(3,3,0b01010101); |
burked01 | 4:8f0d7520027d | 158 | max7219.write_digit(3,4,0b10001010); |
burked01 | 4:8f0d7520027d | 159 | max7219.write_digit(3,5,0b01010101); |
burked01 | 4:8f0d7520027d | 160 | max7219.write_digit(3,6,0b10101010); |
burked01 | 4:8f0d7520027d | 161 | max7219.write_digit(3,7,0b01010101); |
burked01 | 4:8f0d7520027d | 162 | max7219.write_digit(3,8,0b11001100); |
burked01 | 4:8f0d7520027d | 163 | |
burked01 | 4:8f0d7520027d | 164 | |
burked01 | 4:8f0d7520027d | 165 | max7219.write_digit(4,1,0b01010101); |
burked01 | 4:8f0d7520027d | 166 | max7219.write_digit(4,2,0b10101010); |
burked01 | 4:8f0d7520027d | 167 | max7219.write_digit(4,3,0b01010101); |
burked01 | 4:8f0d7520027d | 168 | max7219.write_digit(4,4,0b10101010); |
burked01 | 4:8f0d7520027d | 169 | max7219.write_digit(4,5,0b01011101); |
burked01 | 4:8f0d7520027d | 170 | max7219.write_digit(4,6,0b10101010); |
burked01 | 4:8f0d7520027d | 171 | max7219.write_digit(4,7,0b01010101); |
burked01 | 4:8f0d7520027d | 172 | max7219.write_digit(4,8,0b11001100); |
burked01 | 4:8f0d7520027d | 173 | ; |
burked01 | 4:8f0d7520027d | 174 | |
fabeltranm | 0:61199d9d0aed | 175 | } |
fabeltranm | 0:61199d9d0aed | 176 | } |
fabeltranm | 0:61199d9d0aed | 177 | |
burked01 | 4:8f0d7520027d | 178 |