Mercurial > public > hwos_code
annotate src/tft.asm @ 655:c7b7b8a358cd default tip
hwOS tech 3.22 release
author | heinrichsweikamp |
---|---|
date | Mon, 29 Apr 2024 13:05:18 +0200 |
parents | 75e90cd0c2c3 |
children |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
634 | 3 ; File tft.asm combined next generation V3.09.4n |
0 | 4 ; |
623 | 5 ; low-level Display Outputs |
0 | 6 ; |
654 | 7 ; Copyright (c) 2011, JD Gascuel, heinrichs weikamp gmbh, all right reserved. |
0 | 8 ;============================================================================= |
9 ; HISTORY | |
10 ; 2011-05-24 : [jDG] Cleanups from initial Matthias code. | |
11 | |
275 | 12 #include "hwos.inc" |
0 | 13 #include "wait.inc" |
14 #include "varargs.inc" | |
15 #include "tft_outputs.inc" | |
16 #include "eeprom_rs232.inc" | |
17 | |
634 | 18 ;----------------------------------------------------------------------------- |
0 | 19 ; Basic bit-level macros |
20 | |
582 | 21 RD_H macro |
22 bsf tft_rd,0 | |
23 endm | |
0 | 24 |
582 | 25 RD_L macro |
26 bcf tft_rd,0 | |
27 endm | |
0 | 28 |
582 | 29 RS_H macro |
30 bsf tft_rs,0 | |
31 endm | |
0 | 32 |
582 | 33 RS_L macro |
34 bcf tft_rs,0 | |
35 endm | |
0 | 36 |
582 | 37 NCS_H macro |
38 bsf tft_cs,0 | |
39 endm | |
0 | 40 |
582 | 41 NCS_L macro |
42 bcf tft_cs,0 | |
43 endm | |
0 | 44 |
582 | 45 WR_H macro |
46 bsf tft_nwr,0 | |
47 endm | |
0 | 48 |
582 | 49 WR_L macro |
50 bcf tft_nwr,0 | |
51 endm | |
0 | 52 |
634 | 53 ;----------------------------------------------------------------------------- |
582 | 54 ; Byte-level macros |
55 | |
0 | 56 Index_out macro low_b |
57 movlw low_b | |
58 rcall TFT_CmdWrite | |
59 endm | |
60 | |
61 Parameter_out macro high_b, low_b | |
62 movlw high_b | |
604 | 63 movwf PORTA ; upper |
0 | 64 movlw low_b |
65 rcall TFT_DataWrite | |
66 endm | |
67 | |
634 | 68 ;============================================================================= |
604 | 69 tft CODE |
634 | 70 ;============================================================================= |
582 | 71 |
72 global TFT_ClearScreen | |
0 | 73 TFT_ClearScreen: |
654 | 74 btfsc screen_type4 ; screen type 4? |
75 bra TFT_ClearScreen_display4; YES | |
76 btfsc screen_type3 ; screen type 3? | |
77 bra TFT_ClearScreen_display3; YES | |
628 | 78 btfsc screen_type2 ; screen type 2? |
623 | 79 bra TFT_ClearScreen_display2; YES |
80 | |
604 | 81 Index_out 0x50 ; window horizontal start address |
654 | 82 Parameter_out 0x00, 0x00 ; 0 |
604 | 83 Index_out 0x51 ; window horizontal end address |
654 | 84 Parameter_out 0x00, 0xEF ; 239 |
604 | 85 Index_out 0x52 ; window vertical start address |
654 | 86 Parameter_out 0x00, 0x00 ; 0 |
604 | 87 Index_out 0x53 ; window vertical end address |
654 | 88 Parameter_out 0x01, 0x3F ; 319 |
604 | 89 Index_out 0x20 ; frame memory horizontal address |
654 | 90 Parameter_out 0x00, 0x00 ; 0 |
604 | 91 Index_out 0x21 ; frame memory vertical address |
654 | 92 Parameter_out 0x01, 0x3F ; 319 |
0 | 93 |
604 | 94 Index_out 0x22 ; frame memory data write start |
0 | 95 |
604 | 96 RD_H ; not read |
97 RS_H ; data | |
98 NCS_L ; not CS | |
648 | 99 |
100 btfsc less_io_cpu ; less I/O CPU? | |
101 clrf PORTA ; YES, data lower | |
102 btfss less_io_cpu ; less I/O CPU? | |
103 clrf PORTH ; NO, data lower | |
0 | 104 |
105 movlw d'10' | |
106 movwf tft_temp3 | |
107 TFT_ClearScreen2: | |
108 movlw d'30' | |
109 movwf tft_temp2 | |
110 TFT_ClearScreen3: | |
604 | 111 clrf tft_temp1 ; 30*10*256=76800 pixels -> clear complete 240*320 |
582 | 112 bcf INTCON,GIE |
0 | 113 TFT_ClearScreen4: |
114 WR_L | |
604 | 115 WR_H ; tick |
648 | 116 btfss less_io_cpu ; less I/O CPU? |
117 bra TFT_ClearScreen5 ; NO | |
118 WR_L | |
119 WR_H ; tick | |
120 WR_L | |
121 WR_H ; tick | |
122 WR_L | |
123 WR_H ; tick | |
124 TFT_ClearScreen5: | |
0 | 125 decfsz tft_temp1,F |
126 bra TFT_ClearScreen4 | |
582 | 127 bsf INTCON,GIE |
0 | 128 decfsz tft_temp2,F |
129 bra TFT_ClearScreen3 | |
130 decfsz tft_temp3,F | |
131 bra TFT_ClearScreen2 | |
582 | 132 |
133 movlw 0x00 ; NOP, to stop window mode | |
604 | 134 bra TFT_CmdWrite ; and return |
582 | 135 |
623 | 136 TFT_ClearScreen_display2: |
137 movlw 0x02 ; column address start | |
608 | 138 rcall TFT_CmdWrite |
139 movlw 0x00 | |
140 rcall TFT_DataWrite | |
141 movlw 0x03 | |
142 rcall TFT_CmdWrite | |
143 movlw 0x00 | |
144 rcall TFT_DataWrite | |
145 | |
623 | 146 movlw 0x04 ; column address end |
608 | 147 rcall TFT_CmdWrite |
148 movlw 0x00 | |
149 rcall TFT_DataWrite | |
150 movlw 0x05 | |
151 rcall TFT_CmdWrite | |
152 movlw 0xEF | |
153 rcall TFT_DataWrite | |
154 | |
623 | 155 movlw 0x06 ; row address start |
608 | 156 rcall TFT_CmdWrite |
157 movlw 0x00 | |
158 rcall TFT_DataWrite | |
159 movlw 0x07 | |
160 rcall TFT_CmdWrite | |
161 movlw 0x00 | |
162 rcall TFT_DataWrite | |
163 | |
623 | 164 movlw 0x08 ; row address end |
608 | 165 rcall TFT_CmdWrite |
166 movlw 0x01 | |
167 rcall TFT_DataWrite | |
168 movlw 0x09 | |
169 rcall TFT_CmdWrite | |
170 movlw 0x3F | |
171 rcall TFT_DataWrite | |
172 | |
623 | 173 movlw 0x22 ; start writing data to GRAM |
608 | 174 rcall TFT_CmdWrite |
175 | |
628 | 176 movlw .160 ; 160 x 240 x 6 = 230400 ticks |
177 TFT_ClearScreen_display2_loop0: | |
623 | 178 bsf tft_rs ; data! |
608 | 179 movwf PRODH |
180 clrf PORTH | |
623 | 181 TFT_ClearScreen_display2_loop1: |
608 | 182 movlw .240 |
183 movwf PRODL | |
623 | 184 TFT_ClearScreen_display2_loop2: |
608 | 185 bcf tft_nwr |
623 | 186 bsf tft_nwr ; upper |
608 | 187 bcf tft_nwr |
623 | 188 bsf tft_nwr ; high |
608 | 189 bcf tft_nwr |
623 | 190 bsf tft_nwr ; lower |
608 | 191 bcf tft_nwr |
623 | 192 bsf tft_nwr ; upper |
608 | 193 bcf tft_nwr |
623 | 194 bsf tft_nwr ; high |
608 | 195 bcf tft_nwr |
623 | 196 bsf tft_nwr ; lower |
608 | 197 decfsz PRODL,F |
623 | 198 bra TFT_ClearScreen_display2_loop2 |
608 | 199 decfsz PRODH,F |
623 | 200 bra TFT_ClearScreen_display2_loop1 |
201 return | |
0 | 202 |
628 | 203 TFT_ClearScreen_display3: |
204 movlw 0x35 ; vertical start address HIGH:LOW | |
205 rcall TFT_CmdWrite | |
631 | 206 mullw 0 |
628 | 207 rcall TFT_DataWrite_PROD |
208 | |
209 movlw 0x36 ; vertical end address HIGH:LOW | |
210 rcall TFT_CmdWrite | |
211 movlw 0x01 | |
212 rcall TFT_DataWrite | |
213 movlw 0x3F | |
214 rcall TFT_DataWrite | |
215 | |
216 movlw 0x37 ; horizontal address START:END | |
217 rcall TFT_CmdWrite | |
218 movlw 0x00 | |
219 rcall TFT_DataWrite | |
220 movlw 0xEF | |
221 rcall TFT_DataWrite | |
222 | |
223 movlw 0x20 ; start address horizontal (.0 - .239) | |
224 rcall TFT_CmdWrite | |
225 rcall TFT_DataWrite_PROD | |
226 | |
227 movlw 0x21 ; start address vertical (.0 - .319) | |
228 rcall TFT_CmdWrite | |
229 rcall TFT_DataWrite_PROD | |
230 | |
231 movlw 0x22 ; start writing data to GRAM | |
232 rcall TFT_CmdWrite | |
233 | |
234 movlw .107 ; 107 x 240 x 6 = 154080 ticks (153600 would be enough) | |
235 bra TFT_ClearScreen_display2_loop0 | |
236 | |
654 | 237 TFT_ClearScreen_display4: |
238 ; Column Address start | |
239 movlw 0x2A | |
240 rcall TFT_CmdWrite | |
241 movlw 0x00 | |
242 rcall TFT_DataWrite | |
243 movlw 0x00 | |
244 rcall TFT_DataWrite | |
245 ; Column Address end (d'239') | |
246 movlw 0x00 | |
247 rcall TFT_DataWrite | |
248 movlw 0xEF | |
249 rcall TFT_DataWrite | |
250 | |
251 ; Row address start | |
252 movlw 0x2B | |
253 rcall TFT_CmdWrite | |
254 movlw 0x00 | |
255 rcall TFT_DataWrite | |
256 movlw 0x00 | |
257 rcall TFT_DataWrite | |
258 ; Row address end (d'319) | |
259 movlw 0x01 | |
260 rcall TFT_DataWrite | |
261 movlw 0x3F | |
262 rcall TFT_DataWrite | |
263 | |
264 movlw 0x2C ; Start Writing Data to GRAM | |
265 rcall TFT_CmdWrite | |
266 | |
267 RD_H ; Not Read | |
268 RS_H ; Data | |
269 NCS_L ; Not CS | |
270 clrf PORTA ; Data Upper | |
271 clrf PORTH ; Data Lower | |
272 bcf INTCON,GIE | |
273 movlw d'10' | |
274 movwf tft_temp3 | |
275 TFT_ClearScreen_display4_loop1: | |
276 movlw d'30' | |
277 movwf tft_temp2 | |
278 TFT_ClearScreen_display4_loop2: | |
279 clrf tft_temp1 ; 30*10*256=76800 Pixels -> Clear complete 240*320 | |
280 TFT_ClearScreen_display4_loop3: | |
281 WR_L | |
282 WR_H ; Tick | |
283 decfsz tft_temp1,F | |
284 bra TFT_ClearScreen_display4_loop3 | |
285 decfsz tft_temp2,F | |
286 bra TFT_ClearScreen_display4_loop2 | |
287 decfsz tft_temp3,F | |
288 bra TFT_ClearScreen_display4_loop1 | |
289 bsf INTCON,GIE | |
290 return | |
291 | |
628 | 292 |
582 | 293 global TFT_DisplayOff |
0 | 294 TFT_DisplayOff: |
628 | 295 bcf lightsen_power ; power-down light sensor |
631 | 296 btfsc screen_type3 ; screen type 3 ? |
297 bra TFT_DisplayOff_display3 ; YES - screen needs special power-down sequence | |
298 clrf CCP1CON ; NO - stop PWM | |
299 bcf PORTC,2 ; - pull PWM out to GND | |
0 | 300 clrf PORTA |
582 | 301 clrf PORTH |
623 | 302 RD_L ; LOW |
303 RS_L ; LOW | |
640 | 304 WR_L |
305 NCS_L | |
623 | 306 bcf tft_nreset |
307 bsf tft_power ; inverted... | |
628 | 308 return |
309 | |
310 TFT_DisplayOff_display3: | |
311 movlw 0x05 | |
312 rcall TFT_CmdWrite | |
313 movlw 0x00 | |
314 rcall TFT_DataWrite | |
315 movlw 0x00 | |
316 rcall TFT_DataWrite | |
317 WAITMS d'32' | |
318 clrf CCP1CON ; stop PWM | |
319 bcf PORTC,2 ; pull PWM out to GND | |
320 WAITMS d'32' | |
321 movlw 0x10 | |
322 rcall TFT_CmdWrite | |
323 movlw 0x00 | |
324 rcall TFT_DataWrite | |
325 movlw 0x01 | |
326 rcall TFT_DataWrite | |
327 WAITMS d'100' | |
328 clrf PORTH | |
329 bcf tft_nwr | |
330 bcf tft_cs | |
331 bcf tft_nreset | |
332 WAITMS d'10' | |
333 bsf tft_power ; inverted... | |
0 | 334 return |
335 | |
336 ; ----------------------------- | |
337 ; TFT boot | |
338 ; ----------------------------- | |
582 | 339 |
340 global TFT_boot | |
0 | 341 TFT_boot: |
623 | 342 ; switch off backlight |
343 clrf CCP1CON ; stop PWM | |
344 bcf PORTC,2 ; pull PWM out to GND | |
345 | |
0 | 346 clrf PORTA |
347 clrf PORTH | |
348 RD_L ; LOW | |
349 nop | |
628 | 350 WR_L |
351 nop | |
352 NCS_L ; Not CS | |
0 | 353 nop |
354 bcf tft_nreset | |
355 WAITMS d'1' | |
356 bcf tft_power ; inverted... | |
357 WAITMS d'1' | |
358 RD_H ; Keep high | |
628 | 359 nop |
0 | 360 WAITMS d'2' |
361 bsf tft_nreset | |
461 | 362 WAITMS d'5' |
363 bcf tft_nreset | |
364 WAITMS d'5' | |
365 bsf tft_nreset | |
0 | 366 WAITMS d'150' |
628 | 367 WR_H ; release bus |
604 | 368 bsf lightsen_power ; supply power to light sensor |
0 | 369 |
628 | 370 btfsc screen_type3 ; display type 3 ? |
371 bra TFT_boot_screen3 ; YES | |
372 | |
654 | 373 btfsc screen_type4 ; display type 4 ? |
374 bra TFT_boot_screen4 ; YES | |
375 | |
582 | 376 ; Data Transfer Synchronization |
0 | 377 Parameter_out 0x00, 0x00 |
378 Parameter_out 0x00, 0x00 | |
582 | 379 |
623 | 380 btfsc screen_type2 ; display type 2 ? |
381 bra TFT_boot_screen2 ; YES | |
608 | 382 |
623 | 383 ; Get screen type from Bootloader-Info |
582 | 384 movlw 0x7B |
385 movwf TBLPTRL | |
386 movlw 0xF7 | |
387 movwf TBLPTRH | |
388 movlw 0x01 | |
389 movwf TBLPTRU | |
623 | 390 TBLRD*+ ; reads 0x6E for cR and USB OSTC3, 0x00 for BLE (2 and 3), and 0x02 for display 1 OSTC |
391 movlw 0x02 ; coding for display 1 | |
392 cpfseq TABLAT ; display 1 ? | |
393 bra TFT_boot_0 ; NO - display 0 | |
360 | 394 |
395 TFT_boot_1: | |
582 | 396 ; Init through config table... |
397 movlw 0x74 | |
398 movwf TBLPTRL | |
399 movlw 0xF7 | |
400 movwf TBLPTRH | |
401 movlw 0x01 | |
402 movwf TBLPTRU | |
628 | 403 bsf screen_type1 |
582 | 404 bra TFT_boot_com |
360 | 405 |
441
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
436
diff
changeset
|
406 TFT_boot_0: |
582 | 407 ; Init through config table... |
408 movlw LOW display0_config_table | |
409 movwf TBLPTRL | |
410 movlw HIGH display0_config_table | |
411 movwf TBLPTRH | |
412 movlw UPPER display0_config_table | |
413 movwf TBLPTRU | |
648 | 414 btfss less_io_cpu ; less I/O CPU? |
415 bcf screen_type1 ; NO | |
582 | 416 |
360 | 417 TFT_boot_com: |
582 | 418 rcall display0_init_loop |
0 | 419 |
582 | 420 Index_out 0x03 |
421 btfsc flip_screen ; 180° rotation ? | |
604 | 422 bra TFT_boot2 ; YES |
360 | 423 |
628 | 424 btfss screen_type1 ; display1? |
604 | 425 bra TFT_boot1a ; NO |
582 | 426 Parameter_out 0x10, 0x00 ; display1 |
427 bra TFT_boot3 | |
360 | 428 TFT_boot1a: |
582 | 429 Parameter_out 0x50, 0x20 ; display0 |
430 bra TFT_boot3 | |
152
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
151
diff
changeset
|
431 TFT_boot2: |
628 | 432 btfss screen_type1 ; display1? |
604 | 433 bra TFT_boot2a ; NO |
582 | 434 Parameter_out 0x10, 0x30 ; display1 |
435 bra TFT_boot3 | |
360 | 436 TFT_boot2a: |
582 | 437 Parameter_out 0x50, 0x10 ; display0 |
152
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
151
diff
changeset
|
438 TFT_boot3: |
0 | 439 Index_out 0x22 |
225
31088352ee32
BUGFIX: Show dives with >999mins divetime correctly
heinrichsweikamp
parents:
152
diff
changeset
|
440 rcall TFT_ClearScreen |
0 | 441 Index_out 0x07 |
312 | 442 Parameter_out 0x01, 0x33 |
654 | 443 return ; done TFT_boot |
0 | 444 |
445 display0_config_table: | |
582 | 446 ; Reg, Dat0, Dat1 or 0xFF,0x00,0x00 for end |
447 db 0xA4,0x00,0x01,0xFF,.002,0x00 | |
448 db 0x09,0x00,0x01,0x92,0x04,0x00 | |
449 db 0x93,0x04,0x02,0x94,0x00,0x02 | |
450 db 0x07,0x00,0x00,0x10,0x04,0x30 | |
451 db 0x11,0x02,0x37,0x12,0x11,0x8D | |
452 db 0x13,0x11,0x00,0x01,0x01,0x00 | |
453 db 0x02,0x02,0x00,0x03,0x50,0x20 | |
454 db 0x0A,0x00,0x08,0x0D,0x00,0x00 | |
455 db 0x0E,0x00,0x30,0xFF,.151,0x00 | |
456 db 0x12,0x11,0xBD,0x20,0x00,0x00 | |
457 db 0x21,0x00,0x00,0x30,0x06,0x02 | |
458 db 0x31,0x56,0x0D,0x32,0x05,0x07 | |
459 db 0x33,0x06,0x09,0x34,0x00,0x00 | |
460 db 0x35,0x09,0x06,0x36,0x57,0x05 | |
461 db 0x37,0x0D,0x06,0x38,0x02,0x06 | |
462 db 0x39,0x00,0x00,0xFF,0x00,0x00 | |
0 | 463 |
464 display0_init_loop: | |
582 | 465 TBLRD*+ |
466 movlw 0xFF | |
467 cpfseq TABLAT | |
623 | 468 bra display0_config_write ; write configuration data pair to display |
582 | 469 ; Delay ms or quit (return) |
470 TBLRD*+ | |
623 | 471 tstfsz TABLAT ; end of configuration data? |
604 | 472 bra $+4 ; NO |
473 return ; YES - done | |
582 | 474 movf TABLAT,W |
604 | 475 call WAITMSX ; wait WREG milliseconds |
476 TBLRD*+ ; dummy read (Third byte of delay command) | |
477 bra display0_init_loop ; loop | |
0 | 478 |
604 | 479 display0_config_write: ; with command in WREG |
582 | 480 movf TABLAT,W |
604 | 481 rcall TFT_CmdWrite ; write command |
482 TBLRD*+ ; get config0 | |
582 | 483 movff TABLAT,PORTA |
604 | 484 TBLRD*+ ; get config1 |
582 | 485 movf TABLAT,W |
623 | 486 rcall TFT_DataWrite ; write configuration |
604 | 487 bra display0_init_loop ; loop |
0 | 488 |
623 | 489 |
608 | 490 TFT_boot_screen2: |
623 | 491 rcall display1_init ; initialization sequence |
608 | 492 |
623 | 493 btfss flip_screen ; 180° rotation? |
494 bra TFT_ClearScreen ; NO - done: clear screen and return | |
495 ; flip the GRAM | |
496 Index_out 0x16 | |
497 movlw 0x48 ; flip image in the GRAM (very elegant with display 2...) | |
498 rcall TFT_DataWrite ; Write configuration | |
499 bra TFT_ClearScreen ; clear screen and return | |
608 | 500 |
628 | 501 TFT_boot_screen3: |
502 rcall display1_init ; init sequence | |
503 rcall TFT_ClearScreen | |
504 setf CCPR1L ; duty cycle, 255 is required for OLED | |
505 ; Set brightness | |
645 | 506 movff brightness,PRODL ; =0: Eco, =1:Medium, =2:Full |
628 | 507 incf PRODL,F ; +1 |
508 dcfsnz PRODL,F | |
509 rcall TFT_display3_low | |
510 dcfsnz PRODL,F | |
511 rcall TFT_display3_med | |
512 dcfsnz PRODL,F | |
513 rcall TFT_display3_high | |
514 ; ToDo: Flip.... | |
515 return | |
516 | |
608 | 517 display1_init: |
623 | 518 movlw LOW (0x1F8BC ) |
519 movwf TBLPTRL | |
520 movlw HIGH (0x1F8BC & 0xFFFF) | |
521 movwf TBLPTRH | |
522 movlw UPPER (0x1F8BC ) | |
523 movwf TBLPTRU | |
608 | 524 display1_init_loop: |
623 | 525 TBLRD*+ |
526 movlw 0xFF ; coding for end of configuration or wait step | |
527 cpfseq TABLAT | |
528 bra display1_config_write ; write configuration pair to display | |
529 ; Delay ms or quit (return) | |
530 TBLRD*+ | |
531 tstfsz TABLAT ; end of configuration? | |
532 bra $+4 ; NO - skip return | |
533 return ; YES - done | |
534 movf TABLAT,W ; read waiting time | |
535 call WAITMSX ; wait WREG milliseconds | |
536 bra display1_init_loop ; loop | |
537 display1_config_write: ; with command in WREG | |
538 movf TABLAT,W | |
539 rcall TFT_CmdWrite ; write command | |
540 TBLRD*+ ; get configuration | |
541 movf TABLAT,W | |
542 rcall TFT_DataWrite ; write configuration | |
628 | 543 btfss screen_type3 ; screen 3 ? |
544 bra display1_init_loop ; NO - loop | |
545 ; Screen 3 gets another byte from the table | |
546 TBLRD*+ ; get configuration | |
547 movf TABLAT,W | |
548 rcall TFT_DataWrite ; write configuration | |
623 | 549 bra display1_init_loop ; loop |
608 | 550 |
654 | 551 TFT_boot_screen4: |
552 movlw 0xB0 | |
553 rcall TFT_CmdWrite | |
554 movlw 0x00 | |
555 rcall TFT_DataWrite | |
556 movlw 0xC4 | |
557 rcall TFT_DataWrite | |
558 | |
559 movlw 0xB1 | |
560 rcall TFT_CmdWrite | |
561 movlw 0xC0 | |
562 rcall TFT_DataWrite | |
563 | |
564 movlw 0x3A | |
565 rcall TFT_CmdWrite | |
566 movlw 0x55 | |
567 rcall TFT_DataWrite | |
568 | |
569 movlw 0x36 ; x/y mirror, see page 125 of ST7789V datasheet | |
570 rcall TFT_CmdWrite | |
571 movlw 0x40 ; 0x40 (normal orientation) | |
572 rcall TFT_DataWrite | |
573 | |
574 movlw 0xB0 | |
575 rcall TFT_CmdWrite | |
576 movlw 0x00 | |
577 rcall TFT_DataWrite | |
578 | |
579 movlw 0xB2 | |
580 call TFT_CmdWrite | |
581 movlw 0x0C | |
582 rcall TFT_DataWrite | |
583 movlw 0x0C | |
584 rcall TFT_DataWrite | |
585 movlw 0x00 | |
586 rcall TFT_DataWrite | |
587 movlw 0x33 | |
588 rcall TFT_DataWrite | |
589 movlw 0x33 | |
590 rcall TFT_DataWrite | |
591 | |
592 movlw 0xB7 | |
593 rcall TFT_CmdWrite | |
594 movlw 0x75 | |
595 rcall TFT_DataWrite | |
596 | |
597 movlw 0xBB | |
598 rcall TFT_CmdWrite | |
599 movlw 0x20 | |
600 rcall TFT_DataWrite | |
601 | |
602 movlw 0xC0 | |
603 rcall TFT_CmdWrite | |
604 movlw 0x2C | |
605 rcall TFT_DataWrite | |
606 | |
607 movlw 0xC2 | |
608 rcall TFT_CmdWrite | |
609 movlw 0x01 | |
610 rcall TFT_DataWrite | |
611 | |
612 movlw 0xC3 | |
613 rcall TFT_CmdWrite | |
614 movlw 0x19 | |
615 rcall TFT_DataWrite | |
616 | |
617 movlw 0xC4 | |
618 rcall TFT_CmdWrite | |
619 movlw 0x20 | |
620 rcall TFT_DataWrite | |
621 | |
622 movlw 0xC6 | |
623 rcall TFT_CmdWrite | |
624 movlw 0x0F | |
625 rcall TFT_DataWrite | |
626 | |
627 movlw 0xD0 | |
628 rcall TFT_CmdWrite | |
629 movlw 0xA7 | |
630 rcall TFT_DataWrite | |
631 movlw 0xA1 | |
632 rcall TFT_DataWrite | |
633 | |
634 movlw 0xBB | |
635 rcall TFT_CmdWrite | |
636 movlw 0x35 | |
637 rcall TFT_DataWrite | |
638 | |
639 movlw 0xC0 | |
640 rcall TFT_CmdWrite | |
641 movlw 0x2C | |
642 rcall TFT_DataWrite | |
643 | |
644 movlw 0xC2 | |
645 rcall TFT_CmdWrite | |
646 movlw 0x01 | |
647 rcall TFT_DataWrite | |
648 | |
649 movlw 0xC3 | |
650 rcall TFT_CmdWrite | |
651 movlw 0x11 | |
652 rcall TFT_DataWrite | |
653 | |
654 movlw 0xC4 | |
655 rcall TFT_CmdWrite | |
656 movlw 0x20 | |
657 rcall TFT_DataWrite | |
658 | |
659 movlw 0xC6 | |
660 rcall TFT_CmdWrite | |
661 movlw 0x0F | |
662 rcall TFT_DataWrite | |
663 | |
664 movlw 0xD0 | |
665 rcall TFT_CmdWrite | |
666 movlw 0xA7 | |
667 rcall TFT_DataWrite | |
668 movlw 0xA1 | |
669 rcall TFT_DataWrite | |
670 | |
671 movlw 0xBB | |
672 rcall TFT_CmdWrite | |
673 movlw 0x35 | |
674 rcall TFT_DataWrite | |
675 | |
676 movlw 0xC0 | |
677 rcall TFT_CmdWrite | |
678 movlw 0x2C | |
679 rcall TFT_DataWrite | |
680 | |
681 movlw 0x2C | |
682 rcall TFT_CmdWrite | |
683 movlw 0x01 | |
684 rcall TFT_DataWrite | |
685 | |
686 movlw 0xC3 | |
687 rcall TFT_CmdWrite | |
688 movlw 0x11 | |
689 rcall TFT_DataWrite | |
690 | |
691 movlw 0xC4 | |
692 rcall TFT_CmdWrite | |
693 movlw 0x20 | |
694 rcall TFT_DataWrite | |
695 | |
696 movlw 0xC6 | |
697 rcall TFT_CmdWrite | |
698 movlw 0x0F | |
699 rcall TFT_DataWrite | |
700 | |
701 movlw 0xD0 | |
702 rcall TFT_CmdWrite | |
703 movlw 0xA4 | |
704 rcall TFT_DataWrite | |
705 movlw 0xA1 | |
706 rcall TFT_DataWrite | |
707 ; gamma | |
708 movlw 0x11 | |
709 rcall TFT_CmdWrite | |
710 | |
711 movlw 0x21 | |
712 rcall TFT_CmdWrite | |
713 WAITMS d'60' | |
714 | |
715 movlw 0x29 | |
716 rcall TFT_CmdWrite | |
717 WAITMS d'50' | |
718 rcall TFT_ClearScreen | |
719 ; ToDo: Flip.... | |
720 return ; done TFT_boot | |
721 | |
623 | 722 |
723 global TFT_CmdWrite | |
608 | 724 TFT_CmdWrite: |
725 RS_L ; command | |
628 | 726 ; btfsc screen_type2 |
727 ; bra TFT_CmdWrite_screen2 | |
608 | 728 clrf PORTA ; upper |
729 bcf INTCON,GIE | |
648 | 730 btfsc less_io_cpu ; less I/O CPU? |
731 bra TFT_CmdWrite_less_io ; YES | |
608 | 732 movwf PORTH ; lower |
733 WR_L | |
734 WR_H ; tick | |
735 bsf INTCON,GIE | |
736 return | |
628 | 737 ;TFT_CmdWrite_screen2: |
738 ; movwf PORTH ; lower | |
739 ; WR_L | |
740 ; WR_H ; tick | |
741 ; return; | |
608 | 742 |
648 | 743 TFT_CmdWrite_less_io: |
744 WR_L | |
745 WR_H ; tick | |
746 movwf PORTA ; lower | |
747 WR_L | |
748 WR_H ; tick | |
749 bsf INTCON,GIE | |
750 return | |
751 | |
608 | 752 global TFT_DataWrite |
753 TFT_DataWrite: | |
754 RS_H ; data | |
628 | 755 ; btfsc screen_type2 |
756 ; bra TFT_DataWrite_screen2 | |
608 | 757 bcf INTCON,GIE |
648 | 758 btfsc less_io_cpu ; less I/O CPU? |
759 bra TFT_DataWrite_less_io ; YES | |
623 | 760 movwf PORTH ; lower |
608 | 761 WR_L |
762 WR_H ; tick | |
763 bsf INTCON,GIE | |
764 return | |
628 | 765 ;TFT_DataWrite_screen2: |
766 ; movwf PORTH ; lower | |
767 ; WR_L | |
768 ; WR_H ; tick | |
769 ; return | |
648 | 770 TFT_DataWrite_less_io: |
771 WR_L | |
772 WR_H ; tick | |
773 movwf PORTA ; lower | |
774 WR_L | |
775 WR_H ; tick | |
776 bsf INTCON,GIE | |
777 return | |
608 | 778 |
623 | 779 |
634 | 780 ;----------------------------------------------------------------------------- |
0 | 781 ; Smooth lighting-up of the display: |
782 ; | |
783 ; Trashes: WREG, PRODL | |
784 ; Typical usage: | |
604 | 785 ; clrf CCPR1L ; backlight off |
582 | 786 ; [draw splash screen] |
787 ; call TFT_DisplayFadeIn | |
634 | 788 ; |
582 | 789 global TFT_Display_FadeIn |
0 | 790 TFT_Display_FadeIn: |
623 | 791 movlw CCP1CON_VALUE ; get configuration |
792 movwf CCP1CON ; set configuration | |
604 | 793 bsf tft_is_dimming ; TFT is dimming, ignore ambient sensor |
628 | 794 btfsc screen_type3 |
634 | 795 bra TFT_Display_FadeIn_1 |
604 | 796 clrf CCPR1L ; backlight off - to be sure |
582 | 797 movff max_CCPR1L,PRODL |
0 | 798 TFT_Display_FadeIn_0: |
604 | 799 incf CCPR1L,F ; duty cycle |
582 | 800 WAITMS d'2' |
801 decfsz PRODL,F | |
623 | 802 bra TFT_Display_FadeIn_0 |
604 | 803 bcf tft_is_dimming ; dimming done |
582 | 804 return |
628 | 805 TFT_Display_FadeIn_1: |
806 setf CCPR1L | |
807 return | |
0 | 808 |
634 | 809 ;----------------------------------------------------------------------------- |
0 | 810 ; Smooth lighting-off of the display: |
811 ; Trashes: WREG, PRODL | |
634 | 812 ; |
582 | 813 global TFT_Display_FadeOut |
0 | 814 TFT_Display_FadeOut: |
582 | 815 movff max_CCPR1L,PRODL |
604 | 816 bsf tft_is_dimming ; TFT is dimming, ignore ambient sensor |
628 | 817 btfsc screen_type3 |
640 | 818 return ; Do not fade out screen type 3 |
0 | 819 TFT_Display_FadeOut_0: |
604 | 820 movff PRODL,CCPR1L ; duty cycle |
582 | 821 WAITMS d'1' |
822 decfsz PRODL,F | |
823 bra TFT_Display_FadeOut_0 | |
628 | 824 TFT_Display_FadeOut_1: |
582 | 825 clrf CCPR1L |
826 return | |
0 | 827 |
634 | 828 ;----------------------------------------------------------------------------- |
829 ; OLED brightness control | |
830 ; | |
628 | 831 TFT_display3_high: ; 0x01F8F8 |
832 movlw LOW (0x01F8F8 ) | |
833 movwf TBLPTRL | |
834 movlw HIGH (0x01F8F8 & 0xFFFF) | |
835 movwf TBLPTRH | |
836 movlw UPPER (0x01F8F8 ) | |
837 movwf TBLPTRU | |
838 bra display1_init_loop ; and return | |
839 | |
840 TFT_display3_med: ; 0x01F91C | |
841 movlw LOW (0x01F91C ) | |
842 movwf TBLPTRL | |
843 movlw HIGH (0x01F91C & 0xFFFF) | |
844 movwf TBLPTRH | |
845 movlw UPPER (0x01F91C ) | |
846 movwf TBLPTRU | |
847 bra display1_init_loop ; and return | |
848 | |
849 TFT_display3_low: ; 0x01F8D4 | |
850 movlw LOW (0x01F8D4 ) | |
851 movwf TBLPTRL | |
852 movlw HIGH (0x01F8D4 & 0xFFFF) | |
853 movwf TBLPTRH | |
854 movlw UPPER (0x01F8D4 ) | |
855 movwf TBLPTRU | |
856 bra display1_init_loop ; and return | |
857 | |
0 | 858 |
634 | 859 ;----------------------------------------------------------------------------- |
860 ; colored (filled) Boxes | |
861 ; | |
862 global box_std_block, box_black_block, box_color_block, box_color | |
0 | 863 |
604 | 864 box_std_block: ; use white color |
582 | 865 setf WREG |
634 | 866 bra box_color_block |
604 | 867 box_black_block: ; use black color |
582 | 868 clrf WREG |
634 | 869 box_color_block: ; use color from WREG |
582 | 870 rcall TFT_set_color |
871 VARARGS_BEGIN | |
872 VARARGS_GET8 win_top | |
873 VARARGS_GET8 win_height | |
874 VARARGS_GET8 win_leftx2 | |
875 VARARGS_GET8 win_width | |
876 VARARGS_END | |
877 bra TFT_box | |
0 | 878 |
634 | 879 box_color: ; use color from WREG and pre-set coordinates |
880 rcall TFT_set_color | |
881 bra TFT_box | |
0 | 882 |
883 | |
634 | 884 ;----------------------------------------------------------------------------- |
885 ; colored Frames | |
886 ; | |
887 global box_frame_std, box_frame_color | |
888 | |
889 box_frame_std: ; use white color | |
582 | 890 setf WREG |
634 | 891 box_frame_color: ; use color from WREG |
582 | 892 rcall TFT_set_color |
893 VARARGS_BEGIN | |
894 VARARGS_GET8 win_top | |
895 VARARGS_GET8 win_height | |
896 VARARGS_GET8 win_leftx2 | |
897 VARARGS_GET8 win_width | |
898 VARARGS_END | |
899 bra TFT_frame | |
634 | 900 |
0 | 901 |
634 | 902 ; ;----------------------------------------------------------------------------- |
903 ; ; Init for half_pixel_write | |
904 ; ; Set column register on TFT device, and current color. | |
905 ; ; Inputs: win_leftx2 | |
906 ; ; Outputs: win_color_1/_2 | |
907 ; ; Trashed: WREG, PROD | |
908 ; ; | |
909 ; ; global init_pixel_write | |
910 ; ;init_pixel_write: | |
911 ; ; movf win_leftx2,W | |
912 ; ; mullw 2 | |
913 ; ; rcall pixel_write_col320 ; start address vertical (.0 - .319) | |
914 ; ; setf WREG | |
915 ; ; bra TFT_set_color | |
916 | |
0 | 917 |
918 ;----------------------------------------------------------------------------- | |
634 | 919 ; Draw two half-pixels at position (win_top,win_leftx2) |
920 ; Inputs: win_leftx2, win_top, win_color_1/_2 | |
0 | 921 ; Trashed: WREG, PROD |
634 | 922 ; |
582 | 923 global pixel_write |
0 | 924 pixel_write: |
582 | 925 movf win_leftx2,W |
623 | 926 mullw .2 ; win_leftx2 x 2 -> PRODH:PRODL |
604 | 927 rcall pixel_write_col320 ; start address vertical (.0 - .319) |
928 rcall half_pixel_write ; write this half-one | |
628 | 929 |
604 | 930 movf win_leftx2,W ; address of next one |
623 | 931 mullw .2 ; win_leftx2 x 2 -> PRODH:PRODL |
932 INCI PROD ; PROD++ | |
582 | 933 rcall pixel_write_col320 |
628 | 934 bra half_pixel_write ; and return... note: cmd 0x20 is mandatory, because |
582 | 935 ; of the auto-increment going vertical |
0 | 936 |
937 global pixel_write_col320 | |
938 pixel_write_col320: | |
654 | 939 btfsc screen_type4 ; display type 4 ? |
940 bra pixel_write_col320_d4 ; YES | |
941 btfsc screen_type3 ; display type 3 ? | |
942 bra pixel_write_col320_d3 ; YES | |
628 | 943 btfsc screen_type2 ; display type 2 ? |
944 bra pixel_write_col320_d2 ; YES | |
945 btfsc screen_type1 ; display type 1 ? | |
946 bra pixel_write_col320_d1 ; YES | |
947 ; NO to all - display type 0 | |
582 | 948 btfss flip_screen ; 180° rotation? |
604 | 949 bra pixel_write_noflip_H ; NO |
950 bra pixel_write_flip_H ; YES | |
623 | 951 pixel_write_col320_d1: ; display type 1 |
582 | 952 btfsc flip_screen ; 180° rotation? |
623 | 953 bra pixel_write_noflip_H ; YES |
604 | 954 pixel_write_flip_H: ; flip d0 |
955 movf PRODL,W ; 16 bits 319 - PROD --> PROD | |
623 | 956 sublw LOW .319 ; 319-W --> W |
582 | 957 movwf PRODL |
958 movf PRODH,W | |
604 | 959 btfss STATUS,C ; borrow = /CARRY |
582 | 960 incf WREG |
623 | 961 sublw HIGH .319 |
582 | 962 movwf PRODH |
151 | 963 |
964 pixel_write_noflip_H: | |
604 | 965 Index_out 0x21 ; frame memory vertical address |
582 | 966 bra TFT_DataWrite_PROD ; and return... |
0 | 967 |
608 | 968 pixel_write_col320_d2: |
623 | 969 movlw 0x06 |
970 rcall TFT_CmdWrite | |
971 movf PRODH,W | |
972 rcall TFT_DataWrite | |
973 movlw 0x07 | |
974 rcall TFT_CmdWrite | |
975 movf PRODL,W | |
976 rcall TFT_DataWrite | |
608 | 977 |
623 | 978 incf PRODL,F |
979 movlw .0 | |
980 addwfc PRODH,F ; +1 | |
608 | 981 |
623 | 982 movlw 0x08 |
983 rcall TFT_CmdWrite | |
984 movf PRODH,W | |
985 rcall TFT_DataWrite | |
986 movlw 0x09 | |
987 rcall TFT_CmdWrite | |
988 movf PRODL,W | |
989 bra TFT_DataWrite ; ... and return | |
608 | 990 |
628 | 991 pixel_write_col320_d3: |
992 movlw 0x21 ; start address vertical (.0 - .319) | |
993 rcall TFT_CmdWrite | |
994 bra TFT_DataWrite_PROD ; and return... | |
995 | |
654 | 996 pixel_write_col320_d4: |
997 movlw 0x2A | |
998 rcall TFT_CmdWrite | |
999 rcall TFT_DataWrite_PROD | |
1000 incf PRODL,F | |
1001 movlw .0 | |
1002 addwfc PRODH,F ; +1 | |
1003 bra TFT_DataWrite_PROD ; and return... | |
1004 | |
0 | 1005 ;----------------------------------------------------------------------------- |
634 | 1006 ; Write one half-pixel at position (win_top,win_leftx2). |
1007 ; Inputs: win_leftx2, win_top, win_color_1/_2 | |
0 | 1008 ; Trashed: WREG, PROD |
634 | 1009 ; |
582 | 1010 global half_pixel_write |
0 | 1011 half_pixel_write: |
628 | 1012 movf win_top,W ; d'0' ... d'239' |
1013 ; Variant with Y position in WREG | |
0 | 1014 half_pixel_write_1: |
654 | 1015 btfsc screen_type4 ; display type 4 ? |
1016 bra half_pixel_write_1_display4 ; YES | |
1017 btfsc screen_type3 ; display type 3 ? | |
1018 bra half_pixel_write_1_display3 ; YES | |
628 | 1019 btfsc screen_type2 ; display type 2 ? |
1020 bra half_pixel_write_1_display2 ; YES | |
608 | 1021 |
628 | 1022 half_pixel_write_1_display1: |
582 | 1023 btfss flip_screen ; 180° rotation? |
1024 sublw .239 ; 239-Y --> Y | |
604 | 1025 mullw .1 ; copy row to PRODL (PRODH=0) |
1026 Index_out 0x20 ; frame memory horizontal address | |
582 | 1027 rcall TFT_DataWrite_PROD |
0 | 1028 |
604 | 1029 Index_out 0x22 ; frame memory data write start |
1030 RS_H ; data | |
582 | 1031 bcf INTCON,GIE |
648 | 1032 movff win_color1,PORTA ; upper |
1033 btfsc less_io_cpu ; less I/O CPU? | |
1034 bra half_pixel_write_1_display1_l_io ; YES | |
1035 movff win_color2,PORTH ; lower | |
582 | 1036 WR_L |
648 | 1037 WR_H ; tick |
582 | 1038 bsf INTCON,GIE |
1039 return | |
0 | 1040 |
648 | 1041 half_pixel_write_1_display1_l_io: |
1042 WR_L | |
1043 WR_H ; tick | |
1044 movff win_color2,PORTA ; lower | |
1045 WR_L | |
1046 WR_H ; tick | |
1047 bsf INTCON,GIE | |
1048 return | |
1049 | |
628 | 1050 half_pixel_write_1_display2: |
623 | 1051 mullw 1 ; copy row to PRODL (PRODH=0) |
1052 ; Row address start | |
1053 movlw 0x02 | |
1054 rcall TFT_CmdWrite | |
1055 movlw .0 | |
1056 rcall TFT_DataWrite | |
1057 movlw 0x03 | |
1058 rcall TFT_CmdWrite | |
1059 movf PRODL,W | |
1060 rcall TFT_DataWrite | |
608 | 1061 |
623 | 1062 incf PRODL,F |
608 | 1063 |
623 | 1064 movlw 0x04 |
1065 rcall TFT_CmdWrite | |
1066 movlw .0 | |
1067 rcall TFT_DataWrite | |
1068 movlw 0x05 | |
1069 rcall TFT_CmdWrite | |
1070 movf PRODL,W | |
1071 rcall TFT_DataWrite | |
608 | 1072 |
1073 movff win_color1,PRODH | |
1074 movff win_color2,PRODL | |
1075 rcall convert_for_display2 | |
1076 | |
623 | 1077 movlw 0x22 ; start writing data to GRAM |
1078 rcall TFT_CmdWrite | |
1079 RS_H ; data | |
1080 movff win_color5, PORTH | |
608 | 1081 WR_L |
623 | 1082 WR_H ; tick |
1083 movff win_color4, PORTH | |
608 | 1084 WR_L |
623 | 1085 WR_H ; tick |
1086 movff win_color3, PORTH | |
608 | 1087 WR_L |
623 | 1088 WR_H ; tick |
1089 return | |
608 | 1090 |
628 | 1091 half_pixel_write_1_display3: |
1092 mullw 1 ; copy row to PRODL (PRODH=0) | |
1093 | |
1094 movlw 0x20 ; horizontal address START:END | |
1095 rcall TFT_CmdWrite | |
1096 rcall TFT_DataWrite_PROD | |
1097 | |
1098 movlw 0x22 ; start writing data to GRAM | |
1099 rcall TFT_CmdWrite | |
1100 RS_H ; data | |
1101 movff win_color1, PORTH | |
1102 WR_L | |
1103 WR_H ; tick | |
1104 movff win_color2, PORTH | |
1105 WR_L | |
1106 WR_H ; tick | |
1107 return ; done | |
1108 | |
654 | 1109 half_pixel_write_1_display4: |
1110 mullw 1 ; copy row to PRODL (PRODH=0) | |
1111 ; Row address start | |
1112 movlw 0x2B | |
1113 rcall TFT_CmdWrite | |
1114 movlw 0x00 | |
1115 rcall TFT_DataWrite | |
1116 movf PRODL,W | |
1117 rcall TFT_DataWrite | |
1118 | |
1119 incf PRODL,F ; +1 | |
1120 movlw 0x00 | |
1121 rcall TFT_DataWrite | |
1122 movf PRODL,W | |
1123 rcall TFT_DataWrite | |
1124 | |
1125 movlw 0x2C ; Start Writing Data to GRAM | |
1126 rcall TFT_CmdWrite | |
1127 RS_H ; data | |
1128 movff win_color1,PORTA ; upper | |
1129 movff win_color2,PORTH ; lower | |
1130 WR_L | |
1131 WR_H ; tick | |
1132 bsf INTCON,GIE | |
1133 return | |
1134 | |
0 | 1135 ;----------------------------------------------------------------------------- |
634 | 1136 ; Draw a vertical line of half-pixel at position (win_top,win_leftx2,win_height). |
1137 ; Inputs: win_leftx2, win_top, win_height, win_color_1/_2 | |
0 | 1138 ; Trashed: WREG, PROD, TABLAT, TBLPTRL |
634 | 1139 ; |
0 | 1140 global half_vertical_line |
1141 half_vertical_line: | |
604 | 1142 clrf TABLAT ; loop index |
0 | 1143 |
1144 half_vertical_line_loop: | |
604 | 1145 movf win_leftx2,W ; init X position |
623 | 1146 mullw .2 ; win_leftx2 x 2 -> PRODH:PRODL |
604 | 1147 movf TABLAT,W ; get loop index |
1148 andlw .1 ; just low bit | |
1149 xorwf PRODL,F ; and use it to jitter current X position | |
1150 rcall pixel_write_col320 ; start address vertical (.0 - .319) | |
0 | 1151 |
604 | 1152 movf win_height,W ; index reached height (bank0 read) ? |
582 | 1153 xorwf TABLAT,W |
604 | 1154 btfsc STATUS,Z ; Equal ? |
1155 return ; YES - done | |
1156 movf win_top,W ; Y = top + index (bank0 read) | |
582 | 1157 addwf TABLAT,W |
1158 rcall half_pixel_write_1 | |
1159 incf TABLAT,F ; index++ | |
1160 bra half_vertical_line_loop | |
0 | 1161 |
1162 ;----------------------------------------------------------------------------- | |
634 | 1163 ; Draw a horizontal line of half-pixel at position (win_top,win_leftx2,win_width). |
1164 ; Inputs: win_leftx2, win_top, win_width, win_color_1/_2 | |
0 | 1165 ; Trashed: WREG, PROD, TABLAT, TBLPTRL |
634 | 1166 ; |
0 | 1167 global half_horizontal_line |
1168 half_horizontal_line: | |
604 | 1169 clrf TABLAT ; loop index |
0 | 1170 |
1171 half_horizontal_line_loop: | |
604 | 1172 movf win_leftx2,W ; init X position |
623 | 1173 mullw .2 ; win_leftx2 x 2 -> PRODH:PRODL |
604 | 1174 rcall pixel_write_col320 ; start address vertical (.0 - .319) |
1175 movf win_width,W ; index reached height (bank0 read) ? | |
582 | 1176 xorwf TABLAT,W |
604 | 1177 btfsc STATUS,Z ; equal ? |
1178 return ; YES - done | |
1179 movf win_top,W ; Y = top + index (bank0 read) | |
582 | 1180 addwf TABLAT,W |
1181 rcall half_pixel_write_1 | |
1182 incf TABLAT,F ; index++ | |
1183 bra half_horizontal_line_loop | |
0 | 1184 |
1185 | |
1186 ;----------------------------------------------------------------------------- | |
634 | 1187 ; TFT Data Command |
1188 ; | |
0 | 1189 TFT_DataWrite_PROD: |
623 | 1190 ; RD_H ; keep high |
1191 RS_H ; data | |
1192 btfsc screen_type2 ; screen type 2 ? | |
1193 bra TFT_DataWrite_PROD_display2 ; YES | |
628 | 1194 btfsc screen_type3 ; screen type 3 ? |
1195 bra TFT_DataWrite_PROD_display2 ; YES | |
623 | 1196 bcf INTCON,GIE ; NO - |
1197 movff PRODH,PORTA ; - move high byte to PORTA | |
648 | 1198 btfsc less_io_cpu ; less I/O CPU? |
1199 bra TFT_DataWrite_PROD_less_io ; YES | |
623 | 1200 movff PRODL,PORTH ; - move low byte to PORTH |
1201 WR_L ; - tick | |
1202 WR_H ; - tack | |
1203 bsf INTCON,GIE ; - | |
1204 return ; - done | |
0 | 1205 |
648 | 1206 TFT_DataWrite_PROD_less_io: |
1207 WR_L | |
1208 WR_H ; tick | |
1209 movff PRODL,PORTA ; - move low byte to PORTH | |
1210 WR_L ; - tick | |
1211 WR_H ; - tack | |
1212 bsf INTCON,GIE ; - | |
1213 return ; - done | |
1214 | |
608 | 1215 TFT_DataWrite_PROD_display2: |
623 | 1216 movff PRODH,PORTH ; move high byte to PORTH (display 2 is big endian) |
1217 WR_L ; tick | |
1218 WR_H ; tack | |
1219 movff PRODL,PORTH ; move low byte to PORTH | |
1220 WR_L ; tick | |
1221 WR_H ; tack | |
628 | 1222 btfsc screen_type3 ; screen type 3 ? |
1223 return ; YES - done | |
1224 movff win_color3,PORTH ; NO - move low(est) byte to PORTH | |
1225 WR_L ; - tick | |
1226 WR_H ; - tack | |
1227 return ; - done | |
623 | 1228 |
608 | 1229 |
0 | 1230 TFT_DataRead_PROD: |
604 | 1231 Index_out 0x22 ; frame memory data read start |
360 | 1232 TFT_CmdRead_PROD: |
604 | 1233 setf TRISA ; port A as input |
1234 setf TRISH ; port H as input | |
1235 RS_H ; data | |
1236 WR_H ; not write | |
1237 RD_L ; read | |
582 | 1238 nop |
1239 nop | |
1240 nop | |
604 | 1241 RD_H ; tick |
582 | 1242 nop |
1243 nop | |
1244 nop | |
604 | 1245 RD_L ; read |
582 | 1246 nop |
1247 ;nop | |
1248 ;nop | |
1249 movff PORTA,PRODH | |
1250 movff PORTH,PRODL | |
604 | 1251 RD_H ; tick |
582 | 1252 nop |
604 | 1253 clrf TRISA ; port A as output |
1254 clrf TRISH ; port H as output | |
0 | 1255 return |
1256 | |
634 | 1257 ;----------------------------------------------------------------------------- |
604 | 1258 ; Output TFT Window Address commands |
1259 ; Inputs : win_top, win_leftx2, win_height, win_width | |
1260 ; Output : PortA/PortH commands | |
0 | 1261 ; Trashed: PROD |
634 | 1262 ; |
582 | 1263 global TFT_box_write |
0 | 1264 TFT_box_write: |
634 | 1265 movf win_leftx2,W ; compute left = 2 * leftx2 --> PROD |
1266 mullw .2 ; win_leftx2 x 2 -> PRODH:PRODL | |
0 | 1267 |
654 | 1268 btfsc screen_type4 ; screen type 4 ? |
1269 bra TFT_box_write_display4 ; YES | |
1270 btfsc screen_type3 ; screen type 3 ? | |
1271 bra TFT_box_write_display3 ; YES | |
634 | 1272 btfsc screen_type2 ; screen type 2 ? |
1273 bra TFT_box_write_display2 ; YES | |
1274 btfsc screen_type1 ; screen type 1 ? | |
1275 bra TFT_box_write_display1 ; YES | |
608 | 1276 |
623 | 1277 ; screen type 0 |
634 | 1278 TFT_box_write_display0: |
1279 btfsc flip_screen ; 180° rotation? | |
1280 bra TFT_box_do_flip_H ; YES | |
1281 bra TFT_box_no_flip_H ; NO | |
1282 | |
1283 ; screen type 1 | |
1284 TFT_box_write_display1: | |
1285 btfss flip_screen ; 180° rotation? | |
1286 bra TFT_box_do_flip_H ; NO | |
1287 ;bra TFT_box_no_flip_H ; YES | |
1288 | |
582 | 1289 ;---- Normal horizontal window --------------------------------------- |
634 | 1290 TFT_box_no_flip_H: |
604 | 1291 Index_out 0x52 ; window vertical start address |
1292 rcall TFT_DataWrite_PROD ; output left | |
1293 Index_out 0x21 ; frame memory vertical address | |
1294 rcall TFT_DataWrite_PROD ; output left | |
0 | 1295 |
582 | 1296 movf win_width+0,W ; right = left + width - 1 |
432 | 1297 addwf PRODL,F |
1298 movf win_width+1,W | |
1299 addwfc PRODH,F | |
623 | 1300 decf PRODL,F ; right-- |
582 | 1301 btfss STATUS,C |
432 | 1302 decf PRODH,F |
0 | 1303 |
604 | 1304 Index_out 0x53 ; window vertical end address |
582 | 1305 rcall TFT_DataWrite_PROD |
634 | 1306 bra TFT_box_common_H |
0 | 1307 |
582 | 1308 ;---- Flipped horizontal window -------------------------------------- |
634 | 1309 TFT_box_do_flip_H: |
623 | 1310 ; calculate new coordinate |
604 | 1311 movf PRODL,W ; 16 bits 319 - PROD --> PROD |
623 | 1312 sublw LOW .319 ; 319 - WREG --> WREG |
582 | 1313 movwf PRODL |
1314 movf PRODH,W | |
604 | 1315 btfss STATUS,C ; borrow = /CARRY |
582 | 1316 incf WREG |
623 | 1317 sublw HIGH .319 |
582 | 1318 movwf PRODH |
152
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
151
diff
changeset
|
1319 |
604 | 1320 Index_out 0x53 ; window vertical start address |
1321 rcall TFT_DataWrite_PROD ; output left | |
1322 Index_out 0x21 ; frame memory vertical address | |
1323 rcall TFT_DataWrite_PROD ; output left | |
151 | 1324 |
623 | 1325 ; calculate new coordinate |
604 | 1326 movf win_width+0,W ; 16 bits PROD - width --> PROD |
582 | 1327 subwf PRODL,F ; PRODL - WREG --> PRODL |
1328 movf win_width+1,W | |
1329 subwfb PRODH,F | |
623 | 1330 INCI PROD ; PROD++ |
151 | 1331 |
604 | 1332 Index_out 0x52 ; window vertical end address |
582 | 1333 rcall TFT_DataWrite_PROD |
151 | 1334 |
634 | 1335 TFT_box_common_H: |
582 | 1336 btfss flip_screen ; 180° rotation ? |
634 | 1337 bra TFT_box_no_flip_V ; NO |
1338 ;bra TFT_box_do_flip_V ; YES | |
151 | 1339 |
582 | 1340 ;---- Flipped vertical window ----------------------------------------- |
634 | 1341 TFT_box_do_flip_V: |
623 | 1342 ; calculate new coordinate |
582 | 1343 movff win_top,PRODH ; top --> PRODH (first byte) |
1344 movf win_height,W | |
1345 addwf PRODH,W | |
432 | 1346 decf WREG |
604 | 1347 movwf PRODL ; top + height - 1 --> PRODL (second byte) |
151 | 1348 |
604 | 1349 Index_out 0x50 ; window horizontal start address |
432 | 1350 movf PRODH,W |
604 | 1351 rcall TFT_DataWrite ; lower (and tick) |
151 | 1352 |
604 | 1353 Index_out 0x51 ; window horizontal end address |
582 | 1354 movf PRODL,W |
604 | 1355 rcall TFT_DataWrite ; lower (and tick) |
582 | 1356 |
604 | 1357 Index_out 0x20 ; frame memory horizontal address |
432 | 1358 movf PRODH,W |
604 | 1359 bra TFT_DataWrite ; lower (and tick) and return |
151 | 1360 |
582 | 1361 ;---- Normal vertical window ---------------------------------------- |
634 | 1362 TFT_box_no_flip_V: |
582 | 1363 movff win_top,PRODL |
1364 movf win_height,W | |
1365 addwf PRODL,W | |
1366 sublw .240 ; 240 - top - height | |
604 | 1367 movwf PRODH ; first byte |
0 | 1368 |
432 | 1369 movf PRODL,W |
604 | 1370 sublw .239 ; 239 - top |
1371 movwf PRODL ; --> second byte | |
0 | 1372 |
604 | 1373 Index_out 0x50 ; window horizontal start address |
432 | 1374 movf PRODH,W |
604 | 1375 rcall TFT_DataWrite ; lower (and tick) |
0 | 1376 |
604 | 1377 Index_out 0x51 ; window horizontal end address |
432 | 1378 movf PRODL,W |
604 | 1379 rcall TFT_DataWrite ; lower (and tick) |
0 | 1380 |
604 | 1381 Index_out 0x20 ; frame memory horizontal address |
432 | 1382 movf PRODL,W |
604 | 1383 bra TFT_DataWrite ; lower (and tick) and return |
582 | 1384 |
608 | 1385 |
623 | 1386 TFT_box_write_display2: |
631 | 1387 ; setup left border |
623 | 1388 movlw 0x06 |
1389 rcall TFT_CmdWrite | |
1390 movf PRODH,W | |
1391 rcall TFT_DataWrite | |
1392 movlw 0x07 | |
1393 rcall TFT_CmdWrite | |
1394 movf PRODL,W | |
1395 rcall TFT_DataWrite | |
608 | 1396 |
623 | 1397 movf win_width+0,W ; right = left + width - 1 |
1398 addwf PRODL,F | |
1399 movf win_width+1,W | |
1400 addwfc PRODH,F | |
631 | 1401 decf PRODL,F ; decrement result |
623 | 1402 btfss STATUS,C |
631 | 1403 decf PRODH,F |
608 | 1404 |
631 | 1405 ; setup right border |
623 | 1406 movlw 0x08 |
1407 rcall TFT_CmdWrite | |
1408 movf PRODH,W | |
1409 rcall TFT_DataWrite | |
1410 movlw 0x09 | |
1411 rcall TFT_CmdWrite | |
1412 movf PRODL,W | |
1413 rcall TFT_DataWrite | |
1414 | |
1415 ;---- Normal vertical window ----------------------------------------- | |
1416 ; Output (top) (bottom) | |
1417 movff win_top,PRODH ; top --> PRODH (first byte) | |
1418 movf win_height,W | |
1419 addwf PRODH,W | |
1420 decf WREG | |
1421 movwf PRODL ; top+height-1 --> PRODL (second byte) | |
608 | 1422 |
623 | 1423 movlw 0x02 |
1424 rcall TFT_CmdWrite | |
1425 movlw 0x00 | |
1426 rcall TFT_DataWrite | |
1427 movlw 0x03 | |
1428 rcall TFT_CmdWrite | |
1429 movf PRODH,W | |
1430 rcall TFT_DataWrite | |
608 | 1431 |
623 | 1432 movlw 0x04 |
1433 rcall TFT_CmdWrite | |
1434 movlw 0x00 | |
1435 rcall TFT_DataWrite | |
1436 movlw 0x05 | |
1437 rcall TFT_CmdWrite | |
1438 movf PRODL,W | |
1439 bra TFT_DataWrite ; ... and return | |
0 | 1440 |
628 | 1441 TFT_box_write_display3: |
1442 ;---- Normal horizontal window --------------------------------------- | |
1443 ; Output 0x35 left, | |
631 | 1444 ; 0x36 right == left + width - 1. |
628 | 1445 |
1446 Index_out 0x35 ; window vertical start address | |
1447 rcall TFT_DataWrite_PROD ; output left | |
1448 Index_out 0x21 ; also the horizontal first pix coordinate | |
1449 rcall TFT_DataWrite_PROD ; output left | |
1450 | |
631 | 1451 movf win_width+0,W ; right = left + width - 1 |
628 | 1452 addwf PRODL,F |
631 | 1453 movf win_width+1,W |
628 | 1454 addwfc PRODH,F |
631 | 1455 decf PRODL,F ; decrement result |
634 | 1456 btfss STATUS,C |
631 | 1457 decf PRODH,F |
628 | 1458 |
631 | 1459 Index_out 0x36 ; write and the right border |
628 | 1460 rcall TFT_DataWrite_PROD |
1461 | |
1462 ;---- Normal vertical window ----------------------------------------- | |
1463 ; Output 0x37 (top) (bottom) | |
1464 movff win_top,PRODH ; top --> PRODH (first byte) | |
1465 movff win_height,WREG | |
1466 addwf PRODH,W | |
1467 decf WREG | |
1468 movwf PRODL ; top + height - 1 --> PRODL (second byte) | |
1469 | |
1470 Index_out 0x37 | |
1471 rcall TFT_DataWrite_PROD | |
1472 | |
1473 movff PRODH,PRODL | |
1474 clrf PRODH ; start pixel V coord == top. | |
1475 Index_out 0x20 | |
1476 bra TFT_DataWrite_PROD ; and return... | |
1477 | |
654 | 1478 TFT_box_write_display4: |
1479 movlw 0x2B | |
1480 rcall TFT_CmdWrite | |
1481 movf PRODH,W | |
1482 rcall TFT_DataWrite | |
1483 movf PRODL,W | |
1484 rcall TFT_DataWrite | |
1485 | |
1486 movf win_width+0,W ; right = left + width - 1 | |
1487 addwf PRODL,F | |
1488 movf win_width+1,W | |
1489 addwfc PRODH,F | |
1490 decf PRODL,F ; decrement result | |
1491 btfss STATUS,C | |
1492 decf PRODH,F | |
1493 | |
1494 ; setup right border | |
1495 movf PRODH,W | |
1496 rcall TFT_DataWrite | |
1497 movf PRODL,W | |
1498 rcall TFT_DataWrite | |
1499 | |
1500 ;---- Normal vertical window ----------------------------------------- | |
1501 ; Output (top) (bottom) | |
1502 movff win_top,PRODH ; top --> PRODH (first byte) | |
1503 movf win_height,W | |
1504 addwf PRODH,W | |
1505 decf WREG | |
1506 movwf PRODL ; top+height-1 --> PRODL (second byte) | |
1507 | |
1508 movlw 0x2A | |
1509 rcall TFT_CmdWrite | |
1510 movlw 0x00 | |
1511 rcall TFT_DataWrite | |
1512 movf PRODH,W | |
1513 rcall TFT_DataWrite | |
1514 | |
1515 ; setup bottom border | |
1516 movlw 0x00 | |
1517 rcall TFT_DataWrite | |
1518 movf PRODL,W | |
1519 bra TFT_DataWrite ; ... and return | |
1520 | |
628 | 1521 |
634 | 1522 ;----------------------------------------------------------------------------- |
604 | 1523 ; TFT_frame : draw a frame around current box with current color |
0 | 1524 ; Inputs: win_top, win_leftx2, win_height, win_width, win_color1, win_color2 |
1525 ; Outputs: (none) | |
1526 ; Trashed: WREG, PROD, aa_start:2, aa_end:2 | |
634 | 1527 ; |
582 | 1528 global TFT_frame |
1529 TFT_frame: | |
623 | 1530 movff win_top,tft_save_top ; backup everything |
1531 movff win_height,tft_save_height | |
1532 movff win_leftx2,tft_save_left | |
631 | 1533 movff win_width+0,tft_save_width |
0 | 1534 |
582 | 1535 ;---- TOP line ----------------------------------------------------------- |
623 | 1536 movlw .1 ; row ~ height = 1 |
582 | 1537 movwf win_height |
1538 rcall TFT_box | |
0 | 1539 |
582 | 1540 ;---- BOTTOM line -------------------------------------------------------- |
623 | 1541 movff tft_save_top,PRODL ; get back top |
1542 movff tft_save_height,WREG ; get back height | |
1543 addwf PRODL,W ; top + height | |
1544 decf WREG ; top + height - 1 | |
1545 movwf win_top ; top + height - 1 --> top | |
582 | 1546 rcall TFT_box |
0 | 1547 |
582 | 1548 ;---- LEFT column -------------------------------------------------------- |
623 | 1549 movff tft_save_top,win_top ; restore top/height |
1550 movff tft_save_height,win_height | |
1551 movlw .1 ; column ~ width = 1 | |
582 | 1552 movwf win_width+0 |
1553 rcall TFT_box | |
1554 | |
1555 ;---- RIGHT column ------------------------------------------------------- | |
623 | 1556 movff tft_save_left,WREG |
1557 movff tft_save_width,PRODL | |
582 | 1558 addwf PRODL,W |
1559 decf WREG | |
1560 movwf win_leftx2 | |
1561 rcall TFT_box | |
1562 | |
1563 ;---- Restore everything ------------------------------------------------- | |
623 | 1564 movff tft_save_left,win_leftx2 |
631 | 1565 movff tft_save_width,win_width+0 |
582 | 1566 return |
0 | 1567 |
634 | 1568 ;----------------------------------------------------------------------------- |
604 | 1569 ; TFT_box: fills current box with current color |
1570 ; Inputs : win_top, win_leftx2, win_height, win_width, win_color1, win_color2 | |
0 | 1571 ; Outputs: (none) |
1572 ; Trashed: WREG, PROD | |
634 | 1573 ; |
582 | 1574 global TFT_box |
0 | 1575 TFT_box: |
582 | 1576 ;---- Define Window ------------------------------------------------------ |
1577 bcf STATUS,C | |
1578 rlcf win_width+0,F | |
1579 rlcf win_width+1,F ; x2 | |
604 | 1580 rcall TFT_box_write ; setup box |
0 | 1581 |
582 | 1582 bcf STATUS,C |
1583 rrcf win_width+1,F ; width /= 2 | |
1584 rrcf win_width+0,F | |
0 | 1585 |
582 | 1586 ;---- Fill Window -------------------------------------------------------- |
654 | 1587 movlw 0x22 ; frame memory data write start |
1588 btfsc screen_type4 | |
1589 movlw 0x2C ; Start Writing Data to GRAM (Display 4) | |
1590 rcall TFT_CmdWrite | |
1591 | |
604 | 1592 clrf PRODH ; column counter |
1593 RS_H ; data | |
0 | 1594 |
654 | 1595 btfsc screen_type4 ; display type 4 ? |
1596 bra TFT_box_display4 ; YES | |
1597 btfsc screen_type3 ; display type 3 ? | |
1598 bra TFT_box_display3 ; YES | |
628 | 1599 btfsc screen_type2 ; display type 2 ? |
1600 bra TFT_box_display2 ; YES | |
1601 | |
604 | 1602 TFT_box2: ; loop height times |
0 | 1603 movff win_height,PRODL |
1604 | |
582 | 1605 TFT_box3: ; loop width times |
623 | 1606 bcf INTCON,GIE |
604 | 1607 movff win_color1,PORTA ; upper |
648 | 1608 btfsc less_io_cpu ; less I/O CPU? |
1609 bra TFT_box3_less_io ; YES | |
604 | 1610 movff win_color2,PORTH ; lower |
634 | 1611 WR_L ; tick |
1612 WR_H ; ... | |
1613 WR_L ; tick | |
1614 WR_H ; ... | |
582 | 1615 bsf INTCON,GIE |
1616 decfsz PRODL,F ; row loop finished ? | |
604 | 1617 bra TFT_box3 ; NO - continue |
0 | 1618 |
582 | 1619 incf PRODH,F ; column count ++ |
628 | 1620 movf win_bargraph,W ; get width of active bargraph part |
1621 cpfseq PRODH ; current column == end of active bargraph ? | |
604 | 1622 bra TFT_box4 ; NO - just loop |
628 | 1623 clrf win_color1 ; YES - switch to black |
604 | 1624 clrf win_color2 ; - ... |
0 | 1625 TFT_box4: |
628 | 1626 movf win_width+0,W ; get total bargraph width |
1627 xorwf PRODH,W ; all columns done? | |
1628 bnz TFT_box2 ; NO - loop | |
0 | 1629 |
582 | 1630 movlw 0x00 ; NOP, to stop window mode |
1631 rcall TFT_CmdWrite | |
0 | 1632 |
604 | 1633 ; reset bargraph mode... |
582 | 1634 setf win_bargraph |
1635 return | |
623 | 1636 |
648 | 1637 TFT_box3_less_io: |
1638 WR_L ; tick | |
1639 WR_H ; ... | |
1640 movff win_color2,PORTA ; lower | |
1641 WR_L ; tick | |
1642 WR_H ; ... | |
1643 movff win_color1,PORTA ; upper | |
1644 WR_L ; tick | |
1645 WR_H ; ... | |
1646 movff win_color2,PORTA ; lower | |
1647 WR_L ; tick | |
1648 WR_H ; ... | |
1649 bsf INTCON,GIE | |
1650 decfsz PRODL,F ; row loop finished ? | |
1651 bra TFT_box3 ; NO - continue | |
1652 | |
1653 incf PRODH,F ; column count ++ | |
1654 movf win_bargraph,W ; get width of active bargraph part | |
1655 cpfseq PRODH ; current column == end of active bargraph ? | |
1656 bra TFT_box4 ; NO - just loop | |
1657 clrf win_color1 ; YES - switch to black | |
1658 clrf win_color2 ; - ... | |
1659 bra TFT_box4 ; NO - just loop | |
1660 | |
608 | 1661 TFT_box_display2: |
628 | 1662 ; Screen 2 |
608 | 1663 movff win_color1,PRODH |
1664 movff win_color2,PRODL | |
1665 rcall convert_for_display2 | |
631 | 1666 clrf PRODH ; column counter |
623 | 1667 TFT_box2_display2: ; loop height times |
608 | 1668 movff win_height,PRODL |
623 | 1669 TFT_box3_display2: ; loop width times |
608 | 1670 movff win_color5,PORTH |
623 | 1671 bcf tft_nwr |
1672 bsf tft_nwr ; upper | |
608 | 1673 movff win_color4,PORTH |
1674 bcf tft_nwr | |
623 | 1675 bsf tft_nwr ; high |
608 | 1676 movff win_color3,PORTH |
1677 bcf tft_nwr | |
623 | 1678 bsf tft_nwr ; low |
608 | 1679 |
1680 movff win_color5,PORTH | |
1681 bcf tft_nwr | |
623 | 1682 bsf tft_nwr ; upper |
608 | 1683 movff win_color4,PORTH |
1684 bcf tft_nwr | |
623 | 1685 bsf tft_nwr ; high |
608 | 1686 movff win_color3,PORTH |
1687 bcf tft_nwr | |
623 | 1688 bsf tft_nwr ; low |
1689 decfsz PRODL,F ; row loop finished? | |
1690 bra TFT_box3_display2 ; NO - loop | |
1691 incf PRODH,F ; YES - column count ++ | |
1692 movf win_bargraph,W ; - get bargraph width | |
1693 cpfseq PRODH ; - current column = bargraph ? | |
1694 bra TFT_box4_display2 ; NO | |
1695 clrf win_color5 ; YES - switch to black | |
1696 clrf win_color4 ; - ... | |
1697 clrf win_color3 ; - ... | |
608 | 1698 TFT_box4_display2: |
623 | 1699 movf win_width+0,W ; get width |
1700 cpfseq PRODH ; width loop finished ? | |
1701 bra TFT_box2_display2 ; NO - loop | |
1702 setf win_bargraph ; YES - reset bargraph mode | |
1703 return ; - done | |
0 | 1704 |
628 | 1705 TFT_box_display3: |
1706 ; Screen 3 | |
1707 TFT_box2_display3: ; loop height times | |
1708 movff win_height,PRODL | |
1709 TFT_box3_display3: ; loop width times | |
1710 movff win_color1,PORTH | |
1711 bcf tft_nwr | |
1712 bsf tft_nwr ; upper | |
1713 movff win_color2,PORTH | |
1714 bcf tft_nwr | |
1715 bsf tft_nwr ; high | |
1716 movff win_color1,PORTH | |
1717 bcf tft_nwr | |
1718 bsf tft_nwr ; low | |
1719 movff win_color2,PORTH | |
1720 bcf tft_nwr | |
1721 bsf tft_nwr ; upper | |
1722 decfsz PRODL,F ; row loop finished? | |
1723 bra TFT_box3_display3 ; NO - loop | |
1724 incf PRODH,F ; YES - column count ++ | |
1725 movf win_bargraph,W ; - get bargraph width | |
1726 cpfseq PRODH ; - current column = bargraph ? | |
1727 bra TFT_box4_display3 ; NO | |
1728 clrf win_color1 ; Yes - switch to black | |
1729 clrf win_color2 ; - ... | |
1730 TFT_box4_display3: | |
1731 movf win_width+0,W ; get width | |
1732 cpfseq PRODH ; width loop finished ? | |
1733 bra TFT_box2_display3 ; NO - loop | |
1734 setf win_bargraph ; YES - reset bargraph mode | |
1735 return | |
1736 | |
654 | 1737 TFT_box_display4: |
1738 ; Screen 4 | |
1739 clrf PRODH ; column counter | |
1740 TFT_box2_display4: ; loop height times | |
1741 movff win_height,PRODL | |
1742 TFT_box3_display4: ; loop width times | |
1743 movff win_color1,PORTA | |
1744 movff win_color2,PORTH | |
1745 WR_L ; tick | |
1746 WR_H ; ... | |
1747 WR_L ; tick | |
1748 WR_H ; ... | |
1749 decfsz PRODL,F ; row loop finished? | |
1750 bra TFT_box3_display4 ; NO - loop | |
1751 incf PRODH,F ; YES - column count ++ | |
1752 movf win_bargraph,W ; - get bargraph width | |
1753 cpfseq PRODH ; - current column = bargraph ? | |
1754 bra TFT_box4_display4 ; NO | |
1755 clrf win_color1 ; Yes - switch to black | |
1756 clrf win_color2 ; - ... | |
1757 TFT_box4_display4: | |
1758 movf win_width+0,W ; get width | |
1759 cpfseq PRODH ; width loop finished ? | |
1760 bra TFT_box2_display4 ; NO - loop | |
1761 setf win_bargraph ; YES - reset bargraph mode | |
1762 return ; - done | |
0 | 1763 |
634 | 1764 ;----------------------------------------------------------------------------- |
1765 ; Convert 8 bit RGB b'RRRGGGBB' into 16 bit RGB b'RRRRRGGGGGGBBBBB' | |
1766 ; WREG win_color1 win_color2 | |
582 | 1767 global TFT_set_color |
0 | 1768 TFT_set_color: |
631 | 1769 movwf tft_temp1 ; get 8 bit RGB b'RRRGGGBB' into tft_temp1... |
634 | 1770 movwf tft_temp2 ; ... and tft_temp2 |
0 | 1771 |
604 | 1772 ; mask bit 7,6,5,4,3,2 |
0 | 1773 movlw b'00000011' |
1774 andwf tft_temp2,F | |
1775 | |
1776 movlw b'00000000' | |
1777 dcfsnz tft_temp2,F | |
1778 movlw b'01010000' | |
1779 dcfsnz tft_temp2,F | |
1780 movlw b'10100000' | |
1781 dcfsnz tft_temp2,F | |
1782 movlw b'11111000' | |
604 | 1783 movwf tft_temp3 ; blue done |
0 | 1784 |
604 | 1785 movff tft_temp1,tft_temp2 ; copy |
1786 ; mask bit 7,6,5,1,0 | |
0 | 1787 movlw b'00011100' |
1788 andwf tft_temp2,F | |
1789 rrncf tft_temp2,F | |
1790 rrncf tft_temp2,F | |
1791 | |
1792 movlw b'00000000' | |
1793 dcfsnz tft_temp2,F | |
1794 movlw b'00000100' | |
1795 dcfsnz tft_temp2,F | |
1796 movlw b'00001000' | |
1797 dcfsnz tft_temp2,F | |
1798 movlw b'00001100' | |
1799 dcfsnz tft_temp2,F | |
1800 movlw b'00010000' | |
1801 dcfsnz tft_temp2,F | |
1802 movlw b'00010100' | |
1803 dcfsnz tft_temp2,F | |
1804 movlw b'00100000' | |
1805 dcfsnz tft_temp2,F | |
1806 movlw b'00111111' | |
582 | 1807 movwf tft_temp4 |
0 | 1808 |
1809 rrcf tft_temp4,F | |
1810 rrcf tft_temp3,F | |
1811 | |
1812 rrcf tft_temp4,F | |
1813 rrcf tft_temp3,F | |
1814 | |
1815 rrcf tft_temp4,F | |
604 | 1816 rrcf tft_temp3,W ; tft_temp3 (b'GGGBBBBB') done |
1817 movwf win_color2 ; set color registers... | |
0 | 1818 |
604 | 1819 movff tft_temp1,tft_temp2 ; copy |
0 | 1820 clrf tft_temp1 |
1821 | |
1822 rrcf tft_temp4,F | |
1823 rrcf tft_temp1,F | |
1824 | |
1825 rrcf tft_temp4,F | |
1826 rrcf tft_temp1,F | |
1827 | |
1828 rrcf tft_temp4,F | |
604 | 1829 rrcf tft_temp1,F ; green done |
0 | 1830 |
604 | 1831 ; mask bit 4,3,2,1,0 |
0 | 1832 movlw b'11100000' |
1833 andwf tft_temp2,F | |
1834 | |
1835 rrncf tft_temp2,F | |
1836 rrncf tft_temp2,F | |
1837 rrncf tft_temp2,F | |
1838 rrncf tft_temp2,F | |
1839 rrncf tft_temp2,F | |
1840 | |
1841 movlw b'00000000' | |
1842 dcfsnz tft_temp2,F | |
1843 movlw b'00000100' | |
1844 dcfsnz tft_temp2,F | |
1845 movlw b'00001000' | |
1846 dcfsnz tft_temp2,F | |
1847 movlw b'00001100' | |
1848 dcfsnz tft_temp2,F | |
1849 movlw b'00010000' | |
1850 dcfsnz tft_temp2,F | |
1851 movlw b'00010100' | |
1852 dcfsnz tft_temp2,F | |
1853 movlw b'00100000' | |
1854 dcfsnz tft_temp2,F | |
1855 movlw b'00111111' | |
582 | 1856 movwf tft_temp4 |
0 | 1857 |
1858 rrcf tft_temp4,F | |
1859 rrcf tft_temp1,F | |
1860 | |
1861 rrcf tft_temp4,F | |
604 | 1862 rrcf tft_temp1,F |
0 | 1863 |
1864 rrcf tft_temp4,F | |
1865 rrcf tft_temp1,F | |
1866 | |
1867 rrcf tft_temp4,F | |
1868 rrcf tft_temp1,F | |
1869 | |
1870 rrcf tft_temp4,F | |
604 | 1871 rrcf tft_temp1,W ; red done |
648 | 1872 ; tft_temp1 (b'RRRRRGGG') done |
1873 movwf win_color1 ; set color registers... | |
0 | 1874 return |
623 | 1875 |
1876 | |
608 | 1877 global convert_for_display2 |
623 | 1878 convert_for_display2: ; convert 16 bit RGB b'RRRRRGGG GGGBBBBB' into 24 bit RGB b'RRRRRR00 GGGGGG00 BBBBBB00' |
1879 ; PRODH PRODL win_color5 win_color4 win_color3 | |
1880 ; Red | |
1881 movff PRODH,win_color5 ; = RRRRRGGG | |
1882 bcf win_color5,2 ; = RRRRR0GG | |
1883 btfsc win_color5,7 | |
1884 bsf win_color5,2 ; = RRRRR1GG the lower two bits are ignored by the screen | |
1885 ; Blue | |
1886 movff PRODL,win_color3 | |
1887 rrcf win_color3,F ; = UGGGBBBB and the LSB-blue into carry | |
1888 swapf win_color3,F ; = BBBBUGGG | |
1889 bcf win_color3,3 ; = BBBB0GGG | |
608 | 1890 btfsc STATUS,C |
623 | 1891 bsf win_color3,3 ; = BBBB1GGG |
1892 bcf win_color3,2 ; = BBBBB0GG | |
1893 btfsc win_color3,7 | |
1894 bsf win_color3,2 ; = BBBBB1GG | |
1895 ; Green | |
1896 rrcf PRODH,F | |
1897 rrcf PRODL,F | |
1898 rrcf PRODH,F | |
1899 rrcf PRODL,F | |
1900 rrcf PRODH,F | |
1901 rrcf PRODL,F ; = GGGGGGBB the lower two bits are ignored by the screen | |
1902 movff PRODL,win_color4 | |
608 | 1903 return |
623 | 1904 |
0 | 1905 |
634 | 1906 ;----------------------------------------------------------------------------- |
0 | 1907 |
604 | 1908 IFDEF _screendump |
1909 | |
623 | 1910 ;----------------------------------------------------------------------------- |
1911 ; Dump screen contents to the UART | |
1912 ; | |
604 | 1913 global TFT_dump_screen_check |
1914 TFT_dump_screen_check: | |
1915 btfss vusb_in ; USB (still) plugged in? | |
623 | 1916 bcf screen_dump_avail ; NO - disable screen dump function |
631 | 1917 |
1918 SERIAL_CC_RECEIVE WREG ; try to read a byte from RS232 | |
623 | 1919 btfsc rs232_rx_timeout ; anything received? |
631 | 1920 return ; NO - done |
1921 xorlw "l" ; YES - exclusive-or with coding of screen dump command | |
1922 tstfsz WREG ; - screen dump command received? | |
604 | 1923 return ; NO - return |
631 | 1924 ;bra TFT_dump_screen ; YES - serve screen dump request |
623 | 1925 |
631 | 1926 global TFT_dump_screen |
623 | 1927 TFT_dump_screen: |
1928 btfsc screen_type2 ; is this an OSTC with a screen of type 2? | |
631 | 1929 return ; YES - not supported, abort |
623 | 1930 bsf block_sensor_interrupt ; NO - disable sensor interrupts |
631 | 1931 SERIAL_LC_SEND 'l' ; - send command acknowledge |
1932 | |
604 | 1933 |
582 | 1934 ;---- Send DISPLAY box command for the full screen window ------------------- |
604 | 1935 Index_out 0x50 ; window horizontal start address |
582 | 1936 Parameter_out 0x00, 0x00 ; 0-239 |
604 | 1937 Index_out 0x51 ; window horizontal end address |
582 | 1938 Parameter_out 0x00, 0xEF ; 0-239 |
604 | 1939 Index_out 0x52 ; window vertical start address |
582 | 1940 Parameter_out 0x00, 0x00 ; 0-319 |
604 | 1941 Index_out 0x53 ; window vertical end address |
582 | 1942 Parameter_out 0x01, 0x3F ; 0-319 |
0 | 1943 |
582 | 1944 clrf ds_column |
1945 rcall dump_screen_pixel_reset | |
0 | 1946 dump_screen_1: |
582 | 1947 btg LEDr ; LED activity toggle |
631 | 1948 ; dump even column |
604 | 1949 movlw .240 ; 240 lines, once |
582 | 1950 movwf ds_line |
0 | 1951 dump_screen_2: |
604 | 1952 Index_out 0x20 ; frame memory horizontal address |
582 | 1953 movff ds_line,WREG ; d'0' ... d'239' |
604 | 1954 mullw .1 ; copy row to PRODH:L |
582 | 1955 rcall TFT_DataWrite_PROD |
0 | 1956 |
623 | 1957 movff ds_column,WREG ; initialize X position |
1958 mullw .2 ; ds_column x 2 -> PRODH:PRODL | |
604 | 1959 rcall pixel_write_col320 ; start address vertical (.0 - .319) |
0 | 1960 |
582 | 1961 rcall TFT_DataRead_PROD ; read pixel |
1962 rcall dump_screen_pixel | |
0 | 1963 |
582 | 1964 decfsz ds_line,F |
1965 bra dump_screen_2 | |
1966 rcall dump_screen_pixel_flush | |
0 | 1967 |
631 | 1968 ; dump odd column |
604 | 1969 movlw .240 ; 240 lines, twice |
582 | 1970 movwf ds_line |
0 | 1971 dump_screen_3: |
604 | 1972 Index_out 0x20 ; frame memory horizontal address |
582 | 1973 movff ds_line,WREG ; d'0' ... d'239' |
623 | 1974 mullw .1 ; copy row to PRODH:L |
582 | 1975 rcall TFT_DataWrite_PROD |
0 | 1976 |
623 | 1977 movff ds_column,WREG ; initialize X position |
1978 mullw .2 ; ds_column x 2 -> PRODH:PRODL | |
1979 INCI PROD ; PROD++ | |
604 | 1980 rcall pixel_write_col320 ; start address vertical (.0 - .319) |
0 | 1981 |
582 | 1982 rcall TFT_DataRead_PROD ; read pixel |
631 | 1983 rcall dump_screen_pixel ; compress and send pixel |
0 | 1984 |
582 | 1985 decfsz ds_line,F |
1986 bra dump_screen_3 | |
1987 rcall dump_screen_pixel_flush | |
0 | 1988 |
582 | 1989 incf ds_column,F |
1990 movlw .160 | |
1991 cpfseq ds_column | |
1992 bra dump_screen_1 | |
0 | 1993 |
623 | 1994 bcf block_sensor_interrupt ; re-enable sensor interrupts |
604 | 1995 clrf RCREG1 ; clear receive buffer |
1996 bcf RCSTA1,CREN ; clear receiver status | |
631 | 1997 bsf RCSTA1,CREN ; ... |
623 | 1998 bsf screen_dump_avail ; enable screen dump function |
582 | 1999 return |
0 | 2000 |
623 | 2001 ;----------------------------------------------------------------------------- |
0 | 2002 ; Pixel compression |
2003 ; | |
604 | 2004 ; Input : PRODH:L = pixel |
0 | 2005 ; Output: Compressed stream on output. |
2006 ; Compressed format: | |
604 | 2007 ; 0ccccccc : BLACK pixel, repeated ccccccc+1 times (1..128) |
2008 ; 11cccccc : WHITE pixel, repeated cccccc+1 times (1.. 64) | |
2009 ; 10cccccc HIGH LOW : color pixel (H:L) repeated ccccc+1 times (1.. 64) | |
623 | 2010 ; |
0 | 2011 dump_screen_pixel: |
604 | 2012 movf PRODH,W ; compare pixel-high |
582 | 2013 xorwf ds_pixel+1,W |
604 | 2014 bnz dump_screen_pixel_1 ; different -> dump |
0 | 2015 |
604 | 2016 movf PRODL,W ; compare pixel-low |
582 | 2017 xorwf ds_pixel+0,W |
604 | 2018 bnz dump_screen_pixel_1 ; different -> dump |
0 | 2019 |
604 | 2020 incf ds_count,F ; same color: just increment |
582 | 2021 return |
0 | 2022 |
604 | 2023 dump_screen_pixel_1: ; send (pixel,count) tuple |
2024 movf ds_count,W ; is count zero ? | |
2025 bz dump_screen_pixel_2 ; YES - skip sending | |
0 | 2026 |
604 | 2027 movf ds_pixel+1,W ; is this a BLACK pixel ? |
582 | 2028 iorwf ds_pixel+0,W |
604 | 2029 bz dump_screen_pix_black ; YES |
0 | 2030 |
604 | 2031 movf ds_pixel+1,W ; is this a white pixel ? |
582 | 2032 andwf ds_pixel+0,W |
2033 incf WREG | |
604 | 2034 bz dump_screen_pix_white ; YES |
0 | 2035 |
582 | 2036 ; No: write the pixel itself... |
604 | 2037 movlw .64 ; max color pixel on a single byte |
2038 cpfsgt ds_count ; skip if count > 64 | |
582 | 2039 movf ds_count,W ; W <- min(64,count) |
2040 subwf ds_count,F ; ds_count <- ds_count-W | |
604 | 2041 decf WREG ; save as 0..63 |
2042 iorlw b'10000000' ; mark as a color pixel | |
0 | 2043 |
631 | 2044 SERIAL_CC_SEND WREG ; send byte in WREG |
2045 SERIAL_CC_SEND ds_pixel+1 ; send bytes in ds_pixel, high byte first | |
2046 SERIAL_CC_SEND ds_pixel+0 ; low byte last | |
2047 | |
582 | 2048 bra dump_screen_pixel_1 |
0 | 2049 |
2050 dump_screen_pixel_2: | |
604 | 2051 movff PRODH,ds_pixel+1 ; save new pixel color |
582 | 2052 movff PRODL,ds_pixel+0 |
2053 movlw 1 | |
604 | 2054 movwf ds_count ; and set count=1 |
582 | 2055 return |
0 | 2056 |
2057 dump_screen_pix_black: | |
604 | 2058 movlw .128 ; max black pixel on a single byte |
2059 cpfsgt ds_count ; skip if count > 128 | |
582 | 2060 movf ds_count,W ; W <- min(128,count) |
2061 subwf ds_count,F ; ds_count <- ds_count-W | |
604 | 2062 decf WREG ; save as 0..127 |
623 | 2063 |
0 | 2064 dump_screen_pix_3: |
631 | 2065 SERIAL_CC_SEND WREG ; send byte in WREG |
604 | 2066 bra dump_screen_pixel_1 ; more to dump ? |
0 | 2067 |
2068 dump_screen_pix_white: | |
604 | 2069 movlw .64 ; max white pixel on a single byte |
2070 cpfsgt ds_count ; skip if count > 64 | |
582 | 2071 movf ds_count,W ; W <- min(64,count) |
2072 subwf ds_count,F ; ds_count <- ds_count-W | |
631 | 2073 decf WREG ; save as 0..63 |
604 | 2074 iorlw b'11000000' ; mark as a compressed white |
631 | 2075 bra dump_screen_pix_3 ; send pixel |
0 | 2076 |
2077 dump_screen_pixel_flush: | |
582 | 2078 clrf PRODH |
2079 clrf PRODL | |
604 | 2080 rcall dump_screen_pixel_1 ; send it |
0 | 2081 dump_screen_pixel_reset: |
604 | 2082 clrf ds_count ; clear count |
582 | 2083 return |
0 | 2084 |
623 | 2085 ENDIF ; _screendump |
2086 | |
634 | 2087 ;----------------------------------------------------------------------------- |
604 | 2088 |
582 | 2089 END |