Mercurial > public > hwos_code
annotate src/tft.asm @ 627:bf5fee575701
minor cleanup, reset rx circuity
author | heinrichsweikamp |
---|---|
date | Sun, 30 Jun 2019 23:22:32 +0200 |
parents | c40025d8e750 |
children | cd58f7fc86db |
rev | line source |
---|---|
0 | 1 ;============================================================================= |
2 ; | |
623 | 3 ; File tft.asm combined next generation V3.03.2 |
0 | 4 ; |
623 | 5 ; low-level Display Outputs |
0 | 6 ; |
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. | |
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 "external_flash.inc" | |
16 #include "tft_outputs.inc" | |
17 #include "eeprom_rs232.inc" | |
18 | |
19 ;============================================================================= | |
20 ; Basic bit-level macros | |
21 | |
582 | 22 RD_H macro |
23 bsf tft_rd,0 | |
24 endm | |
0 | 25 |
582 | 26 RD_L macro |
27 bcf tft_rd,0 | |
28 endm | |
0 | 29 |
582 | 30 RS_H macro |
31 bsf tft_rs,0 | |
32 endm | |
0 | 33 |
582 | 34 RS_L macro |
35 bcf tft_rs,0 | |
36 endm | |
0 | 37 |
582 | 38 NCS_H macro |
39 bsf tft_cs,0 | |
40 endm | |
0 | 41 |
582 | 42 NCS_L macro |
43 bcf tft_cs,0 | |
44 endm | |
0 | 45 |
582 | 46 WR_H macro |
47 bsf tft_nwr,0 | |
48 endm | |
0 | 49 |
582 | 50 WR_L macro |
51 bcf tft_nwr,0 | |
52 endm | |
0 | 53 |
54 ;============================================================================= | |
582 | 55 ; Byte-level macros |
56 | |
0 | 57 Index_out macro low_b |
58 movlw low_b | |
59 rcall TFT_CmdWrite | |
60 endm | |
61 | |
62 Parameter_out macro high_b, low_b | |
63 movlw high_b | |
604 | 64 movwf PORTA ; upper |
0 | 65 movlw low_b |
66 rcall TFT_DataWrite | |
67 endm | |
68 | |
69 | |
604 | 70 tft CODE |
582 | 71 |
151 | 72 ;;============================================================================= |
582 | 73 |
74 global TFT_ClearScreen | |
0 | 75 TFT_ClearScreen: |
623 | 76 btfsc screen_type2 ; screen type ? |
77 bra TFT_ClearScreen_display2; YES | |
78 | |
604 | 79 Index_out 0x50 ; window horizontal start address |
582 | 80 Parameter_out 0x00, 0x00 ; 0-239 |
604 | 81 Index_out 0x51 ; window horizontal end address |
582 | 82 Parameter_out 0x00, 0xEF ; 0-239 |
604 | 83 Index_out 0x52 ; window vertical start address |
582 | 84 Parameter_out 0x00, 0x00 ; 0-319 |
604 | 85 Index_out 0x53 ; window vertical end address |
582 | 86 Parameter_out 0x01, 0x3F ; 0-319 |
604 | 87 Index_out 0x20 ; frame memory horizontal address |
582 | 88 Parameter_out 0x00, 0x00 ; 0-239 |
604 | 89 Index_out 0x21 ; frame memory vertical address |
582 | 90 Parameter_out 0x01, 0x3F ; 0-319 |
0 | 91 |
604 | 92 Index_out 0x22 ; frame memory data write start |
0 | 93 |
604 | 94 RD_H ; not read |
95 RS_H ; data | |
96 NCS_L ; not CS | |
97 clrf PORTH ; data lower | |
0 | 98 |
99 movlw d'10' | |
100 movwf tft_temp3 | |
101 TFT_ClearScreen2: | |
102 movlw d'30' | |
103 movwf tft_temp2 | |
104 TFT_ClearScreen3: | |
604 | 105 clrf tft_temp1 ; 30*10*256=76800 pixels -> clear complete 240*320 |
582 | 106 bcf INTCON,GIE |
0 | 107 TFT_ClearScreen4: |
108 WR_L | |
604 | 109 WR_H ; tick |
0 | 110 decfsz tft_temp1,F |
111 bra TFT_ClearScreen4 | |
582 | 112 bsf INTCON,GIE |
0 | 113 decfsz tft_temp2,F |
114 bra TFT_ClearScreen3 | |
115 decfsz tft_temp3,F | |
116 bra TFT_ClearScreen2 | |
582 | 117 |
118 movlw 0x00 ; NOP, to stop window mode | |
604 | 119 bra TFT_CmdWrite ; and return |
582 | 120 |
623 | 121 TFT_ClearScreen_display2: |
122 movlw 0x02 ; column address start | |
608 | 123 rcall TFT_CmdWrite |
124 movlw 0x00 | |
125 rcall TFT_DataWrite | |
126 movlw 0x03 | |
127 rcall TFT_CmdWrite | |
128 movlw 0x00 | |
129 rcall TFT_DataWrite | |
130 | |
623 | 131 movlw 0x04 ; column address end |
608 | 132 rcall TFT_CmdWrite |
133 movlw 0x00 | |
134 rcall TFT_DataWrite | |
135 movlw 0x05 | |
136 rcall TFT_CmdWrite | |
137 movlw 0xEF | |
138 rcall TFT_DataWrite | |
139 | |
623 | 140 movlw 0x06 ; row address start |
608 | 141 rcall TFT_CmdWrite |
142 movlw 0x00 | |
143 rcall TFT_DataWrite | |
144 movlw 0x07 | |
145 rcall TFT_CmdWrite | |
146 movlw 0x00 | |
147 rcall TFT_DataWrite | |
148 | |
623 | 149 movlw 0x08 ; row address end |
608 | 150 rcall TFT_CmdWrite |
151 movlw 0x01 | |
152 rcall TFT_DataWrite | |
153 movlw 0x09 | |
154 rcall TFT_CmdWrite | |
155 movlw 0x3F | |
156 rcall TFT_DataWrite | |
157 | |
623 | 158 movlw 0x22 ; start writing data to GRAM |
608 | 159 rcall TFT_CmdWrite |
160 | |
623 | 161 bsf tft_rs ; data! |
608 | 162 |
163 movlw .160 | |
164 movwf PRODH | |
165 clrf PORTH | |
623 | 166 TFT_ClearScreen_display2_loop1: |
608 | 167 movlw .240 |
168 movwf PRODL | |
623 | 169 TFT_ClearScreen_display2_loop2: |
608 | 170 bcf tft_nwr |
623 | 171 bsf tft_nwr ; upper |
608 | 172 bcf tft_nwr |
623 | 173 bsf tft_nwr ; high |
608 | 174 bcf tft_nwr |
623 | 175 bsf tft_nwr ; lower |
608 | 176 bcf tft_nwr |
623 | 177 bsf tft_nwr ; upper |
608 | 178 bcf tft_nwr |
623 | 179 bsf tft_nwr ; high |
608 | 180 bcf tft_nwr |
623 | 181 bsf tft_nwr ; lower |
608 | 182 decfsz PRODL,F |
623 | 183 bra TFT_ClearScreen_display2_loop2 |
608 | 184 decfsz PRODH,F |
623 | 185 bra TFT_ClearScreen_display2_loop1 |
186 return | |
0 | 187 |
188 ;============================================================================= | |
582 | 189 |
190 global TFT_DisplayOff | |
0 | 191 TFT_DisplayOff: |
623 | 192 clrf CCP1CON ; stop PWM |
193 bcf PORTC,2 ; pull PWM out to GND | |
0 | 194 clrf PORTA |
582 | 195 clrf PORTH |
623 | 196 RD_L ; LOW |
197 RS_L ; LOW | |
198 bcf tft_nwr | |
199 bcf tft_cs | |
200 bcf tft_nreset | |
201 bsf tft_power ; inverted... | |
202 bcf lightsen_power ; power-down light sensor | |
0 | 203 return |
204 | |
205 ; ----------------------------- | |
206 ; TFT boot | |
207 ; ----------------------------- | |
582 | 208 |
209 global TFT_boot | |
0 | 210 TFT_boot: |
623 | 211 ; switch off backlight |
212 clrf CCP1CON ; stop PWM | |
213 bcf PORTC,2 ; pull PWM out to GND | |
214 | |
0 | 215 clrf PORTA |
216 clrf PORTH | |
217 RD_L ; LOW | |
218 bcf tft_nwr | |
219 nop | |
220 bcf tft_cs | |
221 nop | |
222 bcf tft_nreset | |
223 WAITMS d'1' | |
224 bcf tft_power ; inverted... | |
225 WAITMS d'1' | |
226 | |
227 RD_H ; Keep high | |
228 WR_H ; | |
229 NCS_L ; Not CS | |
230 | |
231 WAITMS d'2' | |
232 bsf tft_nreset | |
461 | 233 WAITMS d'5' |
234 bcf tft_nreset | |
235 WAITMS d'5' | |
236 bsf tft_nreset | |
0 | 237 WAITMS d'150' |
604 | 238 bsf lightsen_power ; supply power to light sensor |
0 | 239 |
582 | 240 ; Data Transfer Synchronization |
0 | 241 Parameter_out 0x00, 0x00 |
242 Parameter_out 0x00, 0x00 | |
582 | 243 |
623 | 244 btfsc screen_type2 ; display type 2 ? |
245 bra TFT_boot_screen2 ; YES | |
608 | 246 |
623 | 247 ; Get screen type from Bootloader-Info |
582 | 248 movlw 0x7B |
249 movwf TBLPTRL | |
250 movlw 0xF7 | |
251 movwf TBLPTRH | |
252 movlw 0x01 | |
253 movwf TBLPTRU | |
623 | 254 TBLRD*+ ; reads 0x6E for cR and USB OSTC3, 0x00 for BLE (2 and 3), and 0x02 for display 1 OSTC |
255 movlw 0x02 ; coding for display 1 | |
256 cpfseq TABLAT ; display 1 ? | |
257 bra TFT_boot_0 ; NO - display 0 | |
360 | 258 |
259 TFT_boot_1: | |
582 | 260 ; Init through config table... |
261 movlw 0x74 | |
262 movwf TBLPTRL | |
263 movlw 0xF7 | |
264 movwf TBLPTRH | |
265 movlw 0x01 | |
266 movwf TBLPTRU | |
267 bsf screen_type | |
268 bra TFT_boot_com | |
360 | 269 |
441
360acdcda0d7
+BUGFIX: Compatibility with "hwOS Config" fixed
heinrichsweikamp
parents:
436
diff
changeset
|
270 TFT_boot_0: |
582 | 271 ; Init through config table... |
272 movlw LOW display0_config_table | |
273 movwf TBLPTRL | |
274 movlw HIGH display0_config_table | |
275 movwf TBLPTRH | |
276 movlw UPPER display0_config_table | |
277 movwf TBLPTRU | |
278 bcf screen_type | |
279 | |
360 | 280 TFT_boot_com: |
582 | 281 rcall display0_init_loop |
0 | 282 |
582 | 283 Index_out 0x03 |
284 btfsc flip_screen ; 180° rotation ? | |
604 | 285 bra TFT_boot2 ; YES |
360 | 286 |
582 | 287 btfss screen_type ; display1? |
604 | 288 bra TFT_boot1a ; NO |
582 | 289 Parameter_out 0x10, 0x00 ; display1 |
290 bra TFT_boot3 | |
360 | 291 TFT_boot1a: |
582 | 292 Parameter_out 0x50, 0x20 ; display0 |
293 bra TFT_boot3 | |
152
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
151
diff
changeset
|
294 TFT_boot2: |
582 | 295 btfss screen_type ; display1? |
604 | 296 bra TFT_boot2a ; NO |
582 | 297 Parameter_out 0x10, 0x30 ; display1 |
298 bra TFT_boot3 | |
360 | 299 TFT_boot2a: |
582 | 300 Parameter_out 0x50, 0x10 ; display0 |
152
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
151
diff
changeset
|
301 TFT_boot3: |
0 | 302 Index_out 0x22 |
225
31088352ee32
BUGFIX: Show dives with >999mins divetime correctly
heinrichsweikamp
parents:
152
diff
changeset
|
303 rcall TFT_ClearScreen |
0 | 304 Index_out 0x07 |
312 | 305 Parameter_out 0x01, 0x33 |
0 | 306 return |
307 | |
308 display0_config_table: | |
582 | 309 ; Reg, Dat0, Dat1 or 0xFF,0x00,0x00 for end |
310 db 0xA4,0x00,0x01,0xFF,.002,0x00 | |
311 db 0x09,0x00,0x01,0x92,0x04,0x00 | |
312 db 0x93,0x04,0x02,0x94,0x00,0x02 | |
313 db 0x07,0x00,0x00,0x10,0x04,0x30 | |
314 db 0x11,0x02,0x37,0x12,0x11,0x8D | |
315 db 0x13,0x11,0x00,0x01,0x01,0x00 | |
316 db 0x02,0x02,0x00,0x03,0x50,0x20 | |
317 db 0x0A,0x00,0x08,0x0D,0x00,0x00 | |
318 db 0x0E,0x00,0x30,0xFF,.151,0x00 | |
319 db 0x12,0x11,0xBD,0x20,0x00,0x00 | |
320 db 0x21,0x00,0x00,0x30,0x06,0x02 | |
321 db 0x31,0x56,0x0D,0x32,0x05,0x07 | |
322 db 0x33,0x06,0x09,0x34,0x00,0x00 | |
323 db 0x35,0x09,0x06,0x36,0x57,0x05 | |
324 db 0x37,0x0D,0x06,0x38,0x02,0x06 | |
325 db 0x39,0x00,0x00,0xFF,0x00,0x00 | |
0 | 326 |
327 display0_init_loop: | |
582 | 328 TBLRD*+ |
329 movlw 0xFF | |
330 cpfseq TABLAT | |
623 | 331 bra display0_config_write ; write configuration data pair to display |
582 | 332 ; Delay ms or quit (return) |
333 TBLRD*+ | |
623 | 334 tstfsz TABLAT ; end of configuration data? |
604 | 335 bra $+4 ; NO |
336 return ; YES - done | |
582 | 337 movf TABLAT,W |
604 | 338 call WAITMSX ; wait WREG milliseconds |
339 TBLRD*+ ; dummy read (Third byte of delay command) | |
340 bra display0_init_loop ; loop | |
0 | 341 |
604 | 342 display0_config_write: ; with command in WREG |
582 | 343 movf TABLAT,W |
604 | 344 rcall TFT_CmdWrite ; write command |
345 TBLRD*+ ; get config0 | |
582 | 346 movff TABLAT,PORTA |
604 | 347 TBLRD*+ ; get config1 |
582 | 348 movf TABLAT,W |
623 | 349 rcall TFT_DataWrite ; write configuration |
604 | 350 bra display0_init_loop ; loop |
0 | 351 |
623 | 352 |
608 | 353 TFT_boot_screen2: |
623 | 354 bsf tft_nwr ; release bus |
355 rcall display1_init ; initialization sequence | |
608 | 356 |
623 | 357 btfss flip_screen ; 180° rotation? |
358 bra TFT_ClearScreen ; NO - done: clear screen and return | |
359 ; flip the GRAM | |
360 Index_out 0x16 | |
361 movlw 0x48 ; flip image in the GRAM (very elegant with display 2...) | |
362 rcall TFT_DataWrite ; Write configuration | |
363 bra TFT_ClearScreen ; clear screen and return | |
608 | 364 |
365 display1_init: | |
623 | 366 movlw LOW (0x1F8BC ) |
367 movwf TBLPTRL | |
368 movlw HIGH (0x1F8BC & 0xFFFF) | |
369 movwf TBLPTRH | |
370 movlw UPPER (0x1F8BC ) | |
371 movwf TBLPTRU | |
608 | 372 display1_init_loop: |
623 | 373 TBLRD*+ |
374 movlw 0xFF ; coding for end of configuration or wait step | |
375 cpfseq TABLAT | |
376 bra display1_config_write ; write configuration pair to display | |
377 ; Delay ms or quit (return) | |
378 TBLRD*+ | |
379 tstfsz TABLAT ; end of configuration? | |
380 bra $+4 ; NO - skip return | |
381 return ; YES - done | |
382 movf TABLAT,W ; read waiting time | |
383 call WAITMSX ; wait WREG milliseconds | |
384 bra display1_init_loop ; loop | |
385 display1_config_write: ; with command in WREG | |
386 movf TABLAT,W | |
387 rcall TFT_CmdWrite ; write command | |
388 TBLRD*+ ; get configuration | |
389 movf TABLAT,W | |
390 rcall TFT_DataWrite ; write configuration | |
391 bra display1_init_loop ; loop | |
608 | 392 |
0 | 393 |
394 ;============================================================================= | |
623 | 395 |
396 global TFT_CmdWrite | |
608 | 397 TFT_CmdWrite: |
398 RS_L ; command | |
399 btfsc screen_type2 | |
623 | 400 bra TFT_CmdWrite_screen2 |
608 | 401 clrf PORTA ; upper |
402 bcf INTCON,GIE | |
403 movwf PORTH ; lower | |
404 WR_L | |
405 WR_H ; tick | |
406 bsf INTCON,GIE | |
407 return | |
623 | 408 TFT_CmdWrite_screen2: |
409 movwf PORTH ; lower | |
608 | 410 WR_L |
623 | 411 WR_H ; tick |
608 | 412 return; |
413 | |
414 global TFT_DataWrite | |
415 TFT_DataWrite: | |
416 RS_H ; data | |
417 btfsc screen_type2 | |
623 | 418 bra TFT_DataWrite_screen2 |
608 | 419 bcf INTCON,GIE |
623 | 420 movwf PORTH ; lower |
608 | 421 WR_L |
422 WR_H ; tick | |
423 bsf INTCON,GIE | |
424 return | |
425 TFT_DataWrite_screen2: | |
623 | 426 movwf PORTH ; lower |
608 | 427 WR_L |
623 | 428 WR_H ; tick |
608 | 429 return |
430 | |
623 | 431 |
608 | 432 ;============================================================================= |
0 | 433 ; Smooth lighting-up of the display: |
434 ; | |
435 ; Trashes: WREG, PRODL | |
436 ; Typical usage: | |
604 | 437 ; clrf CCPR1L ; backlight off |
582 | 438 ; [draw splash screen] |
439 ; call TFT_DisplayFadeIn | |
440 | |
441 global TFT_Display_FadeIn | |
0 | 442 TFT_Display_FadeIn: |
623 | 443 movlw CCP1CON_VALUE ; get configuration |
444 movwf CCP1CON ; set configuration | |
604 | 445 bsf tft_is_dimming ; TFT is dimming, ignore ambient sensor |
446 clrf CCPR1L ; backlight off - to be sure | |
582 | 447 movff max_CCPR1L,PRODL |
0 | 448 TFT_Display_FadeIn_0: |
604 | 449 incf CCPR1L,F ; duty cycle |
582 | 450 WAITMS d'2' |
451 decfsz PRODL,F | |
623 | 452 bra TFT_Display_FadeIn_0 |
604 | 453 bcf tft_is_dimming ; dimming done |
582 | 454 return |
0 | 455 |
456 ;============================================================================= | |
457 ; Smooth lighting-off of the display: | |
458 ; Trashes: WREG, PRODL | |
582 | 459 |
460 global TFT_Display_FadeOut | |
0 | 461 TFT_Display_FadeOut: |
582 | 462 movff max_CCPR1L,PRODL |
604 | 463 bsf tft_is_dimming ; TFT is dimming, ignore ambient sensor |
0 | 464 TFT_Display_FadeOut_0: |
604 | 465 movff PRODL,CCPR1L ; duty cycle |
582 | 466 WAITMS d'1' |
467 decfsz PRODL,F | |
468 bra TFT_Display_FadeOut_0 | |
469 clrf CCPR1L | |
470 return | |
0 | 471 |
472 ;============================================================================= | |
473 | |
604 | 474 global box_std_block, box_black_block, box_color_block |
0 | 475 |
604 | 476 box_std_block: ; use white color |
582 | 477 setf WREG |
623 | 478 bra box_common |
604 | 479 box_black_block: ; use black color |
582 | 480 clrf WREG |
0 | 481 box_common: |
482 box_color_block: | |
582 | 483 rcall TFT_set_color |
484 VARARGS_BEGIN | |
485 VARARGS_GET8 win_top | |
486 VARARGS_GET8 win_height | |
487 VARARGS_GET8 win_leftx2 | |
488 VARARGS_GET8 win_width | |
489 VARARGS_END | |
490 bra TFT_box | |
0 | 491 |
492 ;----------------------------------------------------------------------------- | |
493 | |
582 | 494 global box_frame_std, box_frame_common, box_frame_color, box_frame_color16 |
0 | 495 |
496 box_frame_std: | |
582 | 497 setf WREG |
498 rcall TFT_set_color | |
0 | 499 box_frame_common: |
582 | 500 VARARGS_BEGIN |
501 VARARGS_GET8 win_top | |
502 VARARGS_GET8 win_height | |
503 VARARGS_GET8 win_leftx2 | |
504 VARARGS_GET8 win_width | |
505 VARARGS_END | |
506 bra TFT_frame | |
0 | 507 box_frame_color: |
582 | 508 rcall TFT_set_color |
0 | 509 box_frame_color16: |
582 | 510 bra box_frame_common |
0 | 511 |
434 | 512 ;;============================================================================= |
513 ;; Init for half_pixel_write | |
514 ;; Set column register on TFT device, and current color. | |
515 ;; Inputs: win_leftx2 | |
516 ;; Outputs: win_color:2 | |
517 ;; Trashed: WREG, PROD | |
582 | 518 ; |
519 ; global init_pixel_write | |
434 | 520 ;init_pixel_write: |
582 | 521 ; movf win_leftx2,W |
522 ; mullw 2 | |
604 | 523 ; rcall pixel_write_col320 ; start address vertical (.0 - .319) |
582 | 524 ; setf WREG |
525 ; bra TFT_set_color | |
0 | 526 |
527 ;----------------------------------------------------------------------------- | |
528 ; Writes two half-pixels at position (win_top,win_leftx2) | |
529 ; Inputs: win_leftx2, win_top, win_color:2 | |
530 ; Trashed: WREG, PROD | |
582 | 531 |
532 global pixel_write | |
0 | 533 pixel_write: |
582 | 534 movf win_leftx2,W |
623 | 535 mullw .2 ; win_leftx2 x 2 -> PRODH:PRODL |
604 | 536 rcall pixel_write_col320 ; start address vertical (.0 - .319) |
537 rcall half_pixel_write ; write this half-one | |
538 movf win_leftx2,W ; address of next one | |
623 | 539 mullw .2 ; win_leftx2 x 2 -> PRODH:PRODL |
540 INCI PROD ; PROD++ | |
582 | 541 rcall pixel_write_col320 |
604 | 542 bra half_pixel_write ; note: Cmd 0x20 is mandatory, because |
582 | 543 ; of the auto-increment going vertical |
0 | 544 |
545 global pixel_write_col320 | |
546 pixel_write_col320: | |
623 | 547 btfsc screen_type2 ; display type 2 ? |
548 bra pixel_write_col320_d2 ; YES | |
549 btfsc screen_type ; NO - display type 1 ? | |
550 bra pixel_write_col320_d1 ; YES | |
551 ; NO - display type 0 | |
582 | 552 btfss flip_screen ; 180° rotation? |
604 | 553 bra pixel_write_noflip_H ; NO |
554 bra pixel_write_flip_H ; YES | |
623 | 555 pixel_write_col320_d1: ; display type 1 |
582 | 556 btfsc flip_screen ; 180° rotation? |
623 | 557 bra pixel_write_noflip_H ; YES |
604 | 558 pixel_write_flip_H: ; flip d0 |
559 movf PRODL,W ; 16 bits 319 - PROD --> PROD | |
623 | 560 sublw LOW .319 ; 319-W --> W |
582 | 561 movwf PRODL |
562 movf PRODH,W | |
604 | 563 btfss STATUS,C ; borrow = /CARRY |
582 | 564 incf WREG |
623 | 565 sublw HIGH .319 |
582 | 566 movwf PRODH |
151 | 567 |
568 pixel_write_noflip_H: | |
604 | 569 Index_out 0x21 ; frame memory vertical address |
582 | 570 bra TFT_DataWrite_PROD ; and return... |
0 | 571 |
608 | 572 pixel_write_col320_d2: |
623 | 573 movlw 0x06 |
574 rcall TFT_CmdWrite | |
575 movf PRODH,W | |
576 rcall TFT_DataWrite | |
577 movlw 0x07 | |
578 rcall TFT_CmdWrite | |
579 movf PRODL,W | |
580 rcall TFT_DataWrite | |
608 | 581 |
623 | 582 incf PRODL,F |
583 movlw .0 | |
584 addwfc PRODH,F ; +1 | |
608 | 585 |
623 | 586 movlw 0x08 |
587 rcall TFT_CmdWrite | |
588 movf PRODH,W | |
589 rcall TFT_DataWrite | |
590 movlw 0x09 | |
591 rcall TFT_CmdWrite | |
592 movf PRODL,W | |
593 bra TFT_DataWrite ; ... and return | |
608 | 594 |
0 | 595 ;----------------------------------------------------------------------------- |
596 ; Writes one half-pixel at position (win_top,win_leftx2). | |
597 ; Inputs: win_leftx2, win_top, win_color:2 | |
598 ; Trashed: WREG, PROD | |
582 | 599 |
600 global half_pixel_write | |
0 | 601 half_pixel_write: |
582 | 602 movf win_top,W ; d'0' ... d'239' |
603 ; Variant with Y position in WREG. | |
0 | 604 half_pixel_write_1: |
623 | 605 btfsc screen_type2 ; screen tpe 2 ? |
606 bra half_pixel_write_1_display1 ; YES | |
608 | 607 |
582 | 608 btfss flip_screen ; 180° rotation? |
609 sublw .239 ; 239-Y --> Y | |
604 | 610 mullw .1 ; copy row to PRODL (PRODH=0) |
611 Index_out 0x20 ; frame memory horizontal address | |
582 | 612 rcall TFT_DataWrite_PROD |
0 | 613 |
604 | 614 Index_out 0x22 ; frame memory data write start |
615 RS_H ; data | |
582 | 616 bcf INTCON,GIE |
604 | 617 movff win_color1,PORTA ; upper |
618 movff win_color2,PORTH ; lower | |
582 | 619 WR_L |
604 | 620 WR_H ; tick |
582 | 621 bsf INTCON,GIE |
622 return | |
0 | 623 |
608 | 624 half_pixel_write_1_display1: |
623 | 625 mullw 1 ; copy row to PRODL (PRODH=0) |
626 ; Row address start | |
627 movlw 0x02 | |
628 rcall TFT_CmdWrite | |
629 movlw .0 | |
630 rcall TFT_DataWrite | |
631 movlw 0x03 | |
632 rcall TFT_CmdWrite | |
633 movf PRODL,W | |
634 rcall TFT_DataWrite | |
608 | 635 |
623 | 636 incf PRODL,F |
608 | 637 |
623 | 638 movlw 0x04 |
639 rcall TFT_CmdWrite | |
640 movlw .0 | |
641 rcall TFT_DataWrite | |
642 movlw 0x05 | |
643 rcall TFT_CmdWrite | |
644 movf PRODL,W | |
645 rcall TFT_DataWrite | |
608 | 646 |
647 movff win_color1,PRODH | |
648 movff win_color2,PRODL | |
649 rcall convert_for_display2 | |
650 | |
623 | 651 movlw 0x22 ; start writing data to GRAM |
652 rcall TFT_CmdWrite | |
653 RS_H ; data | |
654 movff win_color5, PORTH | |
608 | 655 WR_L |
623 | 656 WR_H ; tick |
657 movff win_color4, PORTH | |
608 | 658 WR_L |
623 | 659 WR_H ; tick |
660 movff win_color3, PORTH | |
608 | 661 WR_L |
623 | 662 WR_H ; tick |
663 return | |
608 | 664 |
0 | 665 ;----------------------------------------------------------------------------- |
666 ; Writes a vertical line of half-pixel at position (win_top,win_leftx2,win_height). | |
667 ; Inputs: win_leftx2, win_top, win_height, win_color:2 | |
668 ; Trashed: WREG, PROD, TABLAT, TBLPTRL | |
582 | 669 |
0 | 670 global half_vertical_line |
671 half_vertical_line: | |
604 | 672 clrf TABLAT ; loop index |
0 | 673 |
674 half_vertical_line_loop: | |
604 | 675 movf win_leftx2,W ; init X position |
623 | 676 mullw .2 ; win_leftx2 x 2 -> PRODH:PRODL |
604 | 677 movf TABLAT,W ; get loop index |
678 andlw .1 ; just low bit | |
679 xorwf PRODL,F ; and use it to jitter current X position | |
680 rcall pixel_write_col320 ; start address vertical (.0 - .319) | |
0 | 681 |
604 | 682 movf win_height,W ; index reached height (bank0 read) ? |
582 | 683 xorwf TABLAT,W |
604 | 684 btfsc STATUS,Z ; Equal ? |
685 return ; YES - done | |
686 movf win_top,W ; Y = top + index (bank0 read) | |
582 | 687 addwf TABLAT,W |
688 rcall half_pixel_write_1 | |
689 incf TABLAT,F ; index++ | |
690 bra half_vertical_line_loop | |
0 | 691 |
692 ;----------------------------------------------------------------------------- | |
693 ; Writes a horizontal line of half-pixel at position (win_top,win_leftx2,win_width). | |
694 ; Inputs: win_leftx2, win_top, win_width, win_color:2 | |
695 ; Trashed: WREG, PROD, TABLAT, TBLPTRL | |
582 | 696 |
0 | 697 global half_horizontal_line |
698 half_horizontal_line: | |
604 | 699 clrf TABLAT ; loop index |
0 | 700 |
701 half_horizontal_line_loop: | |
604 | 702 movf win_leftx2,W ; init X position |
623 | 703 mullw .2 ; win_leftx2 x 2 -> PRODH:PRODL |
604 | 704 rcall pixel_write_col320 ; start address vertical (.0 - .319) |
705 movf win_width,W ; index reached height (bank0 read) ? | |
582 | 706 xorwf TABLAT,W |
604 | 707 btfsc STATUS,Z ; equal ? |
708 return ; YES - done | |
709 movf win_top,W ; Y = top + index (bank0 read) | |
582 | 710 addwf TABLAT,W |
711 rcall half_pixel_write_1 | |
712 incf TABLAT,F ; index++ | |
713 bra half_horizontal_line_loop | |
0 | 714 |
715 | |
716 ;----------------------------------------------------------------------------- | |
623 | 717 ; TFT Data Command via W |
582 | 718 |
719 global TFT_DataWrite_PROD | |
0 | 720 TFT_DataWrite_PROD: |
623 | 721 ; RD_H ; keep high |
722 RS_H ; data | |
723 btfsc screen_type2 ; screen type 2 ? | |
724 bra TFT_DataWrite_PROD_display2 ; YES | |
725 bcf INTCON,GIE ; NO - | |
726 movff PRODH,PORTA ; - move high byte to PORTA | |
727 movff PRODL,PORTH ; - move low byte to PORTH | |
728 WR_L ; - tick | |
729 WR_H ; - tack | |
730 bsf INTCON,GIE ; - | |
731 return ; - done | |
0 | 732 |
608 | 733 TFT_DataWrite_PROD_display2: |
623 | 734 movff PRODH,PORTH ; move high byte to PORTH (display 2 is big endian) |
735 WR_L ; tick | |
736 WR_H ; tack | |
737 movff PRODL,PORTH ; move low byte to PORTH | |
738 WR_L ; tick | |
739 WR_H ; tack | |
740 movff win_color3,PORTH ; move low(est) byte to PORTH | |
741 WR_L ; tick | |
742 WR_H ; tack | |
743 return ; done | |
744 | |
608 | 745 |
0 | 746 TFT_DataRead_PROD: |
604 | 747 Index_out 0x22 ; frame memory data read start |
360 | 748 TFT_CmdRead_PROD: |
604 | 749 setf TRISA ; port A as input |
750 setf TRISH ; port H as input | |
751 RS_H ; data | |
752 WR_H ; not write | |
753 RD_L ; read | |
582 | 754 nop |
755 nop | |
756 nop | |
604 | 757 RD_H ; tick |
582 | 758 nop |
759 nop | |
760 nop | |
604 | 761 RD_L ; read |
582 | 762 nop |
763 ;nop | |
764 ;nop | |
765 movff PORTA,PRODH | |
766 movff PORTH,PRODL | |
604 | 767 RD_H ; tick |
582 | 768 nop |
604 | 769 clrf TRISA ; port A as output |
770 clrf TRISH ; port H as output | |
0 | 771 return |
772 | |
773 ;============================================================================= | |
604 | 774 ; Output TFT Window Address commands |
775 ; Inputs : win_top, win_leftx2, win_height, win_width | |
776 ; Output : PortA/PortH commands | |
0 | 777 ; Trashed: PROD |
582 | 778 |
779 global TFT_box_write | |
0 | 780 TFT_box_write: |
623 | 781 movf win_leftx2,W ; compute left = 2 * leftx2 --> PROD |
782 mullw .2 ; win_leftx2 x 2 -> PRODH:PRODL | |
0 | 783 |
623 | 784 btfsc screen_type2 ; screen type 2 ? |
785 bra TFT_box_write_display2 ; YES | |
608 | 786 |
582 | 787 global TFT_box_write_16bit_win_left |
623 | 788 TFT_box_write_16bit_win_left: ; with column in PRODL:PRODH |
789 btfsc screen_type ; screen type 1 ? | |
604 | 790 bra TFT_box_write_16bit_win_left_d1 ; YES |
623 | 791 ; screen type 0 |
582 | 792 btfsc flip_screen ; 180° rotation? |
604 | 793 bra DISP_box_flip_H ; YES |
794 bra TFT_box_write_16bit_win_left_com ; NO | |
582 | 795 TFT_box_write_16bit_win_left_d1: ; Display1 |
796 btfss flip_screen ; 180° rotation? | |
623 | 797 bra DISP_box_flip_H ; NO |
798 TFT_box_write_16bit_win_left_com: ; YES for screen type 1, NO for type 0 | |
582 | 799 ;---- Normal horizontal window --------------------------------------- |
604 | 800 Index_out 0x52 ; window vertical start address |
801 rcall TFT_DataWrite_PROD ; output left | |
802 Index_out 0x21 ; frame memory vertical address | |
803 rcall TFT_DataWrite_PROD ; output left | |
0 | 804 |
582 | 805 movf win_width+0,W ; right = left + width - 1 |
432 | 806 addwf PRODL,F |
807 movf win_width+1,W | |
808 addwfc PRODH,F | |
623 | 809 decf PRODL,F ; right-- |
582 | 810 btfss STATUS,C |
432 | 811 decf PRODH,F |
0 | 812 |
604 | 813 Index_out 0x53 ; window vertical end address |
582 | 814 rcall TFT_DataWrite_PROD |
815 bra DISP_box_noflip_H | |
0 | 816 |
582 | 817 ;---- Flipped horizontal window -------------------------------------- |
151 | 818 DISP_box_flip_H: |
623 | 819 ; calculate new coordinate |
604 | 820 movf PRODL,W ; 16 bits 319 - PROD --> PROD |
623 | 821 sublw LOW .319 ; 319 - WREG --> WREG |
582 | 822 movwf PRODL |
823 movf PRODH,W | |
604 | 824 btfss STATUS,C ; borrow = /CARRY |
582 | 825 incf WREG |
623 | 826 sublw HIGH .319 |
582 | 827 movwf PRODH |
152
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
151
diff
changeset
|
828 |
604 | 829 Index_out 0x53 ; window vertical start address |
830 rcall TFT_DataWrite_PROD ; output left | |
831 Index_out 0x21 ; frame memory vertical address | |
832 rcall TFT_DataWrite_PROD ; output left | |
151 | 833 |
623 | 834 ; calculate new coordinate |
604 | 835 movf win_width+0,W ; 16 bits PROD - width --> PROD |
582 | 836 subwf PRODL,F ; PRODL - WREG --> PRODL |
837 movf win_width+1,W | |
838 subwfb PRODH,F | |
623 | 839 INCI PROD ; PROD++ |
151 | 840 |
604 | 841 Index_out 0x52 ; window vertical end address |
582 | 842 rcall TFT_DataWrite_PROD |
151 | 843 |
844 DISP_box_noflip_H: | |
582 | 845 btfss flip_screen ; 180° rotation ? |
604 | 846 bra TFT_box_noflip_V ; NO |
151 | 847 |
582 | 848 ;---- Flipped vertical window ----------------------------------------- |
623 | 849 ; calculate new coordinate |
582 | 850 movff win_top,PRODH ; top --> PRODH (first byte) |
851 movf win_height,W | |
852 addwf PRODH,W | |
432 | 853 decf WREG |
604 | 854 movwf PRODL ; top + height - 1 --> PRODL (second byte) |
151 | 855 |
604 | 856 Index_out 0x50 ; window horizontal start address |
432 | 857 movf PRODH,W |
604 | 858 rcall TFT_DataWrite ; lower (and tick) |
151 | 859 |
604 | 860 Index_out 0x51 ; window horizontal end address |
582 | 861 movf PRODL,W |
604 | 862 rcall TFT_DataWrite ; lower (and tick) |
582 | 863 |
604 | 864 Index_out 0x20 ; frame memory horizontal address |
432 | 865 movf PRODH,W |
604 | 866 bra TFT_DataWrite ; lower (and tick) and return |
151 | 867 |
152
19ad15f04f60
BUGFIX: Clear Setpoint-Fallback warning when in bailout
heinrichsweikamp
parents:
151
diff
changeset
|
868 TFT_box_noflip_V: |
582 | 869 ;---- Normal vertical window ---------------------------------------- |
870 movff win_top,PRODL | |
871 movf win_height,W | |
872 addwf PRODL,W | |
873 sublw .240 ; 240 - top - height | |
604 | 874 movwf PRODH ; first byte |
0 | 875 |
432 | 876 movf PRODL,W |
604 | 877 sublw .239 ; 239 - top |
878 movwf PRODL ; --> second byte | |
0 | 879 |
604 | 880 Index_out 0x50 ; window horizontal start address |
432 | 881 movf PRODH,W |
604 | 882 rcall TFT_DataWrite ; lower (and tick) |
0 | 883 |
604 | 884 Index_out 0x51 ; window horizontal end address |
432 | 885 movf PRODL,W |
604 | 886 rcall TFT_DataWrite ; lower (and tick) |
0 | 887 |
604 | 888 Index_out 0x20 ; frame memory horizontal address |
432 | 889 movf PRODL,W |
604 | 890 bra TFT_DataWrite ; lower (and tick) and return |
582 | 891 |
608 | 892 |
623 | 893 TFT_box_write_display2: |
894 movlw 0x06 | |
895 rcall TFT_CmdWrite | |
896 movf PRODH,W | |
897 rcall TFT_DataWrite | |
898 movlw 0x07 | |
899 rcall TFT_CmdWrite | |
900 movf PRODL,W | |
901 rcall TFT_DataWrite | |
608 | 902 |
623 | 903 movf win_width+0,W ; right = left + width - 1 |
904 addwf PRODL,F | |
905 movf win_width+1,W | |
906 addwfc PRODH,F | |
907 decf PRODL,F,A ; decrement result | |
908 btfss STATUS,C | |
909 decf PRODH,F,A | |
608 | 910 |
623 | 911 movlw 0x08 |
912 rcall TFT_CmdWrite | |
913 movf PRODH,W | |
914 rcall TFT_DataWrite | |
915 movlw 0x09 | |
916 rcall TFT_CmdWrite | |
917 movf PRODL,W | |
918 rcall TFT_DataWrite | |
919 | |
920 ;---- Normal vertical window ----------------------------------------- | |
921 ; Output (top) (bottom) | |
922 movff win_top,PRODH ; top --> PRODH (first byte) | |
923 movf win_height,W | |
924 addwf PRODH,W | |
925 decf WREG | |
926 movwf PRODL ; top+height-1 --> PRODL (second byte) | |
608 | 927 |
623 | 928 movlw 0x02 |
929 rcall TFT_CmdWrite | |
930 movlw 0x00 | |
931 rcall TFT_DataWrite | |
932 movlw 0x03 | |
933 rcall TFT_CmdWrite | |
934 movf PRODH,W | |
935 rcall TFT_DataWrite | |
608 | 936 |
623 | 937 movlw 0x04 |
938 rcall TFT_CmdWrite | |
939 movlw 0x00 | |
940 rcall TFT_DataWrite | |
941 movlw 0x05 | |
942 rcall TFT_CmdWrite | |
943 movf PRODL,W | |
944 bra TFT_DataWrite ; ... and return | |
0 | 945 |
946 ;============================================================================= | |
604 | 947 ; TFT_frame : draw a frame around current box with current color |
0 | 948 ; Inputs: win_top, win_leftx2, win_height, win_width, win_color1, win_color2 |
949 ; Outputs: (none) | |
950 ; Trashed: WREG, PROD, aa_start:2, aa_end:2 | |
951 | |
582 | 952 global TFT_frame |
953 TFT_frame: | |
623 | 954 movff win_top,tft_save_top ; backup everything |
955 movff win_height,tft_save_height | |
956 movff win_leftx2,tft_save_left | |
957 movff win_width,tft_save_width | |
0 | 958 |
582 | 959 ;---- TOP line ----------------------------------------------------------- |
623 | 960 movlw .1 ; row ~ height = 1 |
582 | 961 movwf win_height |
962 rcall TFT_box | |
0 | 963 |
582 | 964 ;---- BOTTOM line -------------------------------------------------------- |
623 | 965 movff tft_save_top,PRODL ; get back top |
966 movff tft_save_height,WREG ; get back height | |
967 addwf PRODL,W ; top + height | |
968 decf WREG ; top + height - 1 | |
969 movwf win_top ; top + height - 1 --> top | |
582 | 970 rcall TFT_box |
0 | 971 |
582 | 972 ;---- LEFT column -------------------------------------------------------- |
623 | 973 movff tft_save_top,win_top ; restore top/height |
974 movff tft_save_height,win_height | |
975 movlw .1 ; column ~ width = 1 | |
582 | 976 movwf win_width+0 |
977 rcall TFT_box | |
978 | |
979 ;---- RIGHT column ------------------------------------------------------- | |
623 | 980 movff tft_save_left,WREG |
981 movff tft_save_width,PRODL | |
582 | 982 addwf PRODL,W |
983 decf WREG | |
984 movwf win_leftx2 | |
985 rcall TFT_box | |
986 | |
987 ;---- Restore everything ------------------------------------------------- | |
623 | 988 movff tft_save_left,win_leftx2 |
989 movff tft_save_width,win_width | |
582 | 990 return |
0 | 991 |
992 ;============================================================================= | |
604 | 993 ; TFT_box: fills current box with current color |
994 ; Inputs : win_top, win_leftx2, win_height, win_width, win_color1, win_color2 | |
0 | 995 ; Outputs: (none) |
996 ; Trashed: WREG, PROD | |
997 | |
582 | 998 global TFT_box |
0 | 999 TFT_box: |
623 | 1000 btfsc screen_type2 ; display type 2 ? |
1001 bra TFT_box_display2 ; YES | |
1002 | |
582 | 1003 ;---- Define Window ------------------------------------------------------ |
1004 bcf STATUS,C | |
1005 rlcf win_width+0,F | |
1006 rlcf win_width+1,F ; x2 | |
604 | 1007 rcall TFT_box_write ; setup box |
0 | 1008 |
582 | 1009 global TFT_box_16bit_win_left |
83 | 1010 TFT_box_16bit_win_left: |
582 | 1011 bcf STATUS,C |
1012 rrcf win_width+1,F ; width /= 2 | |
1013 rrcf win_width+0,F | |
0 | 1014 |
582 | 1015 ;---- Fill Window -------------------------------------------------------- |
604 | 1016 Index_out 0x22 ; frame memory data write start |
0 | 1017 |
604 | 1018 clrf PRODH ; column counter |
1019 RS_H ; data | |
0 | 1020 |
604 | 1021 TFT_box2: ; loop height times |
0 | 1022 movff win_height,PRODL |
1023 | |
582 | 1024 TFT_box3: ; loop width times |
623 | 1025 bcf INTCON,GIE |
604 | 1026 movff win_color1,PORTA ; upper |
1027 movff win_color2,PORTH ; lower | |
0 | 1028 WR_L |
604 | 1029 WR_H ; tick |
582 | 1030 |
604 | 1031 ; movff win_color1,PORTA ; upper |
1032 ; movff win_color2,PORTH ; lower | |
0 | 1033 WR_L |
604 | 1034 WR_H ; tick |
582 | 1035 bsf INTCON,GIE |
1036 decfsz PRODL,F ; row loop finished ? | |
604 | 1037 bra TFT_box3 ; NO - continue |
0 | 1038 |
582 | 1039 incf PRODH,F ; column count ++ |
0 | 1040 |
582 | 1041 movf win_bargraph,W ; current column == bargraph ? |
1042 cpfseq PRODH | |
604 | 1043 bra TFT_box4 ; NO - just loop |
1044 clrf win_color1 ; Yes - switch to black | |
1045 clrf win_color2 ; - ... | |
0 | 1046 TFT_box4: |
582 | 1047 movf win_width+0,W ; compare ? |
1048 xorwf PRODH,W | |
623 | 1049 bnz TFT_box2 ; loop not finished |
0 | 1050 |
582 | 1051 movlw 0x00 ; NOP, to stop window mode |
1052 rcall TFT_CmdWrite | |
0 | 1053 |
604 | 1054 ; reset bargraph mode... |
582 | 1055 setf win_bargraph |
1056 return | |
623 | 1057 |
608 | 1058 TFT_box_display2: |
623 | 1059 ;---- Define Window ------------------------------------------------------ |
1060 bcf STATUS,C | |
1061 rlcf win_width+0,F | |
1062 rlcf win_width+1,F ; x2 | |
1063 rcall TFT_box_write ; setup box | |
608 | 1064 |
623 | 1065 bcf STATUS,C |
1066 rrcf win_width+1,F ; width /= 2 | |
1067 rrcf win_width+0,F | |
608 | 1068 |
1069 movff win_color1,PRODH | |
1070 movff win_color2,PRODL | |
1071 rcall convert_for_display2 | |
623 | 1072 ;---- Fill Window -------------------------------------------------------- |
1073 Index_out 0x22 ; frame memory data write start | |
608 | 1074 |
623 | 1075 clrf PRODH ; column counter |
1076 RS_H ; data | |
608 | 1077 |
623 | 1078 TFT_box2_display2: ; loop height times |
608 | 1079 movff win_height,PRODL |
623 | 1080 TFT_box3_display2: ; loop width times |
608 | 1081 movff win_color5,PORTH |
623 | 1082 bcf tft_nwr |
1083 bsf tft_nwr ; upper | |
608 | 1084 movff win_color4,PORTH |
1085 bcf tft_nwr | |
623 | 1086 bsf tft_nwr ; high |
608 | 1087 movff win_color3,PORTH |
1088 bcf tft_nwr | |
623 | 1089 bsf tft_nwr ; low |
608 | 1090 |
1091 movff win_color5,PORTH | |
1092 bcf tft_nwr | |
623 | 1093 bsf tft_nwr ; upper |
608 | 1094 movff win_color4,PORTH |
1095 bcf tft_nwr | |
623 | 1096 bsf tft_nwr ; high |
608 | 1097 movff win_color3,PORTH |
1098 bcf tft_nwr | |
623 | 1099 bsf tft_nwr ; low |
1100 decfsz PRODL,F ; row loop finished? | |
1101 bra TFT_box3_display2 ; NO - loop | |
1102 incf PRODH,F ; YES - column count ++ | |
1103 movf win_bargraph,W ; - get bargraph width | |
1104 cpfseq PRODH ; - current column = bargraph ? | |
1105 bra TFT_box4_display2 ; NO | |
1106 clrf win_color5 ; YES - switch to black | |
1107 clrf win_color4 ; - ... | |
1108 clrf win_color3 ; - ... | |
608 | 1109 TFT_box4_display2: |
623 | 1110 movf win_width+0,W ; get width |
1111 cpfseq PRODH ; width loop finished ? | |
1112 bra TFT_box2_display2 ; NO - loop | |
1113 setf win_bargraph ; YES - reset bargraph mode | |
1114 return ; - done | |
0 | 1115 |
1116 ;============================================================================= | |
623 | 1117 ; Convert 8 bit RGB b'RRRGGGBB' into 16 bit RGB b'RRRRRGGGGGGBBBBB' |
0 | 1118 |
582 | 1119 global TFT_set_color |
0 | 1120 TFT_set_color: |
604 | 1121 movwf tft_temp1 ; get 8 Bit RGB b'RRRGGGBB' |
1122 movwf tft_temp2 ; copy | |
0 | 1123 |
604 | 1124 ; mask bit 7,6,5,4,3,2 |
0 | 1125 movlw b'00000011' |
1126 andwf tft_temp2,F | |
1127 | |
1128 movlw b'00000000' | |
1129 dcfsnz tft_temp2,F | |
1130 movlw b'01010000' | |
1131 dcfsnz tft_temp2,F | |
1132 movlw b'10100000' | |
1133 dcfsnz tft_temp2,F | |
1134 movlw b'11111000' | |
604 | 1135 movwf tft_temp3 ; blue done |
0 | 1136 |
604 | 1137 movff tft_temp1,tft_temp2 ; copy |
1138 ; mask bit 7,6,5,1,0 | |
0 | 1139 movlw b'00011100' |
1140 andwf tft_temp2,F | |
1141 rrncf tft_temp2,F | |
1142 rrncf tft_temp2,F | |
1143 | |
1144 movlw b'00000000' | |
1145 dcfsnz tft_temp2,F | |
1146 movlw b'00000100' | |
1147 dcfsnz tft_temp2,F | |
1148 movlw b'00001000' | |
1149 dcfsnz tft_temp2,F | |
1150 movlw b'00001100' | |
1151 dcfsnz tft_temp2,F | |
1152 movlw b'00010000' | |
1153 dcfsnz tft_temp2,F | |
1154 movlw b'00010100' | |
1155 dcfsnz tft_temp2,F | |
1156 movlw b'00100000' | |
1157 dcfsnz tft_temp2,F | |
1158 movlw b'00111111' | |
582 | 1159 movwf tft_temp4 |
0 | 1160 |
1161 rrcf tft_temp4,F | |
1162 rrcf tft_temp3,F | |
1163 | |
1164 rrcf tft_temp4,F | |
1165 rrcf tft_temp3,F | |
1166 | |
1167 rrcf tft_temp4,F | |
604 | 1168 rrcf tft_temp3,W ; tft_temp3 (b'GGGBBBBB') done |
1169 movwf win_color2 ; set color registers... | |
0 | 1170 |
604 | 1171 movff tft_temp1,tft_temp2 ; copy |
0 | 1172 clrf tft_temp1 |
1173 | |
1174 rrcf tft_temp4,F | |
1175 rrcf tft_temp1,F | |
1176 | |
1177 rrcf tft_temp4,F | |
1178 rrcf tft_temp1,F | |
1179 | |
1180 rrcf tft_temp4,F | |
604 | 1181 rrcf tft_temp1,F ; green done |
0 | 1182 |
604 | 1183 ; mask bit 4,3,2,1,0 |
0 | 1184 movlw b'11100000' |
1185 andwf tft_temp2,F | |
1186 | |
1187 rrncf tft_temp2,F | |
1188 rrncf tft_temp2,F | |
1189 rrncf tft_temp2,F | |
1190 rrncf tft_temp2,F | |
1191 rrncf tft_temp2,F | |
1192 | |
1193 movlw b'00000000' | |
1194 dcfsnz tft_temp2,F | |
1195 movlw b'00000100' | |
1196 dcfsnz tft_temp2,F | |
1197 movlw b'00001000' | |
1198 dcfsnz tft_temp2,F | |
1199 movlw b'00001100' | |
1200 dcfsnz tft_temp2,F | |
1201 movlw b'00010000' | |
1202 dcfsnz tft_temp2,F | |
1203 movlw b'00010100' | |
1204 dcfsnz tft_temp2,F | |
1205 movlw b'00100000' | |
1206 dcfsnz tft_temp2,F | |
1207 movlw b'00111111' | |
582 | 1208 movwf tft_temp4 |
0 | 1209 |
1210 rrcf tft_temp4,F | |
1211 rrcf tft_temp1,F | |
1212 | |
1213 rrcf tft_temp4,F | |
604 | 1214 rrcf tft_temp1,F |
0 | 1215 |
1216 rrcf tft_temp4,F | |
1217 rrcf tft_temp1,F | |
1218 | |
1219 rrcf tft_temp4,F | |
1220 rrcf tft_temp1,F | |
1221 | |
1222 rrcf tft_temp4,F | |
604 | 1223 rrcf tft_temp1,W ; red done |
1224 movwf win_color1 ; set color registers | |
0 | 1225 return |
623 | 1226 |
1227 | |
608 | 1228 global convert_for_display2 |
623 | 1229 convert_for_display2: ; convert 16 bit RGB b'RRRRRGGG GGGBBBBB' into 24 bit RGB b'RRRRRR00 GGGGGG00 BBBBBB00' |
1230 ; PRODH PRODL win_color5 win_color4 win_color3 | |
1231 ; Red | |
1232 movff PRODH,win_color5 ; = RRRRRGGG | |
1233 bcf win_color5,2 ; = RRRRR0GG | |
1234 btfsc win_color5,7 | |
1235 bsf win_color5,2 ; = RRRRR1GG the lower two bits are ignored by the screen | |
1236 ; Blue | |
1237 movff PRODL,win_color3 | |
1238 rrcf win_color3,F ; = UGGGBBBB and the LSB-blue into carry | |
1239 swapf win_color3,F ; = BBBBUGGG | |
1240 bcf win_color3,3 ; = BBBB0GGG | |
608 | 1241 btfsc STATUS,C |
623 | 1242 bsf win_color3,3 ; = BBBB1GGG |
1243 bcf win_color3,2 ; = BBBBB0GG | |
1244 btfsc win_color3,7 | |
1245 bsf win_color3,2 ; = BBBBB1GG | |
1246 ; Green | |
1247 rrcf PRODH,F | |
1248 rrcf PRODL,F | |
1249 rrcf PRODH,F | |
1250 rrcf PRODL,F | |
1251 rrcf PRODH,F | |
1252 rrcf PRODL,F ; = GGGGGGBB the lower two bits are ignored by the screen | |
1253 movff PRODL,win_color4 | |
608 | 1254 return |
623 | 1255 |
0 | 1256 |
1257 ;============================================================================= | |
1258 | |
604 | 1259 IFDEF _screendump |
1260 | |
623 | 1261 ;----------------------------------------------------------------------------- |
1262 ; Dump screen contents to the UART | |
1263 ; | |
604 | 1264 global TFT_dump_screen_check |
582 | 1265 global TFT_dump_screen |
604 | 1266 TFT_dump_screen_check: |
1267 btfss vusb_in ; USB (still) plugged in? | |
623 | 1268 bcf screen_dump_avail ; NO - disable screen dump function |
604 | 1269 call rs232_get_byte ; try to read data from RS232 |
623 | 1270 btfsc rs232_rx_timeout ; anything received? |
604 | 1271 return ; NO - return |
623 | 1272 movlw "l" ; YES - load coding for screen dump command |
1273 cpfseq RCREG1 ; screen dump command received? | |
604 | 1274 return ; NO - return |
623 | 1275 |
1276 TFT_dump_screen: | |
1277 btfsc screen_type2 ; is this an OSTC with a screen of type 2? | |
1278 return ; YES - not supported | |
1279 bsf block_sensor_interrupt ; NO - disable sensor interrupts | |
1280 movlw 'l' ; - prepare response | |
1281 movwf TXREG ; - send response | |
1282 call rs232_wait_tx ; - wait for UART | |
604 | 1283 |
582 | 1284 ;---- Send DISPLAY box command for the full screen window ------------------- |
604 | 1285 Index_out 0x50 ; window horizontal start address |
582 | 1286 Parameter_out 0x00, 0x00 ; 0-239 |
604 | 1287 Index_out 0x51 ; window horizontal end address |
582 | 1288 Parameter_out 0x00, 0xEF ; 0-239 |
604 | 1289 Index_out 0x52 ; window vertical start address |
582 | 1290 Parameter_out 0x00, 0x00 ; 0-319 |
604 | 1291 Index_out 0x53 ; window vertical end address |
582 | 1292 Parameter_out 0x01, 0x3F ; 0-319 |
0 | 1293 |
582 | 1294 clrf ds_column |
1295 rcall dump_screen_pixel_reset | |
0 | 1296 dump_screen_1: |
582 | 1297 btg LEDr ; LED activity toggle |
1298 ; Dump even column | |
604 | 1299 movlw .240 ; 240 lines, once |
582 | 1300 movwf ds_line |
0 | 1301 dump_screen_2: |
604 | 1302 Index_out 0x20 ; frame memory horizontal address |
582 | 1303 movff ds_line,WREG ; d'0' ... d'239' |
604 | 1304 mullw .1 ; copy row to PRODH:L |
582 | 1305 rcall TFT_DataWrite_PROD |
0 | 1306 |
623 | 1307 movff ds_column,WREG ; initialize X position |
1308 mullw .2 ; ds_column x 2 -> PRODH:PRODL | |
604 | 1309 rcall pixel_write_col320 ; start address vertical (.0 - .319) |
0 | 1310 |
582 | 1311 rcall TFT_DataRead_PROD ; read pixel |
1312 rcall dump_screen_pixel | |
0 | 1313 |
582 | 1314 decfsz ds_line,F |
1315 bra dump_screen_2 | |
1316 rcall dump_screen_pixel_flush | |
0 | 1317 |
582 | 1318 ; Dump odd column |
604 | 1319 movlw .240 ; 240 lines, twice |
582 | 1320 movwf ds_line |
0 | 1321 dump_screen_3: |
604 | 1322 Index_out 0x20 ; frame memory horizontal address |
582 | 1323 movff ds_line,WREG ; d'0' ... d'239' |
623 | 1324 mullw .1 ; copy row to PRODH:L |
582 | 1325 rcall TFT_DataWrite_PROD |
0 | 1326 |
623 | 1327 movff ds_column,WREG ; initialize X position |
1328 mullw .2 ; ds_column x 2 -> PRODH:PRODL | |
1329 INCI PROD ; PROD++ | |
604 | 1330 rcall pixel_write_col320 ; start address vertical (.0 - .319) |
0 | 1331 |
582 | 1332 rcall TFT_DataRead_PROD ; read pixel |
1333 rcall dump_screen_pixel | |
0 | 1334 |
582 | 1335 decfsz ds_line,F |
1336 bra dump_screen_3 | |
1337 rcall dump_screen_pixel_flush | |
0 | 1338 |
582 | 1339 incf ds_column,F |
1340 movlw .160 | |
1341 cpfseq ds_column | |
1342 bra dump_screen_1 | |
0 | 1343 |
623 | 1344 bcf block_sensor_interrupt ; re-enable sensor interrupts |
604 | 1345 clrf RCREG1 ; clear receive buffer |
1346 bcf RCSTA1,CREN ; clear receiver status | |
582 | 1347 bsf RCSTA1,CREN |
623 | 1348 bsf screen_dump_avail ; enable screen dump function |
582 | 1349 return |
0 | 1350 |
623 | 1351 ;----------------------------------------------------------------------------- |
0 | 1352 ; Pixel compression |
1353 ; | |
604 | 1354 ; Input : PRODH:L = pixel |
0 | 1355 ; Output: Compressed stream on output. |
1356 ; Compressed format: | |
604 | 1357 ; 0ccccccc : BLACK pixel, repeated ccccccc+1 times (1..128) |
1358 ; 11cccccc : WHITE pixel, repeated cccccc+1 times (1.. 64) | |
1359 ; 10cccccc HIGH LOW : color pixel (H:L) repeated ccccc+1 times (1.. 64) | |
623 | 1360 ; |
0 | 1361 dump_screen_pixel: |
604 | 1362 movf PRODH,W ; compare pixel-high |
582 | 1363 xorwf ds_pixel+1,W |
604 | 1364 bnz dump_screen_pixel_1 ; different -> dump |
0 | 1365 |
604 | 1366 movf PRODL,W ; compare pixel-low |
582 | 1367 xorwf ds_pixel+0,W |
604 | 1368 bnz dump_screen_pixel_1 ; different -> dump |
0 | 1369 |
604 | 1370 incf ds_count,F ; same color: just increment |
582 | 1371 return |
0 | 1372 |
604 | 1373 dump_screen_pixel_1: ; send (pixel,count) tuple |
1374 movf ds_count,W ; is count zero ? | |
1375 bz dump_screen_pixel_2 ; YES - skip sending | |
0 | 1376 |
604 | 1377 movf ds_pixel+1,W ; is this a BLACK pixel ? |
582 | 1378 iorwf ds_pixel+0,W |
604 | 1379 bz dump_screen_pix_black ; YES |
0 | 1380 |
604 | 1381 movf ds_pixel+1,W ; is this a white pixel ? |
582 | 1382 andwf ds_pixel+0,W |
1383 incf WREG | |
604 | 1384 bz dump_screen_pix_white ; YES |
0 | 1385 |
582 | 1386 ; No: write the pixel itself... |
604 | 1387 movlw .64 ; max color pixel on a single byte |
1388 cpfsgt ds_count ; skip if count > 64 | |
582 | 1389 movf ds_count,W ; W <- min(64,count) |
1390 subwf ds_count,F ; ds_count <- ds_count-W | |
604 | 1391 decf WREG ; save as 0..63 |
1392 iorlw b'10000000' ; mark as a color pixel | |
0 | 1393 |
582 | 1394 movwf TXREG |
1395 call rs232_wait_tx ; wait for UART | |
1396 movff ds_pixel+1,TXREG | |
1397 call rs232_wait_tx ; wait for UART | |
1398 movff ds_pixel+0,TXREG | |
1399 call rs232_wait_tx ; wait for UART | |
1400 bra dump_screen_pixel_1 | |
0 | 1401 |
1402 dump_screen_pixel_2: | |
604 | 1403 movff PRODH,ds_pixel+1 ; save new pixel color |
582 | 1404 movff PRODL,ds_pixel+0 |
1405 movlw 1 | |
604 | 1406 movwf ds_count ; and set count=1 |
582 | 1407 return |
0 | 1408 |
1409 dump_screen_pix_black: | |
604 | 1410 movlw .128 ; max black pixel on a single byte |
1411 cpfsgt ds_count ; skip if count > 128 | |
582 | 1412 movf ds_count,W ; W <- min(128,count) |
1413 subwf ds_count,F ; ds_count <- ds_count-W | |
604 | 1414 decf WREG ; save as 0..127 |
623 | 1415 |
0 | 1416 dump_screen_pix_3: |
582 | 1417 movwf TXREG |
1418 call rs232_wait_tx | |
604 | 1419 bra dump_screen_pixel_1 ; more to dump ? |
0 | 1420 |
1421 dump_screen_pix_white: | |
604 | 1422 movlw .64 ; max white pixel on a single byte |
1423 cpfsgt ds_count ; skip if count > 64 | |
582 | 1424 movf ds_count,W ; W <- min(64,count) |
1425 subwf ds_count,F ; ds_count <- ds_count-W | |
1426 decf WREG ; Save as 0..63 | |
604 | 1427 iorlw b'11000000' ; mark as a compressed white |
582 | 1428 bra dump_screen_pix_3 |
0 | 1429 |
1430 dump_screen_pixel_flush: | |
582 | 1431 clrf PRODH |
1432 clrf PRODL | |
604 | 1433 rcall dump_screen_pixel_1 ; send it |
0 | 1434 dump_screen_pixel_reset: |
604 | 1435 clrf ds_count ; clear count |
582 | 1436 return |
0 | 1437 |
623 | 1438 ENDIF ; _screendump |
1439 | |
1440 ;============================================================================= | |
604 | 1441 |
582 | 1442 END |