Steward
分享是一種喜悅、更是一種幸福
微處理器 - STCmicro STC15W4K56S4 - C/C++ - 1.54" ePaper 200x200 Black-Red
屏
main.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | #include "stc15w4k56s4.h" #define SDA P20 #define SCK P21 #define CS P22 #define DC P23 #define RST P24 #define BUSY P25 const unsigned char lut_vcom0[] = { 0x0E, 0x14, 0x01, 0x0A, 0x06, 0x04, 0x0A, 0x0A, 0x0F, 0x03, 0x03, 0x0C, 0x06, 0x0A, 0x00 }; const unsigned char lut_w[] = { 0x0E, 0x14, 0x01, 0x0A, 0x46, 0x04, 0x8A, 0x4A, 0x0F, 0x83, 0x43, 0x0C, 0x86, 0x0A, 0x04 }; const unsigned char lut_b[] = { 0x0E, 0x14, 0x01, 0x8A, 0x06, 0x04, 0x8A, 0x4A, 0x0F, 0x83, 0x43, 0x0C, 0x06, 0x4A, 0x04 }; const unsigned char lut_g1[] = { 0x8E, 0x94, 0x01, 0x8A, 0x06, 0x04, 0x8A, 0x4A, 0x0F, 0x83, 0x43, 0x0C, 0x06, 0x0A, 0x04 }; const unsigned char lut_g2[] = { 0x8E, 0x94, 0x01, 0x8A, 0x06, 0x04, 0x8A, 0x4A, 0x0F, 0x83, 0x43, 0x0C, 0x06, 0x0A, 0x04 }; const unsigned char lut_vcom1[] = { 0x03, 0x1D, 0x01, 0x01, 0x08, 0x23, 0x37, 0x37, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; const unsigned char lut_red0[] = { 0x83, 0x5D, 0x01, 0x81, 0x48, 0x23, 0x77, 0x77, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; const unsigned char lut_red1[] = { 0x03, 0x1D, 0x01, 0x01, 0x08, 0x23, 0x37, 0x37, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; void delayms ( unsigned int ms) { unsigned int cnt = 0; while (ms--) { for (cnt = 0; cnt < 1000; cnt++) { } } } void gpio_init ( void ) { P0M0 = 0x00; P0M1 = 0x00; P1M0 = 0x00; P1M1 = 0x00; P2M0 = 0x00; P2M1 = 0x00; P3M0 = 0x00; P3M1 = 0x00; P4M0 = 0x00; P4M1 = 0x00; P0 = 0xff; P1 = 0xff; P2 = 0xff; P3 = 0xff; P4 = 0xff; } void spi_cmd ( unsigned char cmd ) { unsigned char bit = 0; CS = 0; DC = 0; for (bit = 0; bit < 8; bit++) { SCK = 0; if (( cmd & 0x80) == 0x80) { SDA = 1; } else { SDA = 0; } SCK = 1; cmd <<= 1; } CS = 1; } void spi_dat ( unsigned char dat) { unsigned char bit = 0; CS = 0; DC = 1; for (bit = 0; bit < 8; bit++) { SCK = 0; if ((dat & 0x80) == 0x80) { SDA = 1; } else { SDA = 0; } SCK = 1; dat <<= 1; } CS = 1; } void wait_busy ( void ) { do { delayms (1); } while ( BUSY == 0); } void lcd_init ( void ) { spi_cmd (0x01); spi_dat (0x07); spi_dat (0x00); spi_dat (0x08); spi_dat (0x00); spi_cmd (0x06); spi_dat (0x07); spi_dat (0x07); spi_dat (0x07); spi_cmd (0x04); wait_busy (); spi_cmd (0x00); spi_dat (0xcf); spi_cmd (0x50); spi_dat (0xf0); spi_cmd (0x30); spi_dat (0x39); spi_cmd (0x61); spi_dat (0xc8); spi_dat (0x00); spi_dat (0xc8); spi_cmd (0x82); spi_dat (0x0e); } void lcd_clear ( void ) { unsigned int x = 0; unsigned int y = 0; spi_cmd (0x10); for (y = 0; y < 200; y++) { for (x = 0; x < (200 / 8); x++) { spi_dat (0xff); spi_dat (0xff); } } spi_cmd (0x13); for (y = 0; y < 200; y++) { for (x = 0; x < (200 / 8); x++) { spi_dat (0xff); } } spi_cmd (0x12); wait_busy (); } static void set_lut_bw ( void ) { unsigned int x = 0; spi_cmd (0x20); for (x = 0; x < 15; x++) { spi_dat (lut_vcom0[x]); } spi_cmd (0x21); for (x = 0; x < 15; x++) { spi_dat (lut_w[x]); } spi_cmd (0x22); for (x = 0; x < 15; x++) { spi_dat (lut_b[x]); } spi_cmd (0x23); for (x = 0; x < 15; x++) { spi_dat (lut_g1[x]); } spi_cmd (0x24); for (x = 0; x < 15; x++) { spi_dat (lut_g2[x]); } } void set_lut_red ( void ) { unsigned int x = 0; spi_cmd (0x25); for (x = 0; x < 15; x++) { spi_dat (lut_vcom1[x]); } spi_cmd (0x26); for (x = 0; x < 15; x++) { spi_dat (lut_red0[x]); } spi_cmd (0x27); for (x = 0; x < 15; x++) { spi_dat (lut_red1[x]); } } void main ( void ) { unsigned int x = 0; unsigned int y = 0; gpio_init (); AUXR |= 0x80; RST = 0; delayms (300); RST = 1; delayms (300); lcd_init (); lcd_clear (); set_lut_bw (); set_lut_red (); spi_cmd (0x10); for (y = 0; y < 200; y++) { for (x = 0; x < (200 / 8); x++) { if (y < 70) { spi_dat (0x00); spi_dat (0x00); } else { spi_dat (0xff); spi_dat (0xff); } } } spi_cmd (0x13); for (y = 0; y < 200; y++) { for (x = 0; x < (200 / 8); x++) { if ((y > 70) && (y < 140)) { spi_dat (0x00); } else { spi_dat (0xff); } } } spi_cmd (0x12); wait_busy (); while (1) { P55 = 0; delayms (500); P55 = 1; delayms (500); } } |
Makefile
all: sdcc main.c packihx main.ihx > main.hex flash: sudo stcgal -p /dev/ttyO2 -P stc15 -o clock_source=external main.hex clean: rm -rf main.ihx main.lst main.mem main.rst main.lk main.map main.rel main.sym main.hex
完成