Kamil Ondrousek
/
SakaryaVGA
Sakarya chaotic attractor - uVGAII(SGC) 4DGL version 640x480 pin p9 - rx, pin p10 - tx, pin p11 - rst
main.cpp@0:221d6839bf16, 2011-09-03 (annotated)
- Committer:
- JLS
- Date:
- Sat Sep 03 16:46:25 2011 +0000
- Revision:
- 0:221d6839bf16
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JLS | 0:221d6839bf16 | 1 | #include "mbed.h" |
JLS | 0:221d6839bf16 | 2 | |
JLS | 0:221d6839bf16 | 3 | Serial _cmd (p9, p10); |
JLS | 0:221d6839bf16 | 4 | DigitalOut _rst (p11); |
JLS | 0:221d6839bf16 | 5 | |
JLS | 0:221d6839bf16 | 6 | void startVGA(); |
JLS | 0:221d6839bf16 | 7 | void baudrate(); |
JLS | 0:221d6839bf16 | 8 | void cls(); |
JLS | 0:221d6839bf16 | 9 | void pixel(int, int, int); |
JLS | 0:221d6839bf16 | 10 | int writeCOM(char *, int); |
JLS | 0:221d6839bf16 | 11 | |
JLS | 0:221d6839bf16 | 12 | |
JLS | 0:221d6839bf16 | 13 | int main() { |
JLS | 0:221d6839bf16 | 14 | |
JLS | 0:221d6839bf16 | 15 | startVGA (); |
JLS | 0:221d6839bf16 | 16 | |
JLS | 0:221d6839bf16 | 17 | float x = 1; |
JLS | 0:221d6839bf16 | 18 | float y = -1; |
JLS | 0:221d6839bf16 | 19 | float z = 1; |
JLS | 0:221d6839bf16 | 20 | |
JLS | 0:221d6839bf16 | 21 | float ix = 0; |
JLS | 0:221d6839bf16 | 22 | float iy = 0; |
JLS | 0:221d6839bf16 | 23 | float iz = 0; |
JLS | 0:221d6839bf16 | 24 | |
JLS | 0:221d6839bf16 | 25 | float a = 0.4; |
JLS | 0:221d6839bf16 | 26 | float b = 0.3; |
JLS | 0:221d6839bf16 | 27 | |
JLS | 0:221d6839bf16 | 28 | float dt = 0.001; |
JLS | 0:221d6839bf16 | 29 | |
JLS | 0:221d6839bf16 | 30 | while (1) { |
JLS | 0:221d6839bf16 | 31 | |
JLS | 0:221d6839bf16 | 32 | ix = x+dt*(-x+y+(y*z)); |
JLS | 0:221d6839bf16 | 33 | iy = y+dt*(-x-y+a*(x*z)); |
JLS | 0:221d6839bf16 | 34 | iz = z+dt*(z-b*(x*y)); |
JLS | 0:221d6839bf16 | 35 | |
JLS | 0:221d6839bf16 | 36 | pixel(320+(10*ix),240+(13*iy),65534); |
JLS | 0:221d6839bf16 | 37 | |
JLS | 0:221d6839bf16 | 38 | x = ix; |
JLS | 0:221d6839bf16 | 39 | y = iy; |
JLS | 0:221d6839bf16 | 40 | z = iz; |
JLS | 0:221d6839bf16 | 41 | |
JLS | 0:221d6839bf16 | 42 | } |
JLS | 0:221d6839bf16 | 43 | } |
JLS | 0:221d6839bf16 | 44 | |
JLS | 0:221d6839bf16 | 45 | |
JLS | 0:221d6839bf16 | 46 | void startVGA () { |
JLS | 0:221d6839bf16 | 47 | |
JLS | 0:221d6839bf16 | 48 | _rst = 1; |
JLS | 0:221d6839bf16 | 49 | _rst = 0; |
JLS | 0:221d6839bf16 | 50 | wait_ms(1); |
JLS | 0:221d6839bf16 | 51 | _rst = 1; |
JLS | 0:221d6839bf16 | 52 | wait(3); |
JLS | 0:221d6839bf16 | 53 | |
JLS | 0:221d6839bf16 | 54 | while (_cmd.readable()) _cmd.getc(); |
JLS | 0:221d6839bf16 | 55 | |
JLS | 0:221d6839bf16 | 56 | char autobaud[1] = ""; |
JLS | 0:221d6839bf16 | 57 | autobaud[0] = '\x55'; |
JLS | 0:221d6839bf16 | 58 | writeCOM(autobaud, 1); |
JLS | 0:221d6839bf16 | 59 | |
JLS | 0:221d6839bf16 | 60 | baudrate(); |
JLS | 0:221d6839bf16 | 61 | |
JLS | 0:221d6839bf16 | 62 | cls(); |
JLS | 0:221d6839bf16 | 63 | |
JLS | 0:221d6839bf16 | 64 | char dispctr[3]= ""; |
JLS | 0:221d6839bf16 | 65 | dispctr[0] = '\x59'; |
JLS | 0:221d6839bf16 | 66 | dispctr[1] = 0x0c; |
JLS | 0:221d6839bf16 | 67 | dispctr[2] = 0x01; |
JLS | 0:221d6839bf16 | 68 | writeCOM(dispctr, 3); |
JLS | 0:221d6839bf16 | 69 | |
JLS | 0:221d6839bf16 | 70 | } |
JLS | 0:221d6839bf16 | 71 | |
JLS | 0:221d6839bf16 | 72 | |
JLS | 0:221d6839bf16 | 73 | void pixel(int x, int y, int color) { |
JLS | 0:221d6839bf16 | 74 | |
JLS | 0:221d6839bf16 | 75 | char pixel[7]= ""; |
JLS | 0:221d6839bf16 | 76 | |
JLS | 0:221d6839bf16 | 77 | pixel[0] = '\x50'; |
JLS | 0:221d6839bf16 | 78 | |
JLS | 0:221d6839bf16 | 79 | pixel[1] = (x >> 8) & 0xFF; |
JLS | 0:221d6839bf16 | 80 | pixel[2] = x & 0xFF; |
JLS | 0:221d6839bf16 | 81 | |
JLS | 0:221d6839bf16 | 82 | pixel[3] = (y >> 8) & 0xFF; |
JLS | 0:221d6839bf16 | 83 | pixel[4] = y & 0xFF; |
JLS | 0:221d6839bf16 | 84 | |
JLS | 0:221d6839bf16 | 85 | pixel[5] = (color >> 8) & 0xFF; |
JLS | 0:221d6839bf16 | 86 | pixel[6] = color & 0xFF; |
JLS | 0:221d6839bf16 | 87 | |
JLS | 0:221d6839bf16 | 88 | writeCOM(pixel, 7); |
JLS | 0:221d6839bf16 | 89 | } |
JLS | 0:221d6839bf16 | 90 | |
JLS | 0:221d6839bf16 | 91 | |
JLS | 0:221d6839bf16 | 92 | void baudrate() { |
JLS | 0:221d6839bf16 | 93 | |
JLS | 0:221d6839bf16 | 94 | char baudrate[2]= ""; |
JLS | 0:221d6839bf16 | 95 | |
JLS | 0:221d6839bf16 | 96 | baudrate[0] = '\x51'; |
JLS | 0:221d6839bf16 | 97 | baudrate[1] = '\x0F'; |
JLS | 0:221d6839bf16 | 98 | |
JLS | 0:221d6839bf16 | 99 | int i, resp = 0; |
JLS | 0:221d6839bf16 | 100 | |
JLS | 0:221d6839bf16 | 101 | while (_cmd.readable()) _cmd.getc(); |
JLS | 0:221d6839bf16 | 102 | |
JLS | 0:221d6839bf16 | 103 | long speed = speed = 281000; |
JLS | 0:221d6839bf16 | 104 | |
JLS | 0:221d6839bf16 | 105 | for (i = 0; i <2; i++) _cmd.putc(baudrate[i]); |
JLS | 0:221d6839bf16 | 106 | _cmd.baud(speed); |
JLS | 0:221d6839bf16 | 107 | |
JLS | 0:221d6839bf16 | 108 | while (!_cmd.readable()) wait_ms(1); |
JLS | 0:221d6839bf16 | 109 | |
JLS | 0:221d6839bf16 | 110 | if (_cmd.readable()) resp = _cmd.getc(); |
JLS | 0:221d6839bf16 | 111 | switch (resp) { |
JLS | 0:221d6839bf16 | 112 | case '\x06' : |
JLS | 0:221d6839bf16 | 113 | resp = 1; |
JLS | 0:221d6839bf16 | 114 | break; |
JLS | 0:221d6839bf16 | 115 | case '\x15' : |
JLS | 0:221d6839bf16 | 116 | resp = -1; |
JLS | 0:221d6839bf16 | 117 | break; |
JLS | 0:221d6839bf16 | 118 | default : |
JLS | 0:221d6839bf16 | 119 | resp = 0; |
JLS | 0:221d6839bf16 | 120 | break; |
JLS | 0:221d6839bf16 | 121 | } |
JLS | 0:221d6839bf16 | 122 | |
JLS | 0:221d6839bf16 | 123 | } |
JLS | 0:221d6839bf16 | 124 | |
JLS | 0:221d6839bf16 | 125 | |
JLS | 0:221d6839bf16 | 126 | int writeCOM(char *command, int number) { |
JLS | 0:221d6839bf16 | 127 | |
JLS | 0:221d6839bf16 | 128 | int i, resp = 0; |
JLS | 0:221d6839bf16 | 129 | |
JLS | 0:221d6839bf16 | 130 | while (_cmd.readable()) _cmd.getc(); |
JLS | 0:221d6839bf16 | 131 | |
JLS | 0:221d6839bf16 | 132 | for (i = 0; i < number; i++) _cmd.putc(command[i]); |
JLS | 0:221d6839bf16 | 133 | |
JLS | 0:221d6839bf16 | 134 | while (!_cmd.readable()) wait_ms(1); |
JLS | 0:221d6839bf16 | 135 | if (_cmd.readable()) resp = _cmd.getc(); |
JLS | 0:221d6839bf16 | 136 | switch (resp) { |
JLS | 0:221d6839bf16 | 137 | case '\x06' : |
JLS | 0:221d6839bf16 | 138 | resp = 1; |
JLS | 0:221d6839bf16 | 139 | break; |
JLS | 0:221d6839bf16 | 140 | case '\x15' : |
JLS | 0:221d6839bf16 | 141 | resp = -1; |
JLS | 0:221d6839bf16 | 142 | break; |
JLS | 0:221d6839bf16 | 143 | default : |
JLS | 0:221d6839bf16 | 144 | resp = 0; |
JLS | 0:221d6839bf16 | 145 | break; |
JLS | 0:221d6839bf16 | 146 | } |
JLS | 0:221d6839bf16 | 147 | |
JLS | 0:221d6839bf16 | 148 | return resp; |
JLS | 0:221d6839bf16 | 149 | } |
JLS | 0:221d6839bf16 | 150 | |
JLS | 0:221d6839bf16 | 151 | |
JLS | 0:221d6839bf16 | 152 | void cls() { |
JLS | 0:221d6839bf16 | 153 | char cls[1] = ""; |
JLS | 0:221d6839bf16 | 154 | cls[0] = '\x45'; |
JLS | 0:221d6839bf16 | 155 | writeCOM(cls, 1); |
JLS | 0:221d6839bf16 | 156 | } |