comparison src/tft.asm @ 628:cd58f7fc86db

3.05 stable work
author heinrichsweikamp
date Thu, 19 Sep 2019 12:01:29 +0200
parents c40025d8e750
children 185ba2f91f59
comparison
equal deleted inserted replaced
627:bf5fee575701 628:cd58f7fc86db
1 ;============================================================================= 1 ;=============================================================================
2 ; 2 ;
3 ; File tft.asm combined next generation V3.03.2 3 ; File tft.asm combined next generation V3.03.7
4 ; 4 ;
5 ; low-level Display Outputs 5 ; low-level Display Outputs
6 ; 6 ;
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. 7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
8 ;============================================================================= 8 ;=============================================================================
71 71
72 ;;============================================================================= 72 ;;=============================================================================
73 73
74 global TFT_ClearScreen 74 global TFT_ClearScreen
75 TFT_ClearScreen: 75 TFT_ClearScreen:
76 btfsc screen_type2 ; screen type ? 76 btfsc screen_type2 ; screen type 2?
77 bra TFT_ClearScreen_display2; YES 77 bra TFT_ClearScreen_display2; YES
78 btfsc screen_type3 ; screen type 3?
79 bra TFT_ClearScreen_display3; YES
78 80
79 Index_out 0x50 ; window horizontal start address 81 Index_out 0x50 ; window horizontal start address
80 Parameter_out 0x00, 0x00 ; 0-239 82 Parameter_out 0x00, 0x00 ; 0-239
81 Index_out 0x51 ; window horizontal end address 83 Index_out 0x51 ; window horizontal end address
82 Parameter_out 0x00, 0xEF ; 0-239 84 Parameter_out 0x00, 0xEF ; 0-239
156 rcall TFT_DataWrite 158 rcall TFT_DataWrite
157 159
158 movlw 0x22 ; start writing data to GRAM 160 movlw 0x22 ; start writing data to GRAM
159 rcall TFT_CmdWrite 161 rcall TFT_CmdWrite
160 162
163 movlw .160 ; 160 x 240 x 6 = 230400 ticks
164 TFT_ClearScreen_display2_loop0:
161 bsf tft_rs ; data! 165 bsf tft_rs ; data!
162
163 movlw .160
164 movwf PRODH 166 movwf PRODH
165 clrf PORTH 167 clrf PORTH
166 TFT_ClearScreen_display2_loop1: 168 TFT_ClearScreen_display2_loop1:
167 movlw .240 169 movlw .240
168 movwf PRODL 170 movwf PRODL
183 bra TFT_ClearScreen_display2_loop2 185 bra TFT_ClearScreen_display2_loop2
184 decfsz PRODH,F 186 decfsz PRODH,F
185 bra TFT_ClearScreen_display2_loop1 187 bra TFT_ClearScreen_display2_loop1
186 return 188 return
187 189
190 TFT_ClearScreen_display3:
191 movlw 0x35 ; vertical start address HIGH:LOW
192 rcall TFT_CmdWrite
193 mullw 0
194 rcall TFT_DataWrite_PROD
195
196 movlw 0x36 ; vertical end address HIGH:LOW
197 rcall TFT_CmdWrite
198 movlw 0x01
199 rcall TFT_DataWrite
200 movlw 0x3F
201 rcall TFT_DataWrite
202
203 movlw 0x37 ; horizontal address START:END
204 rcall TFT_CmdWrite
205 movlw 0x00
206 rcall TFT_DataWrite
207 movlw 0xEF
208 rcall TFT_DataWrite
209
210 movlw 0x20 ; start address horizontal (.0 - .239)
211 rcall TFT_CmdWrite
212 rcall TFT_DataWrite_PROD
213
214 movlw 0x21 ; start address vertical (.0 - .319)
215 rcall TFT_CmdWrite
216 rcall TFT_DataWrite_PROD
217
218 movlw 0x22 ; start writing data to GRAM
219 rcall TFT_CmdWrite
220
221 movlw .107 ; 107 x 240 x 6 = 154080 ticks (153600 would be enough)
222 bra TFT_ClearScreen_display2_loop0
223
224
188 ;============================================================================= 225 ;=============================================================================
189 226
190 global TFT_DisplayOff 227 global TFT_DisplayOff
191 TFT_DisplayOff: 228 TFT_DisplayOff:
229 bcf lightsen_power ; power-down light sensor
230 btfsc screen_type3
231 bra TFT_DisplayOff_display3 ; screen needs special power-down sequence
192 clrf CCP1CON ; stop PWM 232 clrf CCP1CON ; stop PWM
193 bcf PORTC,2 ; pull PWM out to GND 233 bcf PORTC,2 ; pull PWM out to GND
194 clrf PORTA 234 clrf PORTA
195 clrf PORTH 235 clrf PORTH
196 RD_L ; LOW 236 RD_L ; LOW
197 RS_L ; LOW 237 RS_L ; LOW
198 bcf tft_nwr 238 bcf tft_nwr
199 bcf tft_cs 239 bcf tft_cs
200 bcf tft_nreset 240 bcf tft_nreset
201 bsf tft_power ; inverted... 241 bsf tft_power ; inverted...
202 bcf lightsen_power ; power-down light sensor 242 return
243
244 TFT_DisplayOff_display3:
245 movlw 0x05
246 rcall TFT_CmdWrite
247 movlw 0x00
248 rcall TFT_DataWrite
249 movlw 0x00
250 rcall TFT_DataWrite
251 WAITMS d'32'
252 clrf CCP1CON ; stop PWM
253 bcf PORTC,2 ; pull PWM out to GND
254 WAITMS d'32'
255 movlw 0x10
256 rcall TFT_CmdWrite
257 movlw 0x00
258 rcall TFT_DataWrite
259 movlw 0x01
260 rcall TFT_DataWrite
261 WAITMS d'100'
262 clrf PORTH
263 bcf tft_nwr
264 bcf tft_cs
265 bcf tft_nreset
266 WAITMS d'10'
267 bsf tft_power ; inverted...
203 return 268 return
204 269
205 ; ----------------------------- 270 ; -----------------------------
206 ; TFT boot 271 ; TFT boot
207 ; ----------------------------- 272 ; -----------------------------
212 clrf CCP1CON ; stop PWM 277 clrf CCP1CON ; stop PWM
213 bcf PORTC,2 ; pull PWM out to GND 278 bcf PORTC,2 ; pull PWM out to GND
214 279
215 clrf PORTA 280 clrf PORTA
216 clrf PORTH 281 clrf PORTH
282
217 RD_L ; LOW 283 RD_L ; LOW
218 bcf tft_nwr
219 nop 284 nop
220 bcf tft_cs 285 WR_L
286 nop
287 NCS_L ; Not CS
221 nop 288 nop
222 bcf tft_nreset 289 bcf tft_nreset
223 WAITMS d'1' 290 WAITMS d'1'
224 bcf tft_power ; inverted... 291 bcf tft_power ; inverted...
225 WAITMS d'1' 292 WAITMS d'1'
226
227 RD_H ; Keep high 293 RD_H ; Keep high
228 WR_H ; 294 nop
229 NCS_L ; Not CS
230
231 WAITMS d'2' 295 WAITMS d'2'
232 bsf tft_nreset 296 bsf tft_nreset
233 WAITMS d'5' 297 WAITMS d'5'
234 bcf tft_nreset 298 bcf tft_nreset
235 WAITMS d'5' 299 WAITMS d'5'
236 bsf tft_nreset 300 bsf tft_nreset
237 WAITMS d'150' 301 WAITMS d'150'
302 WR_H ; release bus
238 bsf lightsen_power ; supply power to light sensor 303 bsf lightsen_power ; supply power to light sensor
304
305 btfsc screen_type3 ; display type 3 ?
306 bra TFT_boot_screen3 ; YES
239 307
240 ; Data Transfer Synchronization 308 ; Data Transfer Synchronization
241 Parameter_out 0x00, 0x00 309 Parameter_out 0x00, 0x00
242 Parameter_out 0x00, 0x00 310 Parameter_out 0x00, 0x00
243 311
262 movwf TBLPTRL 330 movwf TBLPTRL
263 movlw 0xF7 331 movlw 0xF7
264 movwf TBLPTRH 332 movwf TBLPTRH
265 movlw 0x01 333 movlw 0x01
266 movwf TBLPTRU 334 movwf TBLPTRU
267 bsf screen_type 335 bsf screen_type1
268 bra TFT_boot_com 336 bra TFT_boot_com
269 337
270 TFT_boot_0: 338 TFT_boot_0:
271 ; Init through config table... 339 ; Init through config table...
272 movlw LOW display0_config_table 340 movlw LOW display0_config_table
273 movwf TBLPTRL 341 movwf TBLPTRL
274 movlw HIGH display0_config_table 342 movlw HIGH display0_config_table
275 movwf TBLPTRH 343 movwf TBLPTRH
276 movlw UPPER display0_config_table 344 movlw UPPER display0_config_table
277 movwf TBLPTRU 345 movwf TBLPTRU
278 bcf screen_type 346 bcf screen_type1
279 347
280 TFT_boot_com: 348 TFT_boot_com:
281 rcall display0_init_loop 349 rcall display0_init_loop
282 350
283 Index_out 0x03 351 Index_out 0x03
284 btfsc flip_screen ; 180° rotation ? 352 btfsc flip_screen ; 180° rotation ?
285 bra TFT_boot2 ; YES 353 bra TFT_boot2 ; YES
286 354
287 btfss screen_type ; display1? 355 btfss screen_type1 ; display1?
288 bra TFT_boot1a ; NO 356 bra TFT_boot1a ; NO
289 Parameter_out 0x10, 0x00 ; display1 357 Parameter_out 0x10, 0x00 ; display1
290 bra TFT_boot3 358 bra TFT_boot3
291 TFT_boot1a: 359 TFT_boot1a:
292 Parameter_out 0x50, 0x20 ; display0 360 Parameter_out 0x50, 0x20 ; display0
293 bra TFT_boot3 361 bra TFT_boot3
294 TFT_boot2: 362 TFT_boot2:
295 btfss screen_type ; display1? 363 btfss screen_type1 ; display1?
296 bra TFT_boot2a ; NO 364 bra TFT_boot2a ; NO
297 Parameter_out 0x10, 0x30 ; display1 365 Parameter_out 0x10, 0x30 ; display1
298 bra TFT_boot3 366 bra TFT_boot3
299 TFT_boot2a: 367 TFT_boot2a:
300 Parameter_out 0x50, 0x10 ; display0 368 Parameter_out 0x50, 0x10 ; display0
349 rcall TFT_DataWrite ; write configuration 417 rcall TFT_DataWrite ; write configuration
350 bra display0_init_loop ; loop 418 bra display0_init_loop ; loop
351 419
352 420
353 TFT_boot_screen2: 421 TFT_boot_screen2:
354 bsf tft_nwr ; release bus
355 rcall display1_init ; initialization sequence 422 rcall display1_init ; initialization sequence
356 423
357 btfss flip_screen ; 180° rotation? 424 btfss flip_screen ; 180° rotation?
358 bra TFT_ClearScreen ; NO - done: clear screen and return 425 bra TFT_ClearScreen ; NO - done: clear screen and return
359 ; flip the GRAM 426 ; flip the GRAM
360 Index_out 0x16 427 Index_out 0x16
361 movlw 0x48 ; flip image in the GRAM (very elegant with display 2...) 428 movlw 0x48 ; flip image in the GRAM (very elegant with display 2...)
362 rcall TFT_DataWrite ; Write configuration 429 rcall TFT_DataWrite ; Write configuration
363 bra TFT_ClearScreen ; clear screen and return 430 bra TFT_ClearScreen ; clear screen and return
431
432 TFT_boot_screen3:
433 rcall display1_init ; init sequence
434 rcall TFT_ClearScreen
435 setf CCPR1L ; duty cycle, 255 is required for OLED
436 ; Set brightness
437 movff opt_brightness,PRODL ; =0: Eco, =1:Medium, =2:Full
438 incf PRODL,F ; +1
439 dcfsnz PRODL,F
440 rcall TFT_display3_low
441 dcfsnz PRODL,F
442 rcall TFT_display3_med
443 dcfsnz PRODL,F
444 rcall TFT_display3_high
445 ; ToDo: Flip....
446 return
364 447
365 display1_init: 448 display1_init:
366 movlw LOW (0x1F8BC ) 449 movlw LOW (0x1F8BC )
367 movwf TBLPTRL 450 movwf TBLPTRL
368 movlw HIGH (0x1F8BC & 0xFFFF) 451 movlw HIGH (0x1F8BC & 0xFFFF)
386 movf TABLAT,W 469 movf TABLAT,W
387 rcall TFT_CmdWrite ; write command 470 rcall TFT_CmdWrite ; write command
388 TBLRD*+ ; get configuration 471 TBLRD*+ ; get configuration
389 movf TABLAT,W 472 movf TABLAT,W
390 rcall TFT_DataWrite ; write configuration 473 rcall TFT_DataWrite ; write configuration
474 btfss screen_type3 ; screen 3 ?
475 bra display1_init_loop ; NO - loop
476 ; Screen 3 gets another byte from the table
477 TBLRD*+ ; get configuration
478 movf TABLAT,W
479 rcall TFT_DataWrite ; write configuration
391 bra display1_init_loop ; loop 480 bra display1_init_loop ; loop
392
393 481
394 ;============================================================================= 482 ;=============================================================================
395 483
396 global TFT_CmdWrite 484 global TFT_CmdWrite
397 TFT_CmdWrite: 485 TFT_CmdWrite:
398 RS_L ; command 486 RS_L ; command
399 btfsc screen_type2 487 ; btfsc screen_type2
400 bra TFT_CmdWrite_screen2 488 ; bra TFT_CmdWrite_screen2
401 clrf PORTA ; upper 489 clrf PORTA ; upper
402 bcf INTCON,GIE 490 bcf INTCON,GIE
403 movwf PORTH ; lower 491 movwf PORTH ; lower
404 WR_L 492 WR_L
405 WR_H ; tick 493 WR_H ; tick
406 bsf INTCON,GIE 494 bsf INTCON,GIE
407 return 495 return
408 TFT_CmdWrite_screen2: 496 ;TFT_CmdWrite_screen2:
409 movwf PORTH ; lower 497 ; movwf PORTH ; lower
410 WR_L 498 ; WR_L
411 WR_H ; tick 499 ; WR_H ; tick
412 return; 500 ; return;
413 501
414 global TFT_DataWrite 502 global TFT_DataWrite
415 TFT_DataWrite: 503 TFT_DataWrite:
416 RS_H ; data 504 RS_H ; data
417 btfsc screen_type2 505 ; btfsc screen_type2
418 bra TFT_DataWrite_screen2 506 ; bra TFT_DataWrite_screen2
419 bcf INTCON,GIE 507 bcf INTCON,GIE
420 movwf PORTH ; lower 508 movwf PORTH ; lower
421 WR_L 509 WR_L
422 WR_H ; tick 510 WR_H ; tick
423 bsf INTCON,GIE 511 bsf INTCON,GIE
424 return 512 return
425 TFT_DataWrite_screen2: 513 ;TFT_DataWrite_screen2:
426 movwf PORTH ; lower 514 ; movwf PORTH ; lower
427 WR_L 515 ; WR_L
428 WR_H ; tick 516 ; WR_H ; tick
429 return 517 ; return
430 518
431 519
432 ;============================================================================= 520 ;=============================================================================
433 ; Smooth lighting-up of the display: 521 ; Smooth lighting-up of the display:
434 ; 522 ;
441 global TFT_Display_FadeIn 529 global TFT_Display_FadeIn
442 TFT_Display_FadeIn: 530 TFT_Display_FadeIn:
443 movlw CCP1CON_VALUE ; get configuration 531 movlw CCP1CON_VALUE ; get configuration
444 movwf CCP1CON ; set configuration 532 movwf CCP1CON ; set configuration
445 bsf tft_is_dimming ; TFT is dimming, ignore ambient sensor 533 bsf tft_is_dimming ; TFT is dimming, ignore ambient sensor
534 btfsc screen_type3
535 bra TFT_Display_FadeIn_1
446 clrf CCPR1L ; backlight off - to be sure 536 clrf CCPR1L ; backlight off - to be sure
447 movff max_CCPR1L,PRODL 537 movff max_CCPR1L,PRODL
448 TFT_Display_FadeIn_0: 538 TFT_Display_FadeIn_0:
449 incf CCPR1L,F ; duty cycle 539 incf CCPR1L,F ; duty cycle
450 WAITMS d'2' 540 WAITMS d'2'
451 decfsz PRODL,F 541 decfsz PRODL,F
452 bra TFT_Display_FadeIn_0 542 bra TFT_Display_FadeIn_0
453 bcf tft_is_dimming ; dimming done 543 bcf tft_is_dimming ; dimming done
454 return 544 return
545 TFT_Display_FadeIn_1:
546 setf CCPR1L
547 return
455 548
456 ;============================================================================= 549 ;=============================================================================
457 ; Smooth lighting-off of the display: 550 ; Smooth lighting-off of the display:
458 ; Trashes: WREG, PRODL 551 ; Trashes: WREG, PRODL
459 552
460 global TFT_Display_FadeOut 553 global TFT_Display_FadeOut
461 TFT_Display_FadeOut: 554 TFT_Display_FadeOut:
462 movff max_CCPR1L,PRODL 555 movff max_CCPR1L,PRODL
463 bsf tft_is_dimming ; TFT is dimming, ignore ambient sensor 556 bsf tft_is_dimming ; TFT is dimming, ignore ambient sensor
557 btfsc screen_type3
558 bra TFT_Display_FadeOut_1
464 TFT_Display_FadeOut_0: 559 TFT_Display_FadeOut_0:
465 movff PRODL,CCPR1L ; duty cycle 560 movff PRODL,CCPR1L ; duty cycle
466 WAITMS d'1' 561 WAITMS d'1'
467 decfsz PRODL,F 562 decfsz PRODL,F
468 bra TFT_Display_FadeOut_0 563 bra TFT_Display_FadeOut_0
564 TFT_Display_FadeOut_1:
469 clrf CCPR1L 565 clrf CCPR1L
470 return 566 return
567
568 ;=============================================================================
569 ; OLED brightness control
570 TFT_display3_high: ; 0x01F8F8
571 movlw LOW (0x01F8F8 )
572 movwf TBLPTRL
573 movlw HIGH (0x01F8F8 & 0xFFFF)
574 movwf TBLPTRH
575 movlw UPPER (0x01F8F8 )
576 movwf TBLPTRU
577 bra display1_init_loop ; and return
578
579 TFT_display3_med: ; 0x01F91C
580 movlw LOW (0x01F91C )
581 movwf TBLPTRL
582 movlw HIGH (0x01F91C & 0xFFFF)
583 movwf TBLPTRH
584 movlw UPPER (0x01F91C )
585 movwf TBLPTRU
586 bra display1_init_loop ; and return
587
588 TFT_display3_low: ; 0x01F8D4
589 movlw LOW (0x01F8D4 )
590 movwf TBLPTRL
591 movlw HIGH (0x01F8D4 & 0xFFFF)
592 movwf TBLPTRH
593 movlw UPPER (0x01F8D4 )
594 movwf TBLPTRU
595 bra display1_init_loop ; and return
471 596
472 ;============================================================================= 597 ;=============================================================================
473 598
474 global box_std_block, box_black_block, box_color_block 599 global box_std_block, box_black_block, box_color_block
475 600
533 pixel_write: 658 pixel_write:
534 movf win_leftx2,W 659 movf win_leftx2,W
535 mullw .2 ; win_leftx2 x 2 -> PRODH:PRODL 660 mullw .2 ; win_leftx2 x 2 -> PRODH:PRODL
536 rcall pixel_write_col320 ; start address vertical (.0 - .319) 661 rcall pixel_write_col320 ; start address vertical (.0 - .319)
537 rcall half_pixel_write ; write this half-one 662 rcall half_pixel_write ; write this half-one
663
538 movf win_leftx2,W ; address of next one 664 movf win_leftx2,W ; address of next one
539 mullw .2 ; win_leftx2 x 2 -> PRODH:PRODL 665 mullw .2 ; win_leftx2 x 2 -> PRODH:PRODL
540 INCI PROD ; PROD++ 666 INCI PROD ; PROD++
541 rcall pixel_write_col320 667 rcall pixel_write_col320
542 bra half_pixel_write ; note: Cmd 0x20 is mandatory, because 668 bra half_pixel_write ; and return... note: cmd 0x20 is mandatory, because
543 ; of the auto-increment going vertical 669 ; of the auto-increment going vertical
544 670
545 global pixel_write_col320 671 global pixel_write_col320
546 pixel_write_col320: 672 pixel_write_col320:
547 btfsc screen_type2 ; display type 2 ? 673 btfsc screen_type2 ; display type 2 ?
548 bra pixel_write_col320_d2 ; YES 674 bra pixel_write_col320_d2 ; YES
549 btfsc screen_type ; NO - display type 1 ? 675 btfsc screen_type1 ; display type 1 ?
550 bra pixel_write_col320_d1 ; YES 676 bra pixel_write_col320_d1 ; YES
551 ; NO - display type 0 677 btfsc screen_type3 ; display type 3 ?
678 bra pixel_write_col320_d3 ; YES
679 ; NO to all - display type 0
552 btfss flip_screen ; 180° rotation? 680 btfss flip_screen ; 180° rotation?
553 bra pixel_write_noflip_H ; NO 681 bra pixel_write_noflip_H ; NO
554 bra pixel_write_flip_H ; YES 682 bra pixel_write_flip_H ; YES
555 pixel_write_col320_d1: ; display type 1 683 pixel_write_col320_d1: ; display type 1
556 btfsc flip_screen ; 180° rotation? 684 btfsc flip_screen ; 180° rotation?
590 movlw 0x09 718 movlw 0x09
591 rcall TFT_CmdWrite 719 rcall TFT_CmdWrite
592 movf PRODL,W 720 movf PRODL,W
593 bra TFT_DataWrite ; ... and return 721 bra TFT_DataWrite ; ... and return
594 722
723 pixel_write_col320_d3:
724 movlw 0x21 ; start address vertical (.0 - .319)
725 rcall TFT_CmdWrite
726 bra TFT_DataWrite_PROD ; and return...
727
595 ;----------------------------------------------------------------------------- 728 ;-----------------------------------------------------------------------------
596 ; Writes one half-pixel at position (win_top,win_leftx2). 729 ; Writes one half-pixel at position (win_top,win_leftx2).
597 ; Inputs: win_leftx2, win_top, win_color:2 730 ; Inputs: win_leftx2, win_top, win_color:2
598 ; Trashed: WREG, PROD 731 ; Trashed: WREG, PROD
599 732
600 global half_pixel_write 733 global half_pixel_write
601 half_pixel_write: 734 half_pixel_write:
602 movf win_top,W ; d'0' ... d'239' 735 movf win_top,W ; d'0' ... d'239'
603 ; Variant with Y position in WREG. 736 ; Variant with Y position in WREG
604 half_pixel_write_1: 737 half_pixel_write_1:
605 btfsc screen_type2 ; screen tpe 2 ? 738 btfsc screen_type2 ; display type 2 ?
606 bra half_pixel_write_1_display1 ; YES 739 bra half_pixel_write_1_display2 ; YES
607 740 btfsc screen_type3 ; display type 3 ?
741 bra half_pixel_write_1_display3 ; YES
742
743 half_pixel_write_1_display1:
608 btfss flip_screen ; 180° rotation? 744 btfss flip_screen ; 180° rotation?
609 sublw .239 ; 239-Y --> Y 745 sublw .239 ; 239-Y --> Y
610 mullw .1 ; copy row to PRODL (PRODH=0) 746 mullw .1 ; copy row to PRODL (PRODH=0)
611 Index_out 0x20 ; frame memory horizontal address 747 Index_out 0x20 ; frame memory horizontal address
612 rcall TFT_DataWrite_PROD 748 rcall TFT_DataWrite_PROD
619 WR_L 755 WR_L
620 WR_H ; tick 756 WR_H ; tick
621 bsf INTCON,GIE 757 bsf INTCON,GIE
622 return 758 return
623 759
624 half_pixel_write_1_display1: 760 half_pixel_write_1_display2:
625 mullw 1 ; copy row to PRODL (PRODH=0) 761 mullw 1 ; copy row to PRODL (PRODH=0)
626 ; Row address start 762 ; Row address start
627 movlw 0x02 763 movlw 0x02
628 rcall TFT_CmdWrite 764 rcall TFT_CmdWrite
629 movlw .0 765 movlw .0
659 WR_H ; tick 795 WR_H ; tick
660 movff win_color3, PORTH 796 movff win_color3, PORTH
661 WR_L 797 WR_L
662 WR_H ; tick 798 WR_H ; tick
663 return 799 return
800
801 half_pixel_write_1_display3:
802 mullw 1 ; copy row to PRODL (PRODH=0)
803
804 movlw 0x20 ; horizontal address START:END
805 rcall TFT_CmdWrite
806 rcall TFT_DataWrite_PROD
807
808 movlw 0x22 ; start writing data to GRAM
809 rcall TFT_CmdWrite
810 RS_H ; data
811 movff win_color1, PORTH
812 WR_L
813 WR_H ; tick
814 movff win_color2, PORTH
815 WR_L
816 WR_H ; tick
817 return ; done
664 818
665 ;----------------------------------------------------------------------------- 819 ;-----------------------------------------------------------------------------
666 ; Writes a vertical line of half-pixel at position (win_top,win_leftx2,win_height). 820 ; 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 821 ; Inputs: win_leftx2, win_top, win_height, win_color:2
668 ; Trashed: WREG, PROD, TABLAT, TBLPTRL 822 ; Trashed: WREG, PROD, TABLAT, TBLPTRL
720 TFT_DataWrite_PROD: 874 TFT_DataWrite_PROD:
721 ; RD_H ; keep high 875 ; RD_H ; keep high
722 RS_H ; data 876 RS_H ; data
723 btfsc screen_type2 ; screen type 2 ? 877 btfsc screen_type2 ; screen type 2 ?
724 bra TFT_DataWrite_PROD_display2 ; YES 878 bra TFT_DataWrite_PROD_display2 ; YES
879 btfsc screen_type3 ; screen type 3 ?
880 bra TFT_DataWrite_PROD_display2 ; YES
725 bcf INTCON,GIE ; NO - 881 bcf INTCON,GIE ; NO -
726 movff PRODH,PORTA ; - move high byte to PORTA 882 movff PRODH,PORTA ; - move high byte to PORTA
727 movff PRODL,PORTH ; - move low byte to PORTH 883 movff PRODL,PORTH ; - move low byte to PORTH
728 WR_L ; - tick 884 WR_L ; - tick
729 WR_H ; - tack 885 WR_H ; - tack
735 WR_L ; tick 891 WR_L ; tick
736 WR_H ; tack 892 WR_H ; tack
737 movff PRODL,PORTH ; move low byte to PORTH 893 movff PRODL,PORTH ; move low byte to PORTH
738 WR_L ; tick 894 WR_L ; tick
739 WR_H ; tack 895 WR_H ; tack
740 movff win_color3,PORTH ; move low(est) byte to PORTH 896 btfsc screen_type3 ; screen type 3 ?
741 WR_L ; tick 897 return ; YES - done
742 WR_H ; tack 898 movff win_color3,PORTH ; NO - move low(est) byte to PORTH
743 return ; done 899 WR_L ; - tick
900 WR_H ; - tack
901 return ; - done
744 902
745 903
746 TFT_DataRead_PROD: 904 TFT_DataRead_PROD:
747 Index_out 0x22 ; frame memory data read start 905 Index_out 0x22 ; frame memory data read start
748 TFT_CmdRead_PROD: 906 TFT_CmdRead_PROD:
781 movf win_leftx2,W ; compute left = 2 * leftx2 --> PROD 939 movf win_leftx2,W ; compute left = 2 * leftx2 --> PROD
782 mullw .2 ; win_leftx2 x 2 -> PRODH:PRODL 940 mullw .2 ; win_leftx2 x 2 -> PRODH:PRODL
783 941
784 btfsc screen_type2 ; screen type 2 ? 942 btfsc screen_type2 ; screen type 2 ?
785 bra TFT_box_write_display2 ; YES 943 bra TFT_box_write_display2 ; YES
944 btfsc screen_type3 ; screen type 3 ?
945 bra TFT_box_write_display3 ; YES
786 946
787 global TFT_box_write_16bit_win_left 947 global TFT_box_write_16bit_win_left
788 TFT_box_write_16bit_win_left: ; with column in PRODL:PRODH 948 TFT_box_write_16bit_win_left: ; with column in PRODL:PRODH
789 btfsc screen_type ; screen type 1 ? 949 btfsc screen_type1 ; screen type 1 ?
790 bra TFT_box_write_16bit_win_left_d1 ; YES 950 bra TFT_box_write_16bit_win_left_d1 ; YES
791 ; screen type 0 951 ; screen type 0
792 btfsc flip_screen ; 180° rotation? 952 btfsc flip_screen ; 180° rotation?
793 bra DISP_box_flip_H ; YES 953 bra TFT_box_flip_H ; YES
794 bra TFT_box_write_16bit_win_left_com ; NO 954 bra TFT_box_write_16bit_win_left_com ; NO
795 TFT_box_write_16bit_win_left_d1: ; Display1 955 TFT_box_write_16bit_win_left_d1: ; Display1
796 btfss flip_screen ; 180° rotation? 956 btfss flip_screen ; 180° rotation?
797 bra DISP_box_flip_H ; NO 957 bra TFT_box_flip_H ; NO
798 TFT_box_write_16bit_win_left_com: ; YES for screen type 1, NO for type 0 958 TFT_box_write_16bit_win_left_com: ; YES for screen type 1, NO for type 0
799 ;---- Normal horizontal window --------------------------------------- 959 ;---- Normal horizontal window ---------------------------------------
800 Index_out 0x52 ; window vertical start address 960 Index_out 0x52 ; window vertical start address
801 rcall TFT_DataWrite_PROD ; output left 961 rcall TFT_DataWrite_PROD ; output left
802 Index_out 0x21 ; frame memory vertical address 962 Index_out 0x21 ; frame memory vertical address
810 btfss STATUS,C 970 btfss STATUS,C
811 decf PRODH,F 971 decf PRODH,F
812 972
813 Index_out 0x53 ; window vertical end address 973 Index_out 0x53 ; window vertical end address
814 rcall TFT_DataWrite_PROD 974 rcall TFT_DataWrite_PROD
815 bra DISP_box_noflip_H 975 bra TFT_box_noflip_H
816 976
817 ;---- Flipped horizontal window -------------------------------------- 977 ;---- Flipped horizontal window --------------------------------------
818 DISP_box_flip_H: 978 TFT_box_flip_H:
819 ; calculate new coordinate 979 ; calculate new coordinate
820 movf PRODL,W ; 16 bits 319 - PROD --> PROD 980 movf PRODL,W ; 16 bits 319 - PROD --> PROD
821 sublw LOW .319 ; 319 - WREG --> WREG 981 sublw LOW .319 ; 319 - WREG --> WREG
822 movwf PRODL 982 movwf PRODL
823 movf PRODH,W 983 movf PRODH,W
839 INCI PROD ; PROD++ 999 INCI PROD ; PROD++
840 1000
841 Index_out 0x52 ; window vertical end address 1001 Index_out 0x52 ; window vertical end address
842 rcall TFT_DataWrite_PROD 1002 rcall TFT_DataWrite_PROD
843 1003
844 DISP_box_noflip_H: 1004 TFT_box_noflip_H:
845 btfss flip_screen ; 180° rotation ? 1005 btfss flip_screen ; 180° rotation ?
846 bra TFT_box_noflip_V ; NO 1006 bra TFT_box_noflip_V ; NO
847 1007
848 ;---- Flipped vertical window ----------------------------------------- 1008 ;---- Flipped vertical window -----------------------------------------
849 ; calculate new coordinate 1009 ; calculate new coordinate
941 movlw 0x05 1101 movlw 0x05
942 rcall TFT_CmdWrite 1102 rcall TFT_CmdWrite
943 movf PRODL,W 1103 movf PRODL,W
944 bra TFT_DataWrite ; ... and return 1104 bra TFT_DataWrite ; ... and return
945 1105
1106 TFT_box_write_display3:
1107 ;---- Normal horizontal window ---------------------------------------
1108 ; Output 0x35 left,
1109 ; 0x36 right == left + width - 1.
1110
1111 Index_out 0x35 ; window vertical start address
1112 rcall TFT_DataWrite_PROD ; output left
1113 Index_out 0x21 ; also the horizontal first pix coordinate
1114 rcall TFT_DataWrite_PROD ; output left
1115
1116 movf win_width+0,W,ACCESS ; right = left + width - 1
1117 addwf PRODL,F
1118 movf win_width+1,W,ACCESS
1119 addwfc PRODH,F
1120 decf PRODL,F,A ; decrement result
1121 btfss STATUS,C
1122 decf PRODH,F,A
1123
1124 Index_out 0x36 ; Write and the right border
1125 rcall TFT_DataWrite_PROD
1126
1127 ;---- Normal vertical window -----------------------------------------
1128 ; Output 0x37 (top) (bottom)
1129 movff win_top,PRODH ; top --> PRODH (first byte)
1130 movff win_height,WREG
1131 addwf PRODH,W
1132 decf WREG
1133 movwf PRODL ; top + height - 1 --> PRODL (second byte)
1134
1135 Index_out 0x37
1136 rcall TFT_DataWrite_PROD
1137
1138 movff PRODH,PRODL
1139 clrf PRODH ; start pixel V coord == top.
1140 Index_out 0x20
1141 bra TFT_DataWrite_PROD ; and return...
1142
1143
946 ;============================================================================= 1144 ;=============================================================================
947 ; TFT_frame : draw a frame around current box with current color 1145 ; TFT_frame : draw a frame around current box with current color
948 ; Inputs: win_top, win_leftx2, win_height, win_width, win_color1, win_color2 1146 ; Inputs: win_top, win_leftx2, win_height, win_width, win_color1, win_color2
949 ; Outputs: (none) 1147 ; Outputs: (none)
950 ; Trashed: WREG, PROD, aa_start:2, aa_end:2 1148 ; Trashed: WREG, PROD, aa_start:2, aa_end:2
995 ; Outputs: (none) 1193 ; Outputs: (none)
996 ; Trashed: WREG, PROD 1194 ; Trashed: WREG, PROD
997 1195
998 global TFT_box 1196 global TFT_box
999 TFT_box: 1197 TFT_box:
1000 btfsc screen_type2 ; display type 2 ?
1001 bra TFT_box_display2 ; YES
1002
1003 ;---- Define Window ------------------------------------------------------ 1198 ;---- Define Window ------------------------------------------------------
1004 bcf STATUS,C 1199 bcf STATUS,C
1005 rlcf win_width+0,F 1200 rlcf win_width+0,F
1006 rlcf win_width+1,F ; x2 1201 rlcf win_width+1,F ; x2
1007 rcall TFT_box_write ; setup box 1202 rcall TFT_box_write ; setup box
1008 1203
1009 global TFT_box_16bit_win_left
1010 TFT_box_16bit_win_left:
1011 bcf STATUS,C 1204 bcf STATUS,C
1012 rrcf win_width+1,F ; width /= 2 1205 rrcf win_width+1,F ; width /= 2
1013 rrcf win_width+0,F 1206 rrcf win_width+0,F
1014 1207
1015 ;---- Fill Window -------------------------------------------------------- 1208 ;---- Fill Window --------------------------------------------------------
1016 Index_out 0x22 ; frame memory data write start 1209 Index_out 0x22 ; frame memory data write start
1017
1018 clrf PRODH ; column counter 1210 clrf PRODH ; column counter
1019 RS_H ; data 1211 RS_H ; data
1212
1213 btfsc screen_type2 ; display type 2 ?
1214 bra TFT_box_display2 ; YES
1215 btfsc screen_type3 ; display type 3 ?
1216 bra TFT_box_display3 ; YES
1020 1217
1021 TFT_box2: ; loop height times 1218 TFT_box2: ; loop height times
1022 movff win_height,PRODL 1219 movff win_height,PRODL
1023 1220
1024 TFT_box3: ; loop width times 1221 TFT_box3: ; loop width times
1025 bcf INTCON,GIE 1222 bcf INTCON,GIE
1026 movff win_color1,PORTA ; upper 1223 movff win_color1,PORTA ; upper
1027 movff win_color2,PORTH ; lower 1224 movff win_color2,PORTH ; lower
1028 WR_L 1225 WR_L
1029 WR_H ; tick 1226 WR_H ; tick
1030
1031 ; movff win_color1,PORTA ; upper
1032 ; movff win_color2,PORTH ; lower
1033 WR_L 1227 WR_L
1034 WR_H ; tick 1228 WR_H ; tick
1035 bsf INTCON,GIE 1229 bsf INTCON,GIE
1036 decfsz PRODL,F ; row loop finished ? 1230 decfsz PRODL,F ; row loop finished ?
1037 bra TFT_box3 ; NO - continue 1231 bra TFT_box3 ; NO - continue
1038 1232
1039 incf PRODH,F ; column count ++ 1233 incf PRODH,F ; column count ++
1040 1234 movf win_bargraph,W ; get width of active bargraph part
1041 movf win_bargraph,W ; current column == bargraph ? 1235 cpfseq PRODH ; current column == end of active bargraph ?
1042 cpfseq PRODH
1043 bra TFT_box4 ; NO - just loop 1236 bra TFT_box4 ; NO - just loop
1044 clrf win_color1 ; Yes - switch to black 1237 clrf win_color1 ; YES - switch to black
1045 clrf win_color2 ; - ... 1238 clrf win_color2 ; - ...
1046 TFT_box4: 1239 TFT_box4:
1047 movf win_width+0,W ; compare ? 1240 movf win_width+0,W ; get total bargraph width
1048 xorwf PRODH,W 1241 xorwf PRODH,W ; all columns done?
1049 bnz TFT_box2 ; loop not finished 1242 bnz TFT_box2 ; NO - loop
1050 1243
1051 movlw 0x00 ; NOP, to stop window mode 1244 movlw 0x00 ; NOP, to stop window mode
1052 rcall TFT_CmdWrite 1245 rcall TFT_CmdWrite
1053 1246
1054 ; reset bargraph mode... 1247 ; reset bargraph mode...
1055 setf win_bargraph 1248 setf win_bargraph
1056 return 1249 return
1057 1250
1058 TFT_box_display2: 1251 TFT_box_display2:
1059 ;---- Define Window ------------------------------------------------------ 1252 ; Screen 2
1060 bcf STATUS,C
1061 rlcf win_width+0,F
1062 rlcf win_width+1,F ; x2
1063 rcall TFT_box_write ; setup box
1064
1065 bcf STATUS,C
1066 rrcf win_width+1,F ; width /= 2
1067 rrcf win_width+0,F
1068
1069 movff win_color1,PRODH 1253 movff win_color1,PRODH
1070 movff win_color2,PRODL 1254 movff win_color2,PRODL
1071 rcall convert_for_display2 1255 rcall convert_for_display2
1072 ;---- Fill Window --------------------------------------------------------
1073 Index_out 0x22 ; frame memory data write start
1074
1075 clrf PRODH ; column counter
1076 RS_H ; data
1077
1078 TFT_box2_display2: ; loop height times 1256 TFT_box2_display2: ; loop height times
1079 movff win_height,PRODL 1257 movff win_height,PRODL
1080 TFT_box3_display2: ; loop width times 1258 TFT_box3_display2: ; loop width times
1081 movff win_color5,PORTH 1259 movff win_color5,PORTH
1082 bcf tft_nwr 1260 bcf tft_nwr
1110 movf win_width+0,W ; get width 1288 movf win_width+0,W ; get width
1111 cpfseq PRODH ; width loop finished ? 1289 cpfseq PRODH ; width loop finished ?
1112 bra TFT_box2_display2 ; NO - loop 1290 bra TFT_box2_display2 ; NO - loop
1113 setf win_bargraph ; YES - reset bargraph mode 1291 setf win_bargraph ; YES - reset bargraph mode
1114 return ; - done 1292 return ; - done
1293
1294 TFT_box_display3:
1295 ; Screen 3
1296 TFT_box2_display3: ; loop height times
1297 movff win_height,PRODL
1298 TFT_box3_display3: ; loop width times
1299 movff win_color1,PORTH
1300 bcf tft_nwr
1301 bsf tft_nwr ; upper
1302 movff win_color2,PORTH
1303 bcf tft_nwr
1304 bsf tft_nwr ; high
1305 movff win_color1,PORTH
1306 bcf tft_nwr
1307 bsf tft_nwr ; low
1308 movff win_color2,PORTH
1309 bcf tft_nwr
1310 bsf tft_nwr ; upper
1311 decfsz PRODL,F ; row loop finished?
1312 bra TFT_box3_display3 ; NO - loop
1313 incf PRODH,F ; YES - column count ++
1314 movf win_bargraph,W ; - get bargraph width
1315 cpfseq PRODH ; - current column = bargraph ?
1316 bra TFT_box4_display3 ; NO
1317 clrf win_color1 ; Yes - switch to black
1318 clrf win_color2 ; - ...
1319 TFT_box4_display3:
1320 movf win_width+0,W ; get width
1321 cpfseq PRODH ; width loop finished ?
1322 bra TFT_box2_display3 ; NO - loop
1323 setf win_bargraph ; YES - reset bargraph mode
1324 return
1115 1325
1116 ;============================================================================= 1326 ;=============================================================================
1117 ; Convert 8 bit RGB b'RRRGGGBB' into 16 bit RGB b'RRRRRGGGGGGBBBBB' 1327 ; Convert 8 bit RGB b'RRRGGGBB' into 16 bit RGB b'RRRRRGGGGGGBBBBB'
1118 1328
1119 global TFT_set_color 1329 global TFT_set_color
1262 ; Dump screen contents to the UART 1472 ; Dump screen contents to the UART
1263 ; 1473 ;
1264 global TFT_dump_screen_check 1474 global TFT_dump_screen_check
1265 global TFT_dump_screen 1475 global TFT_dump_screen
1266 TFT_dump_screen_check: 1476 TFT_dump_screen_check:
1477 return
1267 btfss vusb_in ; USB (still) plugged in? 1478 btfss vusb_in ; USB (still) plugged in?
1268 bcf screen_dump_avail ; NO - disable screen dump function 1479 bcf screen_dump_avail ; NO - disable screen dump function
1269 call rs232_get_byte ; try to read data from RS232 1480 call rs232_get_byte ; try to read data from RS232
1270 btfsc rs232_rx_timeout ; anything received? 1481 btfsc rs232_rx_timeout ; anything received?
1271 return ; NO - return 1482 return ; NO - return