Nikita Ivanykov
/
LAB_DISPLAY
7
main.cpp@3:9909607749dd, 2019-11-13 (annotated)
- Committer:
- troshha
- Date:
- Wed Nov 13 10:28:49 2019 +0000
- Revision:
- 3:9909607749dd
- Parent:
- 2:82f5f57eac91
7
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
codebreaker7 | 0:02841331478b | 1 | #include "mbed.h" |
codebreaker7 | 0:02841331478b | 2 | #include "ILI9341_Defines.h" |
codebreaker7 | 0:02841331478b | 3 | |
troshha | 3:9909607749dd | 4 | SPI spi_dev(PB_15, PB_14, PB_13, PB_12); |
codebreaker7 | 0:02841331478b | 5 | DigitalOut cs(PC_4); |
codebreaker7 | 0:02841331478b | 6 | DigitalOut ao(PB_3); |
codebreaker7 | 2:82f5f57eac91 | 7 | uint8_t tarr[1024]; |
codebreaker7 | 2:82f5f57eac91 | 8 | uint8_t rarr[1024]; |
codebreaker7 | 0:02841331478b | 9 | |
codebreaker7 | 0:02841331478b | 10 | void writecommand(uint8_t command) { |
codebreaker7 | 0:02841331478b | 11 | cs = 0; |
codebreaker7 | 0:02841331478b | 12 | ao = 0; |
codebreaker7 | 0:02841331478b | 13 | spi_dev.write(command); |
codebreaker7 | 0:02841331478b | 14 | cs = 1; |
codebreaker7 | 0:02841331478b | 15 | } |
codebreaker7 | 0:02841331478b | 16 | |
troshha | 3:9909607749dd | 17 | |
codebreaker7 | 0:02841331478b | 18 | void writedata(uint8_t data) { |
codebreaker7 | 0:02841331478b | 19 | cs = 0; |
codebreaker7 | 0:02841331478b | 20 | ao = 1; |
codebreaker7 | 0:02841331478b | 21 | spi_dev.write(data); |
codebreaker7 | 0:02841331478b | 22 | cs = 1; |
codebreaker7 | 0:02841331478b | 23 | } |
codebreaker7 | 0:02841331478b | 24 | |
codebreaker7 | 2:82f5f57eac91 | 25 | void setAddress(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2) { |
codebreaker7 | 2:82f5f57eac91 | 26 | writecommand(0x2a); |
codebreaker7 | 2:82f5f57eac91 | 27 | writedata(0x00); |
codebreaker7 | 2:82f5f57eac91 | 28 | writedata(x1); |
codebreaker7 | 2:82f5f57eac91 | 29 | writedata(0x00); |
codebreaker7 | 2:82f5f57eac91 | 30 | writedata(x2); |
codebreaker7 | 2:82f5f57eac91 | 31 | writecommand(0x2b); |
codebreaker7 | 2:82f5f57eac91 | 32 | writedata(0x00); |
codebreaker7 | 2:82f5f57eac91 | 33 | writedata(y1); |
codebreaker7 | 2:82f5f57eac91 | 34 | writedata(0x00); |
codebreaker7 | 2:82f5f57eac91 | 35 | writedata(y2); |
codebreaker7 | 2:82f5f57eac91 | 36 | writecommand(0x2c); |
codebreaker7 | 2:82f5f57eac91 | 37 | } |
codebreaker7 | 2:82f5f57eac91 | 38 | |
codebreaker7 | 2:82f5f57eac91 | 39 | void writeColorData(uint8_t * arr, int length) { |
codebreaker7 | 2:82f5f57eac91 | 40 | cs = 0; |
codebreaker7 | 2:82f5f57eac91 | 41 | ao = 1; |
codebreaker7 | 2:82f5f57eac91 | 42 | spi_dev.write((char*)arr, length, NULL, length); |
codebreaker7 | 2:82f5f57eac91 | 43 | cs = 1; |
codebreaker7 | 2:82f5f57eac91 | 44 | } |
codebreaker7 | 2:82f5f57eac91 | 45 | |
codebreaker7 | 0:02841331478b | 46 | int main() { |
codebreaker7 | 1:cdeae0693b01 | 47 | HAL_Init(); |
codebreaker7 | 0:02841331478b | 48 | #include "ILI9341_Init.h" |
codebreaker7 | 2:82f5f57eac91 | 49 | setAddress(0, 0, 127, 127); |
codebreaker7 | 2:82f5f57eac91 | 50 | for (int i = 0; i < 1024; i++) { |
codebreaker7 | 2:82f5f57eac91 | 51 | tarr[i] = 0; |
codebreaker7 | 2:82f5f57eac91 | 52 | } |
troshha | 3:9909607749dd | 53 | |
troshha | 3:9909607749dd | 54 | |
troshha | 3:9909607749dd | 55 | for (int i = 0; i < 32; i++) { |
troshha | 3:9909607749dd | 56 | writeColorData(tarr, 1024); |
troshha | 3:9909607749dd | 57 | } |
troshha | 3:9909607749dd | 58 | |
troshha | 3:9909607749dd | 59 | |
troshha | 3:9909607749dd | 60 | while(1) { |
troshha | 3:9909607749dd | 61 | setAddress(64, 64, 127, 127); |
troshha | 3:9909607749dd | 62 | for (int i = 0; i < 1024; i++) { |
troshha | 3:9909607749dd | 63 | tarr[i] = 10; |
troshha | 3:9909607749dd | 64 | } |
troshha | 3:9909607749dd | 65 | |
troshha | 3:9909607749dd | 66 | |
troshha | 3:9909607749dd | 67 | for (int i = 0; i < 32; i++) { |
troshha | 3:9909607749dd | 68 | writeColorData(tarr, 1024); |
troshha | 3:9909607749dd | 69 | } |
troshha | 3:9909607749dd | 70 | setAddress(0, 0, 64, 64); |
troshha | 3:9909607749dd | 71 | for (int i = 0; i < 1024; i++) { |
troshha | 3:9909607749dd | 72 | tarr[i*2] = 0xF8; |
troshha | 3:9909607749dd | 73 | tarr[i*2+1] = 0x00; |
troshha | 3:9909607749dd | 74 | } |
troshha | 3:9909607749dd | 75 | |
troshha | 3:9909607749dd | 76 | |
troshha | 3:9909607749dd | 77 | for (int i = 0; i < 32; i++) { |
troshha | 3:9909607749dd | 78 | writeColorData(tarr, 1024); |
troshha | 3:9909607749dd | 79 | } |
troshha | 3:9909607749dd | 80 | setAddress(0, 64, 64, 127); |
troshha | 3:9909607749dd | 81 | for (int i = 0; i < 1024; i++) { |
troshha | 3:9909607749dd | 82 | tarr[i] = 07E0; |
troshha | 3:9909607749dd | 83 | } |
troshha | 3:9909607749dd | 84 | |
troshha | 3:9909607749dd | 85 | |
troshha | 3:9909607749dd | 86 | for (int i = 0; i < 32; i++) { |
troshha | 3:9909607749dd | 87 | writeColorData(tarr, 1024); |
troshha | 3:9909607749dd | 88 | } |
troshha | 3:9909607749dd | 89 | setAddress(64, 0, 127, 64); |
troshha | 3:9909607749dd | 90 | for (int i = 0; i < 1024; i++) { |
troshha | 3:9909607749dd | 91 | tarr[i] = 40; |
troshha | 3:9909607749dd | 92 | } |
troshha | 3:9909607749dd | 93 | |
troshha | 3:9909607749dd | 94 | |
codebreaker7 | 2:82f5f57eac91 | 95 | for (int i = 0; i < 32; i++) { |
codebreaker7 | 2:82f5f57eac91 | 96 | writeColorData(tarr, 1024); |
codebreaker7 | 2:82f5f57eac91 | 97 | } |
troshha | 3:9909607749dd | 98 | |
troshha | 3:9909607749dd | 99 | |
troshha | 3:9909607749dd | 100 | wait(0.5); |
troshha | 3:9909607749dd | 101 | setAddress(64, 64, 127, 127); |
troshha | 3:9909607749dd | 102 | for (int i = 0; i < 1024; i++) { |
troshha | 3:9909607749dd | 103 | tarr[i] = 0; |
troshha | 3:9909607749dd | 104 | } |
troshha | 3:9909607749dd | 105 | |
troshha | 3:9909607749dd | 106 | |
troshha | 3:9909607749dd | 107 | for (int i = 0; i < 32; i++) { |
troshha | 3:9909607749dd | 108 | writeColorData(tarr, 1024); |
troshha | 3:9909607749dd | 109 | } |
troshha | 3:9909607749dd | 110 | wait(0.5); |
troshha | 3:9909607749dd | 111 | setAddress(0, 0, 64, 64); |
troshha | 3:9909607749dd | 112 | for (int i = 0; i < 1024; i++) { |
troshha | 3:9909607749dd | 113 | tarr[i] = 0; |
troshha | 3:9909607749dd | 114 | } |
troshha | 3:9909607749dd | 115 | |
troshha | 3:9909607749dd | 116 | |
troshha | 3:9909607749dd | 117 | for (int i = 0; i < 32; i++) { |
troshha | 3:9909607749dd | 118 | writeColorData(tarr, 1024); |
troshha | 3:9909607749dd | 119 | } |
troshha | 3:9909607749dd | 120 | wait(0.5); |
troshha | 3:9909607749dd | 121 | setAddress(0, 64, 64, 127); |
troshha | 3:9909607749dd | 122 | for (int i = 0; i < 1024; i++) { |
troshha | 3:9909607749dd | 123 | tarr[i] = 0; |
troshha | 3:9909607749dd | 124 | } |
troshha | 3:9909607749dd | 125 | |
troshha | 3:9909607749dd | 126 | |
troshha | 3:9909607749dd | 127 | for (int i = 0; i < 32; i++) { |
troshha | 3:9909607749dd | 128 | writeColorData(tarr, 1024); |
troshha | 3:9909607749dd | 129 | } |
troshha | 3:9909607749dd | 130 | wait(0.5); |
troshha | 3:9909607749dd | 131 | setAddress(64, 0, 127, 64); |
troshha | 3:9909607749dd | 132 | for (int i = 0; i < 1024; i++) { |
troshha | 3:9909607749dd | 133 | tarr[i] = 0; |
troshha | 3:9909607749dd | 134 | } |
troshha | 3:9909607749dd | 135 | |
troshha | 3:9909607749dd | 136 | |
troshha | 3:9909607749dd | 137 | for (int i = 0; i < 32; i++) { |
troshha | 3:9909607749dd | 138 | writeColorData(tarr, 1024); |
troshha | 3:9909607749dd | 139 | } |
troshha | 3:9909607749dd | 140 | |
troshha | 3:9909607749dd | 141 | |
codebreaker7 | 0:02841331478b | 142 | } |
codebreaker7 | 0:02841331478b | 143 | } |